GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
System designCAP theorem and consistency

CAP theorem and consistency

What CAP really says, PACELC, strong vs eventual consistency, and how to pick for each feature.

intermediate 11 min read 4 interview questions

On this page

1/5
  1. 01The CAP theorem
  2. 02PACELC
  3. 03Consistency models
  4. 04Interview questions
  5. 05Quick check
Back to top

The CAP theorem

In a distributed data store, when a network partition splits the nodes, you must choose between consistency (every read sees the latest write, or gets an error) and availability (every request gets a non-error response, possibly stale). You can't have both during the partition.

Partitions happen in any real network, so "pick two of three" is misleading: the real choice is CP or AP when a partition happens. When the network is healthy you can have both.

ChoiceDuring a partitionExamplesGood for
CPRefuse some requests to stay correctZooKeeper, etcd, HBase, a single SQL primaryPayments, inventory, locks, leader election
APAnswer everything; reconcile laterCassandra, DynamoDB (default), DNSFeeds, likes, carts, presence

PACELC

PACELC extends CAP: if there's a Partition, choose A or C; Else (normal operation) choose Latency or Consistency. Even without failures, waiting for replicas to agree costs latency. Cassandra and DynamoDB are PA/EL by default; most SQL setups with synchronous replicas are PC/EC.

Consistency models

ModelGuarantee
Linearizable (strong)Behaves like a single copy; once a write is acknowledged, every later read sees it
SequentialAll nodes see operations in the same order, though not necessarily real-time order
CausalOperations that depend on each other are seen in order (a reply never appears before its question)
Read-your-writesA user always sees their own updates
Monotonic readsA user never sees data go backwards in time
EventualIf writes stop, all replicas converge eventually

Choose per feature, not per system. A shop can keep its catalogue eventually consistent while checkout and stock reservation are strongly consistent.

Interview questions

Try answering out loud first, then open the model answer.

Q1Explain the CAP theorem.intermediate

If a network partition separates the replicas of a distributed store, it can either stay consistent (refuse requests it can't serve correctly) or stay available (answer with possibly stale data), not both. Since partitions can't be ruled out, systems decide in advance whether they lean CP or AP.

Q2Is a single-node database CA?intermediate

In CAP terms, a single node has no partition between replicas, so it's trivially consistent and available while it's up, but it's not fault-tolerant: if it's down, it's unavailable. CA only describes systems that don't have to tolerate partitions, which in practice means one machine.

Q3Give an example where eventual consistency is fine and one where it isn't.beginner

Fine: a like count or a follower list being a few seconds behind. Not fine: two people buying the last concert ticket, or withdrawing from an account; those need strong consistency (a transaction or a lock) so the invariant holds.

Q4How do eventually consistent systems resolve conflicts?advanced

Last-write-wins using timestamps (simple, but can silently drop writes), version vectors to detect concurrent updates and let the app merge them, or CRDTs: data types like counters and sets designed so concurrent updates always merge to the same result.

Quick check

Question 1

1.CAP forces a choice between C and A when…

Question 2

2.Which needs strong consistency most?

Question 3

3.In PACELC, the "ELC" part is about…

0 of 3 answered

Sharding and consistent hashingMessage queues and async processing
Log inStart free