Database per Service Pattern

Play
The write-up below meant to be a companion to the video above. Please watch the above video to build a better understanding.

Microservices typically rely on databases to manage their state effectively. We explore various scenarios involving microservices such as order services and payment services. These microservices can either share a common database or possess their own distinct databases, depending on their specific requirements.

The database per service pattern primarily offers the advantage of promoting loosely coupled components, enabling teams to operate independently. This autonomy grants teams the freedom to choose database technologies that best meet the specific needs of each service they manage.

When selecting a database for microservices, it’s essential to consider the specific use cases, as different scenarios demand various database technologies. For instance, chat services need a database that can handle high write throughput, while profile services may find schema-less databases more advantageous. Ultimately, the choice of database plays a crucial role in determining overall performance and scalability.

Utilizing separate databases enables each service to scale independently, tailored to its specific requirements without impacting others. This approach allows for the application of various scaling strategies—both horizontal and vertical—across different database types, optimizing performance and resource allocation.

Database failures can significantly affect services; however, the impact is often contained when databases are isolated. This approach not only minimizes disruption but also simplifies the management of compliance requirements for sensitive data.

The database per service pattern, while beneficial, poses several challenges. It complicates cross-service transactions and requires additional infrastructure for effective monitoring and management.


Arpit's Newsletter read by 100,000 engineers

Weekly essays on real-world system design, distributed systems, or a deep dive into some super-clever algorithm.