Microservices Architecture – Integrating a Shared Database

Architecturemicroservices

We've stuck with designing two services. In fact, these two services have been splitted since traffic issues, so they were one before.

I mean, our platform is consumed by two sort of clients: other services and UI clients (web, desktop and mobile).

So services:

  1. Services are using a very short number of exposed endpoints (addInput, removeInput).
  2. Althought they are using those methods they generates more traffic than clients.

So clients:

  1. Clients are using a very large number of exposed endpoints.
  2. Nevertheless, they are not generating so many traffic.

So, they are sharing code (since they are accessing to the same database), but as far I've been to figure out microservices has no to share base code.

We believe something is wrong using this approach.

I don't know if I've explained so well.

Which would be the keys in order to solve this kind of microservices architecture issues? Is "traffic issue" a key enought in order to split a service?

Best Answer

Ok, so the classic problem with your setup is that the high volume calls slow down, or break the low volume calls. or in your case the Services slow down the Users.

The solution is to split the service into two as you have, sort of, done. You can then either scale up or throttle the Service without affecting the Users

As you point out its not recommended to share code across services. I guess you have it left over from when they were one service. And as you say, they are both using the same datalayer.

Now there IS something wrong. But its not so much the shared code as the fact that you are still sharing a database.

Being on the same db means that the high traffic calls can still affect the Users. If you moved them off you would presumably no longer have any shared code.

Sharing code in of itself may give you some maintenance difficulties and you should try to refactor it out if possible. But its not the root of the problem.

You may find that if the high volume service hits performance limits due to cpu or memory rather than database calls then you have already solved your issues by splitting the service at the code level. In that case sharing datalayer code is not a bad thing.

Related Topic