The user types hello .
Five PUT requests leave but the one carrying hel arrives last.
The server stores hel . The UI shows Saved ✓ .
No error, no log: a lost update , an anomaly the database literature formalized back in 1995 [1]. Your frontend can cause one without any help from the database.
Autosave is only the first of three write bugs this article covers, each with its fix, using @ngsignal/mutation ( introduced here ). Each one has a live page in the demo .
1. Autosave: send only the latest version
Parallel PUTs can be processed in any order. A FIFO queue fixes the order but sends every outdated version. Autosave needs something in between: finish the request in flight, then send only the latest version.
readonly save = httpMutation ( ( doc : Doc ) => ( { method : 'PUT' , url : `/api/docs/${doc.id}` , body : doc } ) , { concurrency : { mode : 'queue-latest' , debounce : 500 } } , ) ;
Enter fullscreen mode
Exit fullscreen mode
At most two calls exist at once: one in flight and one waiting.…