Engineering
11 min read
Notes on a small sync engine
What I learned building Quire: logical clocks, why deletes are the hard part, and the test that pulls the network cable every night.

I set out to build a note app and ended up building a sync engine. These are my notes from the two years in between, mostly things I got wrong.
Start with the log
Every edit is an operation with an id and a place in a logical order. The document is what you get when you replay the log. Once I believed that, half of my bugs disappeared.
Deletes are the hard part
Adding text is easy to merge. Removing it is not, because a device that was offline may edit text another device has already removed. Quire keeps a marker where the text was and cleans up only when every device has seen it.
The cable test
A script starts two clients, makes random edits and cuts the network at random moments for eight hours. If the two documents differ in the morning, I have work to do. In two years it has found eleven real bugs.
Written by
Iri Halvorsen, software engineer in Bergen
More / ls -t ./writing

