Spring Cloud for Microservices
Spring Cloud Gateway, Config, service discovery, load balancing, Circuit Breaker, Stream and Kubernetes integration, and which pieces are still needed on modern platforms.
Components and when to use them
| Component | Purpose | On Kubernetes? |
|---|---|---|
| Spring Cloud Gateway | Reactive (or MVC) API gateway with routes, filters, rate limiting | Useful as a code-centric gateway/BFF; alternatives: Envoy Gateway, cloud gateways |
| Spring Cloud Config | Centralized Git-backed configuration | Often replaced by ConfigMaps/Secrets, external secret operators, or Spring Cloud Kubernetes |
| Eureka / Consul discovery | Service registry | Usually unnecessary: use Kubernetes Services and DNS |
| Spring Cloud LoadBalancer | Client-side load balancing | Rarely needed with K8s Services or a mesh |
| Spring Cloud Circuit Breaker | Abstraction over Resilience4j | Yes, for application-level fallbacks |
| Spring Cloud Stream | Binder abstraction for Kafka/RabbitMQ with functional style | Yes, for event-driven services |
| Spring Cloud Function | Functions portable across serverless platforms | Serverless use |
| Spring Cloud Kubernetes | Config and discovery from Kubernetes APIs | When apps need dynamic config reload from ConfigMaps |
[!VERSION] Spring Cloud Sleuth was replaced by Micrometer Tracing in Spring Boot 3. Netflix Ribbon, Hystrix and Zuul 1 are retired; use Spring Cloud LoadBalancer, Resilience4j and Spring Cloud Gateway.
Gateway route example
spring:
cloud:
gateway:
routes:
- id: orders
uri: http://orders-service
predicates: [ Path=/api/orders/** ]
filters:
- StripPrefix=1
- name: RequestRateLimiter
args:
redis-rate-limiter.replenishRate: 50
redis-rate-limiter.burstCapacity: 100
- name: CircuitBreaker
args: { name: orders, fallbackUri: forward:/fallback/orders }[!VERSION] Spring Cloud Gateway property prefixes changed in recent releases (for example
spring.cloud.gateway.server.webflux.*); check the docs for your release train.
Spring Cloud Stream (functional)
@Bean
Function<OrderPlaced, StockReserved> reserveStock(InventoryService inventory) {
return event -> inventory.reserve(event.orderId(), event.lines());
}spring.cloud.stream.bindings:
reserveStock-in-0: { destination: orders.order-placed.v1, group: inventory }
reserveStock-out-0: { destination: inventory.stock-reserved.v1 }Architect-level considerations
[!ARCHITECT] Do not recreate platform features in application libraries. On Kubernetes, rely on the platform for discovery, config and load balancing; keep Spring Cloud for gateway/BFF needs, resilience and messaging abstractions.
Interview questions and answers
Do you still need Eureka?
Not on Kubernetes or most managed container platforms, which provide discovery and load balancing. Eureka remains relevant on VM-based deployments without a platform registry.
How do you refresh configuration without redeploying?
Spring Cloud Kubernetes or Config with @RefreshScope and a refresh trigger, or rolling restarts driven by config changes (often safer and simpler), or a feature flag system for runtime toggles.