Interview Questions

CAP Theorem

The CAP theorem explained: why a distributed system hit by a network partition must choose between consistency and availability, with CP and AP examples.

  • 7 min read
  • 5 questions
  • +35 XP
Transcript

CAP Theorem, explained by cats. Kitty runs a distributed system. Many servers. Many cats. but only One tuna database. Then the network breaks. Some cats can’t talk to the others. Now Kitty has a problem. This is where CAP Theorem appears.

The theorem says: when there’s a network partition, Kitty can only fully choose two out of three: One: Consistency every cat must sees the same data. Two: Availability every cat gets a response, even if it’s not the latest one.

Three: Partition Tolerance the system keeps working even when cats are split apart. Partition tolerance is not optional. In distributed systems, networks fail. Cats get separated. So the real choice is usually: Consistency or Availability. If Kitty chooses consistency, some cats may have to wait.

No stale tuna allowed. If Kitty chooses availability, every cat gets an answer. But maybe not the newest tuna count. That’s CAP Theorem. in a broken network, you can’t have everything. Distributed systems are hard because sometimes the cats can’t talk. And Kitty must choose what matters more.