CAP Theorem and Distributed Consistency Interview Questions

2,516 multiple-choice tech interview questions on CAP Theorem and Distributed Consistency: CAP and PACELC, including formal definitions, CP and AP design choices, harvest and yield, and the fallacies of distributed computing; consistency models, including linearizability, sequential and causal consistency, session guarantees, and tunable product levels; quorums and leaderless replication, including N/W/R overlap, sloppy quorums, hinted handoff, read repair, and anti-entropy; consensus with Raft and Paxos, including elections, replicated logs, and coordination services such as etcd and ZooKeeper; replication strategies and replication lag, including synchronous and asynchronous shipping, physical and logical copies, and lag measurement; clocks and ordering, including NTP and PTP, logical and hybrid clocks, TrueTime-style uncertainty, and time-ordered IDs; conflict resolution and CRDTs, including last-writer-wins, observed-remove sets and maps, counters, and sequence types; distributed transactions and distributed SQL, including two-phase commit, Percolator and Calvin-style models, and locality in NewSQL systems; partitions, failure detection and split-brain, including heartbeats and suspicion, fencing and STONITH, and membership under network cuts. Written for technical phone screens and interview prep, organized by subtopic, with a short explanation for every answer. Learn the 189 key terms with the flashcards first, then test yourself.

Take the practice test · Flashcards · All study tools

What it covers

  1. 5.1 CAP theorem and PACELC
  2. 5.2 Consistency models
  3. 5.3 Replication strategies and replication lag
  4. 5.4 Quorums and leaderless replication
  5. 5.5 Consensus: Raft, Paxos and coordination services
  6. 5.6 Time, clocks and ordering
  7. 5.7 Conflict resolution and CRDTs
  8. 5.8 Distributed transactions and distributed SQL
  9. 5.9 Partitions, failure detection and split brain

Key terms

5.1 CAP theorem and PACELC

CAP theorem
During a partition, a distributed store must choose consistency or availability
PACELC
Extends CAP: without partitions, trade latency against consistency
Network partition
A failure that splits nodes into groups that cannot communicate
Partition tolerance
Continuing to operate when messages between nodes are lost
CP system
Gives up availability during partitions to stay consistent
AP system
Stays available during partitions, accepting temporary inconsistency
Harvest and yield
Trading answer completeness for the share of requests answered
Fallacies of distributed computing
Common false assumptions, starting with "the network is reliable"
Partial partition
Some nodes can talk while others can't; often hard to detect
Brewer's conjecture
A high-level claim about consistency, availability and partition tolerance that was later proved under formal definitions
CA system
A system that can be consistent and available only because it is not a distributed store that must tolerate a network partition
CAP availability
Every request sent to a non-failed node eventually receives a completed response, even during a partition
Atomic consistency
The name Gilbert and Lynch used for linearizability: operations appear to take effect instantly, as if there were a single copy
Tunable consistency
Client or operator settings that choose, per query or session, whether to wait for stronger agreement or favor lower latency
Latency-consistency tradeoff
The PACELC else decision: when there is no partition, whether to wait for stronger consistency or to favor lower latency
Gilbert-Lynch proof
The 2002 formalization of Brewer's conjecture, showing a linearizable always-available register is impossible once partitions can occur

5.2 Consistency models

Linearizability
Operations appear to happen instantly in real-time order, like one copy
Read-your-writes
A client always sees its own earlier writes
Causal consistency
Causally related operations are seen in the same order everywhere
Sequential consistency
One global order of operations that respects each client's own order
Strict serializability
Serializable transactions that also respect real-time order
Session guarantees
Read-your-writes, monotonic reads, monotonic writes and writes-follow-reads
Monotonic writes
A client's writes are applied in the order it issued them
Consistent prefix
Reads may lag but never see writes out of order
Strong eventual consistency
Replicas with the same updates are identical, with no conflicts
Stale read
Reading a value that has since been overwritten elsewhere
Bounded staleness
Reads lag writes by at most a set time or number of versions
Jepsen
Test suite and analyses checking databases' guarantees under faults
Session consistency
Cosmos DB default: read-your-writes within a session
Monotonic reads
A session guarantee that once a client has seen a version, later reads in that session never return an older version
Writes follow reads
A session guarantee, also called session causality, that a write issued after reading a value is ordered after that value everywhere the write is seen
Client-centric consistency
A family of guarantees whose correctness condition is stated for one client or session over time
Data-centric consistency
A family of guarantees about legal histories of the stored object as observed by any clients, not only one session
Linearization point
A moment between an operation's invocation and its response at which the operation appears to take effect instantly
PRAM consistency
A weak model, also called FIFO consistency, in which writes issued by a single process are seen by others in the order that process issued them
External consistency
A real-time, globally agreed order of transactions: if T1 commits before T2 starts, T2 sees T1's effects

