微服务加入的最佳实践

发布于 2025-01-25 20:51:14 字数 248 浏览 1 评论 0原文

案例1一对:

卡和用户是2个不同的微服务,

例如,每个卡实体包含1个用户ID。

  1. Frontend CALL 2 APIS sequencely(即通过card.userid调用用户API)
  2. 卡微服务呼叫用户API用户使用USERID,然后返回加入结果。前端只需要致电卡API,

哪个是最好的?

案例2很多: 如果我需要加入2个微服务中的许多人,那么最好的做法是什么?

Case 1 one to many:

Card and User are 2 different micro-services

For example Each Card entity contains 1 UserID.

  1. Frontend call 2 APIs sequencely (i.e. Call Card API -> Call User API by Card.UserID)
  2. Card micro-service call User API by UserID and then return joined result. Frontend only need to call Card API

Which one is the best?

Case 2 many to many:
If I need to join many to many in 2 micro-services, what is the best practice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猥琐帝 2025-02-01 20:51:14

为了一行回答您的问题,最好的做法是避免微服务之间的相互依存关系。

根据我的经验,我在下面列出了选项,需要根据性能和amp;可容忍您的系统应符合

  1. 您的前端致电卡API,然后用户API

  2. 将用户服务视为组件 - 如果您的用户服务始终由另一个微服务消费,那么这将是一个更好的选择

To answer your question in one line, the best practice is to avoid interdependencies between microservices.

Based on my experience I have listed below the options, which needs to be chosen based on the performance & fault tolerance that your system should meet

  1. Your front end to call card api and then user api

  2. Consider user service as a component - if your user service is always going to be consumed by another microservice, then this would be a better option

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文