Question

If I have a distributed database that is eventually consistent, what happens if I have something like a site where I'm selling products and I'm changing the price of an item?

If a product has price X and I update it to price Y, some versions of the database might still show price X. If a customer goes to check out, are there strategies to ensure they are actually getting the most up to date price, so they don't get charged the incorrect value?

At some point, don't I need to do some integrity checking of the data to ensure the most up to date value is being used?

Était-ce utile?

La solution

We used to have a custom script which would track the replication lag, but that was a few years ago. Since then, we have moved to the heartbeat monitor provided by Percona Toolkit.

You may also want to consider adding the product they selected to their session, so if the price does change before they checkout, they won't get sticker shock.

Autres conseils

Your database should have a price, a next price, and a date/time when the price becomes effective. Then check the timestamp on the trandaction when the user indicates the order. You should then store that price with the transaction as effective from then on for that purchase.

Better, create a unique identifier for an item/price combination and record it when you display the catalog - then there won't be surprises compared to what you offered them. (of course with some reasonable timeout to prevent abuse.)

As Mike Purcell said: "You may also want to consider adding the product they selected to their session, so if the price does change before they checkout, they won't get sticker shock."

I think this is important for you because if you are in the middle of updating both and one finsihes but the other doesn't at the same time a purchase is being made the user may get trapped into the wrong price.

If you are updating your databases without bringing the whole site down for at least a minut or two to make your updates, I can't think of anyway to deal with this problem without running a script before each transaction makes a request to the payment gateway. Especially if your users are already in session.


You could do something like make a lookup for the item price in each database before a user fowards the request to the payment gateway, if they arent identical, redirect back to the product page?

If the updates are a second apart I could see this being a tangible solution.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top