DEV Community

Discussion on: Should you explicitly define APIs when using Microservices?

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

It depends. I think it's best not to mess with Conway's Law, so...

  • define explicit APIs (and version them) when the service is available to other teams
  • don't, if your team owns the code of all consumers

I think this distinction should be made explicit (e.g. naming conventions) and it should be made very early, maybe as soon as when creating a microservice. You might argue that microservices start with few consumers, maybe a single consumer within your team, but then become popular and are consumed by many others. I don't think that's the case in a corporate environment - here you can plan very well who the possible consumers of your microservice will be.

If in doubt - start with a private microservice. Then, when another team has pretty similar requirements, build a new public microservice that satisfies both teams' requirements. Let the other team use the new microservice first. Fix errors and add missing features. Finally, when the other team is happy, migrate your own code from the private to the public microservice and shutdown the now obsolete private microservice.