置顶推文

CAP Theorem
CAP Theorem talks about tradoffs of disturbed systems
Here
C - Consistency (Every read request to the distributed system should return same result irrespective of whichever node we are reading from)
A - Availability (The system should respond to any request made to it irrespective of any node is failed or not)
P - Partition Tolerance (The system continues to respond/operate even though there is a network breakdown/partition between the nodes)
Before Diving into CAP theorem here is some background knowledge you should know
Distributed System : Data Stored in multiple servers instead of one(like we do when we apply horizontal scaling)
Why distributed systems?
> Spread Workload among multiple servers
> Can handle more number of requesss
> Improves overall performance
In distributed system we replicate same data across multiple systems to get the above benifits.
Server/s are called a node here.
Now let's talk about the CAP
Let's say there are there nodes X, Y and Z
Consistency says that whenever you read data from X, Y or Z they should return the same data and when you write then it should be propogated to other nodes to maintain consistency
Availability says that if B fails due to some hardware issue and go offline then A and C should still be working and should serve the requests
Partition Tolerance says if network partition happens on B and it can't communicate with A and C, then node B will still be serving requests even though it is not up to date with the data with other nodes(A and C) since it got a network partition.
CAP Theorem:
CAP Theorem states that in a distributed system, you can only guarantee two out of these three properties simultaneously. It's impossible to achieve all three
You can refer to the image below for clear understand about the statement once
Only the combination of
CA(Consistency-Availability), AP(Availability-Partition tolerance), CP(Consistency-Partition tolerance)
is possible
In distributed system there are very high chances of network partition so we should must handle P(partition tolerance).
So most of distributed systems choose either AP or CP because they can't afford network partition
What to choose between CP and AP
CP - if you can't afford inconsistent data then go for CP like banking, payment services where numbers are the most important thing
AP - if you can afford in consistent data but can't afford unavailability like social media can have slightly different likes, comments or views for different users but it can't have their apps down.

English












