Search code examples
clientmicroservices

Is it a good practise to share models between Microservice and Client library projects?


I am creating a REST microservice and a Client library for it. For both of them, I am going to use the same language (C# in this case).

Is it a good practice to share Response/Request models between those projects? Or my Client project should be independent and so have own (and actually the same) models?


Solution

  • Is it a good practice to share Response/Request models between ... a REST microservice and a Client library?

    Yes, it's a good practice. Request/response models are part of the service definition, so are one of the few things which should be shared between a service and its consumers. Vertical coupling between services and consumers is unavoidable, so should be embraced. Care should, however, be taken when sharing models between services.

    now I am confusing about the following: if another microservice will use that Client library

    I'm not sure what you mean - the service doesn't use the client library.

    Ideally, there should be no sharing of models between services unless they are models which represent cross-cutting concerns such as security, monitoring, etc.