Lets say i have 2 microservices (Service A, Service B) which can call each other both ways, lets say if A calls B then some parameters of response json of A will be consumed as some other parameter of request paramater of B
now i realized, this problem can be better addressed by using Canonical data model, so that each service consume/produce a canonical data model,
My question is how should a canonical model in this case(json) should look like
suppose response of A looks like
{
"A1": false,
"A2": {
"width": 5,
"height": 10
},
"A3": "A green door"
}
and there would be corresponding json schema, which i am not including here
Similarly request of B looks like
{
"B1": false,
"B2": {
"width": 5,
"height": 10
},
"B3": "A green door",
"B4": ""
.
.
}
Attribute A1 is mapped to B1, should my canonical data model only include this first attribute with some name (business name: eg -->A1 is score B1 -->Report then buisness name might be --> Points) that commonly relates to both the microservice or should it be more of a aggregation of both json with each attribute replaced with corresponding business name?
In theory a "traditional" canonical data model should not be required with a well designed microservices architecture due to the fact that each service has its unique domain of responsibility and only models the data from their specific domain. So when a service consumes other services the data overlap should be minimal. And when consuming another service the data modeling responsibility lies with the source rather than the consumer.
However in practice that may not always be the case, e.g. you'll have to pull data from similar but not identical sources. So to your question - if you find the need to transform the services' data into a canonical model you'll probably want to perform translation to a single representation (your first idea) as soon as possible, rather than keeping both representations (your second idea). This will help with simplicity of consumption further downstream (imagine the messy consumption code where you need to check multiple places in a data structure). If the services are under your control you may want to evolve them towards providing data in the canonical model in the first place.