一键导入
crdt-basics
When CRDTs help mobile apps, which libraries to use, and what to watch out for. Use when evaluating CRDTs for collaborative or offline-first features.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
When CRDTs help mobile apps, which libraries to use, and what to watch out for. Use when evaluating CRDTs for collaborative or offline-first features.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | crdt-basics |
| description | When CRDTs help mobile apps, which libraries to use, and what to watch out for. Use when evaluating CRDTs for collaborative or offline-first features. |
CRDTs (Conflict-free Replicated Data Types) let multiple replicas of data converge without coordination. They are powerful -- and often overkill. Know when to use them.
Use CRDTs when all of these hold:
Good fits:
Poor fits:
Most modern mobile libraries (Yjs, Automerge 2) are delta-state under the hood.
Pick based on language bindings available on your mobile platform and the document shape.
Even with CRDTs, a server is usually present to:
The server can be "dumb" (a pub/sub relay) or "smart" (validates ops, applies domain rules). For multi-tenant systems, "smart" is almost mandatory.
// Node/TS: Yjs server relay (pseudo)
const docs = new Map<string, Y.Doc>();
ws.on("connection", (conn, { docId, userId }) => {
const doc = docs.get(docId) ?? load(docId);
const awareness = new Awareness(doc);
syncProtocol.readSyncMessage(conn, doc); // initial handshake
conn.on("message", buf => {
// validate user can write
Y.applyUpdate(doc, buf);
broadcast(docId, buf, conn); // fanout to peers
scheduleSnapshotSave(docId);
});
});
Plan for 2–10x storage overhead vs plain JSON. Old peer metadata (tombstones) grows indefinitely unless you garbage-collect carefully.
(replica_id, counter) pair. If replica_id repeats (e.g., client reuses an id across reinstalls), divergence follows. Generate a fresh replica_id on first app launch and persist it.iOS (Swift + y-crdt via C bindings):
let doc = YDoc()
let text = doc.getText("body")
doc.observe { update in
syncChannel.send(update)
}
syncChannel.onUpdate { update in
doc.applyUpdate(update)
}
Android (Kotlin + y-crdt JNI):
val doc = YDoc()
val text = doc.getText("body")
doc.onUpdate { update -> syncChannel.send(update) }
syncChannel.setListener { update -> doc.applyUpdate(update) }
If the CRDT approach does not fit one endpoint, do not force it. Most apps use CRDTs for specific collaborative screens and plain REST + optimistic concurrency for the rest.
replica_id generated once per install and persisted.When and how to use a Backend-for-Frontend (BFF) for mobile -- scoping, ownership, and anti-patterns. Use when deciding whether a BFF is justified or designing one.
GraphQL server design tuned for mobile -- persisted queries, batching, N+1 mitigation, and Apollo client integration. Use when building or reviewing a GraphQL API for mobile apps.
Design mobile-friendly HTTP APIs with predictable pagination, filtering, sorting, sparse/partial responses, and a consistent error envelope. Use when specifying new endpoints or reviewing existing ones for mobile use.
REST conventions tuned for mobile clients -- resources, HTTP caching, idempotency, and versioning. Use when designing or reviewing RESTful endpoints.
Server-side OAuth 2.1 + PKCE for native mobile apps -- authorization endpoint, token endpoint, refresh rotation, and device binding. Use when implementing or reviewing the auth server for mobile clients.
Model multi-device sessions on the backend with sliding vs absolute expiry, device listing, and remote logout. Use when building the session model or a "Your devices" screen.