5

So, I just started to learn about the microservices architecture so forgive me if this is an obvios question..

Let's say I have created 2 microservices User and Posts, each one has it's own DB and its decouple from one another trying to follow good practices, the architecture looks something like this:

enter image description here

Now, suddenly, I start to get a surge of calls to my Posts microservice and its too much for it to handle the requests so I want to scale it and create a new instance of it.

Now I have 1 instance of User And I have 2 intances of Posts

Are these 2 instances of Posts sharing the same DB or each instance has it's own DB and I have to find a way to sync both of them to maintain data consistency?

Salvador Molina
  • 315
  • 4
  • 17

2 Answers2

5

Are these 2 instances of Posts sharing the same DB

Yes they are sharing the same Database.

Regardless of the fact that you micro-service is deployed to multiple instances or one instance the deployment instances of your micro-service are accessing and using your one database which belongs to that micro-service. All your instances of your micro-service should access the same database. This is the standard and most common use case. There are exceptions to this. Here is an similar question where I explained it in detailed way.

xargs
  • 2,741
  • 2
  • 21
  • 33
2

All your Microservice (Posts) instances will be sharing single DB.

Generally it's a single Database against all of your particular micro service (Post in this case) instances. However in some cases we can have master copy of DB accompanied by read-only copy to divide the read and write traffic to different respective DBs. We now even have multi master configuration available where we could have even more than one master however that architecture require more thought and generally suitable for very high traffic sites.

Imran Arshad
  • 3,794
  • 2
  • 22
  • 27