Utilizing shared service libraries
If you choose the uniform microservices approach, it is very useful to have a shared library (or several libraries) that all services use and implement many cross-cutting concerns, such as the following:
- Configuration
- Secret management
- Service discovery
- API wrapping
- Logging
- Distributed tracing
This library may implement whole workflows, such as authentication and authorization, that interact with other microservices or third-party dependencies and do the heavy lifting for each microservice. This way, the microservice is only responsible for using these libraries properly and implements its own functionality.
This approach can work even if you choose the polyglot path and support multiple languages. You can implement this library for all the supported languages and the services themselves can be implemented in different languages.
However, there are costs associated with the maintenance and evolution of shared libraries and the rate of adopting them by all microservices. A real danger is that different microservices will use many versions of the shared libraries and cause subtle (or not so subtle) problems when services using different versions of the shared library try to communicate.
The service mesh approach that we will explore later in the book can provide some answers to this issue.