Skip to main content
Before you start: use Mesh SDK v0.27.0 on two connected peers with an established MLS session. The code below extends the quickstart; it does not start a second protocol instance. Use edge sync when several devices need to read and edit the same current state. The SDK merges document changes when replicas communicate. Your application keeps its existing database for records outside that shared scope.

Choose a space

A space is an existing MLS session or group. For a pairwise session, pass the other device’s address as spaceId; each device therefore uses a different address for its side of the same space. For a group, pass its group ID on every member. Start the protocol and establish the encrypted session using the quickstart. The data layer is enabled by default in v0.27.0; it can be explicitly disabled with data.enabled.

Write and read a document

flush waits for local persistence. It does not mean a peer has received the edit. Attach a data_changed listener to your OfflineProtocol instance to refresh the UI after a durable change, and read the document again on the receiving device.

Model concurrent edits

Map values are replaced as a whole. Put fields that must merge independently in separate keys instead of one JSON string. Use one collection type per collection name. Document and collection names are 1 to 128 bytes using letters, digits, ., _ and -. Map keys are 1 to 256 bytes.

Scope replication

setInterest(spaceId, patterns) selects document names or trailing-wildcard prefixes. ['*'] requests all documents; [] requests none. Call setInterest right after start() resolves, on every launch; interests are not persisted. React Native initializes DataStore during startup, so calling it earlier throws. A space accepts at most 32 patterns. This reduces replicated data but is not a substitute for membership authorization: use separate spaces for different access boundaries. deleteDoc evicts this device’s copy; a peer can restore it. removeDoc propagates removal, but a concurrent edit can preserve and restore the document. Use a fresh document name for new content rather than relying on removal as a permanent tombstone.

Verify two different interruptions

  1. Disconnect the backend while keeping peers connected. Edit on one device and observe the other receiving the change.
  2. Disconnect the peer path. Edit different fields on both devices, flush, then reconnect and compare both documents.
  3. Edit the same map key independently and confirm the documented conflict rule.
  4. Restart a device and confirm its persisted state and identity survive.
Convergence does not enforce inventory limits, exclusive assignments or other business invariants. Put those rules in the application and choose an appropriate authority for conflicting decisions. See the DataStore reference for operations and the source-level replication contract for the wire format.

Completion check

Done when: edits replicate with the internet disconnected, and both replicas converge after a peer partition. Continue with production qualification.