CAP in Desc
A very important theorem which helps you to design your distributed application. Ohhh, Please focus on the word “Distributed Application”.

Here distributed application means a cluster of servers that can host applications or databases. So what are the major problems you face in a distributed architecture?
There are many problems, but I will be mainly focusing on three major issues:
A. How we can make sure that whatever data we are writing or reading to/from nodes, it should be the same for/from all nodes.
B. If any request of reading or writing comes to the cluster it should always respond no matter what is in the response.
C. Let’s say one of the servers from cluster got corrupted so in that case how the architecture should respond?
Let’s understand each problem with an example: —
We have two database servers: S1, S2 and both are part of the same cluster(same type of data), so these are the possible combinations I can think of: —
C1: One server to read or another server to write but both will have same data.
C2: Both servers to read and write but can have different data.
C3: Both servers read and write but can have same data.
Note: Let me know if you can think of more.
Let’s take the C1(First Combination):
S1: Reads and S2: Writes: — So what do you think, in which problem category will fall???
It will fall to Problem-A and C, How???
Let’s S2 is wrote something and immediately S1 got read request for the same data, so S1 won’t be able to provide data at that time because S1 has not copied the data yet from S2, which will generate inconsistencies in data. So what if one of the servers goes down then another server has to do both works.
Let’s take C2: So what do you think, in which problem category will fall???
It will fall to Problem-B and C, How???
Let’s say, S1 has 1M hot details and S2 has the remaining details(but similar to S1’s details). One of the servers is unreachable due to some network issues, so now we don’t have another way to get data from that unreachable server. But in the real world, this scenario is rarely gets encountered because we keep enough replicated servers to avoid the issue.
Let’s take the last one, C3: So what do you think, in which problem category will fall???
So here one server will act as a replica of another server. So it might produce problem-A or Problem-B or even Problem-C. It completely depends on how we have design combination 3.
Let’s say S1 is acting as master node(leader) and S2 as a slave(child) and S1 goes down while processing read/write requests then it will produce problem-B because at that time slave will be getting elected as the master node.
So here we have understood all three types of problems, which implies to a theorem, CAP theorem.

Let’s see the definitions:
CAP theorem states that it is impossible for a distributed software system to simultaneously provide more than two out of three of the following guarantees (CAP): Consistency, Availability, and Partition tolerance. When we design a distributed system, trading off among CAP is almost the first thing we want to consider. CAP theorem says while designing a distributed system we can pick only two of the following three options:
Consistency: All nodes see the same data at the same time. Consistency is achieved by updating several nodes before allowing further reads. It signifies problem-A.
Availability: Every request gets a response on success/failure. Availability is achieved by replicating the data across different servers. It signifies problem-B.
Partition tolerance: The system continues to work despite message loss or partial failure. A system that is partition-tolerant can sustain any amount of network failure that doesn’t result in a failure of the entire network. Data is sufficiently replicated across combinations of nodes and networks to keep the system up through intermittent outages. It signifies problem-C.
So that’s why in the above Venn diagram, there is no common area.
But in the real world, we bit of C and bit of A on top of P to make the application more sustainable. Let’s take an example: MySQL servers only. According to the definition of the database, it falls under C-A area considering there will be only one server but in the real world we keep more that one database server as master-slave architecture.
CAP theorem helps you to design the your application, keeping in mind the best possible scenario to handle all use cases.
Note: C1- is a typical example of SQL server and C3- demonstrate Cassandra while C2 can help to explain consistent hashing.
So that’s all my friend. Let me know if the content needs improvement.