5.3 Replication strategies and replication lag

Single-leader replication
One node takes writes and streams changes to followers
Replication lag
Delay before a follower reflects the leader's writes
Synchronous replication
Leader waits for a replica before confirming a write
Asynchronous replication
Leader confirms writes before replicas have them
Semi-synchronous replication
Leader waits for at least one replica to receive the change
Multi-leader replication
Several nodes accept writes and sync with each other
Leaderless replication
Clients write to several replicas directly
Write-ahead log
Ordered log of changes, written first and shipped to replicas
Logical replication
Replicating row-level changes independent of storage format
Change data capture
Streaming a database's committed changes to other systems
Failover
Promoting a replica to leader when the old leader fails
Delayed replica
Follower that applies changes after a set delay
Replication slot
PostgreSQL marker that retains WAL until a consumer reads it
Hot standby
Up-to-date replica that can serve reads and take over
Split-brain
Two nodes both act as leader and accept writes
State machine replication
Replicas start from the same state and apply the same deterministic commands in the same order
Chain replication
Writes enter at the head and flow to the tail; strong reads come from the tail
Logical decoding
Turning the write-ahead log into a stream of row-level changes a consumer can apply
Apply lag
How far a replica is behind in replaying changes it has already received
Write forwarding
Sending a write to the record's owner instead of applying a conflicting local write
Replica identity
The key or old-row image a logical stream uses to find the row to change
Hot standby feedback
A standby tells the primary about its oldest snapshot so vacuum is less likely to conflict

5.4 Quorums and leaderless replication

R + W > N
Quorum overlap rule: reads and writes share at least one replica
Sloppy quorum
Accepting writes on any reachable nodes, not just the key's replicas
Hinted handoff
Stand-in node stores writes for a down replica and delivers them later
Read repair
Updating stale replicas found during a read
Anti-entropy
Background comparison and repair of replicas
Merkle tree
Tree of hashes used to find differing data ranges cheaply
Tombstone
Delete marker that stops old values from resurfacing
Replication factor
Number of copies kept of each piece of data
LOCAL_QUORUM
Cassandra level needing a quorum in the local data center only
Version vector
Per-key counters that distinguish concurrent from sequential writes
Siblings
Concurrent versions of a value the application must merge
Witness replica
Node that votes in quorums but stores little or no data
Preference list
The ordered list of nodes responsible for a key, from which the first N are the usual replicas and further names can be stand-ins
Digest read
A coordinator asks some replicas for a checksum of the requested data instead of the full payload, then fetches more if the digests disagree
EACH_QUORUM
A Cassandra consistency level that waits for a local majority in every data center, not only in the coordinator's DC
Incremental repair
An anti-entropy session that tries to skip ranges already marked repaired, rather than comparing all requested data from scratch
Consistency level ANY
A Cassandra write level that can succeed by storing a hint even when no natural replica is up
gc_grace_seconds
How long Cassandra keeps tombstones so missed deletes can still propagate before those markers may be compacted away
Strict quorum
A quorum in which only the key's intended replicas are allowed to count toward W or R, not sloppy stand-ins

5.5 Consensus: Raft, Paxos and coordination services

