What is the CAP theorem and how does it apply to distributed systems?

Technical