If you have been reading about microservices and databases, most sources seem to (loudly) agree that each microservice should use its own database. This ensures that each service owns its own data, and helps keep the services decoupled. The services then typically communicate with one another using a service bus, with the messages being part of the services’ public API.
However, having separate databases is not a necessary requirement for achieving decoupling. Given some prudent design decisions, a single, shared database can alleviate a lot of the pain points of multiple databases while still allowing control over a service’s public/inter-service API.
What ensures a good separation between services is data ownership (data is only modified by one service) plus well-defined, contractual public APIs. A database can be just another inter-service API, not too different from service bus messages.
Continue reading “Database as public API between microservices”