之前的单体应用架构下,很多逻辑都是在过滤器中开发的,比如权限认证,限流,日志等等工作。
后面,单体架构演变成微服务架构,像日志,权限校验,路由,限流熔断等功能都前置到了网关层。这样就不用每个后端服务去做重复的事情,而且缩短了调用的链路。
网关可以提供后端服务的单一入口,当业务规模非常巨大的时候,网关也是可以部署集群的,有负载均衡器转发/路由到网关集群的某个网关上,再由网关分发到具体的后端服务。
进入网关的流量可以在网关记录请求和响应的日志,一旦发现异常请求,可以根据既定的策略进行拦截。包括黑名单等等。
网关做为请求进入后端服务的第一道屏障,可以对请求做一些安全校验和权限校验,对没有校验过的请求可以直接过滤掉,不用进入到后端服务器上。
当然还有很多其他的功能。
网关的功能介绍可以参考 Netflix Zuul
https://github.com/Netflix/zuul/wiki/How-We-Use-Zuul-At-Netflix
下面是Zuul在Netfilx架构体系中的应用。 图片来源于Github Zuul
Zuul gives us a lot of insight, flexibility, and resiliency, in part by making use of other Netflix OSS components:
- Hystrix is used to wrap calls to our origins, which allows us to shed and prioritize traffic when issues occur
- Ribbon is our client for all outbound requests from Zuul, which provides detailed information into network performance and errors, as well as handles software load balancing for even load distribution
- Turbine aggregates finegrained metrics in realtime so that we can quickly observe and react to problems
- Archaius handles configuration and gives the ability to dynamically change properties
Zuul在Netflix中的使用情况统计
这里的数据是2017年的统计数据