Safe retries
Anything that can happen once can happen twice. The phone loses signal after the server got the request, so the app retries. The user taps again because nothing seemed to happen. A queue redelivers after a worker dies. The question is never whether a write repeats, only what happens when it does.
A timeout is not a failure. It means you do not know. Reads can be retried freely; a write can be retried only if the server can recognise the repeat.
Give every write an identity. The app creates an id or idempotency key once, when the user acts, and sends the same key on every retry. The server answers a repeat with the original result instead of doing the work twice, so a retried “place order” is still one order.
Let the database refuse duplicates. In GoloLink, each click gets its id when it is queued, and that id is the row’s primary key. Inserts skip rows that already exist, so a redelivered batch changes nothing.
Retry what can succeed, park what cannot. A dropped connection is worth retrying; a row the database will never accept is not. GoloLink retries temporary database errors, and after five failed attempts sets the bad rows aside in a dead-letter queue, so one bad row cannot block the rest.
Guard the button, but do not rely on it. At Third Wave Coffee, the add-to-cart button turns into a spinner while its request is in flight, so there is nothing to tap twice. That is good UX, not safety: only the key on the request stops a duplicate that gets through.
The rule underneath all of it: decide what makes two requests the same before they are sent, and let the server refuse the second one. The longer version is in Making every write safe to repeat.