upfront: I have read some articles now about Kafka in combination with microservices and understand that there are multiple ways you could use it. I just wanted to ask a small question because I am still not quite sure if I really got the whole idea:
So let's start with a small example (keep in mind that this is just an example): Let's say I have a service storing users and another one storing blog posts. Let's say when I have to persist a new blog post I have a userId but I would like to also store the username with the blog post. We obviously don't want to make sync calls to the user service so we look for another solution, in this case one with Kafka.
If I got it right the user service should always publish updates to a Kafka queue when a user is updated in it's db, what I am still not sure about is how the blog service would extract the latest username from that queue.
What I have seen so far: The event are change events and the blog service rebuilds the db on its own end by reading all events. The issue I see here is with years of events this could take a while if a new instance spins up. The other thing I saw was reactive Kafka queries and that it is somehow possible to query that internal state of Kafka to get the latest info.
So finally my questions:
- Is my approach to publish updates on the user service (that is owning the user data) to some kind of queue in some kind of way, or would this be done in another way?
- What exactly are now the possibilities the blog service could use to get that username by the userId it has (from that queue)?