An editor I built saves your work as you type. That's the feature users love most, and one evening it was the reason the whole app stopped answering.
No single bug caused it. Five ordinary decisions, each reasonable on its own, lined up. Here they are, with what I changed.
1. Saving things that hadn't changed
The editor sent the cursor position and the current scene on a timer. The server wrote them every time — even when nothing had changed. And the "last saved" baseline on the client never advanced, so every tick looked like a new change.
At normal traffic this was invisible. When usage climbed, the database spent most of its time writing identical rows.
Fix: compare before you write. The client keeps a baseline and sends only real diffs; the server skips writes where the value is unchanged. A no-op save should cost nothing.
2. Read-before-write on every save
Each save first selected the row, then updated it.…