In a household app where partners edit shared lists offline, which conflict policy fits a checked flag, a note body, item order and a counter?
answer
- what does losing one edit cost
- flags and titles: newest value is fine
- items merge field by field
- counters travel as increments
- order as a sort key per item
basics
~20 sChoose per data type by what losing an edit costs: last-write-wins for a checked flag or a title, per-field merge for items, increments for counters, a sort key per item for order, and the user's choice for a note body.
solid answer
~50 sOne app, several policies. A checked flag or a list title is cheap to get wrong and the newest value is what people mean, so last-write-wins by the server's order is fine. An item is several independent fields, name, quantity and checked, so merge field by field: one partner's rename and the other's tick both survive, and last-write-wins applies only when both changed the same field. A counter, such as how many times a chore was done, must travel as an increment, not a total, or two offline `+1`s become one. Order needs a sort key per item rather than one array, so a move and a concurrent add do not erase each other. A note body is free text where either version may hold real work, so keep both and let a person choose.
code
pseudocode · 13 lineson edit(record_id, base_rev, changes):
current = load(record_id)
for field in changes:
if policy(field) == "ask_user" and changed_since(record_id, field, base_rev):
return conflict(current) # nothing applied yet
for field, value in changes:
if policy(field) == "increment":
current[field] = current[field] + value
else:
current[field] = value # merge by field; same field: arrival wins
current.rev = current.rev + 1
save(current)
return ok(current.rev)go deeper
Remember that different data in one app needs different conflict rules, and that a counter must be sent as a change, not a total.
Explain per field why each policy fits: what the users meant, what a lost edit costs, and what the server needs to merge.
Show the information the merge depends on, changed fields, base revision and field history, and how order and counters avoid lost concurrent changes.
Frame the policy table as a product contract: who decides it, how it is declared once on the server, and how it changes safely over time.
## Why one policy for the whole app fails A **conflict policy** is the rule the server applies when an edit arrives with a stale base revision, meaning another write landed after the phone last saw the record. In a **shared household app**, two partners keep shopping lists, chore checklists and notes on their own phones, often offline, so stale edits are normal rather than rare. Picking a single policy for everything goes wrong in one of two directions. Last-write-wins everywhere quietly loses a paragraph someone wrote or a chore someone did. Asking the user everywhere buries them in prompts about ticks and titles they do not care about, and they learn to tap through without reading. The useful question for each data type is: **what does losing one of the two edits cost, and what did the users mean?** ## The policies on offer - **Last-write-wins (LWW):** keep the value that the server applied last. Simple, and right when either value is acceptable and the newer one is what people meant. "Last" should be the server's order, not a phone's clock. - **Per-field merge:** treat a record as independent fields. Apply the fields each edit changed; only a field changed by both sides needs a tie-break. - **Operations instead of values:** send what was done (`+1`, "move after item X") rather than the resulting value, so the server can apply both. - **Sort key per item:** store order as a key on each item, so a move is an edit to one field of one item. - **User's choice:** keep both versions and ask a person, for data where either version may hold work that cannot be recreated. ## Matching each data type | Data | Example | Policy | Why | What one lost edit costs | |---|---|---|---|---| | Checked flag | "Oat milk" ticked | LWW | Either value is plausible; the newest is the intent | One tick, visible at once | | List title | "Weekend shop" | LWW | Short, rarely edited, easy to retype | A few characters | | Item record | name, quantity, checked | Per-field merge | Partners usually change different fields | One field, only when both edit it | | Counter | chore done 3 times | Increments | Two `+1`s must both count | A recorded completion | | Item order | position in the list | Sort key per item | A whole-array write erases concurrent adds and moves | One item's position | | Note body | a shared recipe | User's choice | Either version may hold real writing | Text the user typed | Creating items rarely conflicts at all: when the phone gives each new item its own id, two adds made offline simply coexist. ## What the server needs to apply these rules 1. **The base revision** of every edit, so it knows when a policy has to run. 2. **Only the changed fields**, so an untouched field with an old value is not mistaken for an edit. 3. **A record of which fields changed since a given revision**, kept per field or derived from stored history, so it can tell "both changed quantity" from "one changed quantity, one changed the name". 4. **The policy for each field**, declared once on the server, so both phones get the same verdict. 5. **Operations for counters and order**, so concurrent changes add up instead of replacing each other. The pseudocode example shows the shape: check first whether any field needs a person, then apply every changed field by its policy. ## Where candidates go wrong - Treating LWW as always a bug. For a tick or a title it is the right policy; the loss is small and visible. - Syncing a counter's total. Two phones each turn 3 into 4, and the server stores 4 instead of 5. - Storing order as one array. One partner moves an item while the other adds one; whichever array lands last erases the other change. - Asking the user about everything. Prompts lose their meaning when most of them are about trivia. - Forgetting that per-field merge needs field-level information. Without the changed-field list and base revision, the server cannot know what to merge. Each policy here is a product decision as much as a technical one: it says whose edit the household keeps and when a person is asked.
- Why is a sort key per item better than syncing the whole order as one array?An array is one value, so last-write-wins on it erases a concurrent add or move from the other phone. With a sort key on each item, a number or string between its neighbours' keys, a move is an edit to one field of one item and merges like any other field, and a new item brings its own key. Ties between equal keys are broken by item id so both phones show the same order.
- When is last-write-wins the right choice here, even though one edit is lost?When both values are acceptable and the newer one is what people mean: a checked flag, a list title, a due date. The loss is small and the user sees the result at once. Decide 'last' by the server's order of arrival or the revision it assigns, not by the phones' clocks, which can be wrong or set by hand.
- One conflict policy for the whole app is enough because conflicts are rare.
- Last-write-wins is always a data-loss bug and should never be used.
- A counter can sync its total with last-write-wins like any other field.
- Item order can be stored as one array because partners rarely reorder together.
- Prompting the user on every conflicting field costs nothing.