CAP Theorem and Consistency Models Questions
Understand the CAP theorem and how Consistency, Availability, and Partition Tolerance interact in distributed systems. Know different consistency models including strong consistency such as linearizability, eventual consistency, causal consistency, and session consistency, and how to apply them to different use cases. Be familiar with consensus protocols and distributed coordination primitives such as Raft and Paxos, quorum reads and writes, two phase commit and when to use them. Understand trade offs between consistency and availability under network partitions, patterns for hybrid approaches where different data uses different guarantees, and the product and developer experience implications such as latency, stale reads, and API contract clarity.
Sample Answer
Sample Answer
Sample Answer
Sample Answer
def compare_vector_clocks(A: dict, B: dict) -> int:
"""
Compare two vector clocks A and B.
Returns:
-1 if A happened-before B
1 if A happened-after B
0 if concurrent
2 if equal
Missing keys imply zero.
"""
keys = set(A) | set(B)
a_less = False
a_greater = False
for k in keys:
av = A.get(k, 0)
bv = B.get(k, 0)
if av < bv:
a_less = True
elif av > bv:
a_greater = True
# early exit: if we already saw both directions, they're concurrent
if a_less and a_greater:
return 0
if not a_less and not a_greater:
return 2
if a_less and not a_greater:
return -1
if a_greater and not a_less:
return 1
return 0 # fallback (shouldn't reach)Sample Answer
Unlock Full Question Bank
Get access to hundreds of CAP Theorem and Consistency Models interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.