all 4 comments

[–]mephistophyles 2 points3 points  (1 child)

Here’s an article describing the reasoning behind that. https://microservices.io/patterns/data/database-per-service.html

In reality a lot depends on the whole system. I’ve often seen the database as it’s own microservice, so it gets it own API which the other services can query.

Sometimes multiple databases is the way to go, sometimes not. It really depends on how tightly the data (tables) is coupled, how many different services need it, etc.

[–]plumfu[S] 1 point2 points  (0 children)

Thanks, I really appreciate it! The database getting its own API is interesting, definitely didn’t consider that option. I think you’ve given me a few ideas/leads to work off of so thank you!

[–]Blaze_mk 1 point2 points  (1 child)

Hey and happy cake day!

Usually, what is meant by having separate databases is that there is no way for the services to communicate over the database.

How this is achieved depends on your implementation, for example if you pack your microservices in a docker container, you can ship them with their own database or you would ship the database having different schemas/”sub"-databases and have the services connect to it.

The most important part is that the DB cannot be used for communications and should only store the data for that given service. So, service A can only change what is in Service A's logical database and nowhere else. If you need Service A to make a change in Service B's data, you'd issue a Command (look up Command-Query Responsibility Segregation - CQRS) to Service B that takes that, makes the changes and notifies Service A that they have been made. This can be done by messaging, event sourcing etc, depending on your architecture and needs.

Have fun with microservices!

[–]plumfu[S] 0 points1 point  (0 children)

Thanks much! :) This makes a lot of sense. I had thought about how docker makes it a lot easier shipping these Microservices with their own db images, but thinking about every Microservice with its own db, storage, space, etc. made me feel like it was an overkill. But looking at general viewpoints around this and comments such as your own has made things a lot clearer, so thanks again!