mobile-data-modeling
Installation
SKILL.md
Data Modeling for Sync Gateway
Mobile sync adds constraints that don't exist in pure server-side modeling. The Sync Function sees every document write and makes routing decisions based on document fields — so your schema must carry the metadata the Sync Function needs.
The core difference from server-side modeling
On the server, embed aggressively to avoid JOINs. For sync:
- Documents are the unit of sync — the entire document is sent to the device on every change
- Channels are the unit of access control — a document belongs to channels; a user gets channels
- Conflicts happen at the document level — large embedded arrays create large conflict surface
- Document size affects sync performance — keep documents small and focused
Rule of thumb: If two users could independently modify the same document, or if a document would grow unboundedly, split it.
Required fields for Sync Gateway
Every document that syncs needs fields the Sync Function can act on: