0

I want to decompose my application to adopt microservices architecture, and i will need to come up with a solid strategy to split my database (Mysql) into multiple small databases (mysql) aligned with my applications.

1 Answers1

0

TL;DR: Depends on the scenario and from what each service will do

Although there is no clear answer to this, since it really depends on your needs and on what each service should do, you can come up with a general starting point (assuming you don't need to keep the existing database type).

Let's assume you have a monolithic application for an e-commerce, and you want to split this application into smaller services, each one with it's own database. The approach you could use is to create some services that handles some parts of the website: for example you could have one service that handles users authentication,one for the orders, one for the products, one for the invoices and so on...

Now, each service will have it's own database, and here's come another question: which database a specific service should have? Because one of the advantages of this kind of architecture is that each service can have it's own kind of database, so for example the products service can have a non relational database, such as MongoDB, since all it does is getting details about products, so you don't have to manage any relation.

The orders service, on the other hand, could have a relational database, since you want to keep a relation between the order and the invoice for that order. But wait, invoices are handled by the invoice service, so how can you keep the relation between these two without sharing the database? Well, that's one of the "issues" of this approach: you have to keep services independent while also let them communicate each other. How can we do this? There is no clear answer here too... One approach could be to just pass all invoices details to the orders service as well, or you can just pass the invoice ID when saving the order and later retrieve the invoice via an API call to the invoice service, or you can pass all the relevant details you need for the invoice to an API endpoint in the order service that stores these data to a specific table in the database (since most of the times you don't need the entire actual object), etc... The possibilities are endless...

Jimi
  • 1,605
  • 1
  • 16
  • 33
  • I want to decompose my current database into several databases. I have a mysql database and I want to split a part of this database for a microservice – mohamed benayad Feb 20 '20 at 13:40
  • Then as I mentioned above you have to create several mysql databases and put the tables you want to extract in it. You can then choose to leave the tables in the existing database or drop them as you won't need them anymore (of course if are totally sure that this won't cause any issue) – Jimi Feb 20 '20 at 13:52
  • But he has an ORM system that would break if you just copy it and throw out some tables.. – Wimanicesir Feb 20 '20 at 14:46
  • Yeah, of course it won't be a painful task, but if you don't need those tables anymore in the shared database chances are you don't need the ORM code that access those tables in the monolithic code, so you should remove that piece of code too. Unfortunately there's (yet) no magic button that transforms applications from monolithic to micro system – Jimi Feb 20 '20 at 14:53