Quorum
The minimum number of replicas that must agree; R + W > N overlaps reads and writes
Raft
Understandable consensus algorithm for a replicated log with an elected leader
Paxos
Classic consensus algorithm by Leslie Lamport
Multi-Paxos
Paxos with a stable leader for a sequence of decisions
Raft term
Numbered period starting with an election; stale leaders are spotted by older terms
Election timeout
Randomized wait after which a follower starts an election
Committed entry
Log entry replicated to a majority, so it won't be lost
FLP impossibility
No deterministic consensus is guaranteed in an async system with one crash
Byzantine fault tolerance
Agreement despite malicious or lying nodes
ZooKeeper
Coordination service using the ZAB protocol
etcd
Raft-based key-value store; Kubernetes stores its state there
KRaft
Kafka's Raft-based metadata quorum, replacing ZooKeeper
Joint consensus
Raft method for safely changing cluster membership
Leader lease
Window when a leader serves reads locally, assuming no rival leader
Safety and liveness
Safety: nothing bad happens; liveness: something good eventually happens
AppendEntries
Raft RPC the leader uses to replicate log entries and to send heartbeats
RequestVote
Raft RPC a candidate uses to ask other servers for their vote in an election
Log matching
If two logs contain an entry with the same index and term, they are identical through that index
Leader completeness
A log entry committed in a given term is present in the logs of all leaders of later terms
Pre-vote
An extension that checks whether a candidate could win an election before it increments its term
Flexible Paxos
A Paxos variant where phase-1 and phase-2 quorums need only intersect, not both be majorities
Ephemeral node
A ZooKeeper znode that exists only while the creating client's session is alive
Read index
A linearizable-read method: the leader confirms leadership with a majority, then serves a read at the current commit index

5.6 Time, clocks and ordering

Lamport clock
Logical counter ordering events consistently with causality
CRDT
Replicated data type whose concurrent updates always merge deterministically
Clock skew
Difference between two machines' clocks at the same moment
NTP
Network Time Protocol for synchronizing clocks
Monotonic clock
Clock that never goes backward; used for durations
Vector clock
Per-node counters that detect concurrent events
Happens-before
Causal ordering relation defined by Lamport in 1978
Hybrid logical clock
Physical time plus a logical counter
TrueTime
Spanner's clock API returning a bounded uncertainty interval
Commit wait
Spanner's wait for clock uncertainty to pass before commit
Total order broadcast
Every node delivers the same messages in the same order
Snowflake ID
Sortable 64-bit ID: timestamp, machine ID and sequence
UUIDv7
Time-ordered UUID standardized in RFC 9562
Leap smearing
Spreading a leap second over hours to avoid clock jumps
PTP
Precision Time Protocol; sub-microsecond clock sync with hardware support
Clock drift
The rate at which a clock gains or loses time relative to a reference
Clock slew
A gradual frequency adjustment that corrects offset without a sudden jump
NTP stratum
Hop count from a reference clock; stratum 1 is attached to a reference, and 16 often means unsynchronized
Cristian's algorithm
A client sets its clock to a server's time plus half the measured round-trip, assuming a symmetric path
Network Time Security
A TLS-backed way to authenticate NTP, standardized in RFC 8915
Grandmaster clock
The clock that a PTP domain currently treats as the root time source
Uncertainty interval
A bounded window around 'now' that a TrueTime-style or HLC-based protocol treats as possibly still in flux
Causal broadcast
A delivery guarantee that if send(m1) happens-before send(m2), no correct process delivers m2 before m1

5.7 Conflict resolution and CRDTs

Write conflict
Concurrent different updates to the same data on two replicas
G-Counter
Grow-only CRDT counter with a slot per node
PN-Counter
CRDT counter built from two grow-only counters
OR-Set
Observed-remove set: concurrent adds win over removes
LWW-Register
Keeps the value with the highest timestamp
Multi-value register
Keeps all concurrent values for the reader to resolve
Operation-based CRDT
Sends operations to every replica instead of whole states
Delta CRDT
State-based CRDT shipping only recent changes
Operational transformation
Transforms concurrent edits so documents converge
Local-first software
Data lives on the device and syncs; works offline
Automerge
CRDT library for collaborative, local-first apps
Yjs
CRDT framework for real-time collaborative editing
Convergence
Replicas with the same updates end in the same state
Escrow transactions
Splitting a quota among replicas so each spends locally
State-based CRDT
A CRDT that replicas synchronize by merging states with a join that is idempotent, commutative, and associative
Grow-only set
A set CRDT that only supports adding elements; merge is union
Two-phase set
A set with grow-only added and removed collections; an element cannot be re-added after it is removed
OR-Map
A map whose keys follow observed-remove semantics and whose values are themselves CRDTs
Replicated Growable Array
A sequence CRDT that gives elements unique identities so concurrent inserts can be merged into one order
Causal stability
The point at which an update can no longer have unseen concurrent operations, so related metadata can be discarded
Join-semilattice
A partial order in which any two elements have a least upper bound; state-based CRDT merge is that join
Interleaving anomaly
Concurrent inserts of two ordered runs mixed together instead of staying as intact adjacent blocks

