Design problem in Microservice architecture.

huangapple go评论65阅读模式
英文:

Design problem in Microservice architecture

问题

在我们的公司,我们正在使用“微服务”,但迄今为止我们没有遵循“微服务原则”。因此,在架构审查中,我们被告知要进行替换。

我们有一个名为“CommonService”的服务,所以客户发来的任何请求都会命中这个服务。这个请求会访问数据库并创建记录,然后将请求转发给“ManagementService”。管理服务访问相同的数据库和表,并更新由“CommonService”创建的记录。(在这里,“Common”和“Management”两个API都会访问数据库中的相同表。)
其他两个服务也是如此。

Common-->DB(Common_MGMT)--Management-->DB(Common_MGMT)
Common-->DB(Common_Sales)--Sales-->DB(Common_Sales)
Common-->DB--HR-->DB

因此,“Common_MGMT”表由前两个服务访问,“Common_Sales”表由Common和Sales API访问,第三个也是如此。
特定客户将只访问一个服务,它可以是“Management”、“Sales”或“HR”,但他将通过“commonservice”进入。

现在我们必须遵循微服务原则,但由于管理原因,我们无法遵循“数据库作为服务”的方式,也没有从头开始重新设计的选项。

因此,我们考虑引入一个“DBservice”,它将访问数据库,这样当新请求发送到“Commonservice”时,它将通过“REST”访问“DBservice”,并且“DBservice”将在数据库中创建记录。然后,“Management”服务将访问“DBservice”,并且“DBService”将更新数据库中的相同记录,销售服务和HR服务也一样。

现在,我仍然在使用相同的数据库中的相同表,但这次只有“DBservice”在访问。这里我是否遵循了微服务原则?

  1. 这里哪种方法更好,是“每个服务使用私有表”还是“模式作为服务”?或者两者都可以工作,我可以选择其中一个吗?

  2. 这种方法会有巨大的延迟,是否可以改进解决方案?

  3. 如果“DBService”出现故障,那是否会成为单点故障?除了创建多个实例之外,我们还能做些什么?

总体上,您能为原始问题提供解决方案吗?我们提出的解决方案是否正确,还是有更好的选项?

欢迎任何其他建议。

英文:

In my company we are using microservices but till now we were not following microservice principles. so in architect review we have been told to replace the same.

We have one service called CommonService,so any request comes by client hits this service. This request hits the database and create the record and then forward the request to ManagementService. Management Service access the same DB and table and update the record created by CommonService.(Here Common and Management Both API hitting the same table in database.)
same we have for other 2 services.

Common-->DB(Common_MGMT)--Management-->DB(Common_MGMT)
Common-->DB(Common_Sales)--Sales-->DB(Common_Sales)
Common-->DB--HR-->DB 

So Common_MGMT table hit by first 2 service, Common_Sales table hit by Common and Sales API ,same for third.
A particular customer will access only one service where it is Management , Sales or HR but he will come through commonservice.
Design problem in Microservice architecture.

Now We have to follow microservice principle and due to management reasons we can not follow Database as a service and also we don't have option to redesign from scratch.

So we have thought to introduce one DBservice which will hit the database,so that it is like when new request will come to Commonservice then it will access DBservice through REST and DB service will create record in database. Then Management Service will access DBservice and DBService will update the same record in database. likewise for sales service and HR service.

Now still I am using same table in Database but this time only DBservice accessing. AM I following the microservice principle here?

  1. Here which approach will be better Private table per service or Schema as a service? or both will work and I can use either of them?

  2. There will be huge latency in this approach, can the solution be improved?

  3. If DBService will fail then it will be single point of failure? can we do something other than creating multiple instances?

Overall can you suggest the solution for original problem? Is the solution we are proposing correct or is there better option?

Any other suggestion most welcome.

Design problem in Microservice architecture.

答案1

得分: 2

您的问题的解决方案并不简单明了,因为在将服务拆分为微服务时涉及许多参数。从我所看到的情况来看,您有多个服务频繁地相互通信,但仍然具有不同的代码库,而且它们访问相同的数据库(我假设您说的是相同的数据库架构)。现在,当您说您无法从头开始时,对于这个问题有很少可能的解决方案。

  1. 不要每次在初始服务中更新和访问数据库,而是为什么不将信息传递给下游服务,让该服务在可能的情况下进行更新(这仍然不是理想的解决方案,但通过减少一次数据库调用来减少延迟)
共享-->传递数据--管理-->数据库(共享管理)
共享-->传递数据--销售-->数据库(共享销售)
共享-->传递数据--人力资源-->数据库
  1. 相反,不要将API调用着陆在共享服务上,而是为什么不将API调用着陆在实际服务中,然后在您的服务中注入共享作为依赖项,让该部分处理其他数据?(这仍然不是从头开始,但我认为需要大量工作,但仍然比第1种解决方案更好)。
英文:

The solution to your problem is not simple and straightforward, because there are many parameters involved while breaking a service into microservices. From what I see, you are having multiple services which are communicating with each other frequently but still are having different code bases and on top of that they do access the same database (I am assuming the same schema when you say the same database). Now when you say that you can not do it from scratch then there are very few possible solutions to this problem

  1. Instead of updating and hitting the DB every time for the calls in the initial service, why don't you just pass the information to downstream services and let that service do the update if possible (this is still not an ideal solution but it reduces the latency by reducing one DB call)
