The CAP theorem and eventual consistency, without the jargon
When the network between two copies of your data breaks, you must choose: refuse requests to stay correct, or keep answering and fix the differences later.
In one sentence
When a network partition splits your replicas, a system can stay Consistent (refuse what it can't answer correctly) or Available (answer anyway, maybe with old data). It can't do both until the network heals.
C, A and P in plain words
- Consistency: every read sees the latest write. Everyone sees the same data at the same time.
- Availability: every request to a working node gets an answer (not an error), even if it's not the latest data.
- Partition tolerance: the system keeps working when messages between nodes are lost or delayed.
The usual "pick two out of three" is misleading. In a distributed system partitions will happen (a cable, a cloud zone, a misconfigured firewall), so P isn't optional. The real question is: during a partition, do you prefer C or A?
Try it: cut the network
Two replicas of Ana's profile, one in Madrid and one in New York. Cut the network, write on one side and read from the other. Then switch between CP and AP and repeat.
CP or AP: it depends on the data
Choose consistency (CP)
- Bank balances, payments, stock
- Seat or ticket bookings
- Usernames that must be unique
- Users see errors during failures, never wrong data
Choose availability (AP)
- Likes, view counts, feeds
- Shopping carts, profiles, presence
- DNS and caches
- Users always get an answer; it may be a few seconds old
A single app usually needs both. In a ticketing app, the seat map can be AP (slightly stale availability is fine), but the final booking must be CP: two people can't buy the same seat.
Eventual consistency and conflicts
AP systems promise eventual consistency: if writes stop, all replicas end up with the same data. Usually within milliseconds; during a partition, as soon as the network heals.
If both sides were written during the partition, there's a conflict. Common ways to resolve it:
| Strategy | How | Cost |
|---|---|---|
| Last write wins | Keep the version with the latest timestamp | Simple, but silently loses the other edit |
| Merge | Combine both (e.g. union of two shopping carts) | Needs data that can be merged (CRDTs) |
| Ask the user | Show both versions | Honest, but extra work for the user |
Beyond CAP: latency (PACELC)
CAP only talks about failures. Most of the time the network is fine, and there's still a trade-off: waiting for every replica to confirm a write makes it consistent but slower. PACELC summarizes it: if Partition, choose A or C; Else, choose Latency or Consistency.
That's why many databases let you choose per query: DynamoDB has eventually consistent and strongly consistent reads; Cassandra lets you pick how many replicas must answer (ONE, QUORUM, ALL).
Key takeaways
- 01Partitions happen, so the real choice is consistency or availability while they last.
- 02CP refuses requests it can't answer correctly; AP answers anyway and reconciles later.
- 03Pick per feature: money and bookings CP, feeds and counters AP.
- 04Eventual consistency needs a conflict strategy: last write wins, merge or ask the user.
Check your understanding
1 of 3
During a network partition, what must a distributed system choose between?
Related concepts
Read replicas
A read replica is a copy of the database that receives every change from the primary and answers read queries, so you can add read capacity without touching writes.
7 min read →Sharding
Sharding splits one big database into several independent databases (shards), each holding a slice of the rows, so storage and writes scale with the number of machines.
8 min read →Types of databases
Each database type is optimized for a different shape of data and access pattern. Pick by the questions you need to answer fast, not by fashion.
10 min read →