This is the seventh day of my participation in the August More text Challenge. For details, see: August More Text Challenge
preface
Data consistency is generally a problem of data consistency between multiple systems or multiple databases
In a distributed system, consistency refers to the result of read and write operations on a logical data copy that has multiple physical data copies.
In a database, consistency and transactions are closely related. Consistency in a distributed database is essentially talking about data consistency and transactional consistency.
Data consistency
Strong consistency (linear consistency)
- Analysis: After the update operation is complete, any access by more than one subsequent process will return the latest updated value. That is, what did the user write the last time and what is guaranteed to read the next time
- Scenario: Payment function. After the payment, the balance in the account needs to be updated in real time. When the balance in the account is read again, the updated amount is read.
Weak consistency
- Analysis: After the data is written successfully, the system does not promise to read the latest updated value in real time, nor does it guarantee when it can read the updated value
- Scenario: It takes a period of time for a user to read that an operation updates system data. For example, after completing a test, it may take some time for the test report to be read
Final consistency (special case of weak consistency)
- After the system updates data, all copies of the data, after a period of synchronization, can finally reach a consistent state. The essence of final consistency is that the system is required to guarantee final consistency, not immediate consistency.
- The end result is consistent, and the main impact may be network latency, system load, or synchronizing multiple replicas in the absence of faults
Ultimate consistency is divided into more models based on the different guarantees it provides
Causal consistency
- Analysis: there is a causal sequence of operations, after the pre-process processing by the post-process processing.
- Scenario: After process A updates some data, process B notifies process B. Then process B obtains the updated data from process A. If process B operates on the data, it is based on the latest updated value of process A
Session consistency
- Analysis: The process of accessing system data is framed in a session, and the convention is that the system can ensure the consistency of “read by yourself” in the same valid session.
- Scenario: There is a distributed session consistency problem
In short, in actual business scenarios, different businesses have different requirements for data inconsistency, which can be used according to ACID and Base theory.