AGENT SKILL

local-first-sync-design

Design the synchronization and conflict-resolution model for systems with authoritative local state, expressing merge semantics as user-visible behavior before any sync machinery is chosen.

License 许可
Apache-2.0
所属仓库
cwik-tech/octopus
最近更新
2026-10-27
Stars
★ 0
Forks
0

01 前言 Front Matter

name
local-first-sync-design
description
Design the synchronization and conflict-resolution model for systems with authoritative local state, expressing merge semantics as user-visible behavior before any sync machinery is chosen.

03 SKILL.md 正文

Local-First Sync Design

Purpose

Decide what happens when the same data exists in two places and both change. This skill forces conflict resolution to be settled as a product and data-modeling decision before it is delegated to a sync library, because the library cannot invent semantics the data model does not support.

When to use

Use this when a desktop or mobile client holds authoritative local state, when the system must function offline, when the same record can be edited from more than one place, or when reviewing an existing sync design for failure modes.

Core principle

Sync is a data model problem, not a library problem. Last-write-wins is not a default — it is a design decision with user-visible consequences. Choose merge semantics first, then select machinery that can express them.

Procedure

Step 1 — Establish the authority model

For each data domain in scope, name where truth lives:

  • Server-authoritative: local is a cache; conflicts resolve toward the server. Simplest, but offline edits can be discarded.
  • Client-authoritative: local is truth for this user's own data; the server aggregates. Good for personal-workspace data.
  • Co-authoritative: both can write meaningfully and neither dominates. The hardest case, and the one that requires real merge semantics.

Different domains within one application commonly warrant different models. Do not force a single answer across all data.

Step 2 — Enumerate concurrent-edit scenarios

List the realistic ways the same data changes in two places. For each, write the scenario in user terms, not in database terms.

Scenario Data touched Realistic frequency Desired user-visible outcome
Edits a note on laptop while phone is offline with an older copy note body common Both edits survive; nothing silently lost
Two users reorder the same list list ordering occasional Deterministic order, no duplication
Deletes an item locally that was edited remotely item rare Prompt, or edit wins over delete

The rightmost column is the actual requirement. Everything downstream serves it.

Step 3 — Choose merge semantics per field, not per record

Whole-record last-write-wins loses data whenever two people edit different fields of the same record. Decompose:

  • Last-write-wins per field: adequate for independent scalar fields where a later value genuinely supersedes an earlier one.
  • Additive/set semantics: for collections where union is the correct answer — tags, memberships, attachments.
  • Counter semantics: for values that accumulate, where increments from both sides must both apply.
  • Ordered-list semantics: for sequences where naive merge duplicates or drops entries; requires stable per-item identity and an ordering scheme that tolerates concurrent insertion.
  • Text-merge semantics: for prose fields where character-level convergence is required. This is the point where a CRDT or OT library becomes genuinely warranted — and the point at which you should confirm the requirement is real, since it dominates the complexity of the whole design.
  • Explicit user resolution: for cases where no automatic merge is defensible. Requires designing the conflict UI, which is product work, not infrastructure work.

Model the data to support the chosen semantics. A field that needs additive merge must not be stored as a replaced blob.

Step 4 — Define identity and ordering primitives

Sync correctness rests on two primitives:

  • Stable identity: every syncable entity needs an identifier generated client-side that will not collide across devices, assigned before the entity ever reaches a server. Server-assigned sequential identity is incompatible with offline creation.
  • Causality tracking: something that lets the system tell "newer" from "concurrent." Wall-clock timestamps cannot do this — clock skew across devices makes concurrent edits look ordered. Use logical clocks, version vectors, or per-entity revision chains as the design requires.

If the design cannot distinguish a concurrent edit from a sequential one, its conflict resolution is guessing.

Step 5 — Design the failure and reconciliation behavior

