Home >Backend Development >PHP Tutorial >Data consistency issues
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
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