What is CAP Theorem?
THE CONCERT TICKET DILEMMA
You are building a ticket booking system with servers in New York and London. One ticket remains for a sold-out concert.
Alice in Boston and Bob in Paris click "Buy" at the same moment. Alice hits New York, Bob hits London. Right then, the network between data centers goes down. The servers cannot communicate.
Choice 1 (Consistency): Both servers say "Cannot complete until I confirm with the other server." Alice and Bob both get errors. Frustrating but fair: nobody gets double-sold.
Choice 2 (Availability): Both servers say "You got it!" and complete the purchase. But there was only 1 ticket. Now you must call one customer and say "actually, we oversold." Terrible experience.
This is CAP. During the partition, you choose: refuse both requests (consistency) or serve both and deal with conflicts later (availability).
THE THREE GUARANTEES
Consistency: Every read returns the most recent write. Never see stale or conflicting data.
Availability: Every request gets a response. No errors just because freshness is uncertain.
Partition Tolerance: System works when network failures split nodes into groups that cannot communicate.