Concept Simulators / Copies and agreement

CAP theorem

Partition the network and see CP and AP systems behave differently.

On the roadmap:Advanced · step 1: CAP & PACELC

Intermediateabout 10 to 20 min6 experiments
Experiments

Pick a database

Defaults to

AP (available)

PACELC

PA/EL

During the partition below

answers on both sides

Every replica accepts reads and writes, even cut off. Tunable consistency levels can trade this for more C, but the default favours availability and low latency. Can be tuned toward CP with QUORUM reads and writes on both sides.

Node A

v0

Node B

v0

Node C

v0

PACELC, in one line

CAP only describes what a system does during a partition (P): choose availability (A) or consistency (C). PACELC adds the other half: else (E), when the network is healthy, every system still trades latency (L) against consistency (C), because waiting for every replica to agree is slower than trusting the nearest one. Cassandra is PA during a partition and EL the rest of the time.

Event log

  • Nothing yet.

In plain words

When the network between machines breaks, a system holding copies on both sides has to choose. It can keep answering on both sides and risk showing different data (available), or refuse to answer on the side that cannot reach the others (consistent). The quorum view shows the middle ground: you choose how many copies each read and write must touch.

Why it matters

Networks do fail, so a partition is not optional. The real question is what your product does when it happens: show a possibly stale balance, or show an error. Quorum settings let one system lean either way, request by request.

How real systems do it

The simulation is a simplified model. Here is what production systems add or do.

  • Cassandra lets each request choose a consistency level. ONE, the default, answers from a single replica and may be stale. QUORUM needs a majority: the newest value by timestamp wins and disagreeing replicas are repaired. ALL needs every replica, so one slow or down replica makes the request fail.
  • A quorum in Cassandra is half the replicas, rounded down, plus one: 2 of 3.
  • Consensus systems such as etcd choose consistency: a node cut off from the majority cannot commit writes.
  • Last write wins is simple, but it can silently drop one of two concurrent updates, as the AP mode here shows.

Study: CAP theorem

Once you have played with it, learn the same idea from people who build these systems. Watch first for the picture, then read for the detail.

Check yourself

1 of 4. In a CP system, what happens on the side of a partition that cannot reach the majority?

Go deeper