APIdevise – 分裂成不同的子域(微服务)

我们的应用程序基于API的第一个架构,目前基于单个域/服务:

api.todos.com

API的消费者是:

  • 我们的networking前端
  • 我们的移动应用程序
  • 其他业务/公共

我们将为同一个应用程序构build用不同语言编写的新的微服务 。 例如,我们可能开发API服务:

  • 统计
  • 博客/内容
  • RSS订阅
  • search

我的问题是围绕处理域。 将每个服务分割成不同的子域是最好的

  • api.todos.com
  • stats.todos.com
  • content.todos.com
  • rss.todos.com
  • search.todos.com

还是有一个单一的统一的API域,我们做HTTP(第7层)路由到达我们的端点更好。 例如

  • api.todos.com/todos
  • api.todos.com/stats
  • api.todos.com/content
  • api.todos.com/rss
  • api.todos.com/search

不知道哪一个公共API更可取? 拥有多个子域会更容易,而不必处理中间路由层/代理。

作为系统架构师,我认为it is better to have a single unified API domain where we do HTTP (layer 7) routing to reach our endpoints 。 您可以使您的系统更灵活,而无需为您的客户进行任何更改。 例如,你有一个微服务与路线:

  • api.todos.com/route1
  • api.todos.com/route2

将来你可以通过这条路线来分割微服务。

但大多数情况下,这取决于您使用的是什么API网关。 API网关是您的系统中的单一入口点,用于纠正微服务的代理请求。 它也使auth和caching。 更多关于这个微服务的模式,你可以在这里阅读。