Code reusability best practices

Imagine you have 15 micro services, all written in Go, all created and maintained by the same team. Ideally, code that can be reused should be reused.

What are best practices to increase reusability ?

One problem is that the knowledge about what already exists and can be reused, needs to be kept updated. Is there a way to maybe document, in a central place, what can be reused from each micro service ? Have you had practical experience with this ?

Create a shared module that can be imported by your microservices.

You’re talking about surface area on your module and godocs. Some good reading on this subject:

So, create a module and publish it for your team. Keep your public API surface area as small as possible and well documented using go doc comments. If you have breaking changes, release a new major version, etc.

In terms of team knowledge (how do they know to use the shared module in the first place?), you generally would address that in pull requests. Let’s say you have some strange data format your team has to deal with. You create a function in yourOrg/shared called MarshalStrangeFormat. You notice in one of your microservices that somebody created their own implementation of MarshalStrangeFormat. You can tell them in a pull request that there’s shared central code to address this already and they refactor to the shared code.