Click here to solve this RACE CONDITION challenge in a DISTRIBUTED purchasing SYSTEM.
DISCLAIMER: It is a simplified and hypothetical scenario. (The diagram is in English because you guys are all stupid, but know that I prefer it in pt_BR ).
I believe this challenge is suitable for those who are already accomplished – perhaps Sandy and Junior will struggle a little to solve it.
SCENARIO: A set of applications with asynchronous customer registration and purchase payment processing services.
However, there is the assumption that a customer must already be persisted in the payments service bank for payments to be processed.
And for this premise to be satisfied, the registration service issues an event whenever a customer is registered. The image shows this flow.
(Note: This pattern in which the payment service stores a customer reference is called "Event-Carried State Transfer"
THE PROBLEM:
However, for new customers, it sometimes happens that the command to process the payment is consumed before the customer registration event is consumed. We have a RACE CONDITION scenario!