5.8 Distributed transactions and distributed SQL

Two-phase commit
Coordinator prepares then commits all participants atomically
Three-phase commit
Adds a pre-commit phase to reduce blocking; assumes bounded delays
XA transactions
Standard interface for distributed 2PC transactions
Distributed SQL
Auto-sharded, replicated databases with SQL and ACID
Cross-shard transaction
Transaction touching more than one shard
Percolator
Snapshot-isolation transactions over a key-value store with a timestamp oracle
Calvin
Deterministic database that orders transactions before executing them
Write skew
Anomaly allowed by snapshot isolation on overlapping reads
Follower read
Reading slightly stale data from a nearby replica
Hot shard
Shard receiving outsized traffic and becoming a bottleneck
Heuristic decision
2PC participant committing or aborting alone while blocked
Optimistic concurrency control
Proceed without locks; validate conflicts at commit
Write intent
CockroachDB provisional value acting as a lock
Timestamp oracle
Central service issuing increasing transaction timestamps
Presumed abort
A 2PC recovery rule: if the coordinator has no decision record, the transaction is treated as aborted
In-doubt transaction
A branch that has been prepared but has not yet learned the coordinator's commit or abort decision
Last agent optimization
A 2PC shortcut that commits one non-XA resource first, then the prepared resources, accepting a mixed outcome if a crash hits the gap
Parallel commit
A cross-range commit optimization that overlaps prepare and commit traffic to cut serial round trips while still aiming for atomicity
Colocated table
A placement that stores related rows, such as a parent and its children, in the same range or tablet so typical transactions stay local
Closed timestamp
A watermark at which a distributed SQL engine can be sure no earlier write is still uncommitted, allowing a safe snapshot or follower read
Primary lock
In Percolator, the lock whose state is the transaction's truth; secondary locks point to it during prewrite and recovery
Global secondary index
A secondary index whose entries may live on other nodes or regions, so maintaining it can require a cross-range transaction

5.9 Partitions, failure detection and split brain

Fencing token
Increasing number issued with a lock so storage rejects stale holders
STONITH
Forcibly powering off a node to prevent split-brain
Gossip protocol
Nodes share state with random peers, spreading it epidemically
Phi accrual failure detector
Outputs a suspicion level from heartbeat timing
Heartbeat
Periodic "I'm alive" message between nodes
Gray failure
Partial failure invisible to health checks but hurting real work
Asymmetric partition
A can reach B, but B can't reach A
SWIM
Gossip membership protocol with indirect probing
Zombie leader
Replaced leader that still thinks it's in charge
Epoch
Leader generation number used to reject stale leaders
Quorum loss
Too few members reachable to form a majority
Quorum device
Extra tiebreaker vote, often in a third site
Fail-stop
Failure model where nodes crash cleanly and stay down
Chaos engineering
Deliberately injecting failures to test resilience
Incarnation number
A per-node counter that increases when the node refutes a suspicion or restarts, so newer membership claims override stale death rumors
I/O fencing
Blocking a suspect node's access to a shared resource so it cannot write even if the process is still running
Fail-slow
A node that stays up and may pass some checks but serves work so slowly that peers experience hangs, timeouts, or an apparent partition
Eventually perfect failure detector
A detector that may make mistakes for a while but eventually suspects every crash and stops wrongly suspecting correct, reachable processes
Suspicion timeout
The window after a failed probe during which a node is suspected but can still refute the claim before it is declared dead
SCSI persistent reservation
A storage-level registration that can exclude other initiators from writing to a shared volume, used to fence a former owner
Membership protocol
The rules for joining, leaving, evicting, and spreading those changes so a cluster can converge on who is currently a member
Power fencing
Forcibly cutting power or equivalent hypervisor stop to a suspect node so it cannot keep acting as an exclusive owner

