So I have a situation with a microservice architecture where I need to guarantee that incoming messages that have common identifier would be processed in order they come from kafka:
      message2, message1 kafka
     ------------------------------
             |message1       |message2
             |               |
         Instace1         Instance2
In the example below, I have two instances of a service that are processing messages from kafka, but I want to ensure that message2 is only processed after message1.
Apparently, this situation is easily solved by configuring one instance to consume only from a particular partition which would store messages with the common indetifier:
message2, message1 kafka
--------------------------------
       | message2
       | message1
     Instance1        Instance2
Now the order is guaranteed, and message2 will never be processed before message1.
However, I was wondering if this issue could be solved another way, directly in code instead of relying on infrastructure? This looks like it could be a standard problem in microservice architecture but I'm not sure what would be the preferred approach to solve it ?
 
     
     
    