Açıklaması şöyle
Postgres says the price is 4.99.Redis says it is 5.49.What does the customer see?"Neither. Postgres and Redis should never disagree. That is why I update both in one distributed transaction."It sounds rigorous, but nobody runs it.Redis cannot join a two-phase commit. And even if it could, every price change would now wait on two systems, and fail when either one is down.So what do teams actually do?1. The price change commits in Postgres first. Only after the commit, the service deletes that product's key in Redis. This happens outside the Postgres transaction.2. If the delete fails, it retries. If it still fails, the key's TTL puts a limit on how long the old price can live.3. Some teams send the invalidation as an event instead, read from the database's change log. Nothing gets lost that way, but it is one more component to run.Either way, for a short window, the two prices can disagree.And that is fine. Because the price on the product page is not the price the customer pays.When they add it to the cart and check out, the price is read from Postgres. If it changed, they see the new one before they pay. You have seen this on shopping sites: one price on the listing, a "price updated" note in the cart.So the design question is not "how do I keep them in sync?"It is "where does the price have to be exactly right?"The product page can be a few seconds behind.The checkout cannot.In a design round, deciding where the data has to be exactly right is a step 1 decision, not a step 4 detail. I have a playbook with all 6 steps, the minutes for each, and the 4 traps that make people freeze.