We have the situation where we have Kafka messages of the same type, which are slightly in the wrong order. For example the Kafka topic has the following messages, each with a creation timestamp:
- Message X, 2021-04-26T19:16:16.010
- Message Y, 2021-04-26T19:16:16.030
- Message Z, 2021-04-26T19:16:16.020
Because of the way, the messages were produced, Message Z is in third position, but based on the creation timestamp should be in second position (before Message Y). The wrong order is only for messages e.g. within a timeframe of 1 second.
We have the requirement, that the Kafka messages are consumed exactly in the order of their timestamps.
One possible solution would be, to consume the messages, cache them shortly in some kind of persistent storage (long enough to gather all messages within above mentioned timeframe) and push them into another Kafka topic in the right order.
But I wonder, if there would be a "Kafka way" of doing this. One without a persistent storage. Could this re-ordering of messages be done with Kafka or Kafka Streams?