Autosave that never lies
Debounced, serialized and honest: how the editor decides when to say “Saved”, and what happens when two people edit at once.
Amina Odhiambo
Staff Engineer
1 min read
An editor that says Saved before the server agrees is lying. Ours has five states and only shows the green one after a confirmed write.
The state machine
type SaveState = 'saved' | 'saving' | 'dirty' | 'failed' | 'conflict';
autosave.changed(); // -> dirty, debounce 1.5s
await autosave.flush(); // before publish or scheduleOne write at a time
Writes are serialized. If you type while a save is in flight, the next save waits and sends the version number the server just returned — so a slow response can never overwrite newer text.
Conflicts are a feature
Every write carries expectedVersion. If someone else saved first, the server answers VERSION_CONFLICT and the editor stops autosaving instead of guessing.
Transient failures retry with bounded backoff
Validation errors never retry
Your local text is kept, always