Skip to main content
1:1 mock interviews with Sumit, scored on a real hiring rubric.Book a slot →
TOPIC 5 OF 5 · 2 MIN READ

CAP Theorem and Consistency Models

The CAP theorem says that during a network partition a distributed system must choose between consistency and availability. Interviewers use it to see whether you understand real trade-offs, along with consistency models like strong and eventual consistency.

What you will learn

  • State CAP correctly
  • Explain strong and eventual consistency
  • Know PACELC and quorum reads and writes
  • Apply the trade-off to real features

Key concepts

CAP

Consistency (every read sees the latest write), Availability (every request gets a response), Partition tolerance (the system keeps working when the network splits). Partitions happen, so the real choice is C or A while one is happening.

PACELC

If there is a Partition, choose Availability or Consistency; Else, choose Latency or Consistency. Even without failures, stronger consistency costs latency.

Eventual consistency

Replicas may disagree briefly but converge if writes stop. Fine for like counts, feeds and product reviews.

Quorum

With N replicas, write to W and read from R. If R + W > N, every read overlaps at least one replica that has the latest write.

Step by step

Pick per feature, not per company

  • Bank balance, seat booking, inventory → consistency
  • Likes, view counts, timelines, recommendations → availability and speed
  • Shopping cart → available, merge conflicts later

Examples

Quorum example

N = 3 replicas
W = 2, R = 2  → R + W = 4 > 3, reads see the latest write
W = 1, R = 1  → fast, but a read may hit a stale replica

Practise it

Try these without looking back. If you can explain each one out loud, you are ready for this question.

  • For a food delivery app, mark each feature as needing strong or eventual consistency.
  • Explain what a user sees during a partition in a CP system and in an AP system.

Interview questions

What interviewers ask next on this topic. Answer out loud first, then open the model answer.

Is PostgreSQL CP or AP?

A single PostgreSQL primary is consistent, and if it becomes unreachable writes stop until failover, so it behaves as CP. Reading from async replicas trades some consistency for availability. Labels depend on configuration.

What is the difference between CAP consistency and ACID consistency?

ACID consistency means transactions keep database rules and constraints valid. CAP consistency means linearizability: all nodes agree on the latest value. Same word, different ideas.

Summary

During a partition choose consistency or availability; otherwise trade latency for consistency (PACELC). Use strong consistency for money and stock, eventual consistency for counts and feeds, and quorums to tune it.

Stuck on this one? Talk to Sumit.

Keys: F focus mode · ← → previous / next topic · Esc leave focus