I have this situation:
microservice MS1 has a db, let's say with N records, and an external source provides new data that, if valids, should be persisted
validation process is performed by a microservice MS2 that is a consumer of a kafka topic T1, on which MS1 sends the new data
the validation of the potential N+1 record involves query on all the previous N records. If the validation is successful MS2 produces the result on topic T2, on which MS1 is consumer,so it can persist the new,valid,data.
The problem is the following.
Imagine that the N+1 valid new data is too big and needs a lot of time to be writed on db: it can happen that validation of potential N+2 record fails because querying the db there are only N available record, instead of N+1.
Is it possible, using kafka capabilities in some way, to pause the validation process until MS1 has committed the previous valid data on the db?
Not using kafka, the only way that i have found to ensure validation queries on a up-to-date db is to make rest call between the two microservices, so to wait the each other responses.
Any help or new solution would be really appreciated.
Thanks!