Why two machines can never be fully sure the other got the last message.
The Two Generals Problem shows that two machines connected by an unreliable link can never be completely sure they agree on something. Whoever sends the last message cannot know it arrived.
Two armies sit on opposite hills with an enemy in the valley between them. Each army alone loses, but if both attack at the same time they win. The generals can only talk by sending a messenger through the valley, and any messenger may be caught.
General A sends "Attack at dawn." But A will not attack unless sure B got it. B receives it and replies "Agreed." But now B is unsure that A got the reply, so B should not attack either. A gets the reply and sends "I got your agreement", and the doubt moves again, to the new last message.
It has been proven that no protocol solves this, with any number of messages, over a link that can lose messages. If it did, you could take the shortest solution and remove its last message. The solution must still work, so that message was never needed, and we can repeat that until nothing is left, which is absurd.
| Technique | How it copes | Leftover risk |
|---|---|---|
| Acknowledgements and retries | Resend until you hear back | Duplicates |
| Idempotency keys | The receiver ignores repeats of the same request | Needs storage for keys |
| Sequence numbers | The receiver spots gaps and duplicates | State per connection |
| Timeouts | Stop waiting after a limit | You may give up too early |
| Reconciliation | Check and repair later (compare ledgers) | A short period of mismatch |
| Two-phase commit | A coordinator decides, everyone follows | Can block if the coordinator dies |
| Probabilistic certainty | More acks make an error less and less likely | Never zero |
A fixed pattern stands in for chance, so the same slider setting always shows the same story. More acknowledgements make a wrong guess less likely (this is what a TCP handshake does) but never remove the doubt completely.
| Term | Meaning in easy words |
|---|---|
| Two Generals Problem | The proof that two parties cannot be certain of agreement over a lossy link |
| Acknowledgement (ack) | A message saying another message was received |
| Unreliable link | A connection that may lose, delay or duplicate messages |
| Common knowledge | Both know it, both know that both know it, and so on forever |
| Idempotent | Doing it twice has the same effect as doing it once |
| Idempotency key | A unique ID that lets a server recognise a repeated request |
| Handshake | A short exchange used to set up agreement, such as TCP's three steps |
| Timeout | A limit on how long to wait for a reply |
| Reconciliation | Comparing two records later and fixing differences |
| Unknown outcome | The state where a request may or may not have run |
| Choice | We gain | We lose |
|---|---|---|
| More acknowledgements | Smaller chance of error | More delay and traffic, still not zero |
| Retry on timeout | Work eventually done | Possible duplicates |
| No retry | No duplicates | Possible lost work |
| Idempotency keys | Safe retries | Key storage and cleanup |
| Status check before retry | Avoids repeating a write | An extra call |