Spring Cloud Spring Cloud Gateway & Load Balancing 1 — Questions and Answers
Question 1: What replaces the deprecated Netflix Zuul as the recommended API gateway in Spring Cloud?
- Spring Cloud Consul Gateway
- Spring Cloud Gateway (Correct answer)
- Spring Cloud Router
- Spring Cloud Proxy
Correct answer: Spring Cloud Gateway
Spring Cloud Gateway, built on Spring WebFlux and Project Reactor, is the modern replacement for the deprecated Netflix Zuul API gateway.
Question 2: Which programming model does Spring Cloud Gateway use for reactive, non-blocking request processing?
- Spring MVC with Tomcat thread pool
- Spring WebFlux with Project Reactor (Correct answer)
- Netty with Vert.x event loop
- Akka HTTP with actor model
Correct answer: Spring WebFlux with Project Reactor
Spring Cloud Gateway is built on Spring WebFlux and Project Reactor, providing non-blocking, reactive request routing and filtering.
Question 3: In Spring Cloud Gateway, what is a 'Predicate' used for?
- Modifying the request or response headers
- Matching incoming requests to determine which route to apply (Correct answer)
- Performing authentication and authorization checks
- Balancing load across downstream service instances
Correct answer: Matching incoming requests to determine which route to apply
Predicates in Spring Cloud Gateway are conditions evaluated against incoming requests (path, headers, method, etc.) to determine if a route matches.
Question 4: What is the purpose of a 'Filter' in Spring Cloud Gateway?
- Selecting which downstream instance receives a request
- Modifying the incoming request or outgoing response before/after routing (Correct answer)
- Caching responses from downstream services
- Discovering available routes from the service registry
Correct answer: Modifying the incoming request or outgoing response before/after routing
Filters in Spring Cloud Gateway can inspect and modify HTTP requests and responses, enabling cross-cutting concerns like authentication, logging, and header manipulation.
Question 5: Which Spring Cloud Gateway predicate routes requests where the path matches `/api/orders/**`?
- PathVariable=/api/orders/**
- Path=/api/orders/** (Correct answer)
- Route=/api/orders/**
- Match=/api/orders/**
Correct answer: Path=/api/orders/**
The Path predicate factory in Spring Cloud Gateway routes requests whose URI path matches the specified Ant-style pattern.
Question 6: How does Spring Cloud Gateway integrate with service discovery to route requests to registered services by name?
- By hardcoding service IPs in route configuration
- Via the lb:// URI scheme which triggers client-side load balancing through DiscoveryClient (Correct answer)
- By querying the DNS server for service IP resolution
- Through a sidecar proxy that intercepts all traffic
Correct answer: Via the lb:// URI scheme which triggers client-side load balancing through DiscoveryClient
Using lb://service-name as the route URI instructs Spring Cloud Gateway to use the load balancer and service discovery to resolve the target service's instances.
What replaces the deprecated Netflix Zuul as the recommended API gateway in Spring Cloud?