Skip to content
NANATEC Delivery + Innovation
Search articles

Autosave that never lies

Engineering

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

ts
type SaveState = 'saved' | 'saving' | 'dirty' | 'failed' | 'conflict';

autosave.changed();      // -> dirty, debounce 1.5s
await autosave.flush();  // before publish or schedule

One 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

  • #Svelte

Keep reading

All posts
Engineering

1 min read

A BFF in front of every frontend

Why our public blog and our dashboard never talk to the API directly — and what the extra hop buys us in security, caching and simplicity.

Amina Odhiambo