Typorithm · medium

CAP & Consistency

cap-consistencysystem-designcapconsistencypartition
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn CAP & Consistency

0%

Fundamentals

The CAP theorem says that during a network partition you must choose consistency or availability. Strong consistency returns the latest write everywhere, eventual consistency converges over time — the ACID vs BASE split — and PACELC adds the latency tradeoff when there is no partition.

The CAP theorem is about behavior during a network partition. When nodes cannot all communicate, you must choose: stay consistent (CP) by refusing or delaying responses, or stay available (AP) by answering with possibly stale data. You cannot have both while partitioned.

Consistency models sit on a spectrum. Strong consistency guarantees every read sees the latest write across all nodes; eventual consistency lets replicas diverge briefly and converge over time. This maps to ACID (strong, transactional) versus BASE (basically available, soft state, eventual).

PACELC extends CAP: if there is a Partition, choose Availability or Consistency; Else (normal operation) choose between Latency and Consistency. It captures that even without partitions, strong consistency costs extra latency.

01

During a partition: pick consistency (CP) or availability (AP).

02

Strong consistency = latest write everywhere; eventual = converges over time.

03

PACELC adds the latency-vs-consistency tradeoff when there is no partition.

cap:
  consistency: all-nodes-same-data
  availability: always-responds
  partition_tolerance: survives-split
  tradeoff: pick-cp-or-ap
  models: strong-vs-eventual

Read the implementation

Connect each part of the code to the concept before you type.

1. Consistency

Consistency means every node returns the same, latest data for a read.

consistency: all-nodes-same-data

2. Availability

Availability means every request gets a non-error response, even if it is not the newest data.

availability: always-responds

3. Partition tolerance

Partition tolerance means the system keeps working when the network splits nodes into groups that cannot talk.

partition_tolerance: survives-split

4. The CAP tradeoff

During a partition you must drop either consistency (AP) or availability (CP) — you cannot keep both.

tradeoff: pick-cp-or-ap

5. Consistency models

Strong consistency returns the latest write everywhere; eventual consistency converges over time.

models: strong-vs-eventual

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

CAP & Consistency: Lesson & Practice · Typorithm | ApplyDjinn