System design · Question 45 of 50

Explain the CAP theorem with a real example.

What they're checking

Distributed trade-offs rather than a slogan.

The answer

In a distributed system, when the network splits (a partition), you have to choose: stay consistent, so every read sees the latest write and some requests are refused, or stay available, so every request gets an answer that may be stale. You cannot have both during a partition; without one, you can.

Partitions happen, so the real choice is per piece of data. A bank balance or a seat booking leans consistent: better to refuse than to sell the seat twice. A like count leans available: a slightly old number is fine. Many databases let you tune it per request with quorum reads and writes (Cassandra, DynamoDB). PACELC adds the everyday case: even with no partition, you trade latency against consistency.

The picture

  node A ──✗ network split ✗── node B
  write x = 2                   read x → ?
CP: B refuses until it hears from A    correct, not available
AP: B answers x = 1, stale             available, not consistent
The follow-up they'll ask

What is eventual consistency?

Show the answer

If writes stop, every copy ends up with the same value after a while; until then, reads may be stale.

Your progress stays on this device.