Say I have a shop application and I want to make some complicated validations for that operation.
- Events are the single source of truth in my system.
- Adding a product is represented by a
ProductAddedmessage. - The microservice responsible for validating the product reads a message, validates it, and produces a
ProductValidatedmessage.
But what happens if I want to microservice to boot up from zero? On bootup, each and every message is reprocessed, resulting in a redundant and duplication of validation for each consumed message. This could be solved by first reading all messages from the messaging queue and when all messages are loaded, start an asynchronous process of validation.
But how can it ensure that all messages are loaded? maybe messages are produced quicker than the process of building the state from events. A solution could be querying the messaging queue for the total number of messages at a given moment. Then, reading all of them and process them. Then, query and process again.
The problem with this one is that it doesn't seem to me like a typical solution for this challenge. I want to find out what is a popular practice to do in this situation.