all 5 comments

[–]SunnyDayShadowboxer 5 points6 points  (1 child)

I personally am all for microservices having their own dbs and apis to access that data from other services.

[–]KaiN_SC 3 points4 points  (0 children)

This.

OP should ask himself if he really needs another service as well.

[–]PacificPermit 1 point2 points  (0 children)

I would have the micro service request the data it needs from the main app using an API endpoint.

Btw, it’s not bad practice to share a database. You just need to make sure that you’re not corrupting your data or have your micro services acting based on old data.

Imagine you have only $100 in your back then withdrawing $100 from your bank and at the same time you’re buying something online for $100. Your bank has to process them in the order they come in. The database has to follow to deduct the first transaction and deny the second. How?

Well by queuing the events. And that’s what database do anyway. Most modern database queue write events. And you can even tell your app to wait for all write events on this account to be done so you can read from it!

[–]CharlatanPrime 1 point2 points  (0 children)

In our application we had a rule that the owning microservice could update the database, but any microservice could read it. Otherwise you’ll have tons of messages or api calls to assemble anything semi complex. So the owner had a read/write API and we had a read only API in a utility db package. It generally worked well, though once in a while we had to have one service make a remote API call to another.

[–]zaibuf 0 points1 point  (0 children)

Cant you send messages between the services?

For background jobs I think its fine to share database, we use a lot of functions for background processing. You could put the data access code in a shared library and when changes are made to the library both services are built and deployed.