Why can’t CAP have both


Why can’t CAP have both in a distributed environment? This problem can be deduced on a chessboard. The key to this problem is to assume that there is a network partition. If P is obtained, that is, the existence of network partitions is tolerated, then C and A can have both.
It can be divided into two situations for further deduction.
Case 1: If there is no copy of data in this distributed system, then the system must meet the condition of strong consistency, because there is only one data and there is no possibility of inconsistent data. At this time, the C and P elements are available. However, if the system has a network partition condition or a machine outage, some data will inevitably be inaccessible. At this time, the availability condition cannot be satisfied, that is, CP system is obtained in this case, but CAP cannot be satisfied at the same time.
Case 2: if there are duplicates of data in the system (see fig. 2-2), assume that variable x has two duplicates and is stored on different machines. the initial data is consistent and its value is v1. At the time of Time=t1, a value update operation for x occurs on machine 1, which assigns the value of x to v2. When time passes to Time=t2, X on machine 1 has been assigned a new value v2. If no network partition condition occurs at this time, the system can synchronize the new value v2 of X to machine 2 to meet the data consistency requirement. However, if a network partition occurs at this time and the two machines cannot communicate, then the new value of x cannot be synchronized to machine 2. at this moment, we have to make a trade-off and choice between c or a. If the system is expected to be highly available (option A), then the query request for reading X on machine 2 must return a value within a limited time, and the latest value v2 is not returned at this time, so the problem of inconsistent data occurs (discarding C). If strong consistency is selected (select c), the x read request from machine 2 must be rejected before the two machines resume communication and synchronize the data to a consistent state. at this time, the availability of the system cannot be guaranteed (discard a). Therefore, no matter which one is chosen, it must be at the expense of another factor, that is, either AP or CP, but there is no perfect CAP.