Opening your learning path
Progress is saved as you study.
Opening your learning path
Progress is saved as you study.
Opening your learning path
Progress is saved as you study.
CAP & Consistency is a core lesson in the Foundations family of the Thita system design course.
The 45-minute interview framework, estimation with modern numbers, and CAP theorem.
It is part of the Interview Soon path: the HLD material that appears in a standard interview loop rather than only in a specialist one.
A distributed system can fail one replica at a time. One replica may accept traffic while another cannot reach it. CAP matters in interviews because it forces a product decision during that split: reject requests to protect correctness, or accept requests and repair conflicts later.
Candidates lose time treating CAP like database trivia. Interviewers expect you to connect consistency choices to user-visible behavior, latency, and business risk.
CAP says that during a network partition, a distributed system must choose between consistency and availability.
Real systems face partitions because networks drop packets, regions isolate, replicas lag, deploys misroute traffic, and clients retry against different nodes.
Most large user-facing systems choose AP with eventual consistency because accepting writes during partial failure often causes less product damage than rejecting traffic.
The phrase “during a partition” matters. CAP covers the moment when two parts of the system cannot communicate reliably. At that point, the system cannot accept every request and guarantee every read sees the latest write.
A useful interview answer is short and concrete:
“During a partition, I’ll choose availability for user-generated content and tolerate temporary inconsistency. For money movement, inventory decrements, and uniqueness constraints, I’ll choose consistency and reject or serialize conflicting writes.”
That answer connects the theorem to the product consequence.
When the link between replicas breaks, the system must either reject a conflicting request to stay correct, or accept it, stay available, and repair the conflict later.
PACELC adds the healthy-network case: if there is a partition, choose availability or consistency; else, choose latency or consistency.
Most requests happen while the network is healthy. Strong consistency can still require coordination with a leader, quorum, or remote replica. Coordination adds latency, especially across regions.
Use PACELC when the interviewer pushes beyond CAP:
“CAP covers failure behavior. PACELC covers healthy-network latency. Stronger consistency usually costs latency because reads or writes need coordination.”
For a system design interview, stop there. Use PACELC to justify a placement decision: social feed reads can be stale; payment confirmation needs coordinated correctness.
Consistency has levels. The useful interview spectrum is strong consistency → causal consistency → eventual consistency.
| Consistency model | Guarantee | Best fit | Example |
|---|---|---|---|
| Strong consistency | Reads observe the latest committed write, or the system rejects the operation until it can make that guarantee. | Financial records, inventory, uniqueness, permissions. | A user cannot spend the same $100 twice. |
| Causal consistency | Related operations appear in order. Unrelated operations may appear in different orders. | Chat, comments, collaborative flows where reply order matters. | If Alice sends “Are you coming?” then “Never mind,” Bob should see them in that order. |
| Eventual consistency | Replicas converge if no new writes arrive. Reads may return stale data for a short time. | Feeds, likes, view counts, recommendations, analytics. | A like count showing 101 instead of 103 for a few seconds is acceptable. |
Strong consistency protects invariants. An invariant is a rule the business cannot violate, such as “account balance cannot go negative” or “only one buyer can purchase the last ticket.” Route those writes through a strongly consistent path. The read path can still use caches or stale projections.
Causal consistency protects user reasoning. Chat is the cleanest example. Users may accept a message arriving 500 ms late. They usually reject replies appearing before the messages they answer. Common implementations use per-conversation sequencing, timestamps with tie-breakers, or one partition key per conversation.
Eventual consistency works for data that can lag because a source of truth exists elsewhere. Feeds, counters, search indexes, notifications, and profile denormalizations usually fit here.
Start with the write that can cause damage. If a stale read is annoying and harmless, choose AP with eventual consistency. If a stale read or concurrent write can lose money, oversell inventory, break authorization, or violate identity uniqueness, use strong consistency on that path.
A clean decision tree:
1Can stale or concurrent data lose money, oversell, or break authorization?
2 yes -> use strong consistency for that write path
3 no -> can users be confused by out-of-order events?
4 yes -> use causal consistency
5 no -> use eventual consistencyAvoid applying strong consistency to the entire system because one endpoint needs it. A ticketing system may use strong consistency for seat reservation, eventual consistency for search indexing, and cached reads for event pages. Real systems split consistency by workflow.
In an e-commerce system:
For e-commerce, use strong consistency for invariants and eventual consistency for derived views.
CAP labels describe behavior under a configuration. Use these placements as interview shorthand, then mention caveats when needed.
| System | Placement | Meaning | Caveat |
|---|---|---|---|
| DynamoDB | PA/EL | During partition, it favors availability. When healthy, it favors low latency. | Strongly consistent reads exist in some modes. The common scaling model favors low-latency AP design. |
| Cassandra | PA/EL | It accepts writes across replicas and reconciles later using tunable consistency and repair. | Quorum levels can be raised. The system is built for availability and partition tolerance. |
| Postgres | PC/EC | During partition, a primary-based deployment protects consistency by refusing unsafe writes. When healthy, it favors consistency. | Single-primary Postgres rejects conflicting writes on disconnected primaries. |
If the interviewer asks about tunable consistency, answer directly. Cassandra and DynamoDB can offer stronger read or write options. Their default scaling posture is AP and low latency. Postgres can be replicated and highly available. Its correctness model normally depends on one authoritative writer.
Strong consistency often makes a request wait for coordination. Inside one availability zone, the cost may be below 1 ms. Across regions, the cost can be 70–250 ms, which changes product behavior.
“Strong consistency everywhere” usually fails in interviews because it routes every read or write through the slowest coordination path. For global users, cross-region strong consistency can make normal interactions feel broken.
Pick the consistency level where the business rule lives. Use strong consistency for the ledger write. Use eventual consistency for balance displays that can lag. Use eventual consistency for the feed. Use strong consistency for the permission check that decides whether a private document can be read.
With no partition, strong consistency waits for the remote replica (about 70-90 ms US to EU); eventual consistency answers locally in under 1 ms and replicates in the background.
State the default, state the exception, then state the implementation direction. That keeps the answer concrete and prevents a theory detour.
A good answer:
“I’d make the system AP with eventual consistency for user-facing derived data like feeds, counters, and search. For financial data and inventory, I’d use a strongly consistent write path through a single owner, transaction, or quorum. That keeps most actions available while protecting invariants that cannot be repaired later.”
That answer shows theory, cost, and scope. It also avoids treating consistency as a global database setting.
Default: Choose AP with eventual consistency unless the data is financial or inventory-related. For financial records, inventory decrements, uniqueness constraints, and authorization decisions, use strong consistency on the write or decision path. For feeds, likes, counters, search, recommendations, notifications, and denormalized views, use eventual consistency and design reconciliation explicitly.
Warning:
- Saying “strong consistency everywhere” without naming the latency and availability cost.
- Treating CAP as a normal-state tradeoff. CAP only forces the choice during a partition. PACELC explains the latency-versus-consistency tradeoff when the network is healthy.
- Applying one consistency model to the whole system. Real designs use strong consistency for invariants and eventual consistency for derived views.
- Calling eventual consistency “inconsistent” and stopping there. A complete answer must include convergence, reconciliation, idempotency, or a source of truth.
- Ignoring user-visible ordering. Chat usually needs causal ordering within a conversation. Full strong consistency may be unnecessary.
- Naming DynamoDB, Cassandra, or Postgres without explaining behavior under partitions, latency, and write ownership.
- Mentioning payments and missing inventory, seats, reservations, and quota enforcement. Those paths are correctness-sensitive too.
- Using quorum as a magic word. Quorum improves consistency only when the read and write quorum overlap and the system handles conflict resolution correctly.
| Category | 2026 number | Design implication |
|---|---|---|
| Same-AZ latency | < 1 ms | Strong coordination inside one AZ can be cheap enough for many backend workflows. |
| Cross-AZ latency | 1–2 ms | Multi-AZ coordination is often acceptable for payments, inventory, and other correctness-sensitive writes. |
| Cross-region latency, US–EU | 70–90 ms | Global strong consistency adds visible latency to interactive requests. |
| Cross-region latency, US–India | 150–250 ms | Avoid synchronous global coordination for feeds, likes, and normal social actions. |
| Redis GET | < 1 ms | Fast cache reads help eventual views. Correctness still needs a source of truth. |
| Postgres indexed read | 1–5 ms | A single primary database can handle many strongly consistent core workflows before sharding. |
| Postgres single primary throughput | 10K–50K TPS | Tens of thousands of transactional writes per second is already large. |
| Postgres storage range | tens of TB before sharding | A 100 GB dataset fits easily. |
| Redis throughput | 100K–500K ops/sec per instance | Use Redis for hot derived reads, rate limits, and ephemeral state. Keep money in a transactional source of truth. |
| Kafka throughput | 1M+ msg/sec per cluster | Eventual pipelines can absorb high write volume and update derived views asynchronously. |
| Elasticsearch throughput | 10K–50K queries/sec per cluster | Search is usually an eventually consistent projection from the primary store. |
| S3 first byte latency | 50–100 ms | Object storage works well for durability and large objects. It is a poor fit for low-latency coordination. |
| CDN edge latency | 5–30 ms | Cache globally for read-heavy content where staleness is acceptable. |
| General-purpose machine RAM | 512 GiB | One machine can hold more state than older interview estimates assume. |
| Memory-optimized RAM | 4 TB | Large in-memory indexes are feasible before adding distributed coordination. |
| High-memory RAM | 24 TB | Check modern hardware before splitting a system for memory alone. |
| General-purpose CPU | 128 vCPUs | A single node can handle substantial coordination or primary-write load. |
| Local SSD | 60 TB | Capacity usually exceeds interview workloads. Watch latency and IOPS first. |
| Local HDD | 336 TB | Cold or archival local storage can be large. Latency stays high. |
| Datacenter network | 25–100 Gbps | Intra-datacenter replication bandwidth is high. Cross-region latency usually dominates. |