I'm trying to employ Materialized view in Microservices. So I have microservice A with own database and the same applies to Microservice B. Now I need to have data from microservice A to in microservice B, so according to pattern I've subscribed to events of change on data of microservice A. All is good until we run into how to populate data that exist prior introduction of additional fields to microservice B data model. I'm thinking of checking added fields from microservice A in data model B, if it's null then we go and get all the data missing and populate it right away. Is there any patterns on how to do it properly?
Below is data model related to microservice A:
{
"UserId": "a8a64066-b546-4b84-9296-4ae0a0f2b561",
"FirstName": "Alex",
"LastName": "Kosh"
}
DataModel related to microservice B:
{
"ProductId": "d5664066-b546-4b84-9296-4ae0a0f2b561",
"Count": "25",
"ProductPrice": "14.5",
"AddedByUserId": "a8a64066-b546-4b84-9296-4ae0a0f2b561"
}
What I wanna have after utilizing of materialized view on microservice B data model:
{
"ProductId": "d5664066-b546-4b84-9296-4ae0a0f2b561",
"Count": "25",
"ProductPrice": "14.5",
"AddedByUserId": "a8a64066-b546-4b84-9296-4ae0a0f2b561",
"FirstName": "Alex",
"LastName": "Kosh"
}
So as you can see we've added FirstName and LastName. It will work for all new products, like whenever we add a new product we request user info and populate it. The problem here how to update old products that do not have FirstName and LastName with values?
Aucun commentaire:
Enregistrer un commentaire