CAP Theorem: ATM Simulation
The CAP theorem is about three properties of a distributed system: Consistency (every read sees the latest write), Availability (every request gets an answer) and Partition tolerance (the system keeps working when the network splits). It is often summarised as "pick two of three", but that's misleading: network partitions are not optional. The real statement is narrower. When a partition happens, the system has to choose between consistency and availability.
This simulation uses an ATM network with a shared account to let you explore the trade-off hands-on. Withdraw money, cut a network link, and see what happens when the network heals.
How It Works
- Withdraw cash at any ATM - the backend confirms and every connected ATM sees the new balance
- Cut a link to isolate an ATM from the backend (a network partition)
- Choose a mode - Consistency (refuse what cannot be verified) or Availability (pay out up to an offline cap)
- Keep withdrawing at both the isolated and the connected ATMs
- Heal the partition to reconcile, and find out whether the account was overdrawn
Live simulation
A partition exists. What should an isolated ATM do when a customer asks for cash?
What to try next
Withdraw cash at any ATM, then cut an ATM's link to create a network partition.
Setup
How much an isolated ATM may pay out in availability mode. Locked once a partition starts.
Event log
Reconciliation
Key Takeaways
- The CAP theorem is not about choosing two of three properties in general - it is about what happens during a partition
- Network partitions are not a choice; they will happen in any distributed system
- The real decision is: when a partition occurs, do you prefer consistency or availability?
- Many real systems choose different strategies for different operations within the same system
- The trade-off is often a spectrum, not a binary choice - techniques like timeouts, quorums, and bounded staleness provide nuance
- Offline caps limit risk in AP mode - a common pattern in real ATM networks. Here an isolated ATM also never pays out more than the balance it last knew about, so every overdraft you see comes from withdrawals on both sides of the partition
Further Reading
- Brewer's original conjecture (2000) and Gilbert & Lynch's proof (2002)
- The "CAP Twelve Years Later" article by Eric Brewer (2012) - clarifies common misconceptions
- PACELC theorem - extends CAP to consider latency vs. consistency even when there is no partition
Decision Angle
In real systems, CAP trade-offs are architectural decisions. Teams should record when they choose consistency over availability, accept bounded staleness, allow offline operations with caps, or adopt specific reconciliation strategies. These are exactly the kinds of decisions that benefit from an Architecture Decision Record - they involve trade-offs, affect system behavior under failure, and are easy to forget once the system is running.