首页 > 解决方案 > Mapping microservices on frontend

问题描述

This is probably a bit opinion-based question, but I will try to be technical to still be relevant.

Consider having several microservices: a, b, c.

To make this available on frontend, these could be made available as:

However, the fact that the endpoints are split between differents services are kind of irrelevant for frontend and basically if we can guarantee the endpoints don't clash, it would be great to have these available directly:

To implement such mapping, one needs to list all endpoint or at least write some matching pattern within the proxy service. This is very nice for the Frontend team to work with, however it is unfortunately very easy to brake.

What are the best practices for mapping the urls of microservices? Only thing which comes to my mind are some exports of OpenApi, which could be handled by FE to get the right path. However, every service generates its own OpenApi json, so we are basically back to the original problem.

标签: url-rewritingarchitecturemicroservices

解决方案


你确定前端团队需要所有暴露的端点吗?通常,前端与 API 网关对话,或者,就像现在酷孩子们所说的那样,“前端的后端”。

简而言之,它是一项特殊服务,只负责公开前端所需的功能/端点。它将调用转发到相关服务,或者在必要时调用多个服务并聚合结果。

在大多数情况下,这些 API 网关没有数据库,因为它们正在从其他服务中检索所有数据。然而,他们可能会使用缓存层来加速事情。

您甚至可以拥有多个 API 网关,每个前端(例如桌面、移动)一个。


推荐阅读