• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Building cloud-native microservices requires solving distributed system challenges: service discovery (how do services find each other?), load balancing (which instance to call?), distributed configuration (how to manage config across services?), and fault tolerance (what happens when a service is down?).

Core Idea

Spring Cloud provides a suite of tools for building cloud-native microservices. It integrates with Netflix OSS (Eureka for service discovery, Ribbon for load balancing, Hystrix for circuit breaking), provides distributed configuration with Spring Cloud Config, API gateway with Spring Cloud Gateway, and distributed tracing with Sleuth/Zipkin.

How It Works

  1. Service discovery: Spring Cloud Netflix Eureka — services register with Eureka server, clients discover via service name
  2. Load balancing: Spring Cloud LoadBalancer (replaced Netflix Ribbon) — client-side load balancing across service instances
  3. API Gateway: Spring Cloud Gateway — routes requests to appropriate services, handles cross-cutting (auth, rate limiting)
  4. Distributed config: Spring Cloud Config Server — external configuration stored in Git, served to all services
  5. Distributed tracing: Spring Cloud Sleuth + Zipkin — trace IDs propagate across service calls, visualized in Zipkin dashboard
  6. Fault tolerance: Resilience4j (replaced Hystrix) — circuit breakers, retries, bulkheads, rate limiters

Visual Explanation

spring_cloud CLIENT Client GATEWAY API Gateway (Spring Cloud Gateway) CLIENT->GATEWAY LB Load Balancer (Spring Cloud LoadBalancer) GATEWAY->LB DISCOVERY Service Registry (Eureka Server) CONFIG Config Server (Git-backed) SVC1 Service A (registered) SVC1->DISCOVERY register / discover SVC1->CONFIG fetch config TRACING Distributed Tracing (Sleuth + Zipkin) SVC1->TRACING SVC2 Service B (registered) SVC2->DISCOVERY SVC2->CONFIG SVC2->TRACING SVC3 Service C (registered) SVC3->DISCOVERY SVC3->CONFIG SVC3->TRACING LB->SVC1 LB->SVC2 LB->SVC3

Key Properties

  • Service discovery: Eureka server for service registration and discovery; Spring Cloud LoadBalancer for client-side load balancing
  • API Gateway: Route requests, add headers, rate-limiting, authentication, circuit breaking at edge
  • Configuration management: Externalized, version-controlled configuration via Spring Cloud Config (Git backend)
  • Circuit breakers: Resilience4j for fault tolerance — prevents cascading failures
  • Distributed tracing: Sleuth adds trace/span IDs; Zipkin visualizes request flows across services
  • Cloud platform support: AWS (EC2, S3, SQS), GCP, Azure integrations via Spring Cloud for each provider

Connections

Edge Cases & Gotchas

  • Eureka self-preservation: In network partitions, Eureka keeps its registrations (AP over CP) — stale entries during real failures
  • Config server SPOF: Config server is a single point of failure — make it highly available or use native cloud config services
  • Gateway latency: Every request goes through the gateway, adding latency — avoid putting heavy logic in gateway filters
  • Bootstrap context: Spring Cloud uses bootstrap.yml (loaded before application.yml) for config server location — easy to misconfigure
  • Version compatibility: Spring Cloud releases are coordinated (2020.0.x, 2021.0.x, etc.) — Spring Boot version must match the cloud release train