End-to-End Correctness and the Exactly-Once Myth
Why transactions and exactly-once messaging inside one component do not stop duplicate effects across the whole system, and how request IDs checked at the end points close the gap.
Overview
The problem: retries happen at every layer
A user presses Pay. The request crosses a browser, a network, a load balancer, an API server, a database and maybe a message broker. Any of them can time out, and the usual fix for a timeout is to try again. The trouble is that a timeout does not tell you whether the first attempt worked. It may have succeeded, and only the reply was lost. Here is how a lost reply becomes a double charge.
- The browser sends POST /pay to the API server.
- The API server inserts the charge into the database, and the insert commits.
- The reply is lost, and the browser times out.
- The browser sends POST /pay again.
- The API server inserts the charge again, and it commits again.
There are now two charges, though each transaction was correct. The database committed the first charge correctly; the retry looks like a brand-new request to every layer below the application.
Nothing here is a bug in a single component. The database gave full ACID guarantees both times. The failure is that nobody could tell the second request was the same as the first.
Key concepts
- End-to-end argument
- Idempotency key
- Idempotent operation
- Effectively once
- Kafka exactly-once
- Deduplication table
- Reconciliation
Interview questions
- How do you make a payment API safe to retry?
- Kafka supports exactly-once. Why can a consumer still apply a message twice?
- What is the end-to-end argument, and how does it apply to data systems?
Sign up free to read the full topic
More DDIA topics
- Clocks and Time in Distributed Systems
- Column-Oriented Storage and Compression
- Consensus Algorithms: Paxos and Raft
- Consistency Guarantees: Eventual, Causal and Linearizable
- Declarative vs Imperative Query Languages
- Encoding Formats: JSON, Protobuf, Avro, Thrift
- Event Streams and Message Brokers
- Fan-Out and the Twitter Timeline Problem
- Fault Tolerance in Stream Processing
- Faults and Partial Failures
- Graph Data Models
- Implementing Serializability
Start free on Cariara · Coding problems · System design studio