Hopefully this topic is not opinionated and I could maybe get meaningful answer please. Our problem is, imagine you have two microservices: Car
and Driver
. DTO of the driver could be let's say as following:
DriverDTO
{
id: 1,
name: "John Smith"
}
and CarDTO:
CarDTO
{
name: "Ford",
driver: {
id: 1,
name: "John Smith"
}
}
This model involves composition of microservices which could be not very nice way how to maintain loose coupling between services - if you update DriverDTO (no breaking change, just adding a field), you have to update all the microservices consuming it if they need it, because frontend is expecting from "driver":
just the whole model as provided in Driver
service.
If we do it as following:
CarDTO
{
name: "Ford",
driverId: 1
}
Then we need to do additional request from frontend. This could be solved by service composer though.
We have to decide between two choices:
1) We are thinking about service composition in API gateway, so basically frontend -> API gateway (Spring Zuul) -> (2 calls, to car AND driver service)
and it will create a nice composed result as seen in the second code block above.
2) We have to stick with to the approach - the Car
service (and other service as well) are consuming it and they need to add a new field if they REALLY need it. So the field driver:
does not have the same format across all microservices.
What do you think?
driver
. So ti means that all other services which havedriver
field (they include DTO object from driver service) have to be updated to have this new field. Because in Java all fields have to be defined to expose them. It means that every service which is including DTO driver, should update this DTO, so that they can expose all fields from the original driver DTO from driver service.