Can microservices duplicate data in your database?
The question, which is better to try to explain with an example.
There are samopisnaya erp/crm system (where the codebase is in a terrible state, which is afraid to touch and all this on an outdated stack) hereinafter will be called a monolith.
The monolith has employees.
Employees have: titles, offices, names.
Need to make a small fan shop for employees with the basic functions:
- to give the opportunity to define rules for the accrual of bonuses to employees (roles, positions with a certain periodicity)
- to give the opportunity to buy goods for accrued bonuses (availability of the goods to the employee is limited to his presence in the office)
Actually what difficulty do not want to write this store inside the monolith, but to do it separately.
Was originally a very simple idea: write a separate app store, synchronism periodically via the API of the erp/crm staff, offices, positions (the data changes infrequently) - persistent database store. All the logic of bonuses, management goods, the purchase is written in the boutiques - everything seems happy.
But yesterday we wondered what is really in those individual apps, you can make a number of functionality from our monolith to bring it into order. Example : time tracking. He nafig nafig do not need the monolith, except for the monthly report, but it contains a bunch of logic - the holidays in different offices, time off, sick leave, etc.
And like you can do everything again very simple - to sezincote of the monolith are needed for time tracking info in another database and it seems again everyone is happy.
All this begins to look like the microservices.
Yesterday I discussed this with dudes from another Department, who allegedly brewed the microservices. They sagovniki this is all saying that duplicate the old Cinco it is cancer and that you need to pull data for apesca of the monolith as if from their own base.
Immediately the question arose: all right, if you have to create the rules of the bonus need info about office and office of employee of - I the rule will remain in the store? The answer was: it means the rules must be within the monolith.
If you follow this logic, then I don't understand at all:
- rules I can't keep in the store because I need the offices of the staff leaves the monolith
products I can keep in the store because I need offices, too, leaving the monolith
- for a directory, the right products, and they are in the monolith - also went to the monolith? :D
Che can anyone tell how such things it is better to organize or throw fiction on the issue of data storage if one and the same infa need several apps?
Discussed in the chat telegram. Came to the conclusion - in the service need to store idiski on the entity other services, and the entities to pull out of the services. Recommended book - reading shop.oreilly.com/product/0636920033158.do
aniya answered on June 10th 19 at 16:58
Each entity - a micro service. One for users - it all appeal, users, and directly related data are stored there; the other for goods etc.
marilyne_Roh answered on June 10th 19 at 17:00
They sagovniki this is all saying that duplicate the old Cinco it is cancer and that you need to pull data for apesca of the monolith as if from their own base.
Shirley.Wunsch answered on June 10th 19 at 17:02
It is not called microservices and integration. Business as usual in the world of enterprise systems. Main thing that some api was a duplicate if the old additional subsystems depends on requirements to system performance and data accuracy.