Microservice architectures simplify the individual components that comprise our applications, but they introduce new complexity in managing a high number of distributed APIs. With so many moving parts, how can you provide a simplified experience for consumers and ensure that your system is resilient and secure?
Centralized gateways have been a long-standing solution for managing APIs, but microservices demand a new generation of lightweight micro-gateway applications. Spring Cloud Gateway is one such solution. It provides a simple yet flexible API to add the routing, resilience, and control you need to protect the edge layer of your applications. Built on Spring WebFlux, it also ensures an inherently nonblocking mechanism for efficiently routing and manipulating requests.
In this talk, we'll review the motivation for Spring Cloud Gateway and demonstrate a variety of features, such as weighted routing, circuit breakers, rate limiters, and more.
2. API Gateway Role & Responsibilities
● Routing
● Security
● Monitoring
● Canarying
● Resiliency
● Monolith Strangling
G
A
T
E
W
A
Y
Server Side
MVC App
Microservice A
JS or
Mobile App
Microservice B
Microservice C
3. API Gateways - Then and Now
Many API Management Gateways can be dated
back to SOA and these tend to have been
implemented as centralized servers. But as
microservices became more popular, modern
lightweight independent and decentralized
micro-gateway applications have appeared –
such as Spring Cloud Gateway.
Source: Ben Wilcock
https://spring.io/blog/2019/06/18/getting-started-with-spring-cloud-gateway
〝
〞
7. Gateway Flow
Client Predicates Pre-Filters Global Filters
Post-Filters
Downstream
Service
Gateway
Handler Mapping Web Handler
8. Gateway Flow
Client Predicates Pre-Filters Global Filters
Post-Filters
Downstream
Service
Gateway
Handler Mapping Web Handler
Predicates
● Date/Time
● Cookies
● Headers
● Host
● Method
● Path
● Query Params
● Remote Address
● Weight
9. Gateway Flow
Client Predicates Pre-Filters Global Filters
Post-Filters
Downstream
Service
Gateway
Handler Mapping Web Handler
Pre-Filters
● Headers
● Parameters
● Path
● Circuit Breaker
● Retry
● Rate Limiter
● Redirect
● Save Session
● Size
● Host
● Metrics
● Modify Body
10. Gateway Flow
Client Predicates Pre-Filters Global Filters
Post-Filters
Downstream
Service
Gateway
Handler Mapping Web Handler
Global Filters
● Netty Router
● Web Sockets
● Load Balancer
● Metrics
11. Gateway Flow
Client Predicates Pre-Filters Global Filters
Post-Filters
Downstream
Service
Gateway
Handler Mapping Web Handler
Post Filters
● Set Status
● Headers
● Modify Body
12. Routes: building blocks of a gateway
Defined by:
● ID
● Destination URI
● Collection of predicates (for matching requests to the route)
● Collection of filters (for modifying the request or response)
Specified as:
● Java
● Properties