Imagine this business logic. I'm buying a tshirt from a store that runs microservices and uses Kafka. When I submit my order the web back end saves my order and kicks out two async requests:
- Payment Service that handles authorizing my payment (credit card stuff).
- User Service that handles creating my user account (email confirmation step).
Both of those services write to their own kafka topics when they've finished. The web back end subscribes to these topics and when an event comes in it updates the order. Once the order back end has confirmed my user and payment information, it will send that order off to be fulfilled.
How do you prevent race conditions when both events come back at the same time?
If two processes both update the order at the same time, it never sees the complete order and you risk having complete orders that never get fulfilled.
If two processes both update and then immediately requery, they could both see a complete order and then we fulfill the order twice.
Thanks!