0

I understand that sharing code between microserices in an anti-pattern, but what about sharing DTOs between the API Gateway and the services it communicates with?

Is it better to copy all of the DTOs from all of the services into the gateway?

Or is it better to have a common module that can be reused by the gateway and each service?

kraikov
  • 53
  • 6
  • by sharing DTOs, do you mean via library? If so, it is OK, but know that you are introducing coupling between the library and the services. If you update the DTO library, then you might need to update the library version to all the services as well. This pattern is usually done for API Clients. To make it easier for client services to create api requests. – froi Sep 16 '22 at 14:33
  • Yes, via library. But not between the services, but only between the Gateway (BFF) and the services. – kraikov Sep 17 '22 at 07:12
  • 1
    I guess that's more acceptable if it's limited to the BFFs. – froi Sep 19 '22 at 04:23

0 Answers0