SoFunction
Updated on 2025-04-07

SpringCloud's gateway Zuul and Gateway details

1. Spring Cloud Zuul

  • Spring Cloud Zuul is a microservice gateway component built on Netflix Zuul, used to build API gateways in the microservice architecture.

Here are some features of Spring Cloud Zuul:

  1. Routing and Filtering: Spring Cloud Zuul can route requests to different microservice instances based on request paths and other conditions. It also supports custom filters that modify and process requests and responses before they enter the gateway and responses return.
  2. Integrated service discovery: Spring Cloud Zuul can be integrated with service registry (such as Eureka, Consul) to achieve automatic service discovery and load balancing. It can dynamically forward requests to available service instances based on the health status and load status of the service instance.
  3. Load balancing: Spring Cloud Zuul has built-in load balancing capabilities, which can evenly distribute requests to multiple service instances to improve system availability and performance.
  4. Fault Tolerance and Fuse: Spring Cloud Zuul integrates a circuit breaker mode that can fuse when the target service is unavailable or fails, preventing the failure from spreading to the entire system. It also supports fault tolerance mechanisms that can be downgraded or return default values ​​when requests fail.
  5. Security: Spring Cloud Zuul provides security features that can authenticate and authorize, protect access to back-end microservices.
  6. Monitoring and logging: Spring Cloud Zuul provides monitoring and logging functions, which can obtain key metrics and runtime information by integrating Spring Boot Actuator, and supports integration with log analysis tools such as ELK (Elasticsearch, Logstash, Kibana).
  7. Scalability: Spring Cloud Zuul is built on Netflix Zuul and can be seamlessly integrated with other Spring Cloud components, such as Spring Cloud Config, Spring Cloud Sleuth, etc.

In short, Spring Cloud Zuul is a feature-rich and scalable microservice gateway component that provides routing and filtering, integrated service discovery, load balancing, fault tolerance and fuse, security and other functions to help developers build a reliable, secure and efficient microservice architecture. However, it should be noted that Spring Cloud Zuul has now entered maintenance mode, and Spring Cloud officially recommends using Spring Cloud Gateway as an alternative.

2. Spring Cloud Gateway (recommended)

  • Spring Cloud Gateway is a non-blocking gateway solution based on Spring Framework 5, Project Reactor and Spring Boot to build API gateways in microservice architectures.

Here are some features of Spring Cloud Gateway:

  1. Based on asynchronous non-blocking model: Spring Cloud Gateway uses a Reactor-based asynchronous non-blocking model that can handle a large number of concurrent requests without blocking threads, providing higher performance and throughput.
  2. Dynamic routing: Spring Cloud Gateway supports dynamic routing, and can forward requests to different target services based on request path, request header, request parameters and other information.
  3. Filter Chain: Spring Cloud Gateway provides a flexible filter mechanism that allows requests and responses to be modified and processed before they enter the gateway and responses return. Filters can be used for authentication, request conversion, request current limit, request retry and other operations.
  4. Integrated service discovery: Spring Cloud Gateway can be integrated with service registries (such as Eureka, Consul) to achieve automatic service discovery and load balancing. It can dynamically forward requests to available service instances based on the health status and load status of the service instance.
  5. Supported circuit breakers: Spring Cloud Gateway integrates circuit breaker mode, which can fuse when the target service is unavailable or fails, preventing the failure from spreading to the entire system.
  6. Scalability: Spring Cloud Gateway is built on the Spring Framework and can seamlessly integrate with components of other Spring ecosystems, such as Spring Security, Spring Cloud Sleuth, etc.
  7. Programmability: Spring Cloud Gateway provides Java and functional programming APIs, which can programmatically define routing rules and filters to achieve more advanced customization and extension.
  8. Monitoring and logging: Spring Cloud Gateway provides rich monitoring and logging functions, which can obtain key metrics and runtime information by integrating Spring Boot Actuator, and supports integration with log analysis tools such as ELK (Elasticsearch, Logstash, Kibana).

In short, Spring Cloud Gateway is a lightweight, high-performance and scalable API gateway solution that provides dynamic routing, filter chain, integrated service discovery, circuit breakers and other functions to help developers build a reliable, secure and efficient microservice architecture.

3. The difference between Spring Cloud Zuul and Spring Cloud Gateway

Spring Cloud Gateway and Spring Cloud Zuul are both components provided by Spring Cloud for building API gateways in microservice architectures. They have the following differences:

  • Architectural Model: Spring Cloud Gateway is built on Spring Framework 5 and Project Reactor, using an asynchronous non-blocking model with higher performance and throughput. Spring Cloud Zuul is built on Netflix Zuul and uses a synchronous blocking model, with relatively low performance.
  • Programming Model: Spring Cloud Gateway provides Java and functional programming APIs, which can programmatically define routing rules and filters to achieve more advanced customization and extension. Spring Cloud Zuul uses annotation-based method to define routing rules and filters, which is relatively simple than Spring Cloud Gateway's programming model.
  • Features: Spring Cloud Gateway provides more features than Spring Cloud Zuul. For example, dynamic routing, more flexible filter chains, integrated service discovery, circuit breakers and more have been improved and enhanced in Spring Cloud Gateway.
  • Eco support: Spring Cloud Zuul is a Netflix open source project that integrates closely with the Netflix ecosystem, such as the integration with the Netflix Eureka Service Registration Center, Netflix Ribbon Load Balancer, etc. Spring Cloud Gateway is an official component provided by Spring Cloud, which is more closely integrated with other components of the Spring ecosystem, such as integration with Spring Cloud Config, Spring Cloud Sleuth, etc.
  • Maintenance status: Spring Cloud Zuul has entered maintenance mode and no new functional development is available. Spring Cloud Gateway is the official recommended API gateway solution for Spring Cloud, and will be the main development direction in the future.

4. Summary

Although Spring Cloud Zuul was the mainstream API gateway solution in the past, Spring Cloud Gateway has some advantages in performance, functional features and ecological support, so when choosing an API gateway, it is recommended to use Spring Cloud Gateway as your preferred choice.

Simple demo examples of Spring Cloud Zuul and Spring Cloud Gateway can be clicked ->Simple examples of Spring Cloud Zuul and Gateway (building method)

The above is personal experience. I hope you can give you a reference and I hope you can support me more.