Offline first
Why it matters "Send the whole list, last write wins" works until two devices edit while offline. Then one person's edits silently vanish, and nobody can say where they went.
A family shopping-list app must work in a supermarket basement with no signal. Each device keeps a log of what it did. When devices reconnect, the two logs are merged into one list. Both logs start with the same shared history (everything synced before they went offline), then each has its own edits.
Operation log: a record of the changes made (add this, remove that), rather than a copy of the result. Logs can be merged; copies can only overwrite.
("add", "milk", "p7") # tag p7 is unique to this add
("remove", "milk", ["p7", "s2"]) # removes exactly the adds this device had seenWrite merge(log_a, log_b) and return the sorted list of items on the merged shopping list (each item once). A log is a list of operations: ("add", item, tag), where every add has a unique tag, and ("remove", item, tags), where tags lists the adds of that item the device could see when it removed it.
Limits. Neither edit may be lost: an item is on the list if at least one of its adds was never removed. A remove cancels only the tags it lists, so an add the other device made while offline survives. Both logs may contain the same shared operations (count them once). merge(a, b) must equal merge(b, a).
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.