Specify:

  • Divergence tolerance: how long may a client stay offline before its state is unreconcilable? What happens at that boundary?
  • Partial sync failure: if half the changes propagate and the connection drops, is the resulting state coherent? Is sync resumable, or does it restart?
  • Schema skew: a client running an older schema syncs against a newer server. Is this rejected, tolerated, or migrated in flight? This is where sync design and schema evolution meet — coordinate with the evolution strategy.
  • Deletion semantics: are deletions tombstoned, and for how long? A client offline longer than the tombstone retention will resurrect deleted data.
  • Reconciliation path: when state has provably diverged beyond automatic repair, what is the manual recovery? Silent permanent drift is the worst outcome.

Step 6 — Only now select machinery

With semantics fixed, evaluate sync approaches against them. Check whether each candidate can express the per-field semantics from Step 3, supports the identity and causality primitives from Step 4, and handles the failure cases from Step 5. Reject any option that requires weakening a semantic decision already made on product grounds.

Output

Produce:

  1. The authority model per data domain.
  2. The concurrent-edit scenario table with desired user-visible outcomes.
  3. Merge semantics per field or field group.
  4. Identity and causality primitives required.
  5. Failure, skew, deletion, and reconciliation behavior.
  6. The sync approach that satisfies all of the above, and what it costs.

Red lines

  • Never accept "last-write-wins" without naming which writes get discarded and whether users will notice.
  • Never use wall-clock timestamps as the causality mechanism across devices.
  • Never rely on server-assigned sequential identity for entities that can be created offline.
  • Never select the sync library before the merge semantics are decided.
  • Never leave the permanent-divergence case unspecified.

04 同仓库更多 Skills

cwik-tech
cwik-tech/octopus

twenty-year-land-plan

Apply the Bren discipline of evaluating every land and development decision on a twenty-year horizon, with a comprehensive plan for how the land, the community, and the surrounding public infrastructure evolve together. Deals optimized for a five-year exit are structurally different from deals that compound across generations; insist on knowing which kind you are making. Use when evaluating land, entitlements, master-planned development, or phasing decisions, and when separating five-year exit deals from generational holds.

★ 0
cwik-tech
cwik-tech/octopus

thematic-gut-check

Apply the Gray discipline of identifying the structural theme behind every real estate deal, testing where that theme sits in its capital-flow lifecycle, and insisting that deals without a named theme — or deals late in a crowded theme — clear a higher bar. A mediocre deal in a strong theme usually beats a clever deal in a weak one. Use when naming the structural thesis behind a deal, judging whether that theme is early or crowded, and setting the bar the deal must clear.

★ 0
cwik-tech
cwik-tech/octopus

supply-pipeline-gut-check

Apply the Zell discipline of grounding every real estate thesis in the local supply pipeline. Demand counts over adjectives — units under construction, units permitted, units proposed — and convert them into a forward absorption schedule. A deal that ignores the pipeline is a bet on a market you have not actually studied. Use when validating a market thesis, forecasting absorption and rent growth, or counting units under construction, permitted, and proposed.

★ 0
cwik-tech
cwik-tech/octopus

ruin-scenario-mapping

Apply the Taleb discipline of identifying, for every real estate deal, the specific chain of events that produces ruin — permanent, unrecoverable capital loss — and verifying that no single such chain has non-trivial probability. Deals with any plausible ruin path must be restructured or abandoned. Use when sizing leverage, testing refinancing, covenant, and liquidity risk, or checking whether any single failure chain can permanently wipe out the position.

★ 0
cwik-tech
cwik-tech/octopus

revenue-cost-architecture

Design a venture's revenue streams, pricing logic, cost structure, and unit economics so the business model has a coherent theory of value capture, not just value creation. Use after the value proposition and customer segment are set and before financial projections, when choosing a pricing model, calculating contribution margin or CAC payback, or checking whether the unit economics hold at scale.

★ 0
cwik-tech
cwik-tech/octopus

replacement-cost-stress-test

Apply the Buffett discipline of pricing every real estate asset against the cost to rebuild it from scratch. The ratio of purchase price to replacement cost sets a ceiling on long-run downside: below replacement cost, new supply cannot profitably undercut you; at or above it, you are buying a liability disguised as an asset. Use when setting a purchase price, judging downside protection, or testing how exposed an asset is to newly built competing supply.

★ 0