微服务 - 在拥有多家业务的组织中
Context
Let's say we have an organization that has multiple businesses.在此示例中,企业A向大学生出售千兆互联网服务。 Business B向老年人出售Megabit Internet服务。企业出售相关产品的略有差异,每种产品都针对不同的人群。
乍一看,这似乎我们只能让一个应用程序处理所有请求。但是,鉴于每个人都针对特定的人口统计,企业自然会彼此分歧 - 从本质上讲,每个企业都会有自己的业务需求。例如,企业A可能会曝光移动应用程序供客户管理其帐户。 Business B可能会揭露必须要求客户管理其帐户的电话号码。列表继续。
在此上下文中,使用微服务的最佳方法是什么?
问题在于,不同业务之间既有常见和罕见的功能。
我们可以保持一定的干燥,并具有一组基本的微服务(计费-API,订单-API等),可以被不同的企业消费。这起作用了,但这会导致微服务具有更多的“一般”抽象 - 导致更复杂的性能。 For a concrete example, let's say the billing-api service has a /charge endpoint that is shared by Business A and B. Business B's requirement is to always discount $5 off the order:
//billing-api
if (businessB) {
orderCost -= 5;
}
In this DRY approach, we would have an API gateway for每个业务(BFF模式)将汇总不同的微服务以满足其业务需求。所有“特定于业务”的逻辑都将从基本微服务转移到各个企业的API网关。 In this discount example, instead of having an if (businessB)
check in the billing-api endpoint, we can invert this control to the consumer:
//billing-api
const { orderDiscountAmount } = req.body; //body parameters
if (orderDiscountAmount > 0) {
orderCost -= orderDiscountAmount;
}
Then the endpoint in Business B's API gateway would pass in an orderDiscountAmount of 5 when calling the billing-api endpoint:
//Business B API Gateway
billingApi({ orderDiscountAmount: 5 });
This seems fine, but all we did was take Business B's logic in the billing-api endpoint and created a generic (but forced) abstraction.这是“合理的”,说可能有一天可能会使用业务 - 但这可能永远不会发生。总体而言,对于开发人员和终点的消费者来说,这感觉就像是不自然的练习。各个方面的复杂性和认知负荷都会增加。
我们可以将干燥垃圾删除,并避免在企业之间共享微服务,以最大程度地灵活性和简单性。但是,如果添加了更多的业务(10-20),那么可能会有很大一部分重复的功能。
在这种情况下,应该如何结构团队?
如果我们可以从上方的干式方法中使用干燥的方法,那么团队应该如何结构?我们可以拥有垂直的功能团队,但这是否意味着如果我们拥有10家业务,一个团队需要在所有业务上拥有一个功能(即结帐)?这种方法的缺点是,该功能团队将不会成为整个业务中的专家 - 这些团队只能是一项特定业务中一个功能的专家。没有关于企业的完整背景可能会使做出正确的决定变得困难。
我们可以为每个专门针对UI和API网关的业务提供一个与溪流一致的团队。然后,我们将让平台团队为溪流一致的团队创建微服务。与此的缺点是,溪流一致的团队与平台团队(又称依赖性)之间存在交接步骤。
我不确定我是否会从错误的镜头中查看所有这些 - 任何反馈都将不胜感激!
Context
Let's say we have an organization that has multiple businesses. In this example, Business A sells a gigabit internet service to college students. Business B sells a megabit internet service to seniors. The businesses sell related products with slight variations, each targeting a different demographic.
At first glance, this seems like we can just have one application handle all the requests. However, it is natural for the businesses to diverge from each other given that they each target a specific demographic - by nature, each business will have its own business requirements. For example, Business A might expose a mobile application for customers to manage their account. Business B might expose a phone number that has to be called for customers to manage their account. The list goes on.
What is the best way to utilize microservices given this context?
The problem is that there is both common and uncommon functionality across the different businesses.
We can remain somewhat DRY and have a set of base microservices (billing-api, order-api, etc.) that can be consumed by the different businesses. This works but this causes the microservices to have more "general" abstractions - leading to more complexity. For a concrete example, let's say the billing-api service has a /charge endpoint that is shared by Business A and B. Business B's requirement is to always discount $5 off the order:
//billing-api
if (businessB) {
orderCost -= 5;
}
In this DRY approach, we would have an API gateway for each business (BFF pattern) which would aggregate different microservices to fulfill their business needs. All "business-specific" logic would get moved from the base microservices into the respective businesses' API gateway. In this discount example, instead of having an if (businessB)
check in the billing-api endpoint, we can invert this control to the consumer:
//billing-api
const { orderDiscountAmount } = req.body; //body parameters
if (orderDiscountAmount > 0) {
orderCost -= orderDiscountAmount;
}
Then the endpoint in Business B's API gateway would pass in an orderDiscountAmount of 5 when calling the billing-api endpoint:
//Business B API Gateway
billingApi({ orderDiscountAmount: 5 });
This seems fine, but all we did was take Business B's logic in the billing-api endpoint and created a generic (but forced) abstraction. This is "justified" by saying maybe Business A may use that one day - but that may never actually happen. Overall, this feels like an unnatural exercise for the developer and the consumer of the endpoint. Complexity and cognitive load on all sides are increased.
We can scrap DRY and avoid sharing microservices between businesses for maximum flexibility and simplicity. However, if more businesses are added (10-20) then there's probably going to be a good chunk of duplicated functionality.
How should teams be structured given this context?
If we are okay with the DRY approach from above, how should teams be structured? We can have vertically-sliced feature teams, but does that mean if we have 10 businesses, a team would need to own a feature (i.e. checkout) on all the businesses? The drawback with this approach is that the feature teams won't be experts in any business as a whole - the teams would only be an expert in one feature in a given business. Not having the full context on a business could make it difficult to make the right decisions.
We can have a stream-aligned team for each business dedicated to the UI and the API gateway. We would then have platform teams creating microservices for the stream-aligned teams to consume. The drawback with this is that there is a handoff step between the stream-aligned team and the platform team, a.k.a a dependency.
I'm not sure if I'm looking at all this from the wrong lens - any feedback would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很抱歉说,但这对于Stackoverflow来说不是一个好问题,因为任何答案都是基于意见的,并且许多方法可能有效,并且取决于您特定用例中的更多细节。因此,如果问题在某个时候结束,请不要失望。
话虽这么说,我并不害羞,无法提出我的意见或至少对您所描述的情况的一些想法。
(明智地提到更多详细 /反映更多业务需求)
最初,第二种方法通常更难,但是根据我的经验,当达到一定的复杂性阈值时,结果将获得更好的结果。
因此,在阅读您的问题时,这些只是我脑海中出现的几件事。抱歉,他们无法回答有关如何切割计费API的详细问题,但也许您还有一些其他考虑因素。
Sorry to say, but this is not a good question for Stackoverflow, because any answer will be a opinion based and many approaches may work and depend on more details in your specific use case. So don't be disappointed if the question get's closed at some point.
That being said I am not too shy to offer my opinion or at least some thoughts about your described situation.
(Smart referring to more elaborate / reflecting more of the business requirements)
The second approach is usually harder initially, but in my experience will have better results when a certain complexity threshold is reached.
So these are just a few things that came to my head when reading your question. I apologize that they cannot answer your detailed question about how to slice the billing API, but maybe you have a few additional considerations at hand.