Ensuring database consistency

If I have a distributed database that is ultimately consistent, what happens if I have something like a site where I sell products and I change the price of an item?

If a product has a price X and I update it to a price Y, some versions of the database may still show a price X. If a customer goes to check if there are strategies to make sure they are actually getting the most recent price information, so are they not getting charged wrong value?

At some point, shouldn't you perform a data consistency check to make sure the most recent value is being used?


source to share

3 answers

We used to have a custom script that tracked replication lag, but that was a few years ago. We have since switched to the Heartbeat Monitor provided by the Percona Toolkit .

You might also consider adding the product they've chosen to their session, so if the price changes before they check out, they won't receive a sticker.



Your database should have the price, the next price, and the date / time the price takes effect. Then check the timestamp on the trandaction when the user specifies the order. Then you must keep that price with a transaction that is effective from now on for that purchase.

Better create a unique identifier for the product / price combination and write it down when displaying the catalog - then there will be no surprises compared to what you offered them. (with some reasonable latency, of course, to prevent abuse.)



As Mike Purcell said, "You might also consider adding the product they chose to their session, so if the price changes before they check, they won't get hit on the sticker."

I think this is important to you, because if you are in the middle of updating both one and one chip and the other is not making a purchase at the same time, the user may fall into the wrong price trap.

If you're updating your databases without taking the entire site to at least a minute or two to do your updates, I can't think of a way to deal with this issue without running a script before each transaction makes a payment gateway request. Especially if your users are already in session.

Could you do something like searching for the item price position in each database before the user makes a request to the payment gateway, if they are identical, redirects back to the product page?

If the updates are second, I can see that this is a tangible solution.



All Articles