CAP Theorem — Full JSON Block Demo
Interactive demo article using every engineering blog block type: video, code, polls, tables, and SEO fields. Learn CAP (Consistency, Availability, Partition tolerance) for interviews and system design.
By Pawan Bisht
What is the CAP theorem?
In a distributed data store, when a network partition happens, you cannot simultaneously guarantee both perfect consistency and perfect availability — you choose a tradeoff.
Colored text block example for emphasis.
This is richText with inline HTML — use sparingly for trusted author content only.
- Consistency C
- Availability A
- Partition P
- 2 of 3 Pick
CAP theorem explained (video)
Pick two — compare
CP (Consistency + Partition)
- Strong reads/writes during partition
- May reject requests (sacrifice A)
- Example: ZooKeeper, etcd
AP (Availability + Partition)
- Always respond during partition
- May return stale data (sacrifice C)
- Example: Cassandra-style tunable consistency
Consistency
Every read receives the most recent write or an error.
Availability
Every request receives a non-error response.
Partition tolerance
System continues despite dropped or delayed messages between nodes.
- Identify your failure domains (AZ, region, network).
- Decide RPO/RTO with product and legal.
- Choose CP vs AP per data path — not one global answer.
- Document partition behavior in runbooks
- Chaos-test network splits in staging
- Expose consistency mode in API docs
checks:
- type: freshness
table: orders
column: updated_at
max_age: 24h
| System style | During partition | User sees |
|---|---|---|
| CP | Reject writes | Errors until quorum |
| AP | Accept writes | Possible stale reads |
| CA | Not partition-tolerant | Only valid on single node |
- Linearizability
- Strongest single-object consistency model.
- Eventual consistency
- Replicas converge if no new writes arrive.
- Quorum
- Majority of nodes required before acknowledging a write.
It's not about choosing CAP — it's about choosing which guarantees matter for each operation.
For a checkout API during a partition, which default do you prefer?
- Fail closed (CP)
- Accept orders (AP)
- Queue + reconcile later
Is CAP still relevant in 2026?
Yes as a framing tool. Modern systems add PACELC and per-operation consistency levels.
Does Redis choose AP or CP?
Depends on mode: single primary with sync replication leans CP; async replication allows availability with lag.
- Brewer's conjecture CAP popularized for distributed systems design.
- Formal proof Gilbert and Lynch proof solidified the theorem.
- Per-request tuning Databases expose consistency knobs per query.
#cap, #distributed, #system-design, #block-demo
Add your own concept
Copy article.template.json, use every block you need, send a PR.