Reputation: 275
I'm trying to get familiar with CQRS and microservices architecture, I understand that CQRS consists of separating read models from domain models and you have a particular service with it database for every read model to optimize the query side.
But as someone who's only used to a monolithic architecture I don't understand how you deal with relational data if they live in different services; let’s say for example I have a users microservice and a posts microservice with their read models, how am I supposed to query the posts with each user that published them, how can I manage related data between different microservices?
Upvotes: 0
Views: 532
Reputation: 57257
I have a users microservice and a posts microservice with their read models, how am I supposed to query the posts with each user that published them, how can I manage related data between different microservices?
You copy the data from the durable storage of the service that owns it to some common location that can build and update the view you want.
A simple implementation of the plumbing might be to have a timer that fires on some schedule, and each time the timer fires you pull updated information into your view, applying any transformations that you might need.
There's some latency, in that it takes time for the change made by the service to propagate to the views, but that's part of what you signed up for when you decided that users and posts should be serviced separately.
Let's say I have a view with the posts and the user's data needed. If the user updates his informations does this mean that I would have to update the data of each post published by that user?
"It depends". You might, for example, be copying the data into a relational database: if your views are described by relations, then updating the user would necessarily update the underlying data for all of the views; any representation of the view constructed after the database update would have the new data.
On the other hand, if you were using a document store, then you would probably need to either update all of the afffected documents, or design those documents with a link relation to the user document. This might be clearer if you think about the different ways that you can combine information on the web.
Upvotes: 1