Database – If a microservice architecture needs a separate database per microservice then it’s too costly & unmanageable. Why do we even need it

Architecturedatabasemicroservicesservicesweb services

I read about microservices and it seems illogical to me to create a separate DB per service just to achieve isolation. I can achieve the same using only web services and a single database. Why do we even need it? The thing that separate database is beyond discussion. Or I am plain wrong? Can you guide me on this?

Best Answer

Why do we even need it?

You don't.

Creating a separate database for each service helps to enforce domain boundaries, but it's only one approach. There's nothing stopping you from having all your services share the same database.

As long as your services behave and don't do unexpected things to data owned by other services, you'll be fine.

I don't know what you read, but you should be aware that there are many differing opinions on microservices architecture. Here's a good blog post on the topic.

I’ve seen folks refer to this idea in part, trivially, as “each microservice should own and control its own database and no two services should share a database.” The idea is sound: don’t share a single database across services because then you run into conflicts like competing read/write patterns, data-model conflicts, coordination challenges, etc.

But a single database does afford us a lot of safeties and conveniences: ACID transactions, single place to look, well understood (kinda?), one place to manage, etc.

The journey to microservices is just that: a journey. It will be different for each company. There are no hard and fast rules, only tradeoffs.

The Hardest Part About Microservices: Your Data

Related Topic