What is the CAP theorem and how does it inform your choice of database?
sql-sys-001
Your answer
Answer as you would in a real interview — explain your thinking, not just the conclusion.
Model answer
The CAP theorem states that a distributed data store can guarantee at most two of three properties simultaneously: Consistency (every read receives the most recent write), Availability (every request receives a non-error response), and Partition Tolerance (the system continues operating despite network partitions). Since network partitions are inevitable in distributed systems, the real choice is between consistency and availability during a partition. Traditional relational databases like PostgreSQL running on a single node sidestep the dilemma entirely — they are CP by nature when run as a single writer. Distributed SQL databases like CockroachDB or Spanner prioritise CP: they refuse writes rather than risk stale reads during a partition. Cassandra and DynamoDB prioritise AP: they allow writes and reads to diverge, offering eventual consistency. In practice I choose relational databases when I need strong ACID guarantees for financial or transactional data, and I accept eventual consistency in distributed caches or activity feeds where staleness is tolerable.
Follow-up
How does the PACELC theorem extend CAP? Why is latency-consistency tradeoff important even when there is no partition?