Search code examples
microservices

How to scale microservice if not sharing database


https://dzone.com/articles/breaking-the-monolithic-database-in-your-microserv

When I want to scale a service (order service), if each instance of order have their own database then we will have incomplete data when some of the order service is down.

Or those same service is using one shared database when scale up? Then it means the database must have redundancy server?


Solution

  • That article only says that the order service should not share the database with other services.

    If you want to scale up the order service (horizontally) to multiple instances those instances could still share a single backing database (which you would need to scale vertically if the load goes up). This does not violate the principle of not sharing databases between services (because everything still stays inside of the order service).

    Or you could partition/shard the database as well to horizontally scale the whole thing.

    Either way, your database needs to be available for the service as a whole to be available, so if you scale it horizontally (i.e. you have more than one node), you will want redundancy as the risk for instance failure is higher for N instances than it is for 1 instance (on the plus side, in a sharded setup, if you lose 1 of the N shards, the other N-1 might still be available so that you can continue to serve parts of your customer base -- whereas a single node vertically scaled database brings down everything when it goes offline).