微服务加入的最佳实践
案例1一对:
卡和用户是2个不同的微服务,
例如,每个卡实体包含1个用户ID。
- Frontend CALL 2 APIS sequencely(即通过card.userid调用用户API)
- 卡微服务呼叫用户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.
- Frontend call 2 APIs sequencely (i.e. Call Card API -> Call User API by Card.UserID)
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了一行回答您的问题,最好的做法是避免微服务之间的相互依存关系。
根据我的经验,我在下面列出了选项,需要根据性能和amp;可容忍您的系统应符合
您的前端致电卡API,然后用户API
将用户服务视为组件 - 如果您的用户服务始终由另一个微服务消费,那么这将是一个更好的选择
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
Your front end to call card api and then user api
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