r/java • • Dec 12 '19

Java Microservices: A Practical Guide

https://www.marcobehler.com/guides/java-microservices-a-practical-guide
237 Upvotes

35 comments sorted by

View all comments

Show parent comments

3

u/DJDavio Dec 13 '19

How do you prevent out of order processing with multiple instances? If service A sends message 1 and 2, but 2 is processed faster than 1, now what?

We use notification pull to mitigate this. Queues are used for notification triggers which cause receiving services to do a REST call to the submitting service to get the current data, which could have changed already.

2

u/randgalt Dec 13 '19

We use SQS which is loosely FIFO. However, there are techniques you can use in cases where ordering is strictly needed. Queue messages should contain timestamps and those timestamps can be used when inserting into your database so that even if a message is received out of order it doesn't overwrite the previously inserted message as it will have an earlier timestamp.

1

u/remixrotation Dec 20 '19

How do you sync clocks for the timestamps?