本文介绍了在利用微服务架构时,底层的读/写数据库是否会成为瓶颈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我在问题中所述,如果我要实现微服务架构,集中式读/写数据库是否会成为瓶颈?

As I described in the question, if I were to implement a microservices architecture, would the centralized read/write database become a bottleneck?

举个例子,假设我有三个微服务:usersteamsteam_members.每个数据库都有自己的微服务,但是它们在数据库中都相互依赖,因此,排他的并行数据库是不合适的.由于微服务旨在将工作分配到多个不同的服务器,因此中央数据库是否最终会破坏这些微服务的目的,因为它们最终都调用同一服务器?

To expand with an example, let's say I have three microservices: users, teams, and team_members. Each has its own microservice, but they all rely on each other in the database, so exclusive, parallel databases wouldn't be appropriate. Since microservices is meant to distribute the work to several different servers, doesn't the central database ultimately defeat the purpose of these microservices, as they all end up calling to the same server?

推荐答案

您的问题中内置一个假设.假设微服务必须在数据库中共享相同的主表.

There is a assumption built-in to your question. The assumption is that the microservices must share the same master tables in the database.

实际上,在您的问题上,您直接表达了这个概念的声音:

In fact, further down your question you give voice to this concept directly:

如果微服务共享数据库表,那么您有效完成的全部工作就是构建一个包含多个组件的单一服务",这些组件在某种带外传输而不是通过直接二进制引用在内存中相互消耗.

If the microservices are sharing database tables then all you have effectively done is built one single "service" with multiple components which all happen to consume each other over some out-of-band transport rather than in-memory by direct binary reference.

面向服务背后最重要的概念之一是自治,这基本上意味着每个服务都应拥有自己的数据.

One of the most important concepts behind service orientation is autonomy, which basically means each service should own its own data.

在您的示例中,用户服务将了解团队.怎么知道好吧,团队服务会将团队数据推送到用户服务.同样, team_members服务将从这两个服务接收数据.现在,所有服务都具有完成工作所需的所有数据.

Extending your example, the users service will know about teams. How will it know? Well, the teams service will push team data to users service. Similarly, the team_members service will receive data from both services. Now, all services have all the data they need to do their jobs.

因此,通过将服务实现为自治服务,就不会出现在同一组基表上争用的可能性.

So by implementing your services as autonomous the potential for contention on the same set of base tables dissapears.

这篇关于在利用微服务架构时,底层的读/写数据库是否会成为瓶颈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:08