Spring Cloud Case Studies & Practical Application 4 — Questions and Answers
Question 1: A company's Spring Cloud Gateway is overwhelmed by a single client making thousands of requests per second. Which built-in filter should be applied to protect backend services?
- AddRequestHeader filter
- RequestRateLimiter filter with Redis backend (Correct answer)
- RewritePath filter with regex throttling
- SetStatus filter returning 429
Correct answer: RequestRateLimiter filter with Redis backend
The RequestRateLimiter GatewayFilter uses Redis and a token bucket algorithm to enforce per-client rate limits, returning 429 when exceeded.
Question 2: A team's Circuit Breaker opens even during normal operations, causing unnecessary fallbacks. Which configuration change would reduce false positives?
- Increase the slidingWindowSize and failure rate threshold in Resilience4j configuration (Correct answer)
- Disable the Circuit Breaker during business hours
- Switch from COUNT_BASED to TIME_BASED sliding window only
- Reduce the waitDurationInOpenState
Correct answer: Increase the slidingWindowSize and failure rate threshold in Resilience4j configuration
Increasing the sliding window size and raising the failure rate threshold requires more evidence of real failures before the circuit opens, reducing false positives from small sample noise.
Question 3: A platform team needs to route requests to different microservice versions based on a custom HTTP header (X-Version: v2). Which Spring Cloud Gateway feature supports this?
- Weight-based routing only
- Header-based RoutePredicateFactory matching on the X-Version header (Correct answer)
- Eureka metadata-based load balancing
- Spring Cloud Config profile-based routing
Correct answer: Header-based RoutePredicateFactory matching on the X-Version header
Spring Cloud Gateway's Header RoutePredicateFactory matches routes based on the presence and value of specific HTTP headers, enabling header-driven version routing.
Question 4: After deploying a Config Server with a Vault backend, services cannot start because Vault is sealed. What is the correct handling strategy?
- Mark config as optional so services start with defaults when Vault is unavailable (Correct answer)
- Increase the Config Server HTTP timeout
- Pre-cache all Vault secrets in Config Server memory at startup
- Configure Eureka to skip services that fail to fetch config
Correct answer: Mark config as optional so services start with defaults when Vault is unavailable
Using spring.config.import=optional:configserver: or fail-fast=false lets services start with local defaults when the config source is unavailable, preventing a startup deadlock.
Question 5: A team wants to test their Feign clients against a WireMock stub server in CI without spinning up real microservices. Which Spring Cloud project provides stub generation from contracts?
- Spring Cloud Sleuth stub server
- Spring Cloud Contract WireMock stub runner (Correct answer)
- Spring Cloud Gateway mock filter
- Spring Cloud Config stub backend
Correct answer: Spring Cloud Contract WireMock stub runner
Spring Cloud Contract's WireMock Stub Runner automatically starts stubs generated from producer contracts, letting consumers test against realistic stubs without live services.
Question 6: A team wants blue/green deployment traffic control using Spring Cloud LoadBalancer and Eureka. How do they shift all traffic to green without downtime?
- Remove blue instances from Eureka registry before deregistering them
- Set Eureka instance status to OUT_OF_SERVICE for blue instances via Actuator, verify green is healthy, then deregister blue (Correct answer)
- Change the LoadBalancer algorithm to RoundRobin during deployment
- Use Spring Cloud Bus to broadcast a LoadBalancer refresh event
Correct answer: Set Eureka instance status to OUT_OF_SERVICE for blue instances via Actuator, verify green is healthy, then deregister blue
Setting an instance's Eureka status to OUT_OF_SERVICE via /actuator/serviceregistry removes it from load balancing without deregistering, allowing zero-downtime traffic drain.
Question 7: A mobile backend uses Spring Cloud Gateway as a BFF (Backend for Frontend). The team wants to aggregate responses from three microservices into a single response. What is the recommended approach?
- Use Gateway's built-in aggregation filter
- Implement a dedicated aggregator microservice that the Gateway routes to, or use reactive composition in a custom GatewayFilter (Correct answer)
- Configure three routes and merge them with Spring Cloud Bus
- Use Feign clients inside the Gateway to call all three services
Correct answer: Implement a dedicated aggregator microservice that the Gateway routes to, or use reactive composition in a custom GatewayFilter
Gateway itself doesn't aggregate responses; a dedicated aggregator microservice (BFF pattern) or a custom reactive GatewayFilter using WebClient parallel calls is the standard solution.
A company's Spring Cloud Gateway is overwhelmed by a single client making thousands of requests per second.
Which built-in filter should be applied to protect backend services?