Home >Backend Development >PHP Tutorial >Data consistency issues

Data consistency issues

WBOY
WBOYOriginal
2016-09-19 09:16:261491browse

In a piece of code, mysql, redis, and mongodb are operated at the same time. How can we ensure the consistency of data between these databases?
For example, msyql saves field A, redis saves field B, and mongodb saves field C. How can we ensure that ABC succeeds or fails at the same time

Reply content:

In a piece of code, mysql, redis, and mongodb are operated at the same time. How can we ensure the consistency of data between these databases?
For example, msyql saves field A, redis saves field B, and mongodb saves field C. How can we ensure that ABC succeeds or fails at the same time

Although the operations are simultaneous, each database is processed differently and there is no guarantee that they will all succeed.
The final success can be considered when all three processes are successful. If one fails, it is regarded as a failure.

Is this setting correct?

I think redis and mysql transactions are easier to operate. Start the transaction before inserting and the mongodb operation is successful. Commit together and rollback together

Because three types of databases are involved, there should be no ready-made XA protocol to ensure strong consistency of each database. So you can settle for the next best thing and ensure eventual consistency.
Distributed Transaction 1
Distributed Transaction 2

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn