Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Availability vs Consistency  ›  Lesson

The CAP Theorem

CAP Theorem 15 minWhen a network partition cuts the copies of a distributed system apart, each part must choose between answering with possibly stale data (availability) and refusing to answer (consistency).

The CAP Theorem

Hop now runs in two regions, Mumbai and Frankfurt, each with its own copy of the links. One afternoon the network link between them breaks. Both regions are healthy; they just cannot talk. A user in Frankfurt asks for a link created in Mumbai two seconds ago. What should Frankfurt say?

The rule

When the network splits, choose: answer possibly stale, or refuse.

CAP names three properties of a system that keeps copies of data on several machines:

  • Consistency (C) — every read sees the most recent write, as if there were one copy.
  • Availability (A) — every request to a working machine gets a non-error answer.
  • Partition tolerance (P) — the system keeps running when messages between machines are lost.

Networks do fail, so P is not optional for a distributed system. The real choice appears only during a partition:

  • CP — refuse or wait rather than risk a stale answer. Correct but sometimes unavailable.
  • AP — answer from the local copy. Always responsive but sometimes out of date.

When the network is healthy, a system can offer both. CAP is about the bad afternoon, not every afternoon.

The shortcut

For each feature, ask: "What is worse here — a wrong answer or no answer?" Wrong is worse → CP. No answer is worse → AP.

Hop during the Mumbai–Frankfurt splitStep 1 of 4
  1. Redirects

    An existing link almost never changes. A slightly stale copy is nearly always right; a failed redirect loses a visitor. No answer is worse → AP.

The trap is thinking you can "pick CA" and skip partitions. You cannot choose whether the network fails; you only choose how to behave when it does.

Drills

Answer fast — trust the rule.

quick drill

In CAP, what does partition tolerance mean?

quick drill

During a partition, a CP system asked for data it cannot confirm is current will do what?

quick drill

Which feature best suits an AP choice?

quick drill

When is CAP's trade-off actually forced?

quick drill

Why can a distributed system not simply choose "CA"?

Remember

  • When the network splits, choose: answer possibly stale (AP), or refuse (CP).
  • Shortcut: "what is worse — a wrong answer or no answer?" Decide per feature.
  • Trap: believing you can opt out of partitions.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainChoose CP or AP for Hop's features

Hop runs in two regions, Mumbai and Frankfurt, and the link between them breaks for ten minutes. For (a) redirecting existing short links and (b) claiming a custom alias like hop.example/sale that must be unique, say whether Hop should favour availability or consistency during the split, and explain why.