在两个微服务之间共享域模型的最佳实践 [英] Best practice to share domain model between two microservices

查看:59
本文介绍了在两个微服务之间共享域模型的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有关于如何在两个微服务之间共享域模型的最佳实践或指南?

Are there any best practices or guidelines on how to share the domain model between two micro-services?

我有一个微服务 (1),它提供端点以与所有 CRUD 的资源(例如,Order)和另一个微服务(2)进行交互,后者在资源(Order)上执行特定的非 CRUD 任务.微服务(2)几乎需要所有的订单属性来执行它的操作.在这种情况下,创建域模型的公共共享库并在两个服务之间共享是否有意义?我可以在技术上将 1 和 2 组合在一起,但微服务 (2) 需要支持可扩展性,因为它非常占用内存和 CPU.

I have a micro-service (1) which provides end points to interact with a resource (e.g, Order) all CRUD and the other micro-service (2) which performs a specific non CRUD task on the resource (Order). The micro-service (2) almost needs all the order attributes to perform its operation. In this case, does it make sense to create a common shared lib of the domain model and share between the two services? I could technically combine 1 and 2 together but the micro-service (2) needs to support scalability as it is quite memory and CPU intensive.

推荐答案

据我所知,这两个服务似乎需要共享相同的数据,而您正在考虑共享用于读取的库/修改此数据.

As far as I can see it seems that these two services need to share the same data and you are thinking to share also the library that is used to read/modify this data.

它们似乎属于同一个有界上下文",因此最好将它们视为一种独特的服务.

They seem to belong to the same "bounded context" and so it would be ideal to consider them as a unique service.

如果你真的不能把他们的数据和他们的逻辑分开,最好把它们放在一起.

If you really can't separate their data and their logic, it would be better to keep them together.

我不认为同一个微服务中的组件必须遵循相同的部署模式:它们将是同一个微服务,由同一个团队管理,始终部署在一起,共享同一个源存储库,但它们将被部署一种不同的策略,因为只有第二个组件需要高可扩展性.

I do not think that components in the same microservices have to follow the same deployment pattern: they will be the same microservice, managed by the same team, deployed always together, sharing the same source repository, but they will be deployed with a different strategy because only the second component needs high scalability.

同样的有界上下文,同样的服务,但不同的组件.

So same bounded context, same service, but different components.

我没有很多经验,所以把这当作我个人的想法.

I do not have a lot of experience and so take this as my personal thought.

这篇关于在两个微服务之间共享域模型的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