Sample practice questions

  1. What does the CAP theorem state?

    1. A system can always provide consistency, availability and partition tolerance together
    2. Every distributed system must give up partition tolerance to stay correct
    3. During a partition, a distributed store must choose consistency or availability
    4. Caching, availability and performance can't all coexist in one system

    Answer: C. During a partition, a distributed store must choose consistency or availability Partitions are unavoidable in real networks, so the practical choice during a partition is C or A.

  2. What is linearizability?

    1. Writes are applied to the data store in alphabetical order by key
    2. Data is always stored in a single linear array on one disk
    3. Operations appear to happen instantly at one point, in real-time order
    4. Reads are allowed to return any value written in the past

    Answer: C. Operations appear to happen instantly at one point, in real-time order Linearizable systems behave as if there were a single copy of the data.

  3. What is single-leader (primary-replica) replication?

    1. One node takes all writes and streams changes to read-only followers
    2. Clients write to several nodes at once and read from any of them
    3. Every node accepts writes and merges them with the others later
    4. Each table is stored on a different node with no copies at all

    Answer: A. One node takes all writes and streams changes to read-only followers The most common setup for relational databases.

  4. With N = 3 replicas, write quorum W = 2 and read quorum R = 2, why do reads see the latest write?

    1. Because the quorum size of 2 is greater than a quorum of 1
    2. R + W > N, so every read overlaps a replica that has the write
    3. Because reads and writes are always sent to different replicas
    4. Because the replica count N is an odd number, not an even one

    Answer: B. R + W > N, so every read overlaps a replica that has the write Dynamo-style stores such as Cassandra let you tune R and W per request.

  5. What problem do consensus algorithms such as Raft and Paxos solve?

    1. Nodes agreeing on a log or leader despite failures
    2. Encrypting all of the traffic between cluster nodes
    3. Load balancing HTTP requests across web servers
    4. Compressing data before it's replicated to followers

    Answer: A. Nodes agreeing on a log or leader despite failures etcd, Consul and many databases use Raft; Google's Chubby and Spanner use Paxos.

  6. What does Google Spanner use to provide globally consistent (externally consistent) transactions?

    1. A single global server that handles every write
    2. TrueTime's bounded clock uncertainty, plus Paxos
    3. Eventual consistency with last-writer-wins merges
    4. Timestamps supplied by each client application

    Answer: B. TrueTime's bounded clock uncertainty, plus Paxos Spanner waits out the clock uncertainty before committing to guarantee ordering.

  7. What is the main risk of "last-writer-wins" conflict resolution?

    1. It always keeps both versions, so storage use grows without any limit
    2. It requires a full consensus round for every single write operation
    3. Concurrent updates are silently lost, and skew can let older writes win
    4. It can't be implemented in any real-world distributed database

    Answer: C. Concurrent updates are silently lost, and skew can let older writes win It is simple and common (Cassandra uses it), but only safe when lost updates are acceptable.

  8. What is two-phase commit (2PC)?

    1. Running a transaction in two regions and keeping the faster one
    2. A coordinator asks all participants to prepare, then tells them all to commit or abort
    3. Committing each change twice to make sure it reaches the disk
    4. Splitting a transaction into a read phase and a write phase

    Answer: B. A coordinator asks all participants to prepare, then tells them all to commit or abort Atomic across nodes, but blocking.

  9. What is a fencing token?

    1. A password that lets a node join the cluster
    2. A token that blocks traffic at the network firewall
    3. A signed cookie used to keep users signed in
    4. A rising number issued with a lock, so storage rejects stale holders

    Answer: D. A rising number issued with a lock, so storage rejects stale holders Storage rejects writes with older tokens.

  10. In CAP, what does "consistency" mean?

    1. The database enforces all foreign key constraints
    2. Every server is running the same software version
    3. Every read sees the latest write or returns an error
    4. All data is stored in one consistent file format

    Answer: C. Every read sees the latest write or returns an error This is different from the C in ACID, which is about integrity constraints.

Practice all 2,516 questions

More Architecture