cap The theorem refers to , In a distributed system , Can only satisfy cap Two of them .
C consistency Uniformity
A availability Usability
P partition tolerance Partition fault tolerance -- In case of any partition network failure, the system can still continue to operate
The Internet is not reliable , So you should support partition fault tolerance , And need to make a trade-off between software availability and consistency .
Why can't we satisfy C and A
- In general distributed systems, we must first ensure P（ Partition fault tolerance ）
- Consistency means that the data returned by all nodes is consistent
- Availability refers to the availability of the server within normal response time
- Suppose a distributed system has two services A and B, stay A Modify the user name of the service admin, Change to user
- If consistency is to be met , That is, the data returned by all nodes is consistent , visit B The service , stay A During data modification by the service , Need to lock B Service read and write operations , After the modification is completed A and B The service returns updated data , This does not guarantee availability （ Because there is a lock time ).
If you want to ensure that you can , You cannot lock during data modification B Read and write operations of the service , After this modification ,A Return the updated data ,B Return old data , Does not satisfy consistency .
- Data sensitive to data in the system , For example, the price of goods , stock , Consistency needs to be guaranteed , Discard availability .
- For data that is less sensitive to data , For example, the name of the product , The avatars , Nickname insensitive data , Availability needs to be guaranteed , Give up consistency .
Web page update
- CAP The meaning of the theorem Ruan Yifeng