Cloud gateway as a Non- Blocking Gateway
Many e-commerce giants such as Amazon, Alibaba has hundred of microservices running and get millions of traffic. To accommodate this traffic, a blocking gateway is definitely not a solution.
A Blocking gateway such as Zuul1 requires as many threads as no of requests to handle requests coming to an API gateway and hence a lot of resources is required to handle these requests.
Hence, spring cloud team provided their own non-blocking gateway solution as Spring Cloud Gateway — a reactive Gateway built upon Project Reactor, Spring WebFlux, and Spring Boot 2.0.
A non-blocking model requires less no of resources to serve the same amount of requests as compared to blocking gateway.
Spring Cloud Gateway Architecture
As we discussed above, the spring cloud gateway is a non-blocking gateway and hence it is built upon Project Reactor and does not work in a traditional Servlet Container. Below is the architecture diagram of Spring Cloud.
Once a request reaches to the gateway, the first thing gateway does is to match the request with each of the available route based on the predicate defined. Once, the route has matched the request moves to web handler and the filters will be applied to the request.
Spring Cloud Gateway Implementation
To get started with the implementation, head over to start.spring.io and download a sample spring boot project which includes gateway artifact and import into your IDE. The complete source code can be found here.
Once, the project is imported, you can start implementing the routes.