Distributed Idempotency and Retry Patterns
Solve the network acknowledgment dilemma, master idempotency keys for financial transactions, and prevent retry storms with exponential backoff.
In distributed computing, networks are inherently unreliable. Packets get dropped, TCP sockets time out, and mobile devices switch between cellular towers.
When a client sends an HTTP request to charge a credit card and experiences a socket timeout after ten seconds, a fundamental question arises: Did the payment fail on its way to the server, or did the server successfully charge the card and the network fail on the response back?
From the client's perspective, these two failure modes look identical: an empty socket timeout. If the client simply retries the request, it risks charging the customer twice. If it does not retry, the order is abandoned.
This is the classic distributed systems acknowledgment dilemma. The only safe way to handle network retries without corrupting data is by enforcing Distributed Idempotency.
01What is Idempotency?
In mathematics and computer science, an operation is idempotent if executing it multiple times produces the exact same end-state as executing it once:
f(f(x)) = f(x)In HTTP semantics:
GET,HEAD,OPTIONS: Naturally safe and idempotent. Querying an account balance ten times changes nothing.PUT: Naturally idempotent. Settingemail = 'alice@example.com'ten times leaves the database in the exact same state as setting it once.DELETE: Generally idempotent. Deletinguser/101once removes the user; deleting it again finds nothing to delete.POST: Non-idempotent by default. ExecutingPOST /paymentswith\$100ten times will debit the bank account ten times, totaling\$1,000.
Loading the rest of the lesson…