Suppose that I have this microservices architecture and they all interact using pubsub.
Basically, if a car sale is made, it will do task 1, which leads to task 2a & 2b, and if leather seat is available, task 3 will be executed. Note that task 2a & 2b happens at the same time since its a pubsub
In theory, this works perfectly, however in practice, I am finding cases where task 2b & 3 is executed before 2a is executed. This causes task 3 to cause errors since CAR 123 has not yet been made from task 2a.
I am thinking of adding a delay when task 2b is being executed, but I was wondering whether there is a "more standard" way of solving this type of issue ?
(And no, we can't change task 3 to upsert command)
To get this to work as you want, you can have Sales and the Leather Seat service publish to the same topic.
If the topic has one partition, then Sales message will always be before the message produced from Seat Service.
If the topic has multiple partitions, set the same value(some sort of ID, uuid preferably, to not create hot partitions) as the partition key on both messages, so both messages can be produced on the same partition and still maintain the order you need.