Skip to content

Spring Cloud Microservices Guide (Eureka, API Gateway, Circuit Breaker)

Spring Cloud is a collection of tools for building distributed microservice systems.

Feature Tool
Service Discovery Eureka
API Gateway Spring Cloud Gateway
Load Balancing Spring LoadBalancer (formerly Ribbon)
Circuit Breaker Resilience4j
Distributed Configuration Spring Cloud Config
Distributed Tracing Micrometer Tracing + Zipkin/OpenTelemetry (Spring Cloud Sleuth on older, pre-Boot-3 stacks)

Interview Definition

Spring Cloud provides tools and frameworks to implement common microservice patterns such as service discovery, centralized configuration, API gateways, circuit breakers, load balancing, and distributed tracing.


Service discovery allows microservices to locate one another dynamically without hardcoding URLs.

Order Service -> http://localhost:8082/payment
Order Service -> PAYMENT-SERVICE

The service registry resolves the actual running instance.

  • Eureka
  • Consul
  • Apache ZooKeeper
  • Kubernetes Service Discovery

Eureka is a Netflix-developed service registry that enables microservices to register themselves and discover other services.

  1. Eureka Server
  2. Eureka Client
sequenceDiagram
    participant U as User Service
    participant O as Order Service
    participant E as Eureka Server
    participant P as Payment Service

    U->>E: Register
    O->>E: Register
    P->>E: Register
    O->>E: Discover PAYMENT-SERVICE
    E-->>O: Return available instance
    O->>P: Invoke API
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
}
@EnableEurekaClient

In modern Spring Cloud, this annotation is optional — simply having spring-cloud-starter-netflix-eureka-client on the classpath auto-registers the service with Eureka. @EnableEurekaClient is still accepted for explicitness/backward compatibility.


An API Gateway acts as the single entry point for all client requests.

Client -> User Service
Client -> Order Service
Client -> Payment Service
Client -> API Gateway -> Microservices
  • Request routing
  • Authentication
  • Rate limiting
  • Logging
  • Load balancing
  • Request aggregation
  • Spring Cloud Gateway
  • Netflix Zuul
  • Kong
  • NGINX

For a full HLD/LLD treatment (component breakdown, class diagram, and Java implementations for routing/auth/rate limiting/load balancing/caching), see the API Gateway system design case study.


A circuit breaker prevents cascading failures by temporarily stopping calls to failing services — see the existing Resilience4j usage example for a code sample. The three states it moves through:

stateDiagram-v2
    [*] --> Closed
    Closed --> Open: Failure threshold exceeded
    Open --> Half_Open: Wait duration elapsed
    Half_Open --> Closed: Successful calls
    Half_Open --> Open: Failure
  • Resilience4j
  • Hystrix (deprecated)

Overall Spring Boot Microservices Architecture

Section titled “Overall Spring Boot Microservices Architecture”
flowchart TD
    Client --> Gateway["API Gateway"]
    Gateway --> User["User Service"]
    Gateway --> Order["Order Service"]
    Gateway --> Payment["Payment Service"]

    User -. Registers .-> Eureka
    Order -. Registers .-> Eureka
    Payment -. Registers .-> Eureka

    Config["Spring Cloud Config Server"] --> User
    Config --> Order
    Config --> Payment

    Trace["Zipkin / Sleuth"] -. Trace Data .-> User
    Trace -. Trace Data .-> Order
    Trace -. Trace Data .-> Payment

    CB["Resilience4j"] -. Protects .-> Order
  • Eureka lets services register themselves and discover each other by name (PAYMENT-SERVICE) instead of hardcoded host:port URLs.
  • An API Gateway centralizes routing, authentication, rate limiting, and request aggregation behind a single entry point.
  • A circuit breaker moves through three states — Closed (normal), Open (blocking calls after too many failures), and Half-Open (testing recovery) — before returning to Closed.
  • A full Spring Cloud microservices setup combines Eureka (discovery), an API Gateway (routing), Spring Cloud Config (configuration), Resilience4j (resilience), and Sleuth/Zipkin (tracing) around the services themselves.