Common-->Pass-Data--Management-->DB(Common_MGMT)
Common-->Pass-Data--Sales-->DB(Common_Sales)
Common-->Pass-Data--HR-->DB
  1. Do the reverse, instead of landing your API call in Common, why don't you land your API calls in actual services first and then inject Common as a dependency in your services and let that part process other data? (this is still not from scratch but I believe will need considerable amount of work, but still better solution than 1).

答案2

得分: 1

Introducing a DBservice as an intermediary between microservices and the database can follow microservice principles.

Private table per service or schema as a service can both work, depending on specific needs. Coordination between services is necessary to avoid conflicts and ensure data consistency.

Using a single database for multiple microservices can cause performance issues.

Database-per-service approach can improve scalability, isolation, and data consistency.

Introducing a DBservice can affect performance due to additional network hops. Caching or optimizing database queries can reduce latency. A load balancer or replicated database cluster can ensure high availability.

Redesigning microservices architecture can improve scalability and data consistency, and reduce contention.

Event-driven architectures and asynchronous messaging can decouple microservices and improve scalability and fault tolerance.

Containerization and orchestration technologies can simplify the deployment and management of microservices.

Actually considering your scenario specifically, I can think of two other possible solutions for you:

  1. Either create Common service as a jar and import it into your Management, Sales, and HR service and use it from there only.

  2. Normalization of a table in such a way that Common Service and Management Service, etc. work on different tables. I am just thinking to divide a table into two parts.

英文:

Introducing a DBservice as an intermediary between microservices and the database can follow microservice principles.
However, there are aspects to consider.

Private table per service or schema as a service can both work, depending on specific needs. Coordination between services is necessary to avoid conflicts and ensure data consistency.
Using a single database for multiple microservices can cause performance issues.
Database-per-service approach can improve scalability, isolation, and data consistency.
Introducing a DBservice can affect performance due to additional network hops. Caching or optimizing database queries can reduce latency. A load balancer or replicated database cluster can ensure high availability.
Redesigning microservices architecture can improve scalability, and data consistency, and reduce contention.

Event-driven architectures and asynchronous messaging can decouple microservices and improve scalability and fault tolerance.
Containerization and orchestration technologies can simplify the deployment and management of microservices.

Actually considering your scenario specifically, I can think of two other possible solutions for you:

  1. Either create Common service as a jar and import it into your Management, Sales, and HR service and use it from there only

  2. Normalization of a table in such a way that Common Service and Management Service etc work on different tables. I am just thinking to divide a table into two parts

答案3

得分: 1

以下是需要牢记的要点。

  • 首先,决定如何将功能分隔成服务。
  • 您可以根据领域进行分隔,例如客户服务、产品服务等。每个服务都将有自己的数据库,每当另一个服务需要处理该数据库中的任何内容时,它将通过这个微服务进行操作。
  • 然后,可以在领域特定服务的基础上构建用例特定的服务。
  • 微服务架构很难通过将数据库作为单一故障点来进行合理化。

有关微服务的更详细信息,请参考此网站。由于您似乎刚刚开始,这是一个很好的起点。
https://microservices.io/

英文:

So below are the points to keep in mind.

  • First, decide how are you segregating your functionalities into services.
  • You can segregate based on domain, e.g. customer service, product service etc. Each of this service would have it's own db, and whenever another service needs to deal with anything in this DB, it will go through this microservice.
  • You can then build usecase specific services on top of the domain specific services.
  • It is really difficult to justify microservice architecture with your DB as a single point of failure.

Please refer to this website for more detailed information on microservices. Since you seem to be just getting started, this is a good starting point.
https://microservices.io/

答案4

得分: 1

One way to approach it would be to split the monolith in terms of functional modules with an interface and implementation and then move those modules into standalone services.

Update#1 -

  1. If you want to improve your understanding try this link - https://microservices.io/
  2. I have answered in a generic way (was trying to get within the bounty window but now it looks like there is a 1 day grace!). Never the less believe they still hold.

If you have a single database and that is your primary concern (which makes sense) then backups are your only friend. So you can first think of a replication db before you start thinking about monolith vs microservices. It would be no fun to tell your customers you lost their data because the db server crashed.

Additionally to improve speed, using RDBMS you can consider sharding concepts (where rows are distributed across multiple servers) in addition to replication. You should ideally be able to manage this within the scope of your definition of 'redesign-from-scratch' limitation.

英文:

One way to approach it would be to split the monolith in terms of functional modules with an interface and implementation and then move those modules into standalone services.

The idea is that if one functional module changes, others don't have to be validated as rigorously.

Update#1 -

  1. If you want to improve your understanding try this link - https://microservices.io/

  2. I have answered in a generic way (was trying to get within the bounty window but now it looks like there is a 1 day grace!). Never the less believe they still hold.

    If you have a single database and that is your primary concern (which makes sense) then backups are your only friend. So you can first think of a replication db before you start thinking about monolith vs microservices. It would be no fun to tell your customers you lost their data because the db server crashed.

    Additionally to improve speed, using RDBMS you can consider sharding concepts (where rows are distributed across multiple servers) in addition to replication. You should ideally be able to manage this within the scope of your definition of 'redesign-from-scratch' limitation.

答案5

得分: 0

通过 REST API 调用 dbservice,会不会像紧耦合一样增加延迟?我们是否可以使用消息 API 来执行此操作?这样,即使 dbservice 停机,消息仍然可以被处理,一旦它重新启动。

英文:

Calling dbservice via rest api, won't it be like tight coupling and add latency? Can we not do this operation using messaging api? Such that even if dbservice goes down, message can still be processed, once it's up.

huangapple
  • 本文由 发表于 2023年4月4日 11:49:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定