Microservice database shared with other services

What I was looking for but cannot find a direct answer to this:

For this service, if there are two instances of this service deployed on two machines, do they have the same permanent store or do they have separate stores with some synchronization mechanism (master / slave, clustering)?

eg. I have an OrderService supported by MySQL. We get a lot of orders, so I need to scale this service, so we are deploying a second OrderService. Where does his data come from?

This may sound silly, but for me, every discussion makes it seem like a service and a database are a packaged unit that is being deployed together. But several discussions mention what happens when you deploy the second service.

+4
source share
1 answer

Conducting this as an answer because it is too long for comment.

Microservices are autonomous components and as such are responsible for their own data. If you want to receive data, you should talk to the service API. This applies mainly to different types of services (i.e. you do not use a database among services that offer different types of business functions - this is bad practice, because you are doing a couple of services on a heap through a database, and then easily combine more things , which are usually performed at the API level, but it is more convenient to do them through the database => you risk losing componentity).

, , , : .

, :

  • OrderService ?
  • , . ? , . ? , .
  • ? , ? ? ?
  • ..

, , , : . , , , , //, - . , (.. , , ). , . , - , .

+4

All Articles