0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · Lección

Bulkheads y limitación de velocidad para la resiliencia

Aísle los fallos y proteja los servicios downstream mediante aislamiento bulkhead y el filtro RequestRateLimiter de la puerta de enlace.

Bulkheads y limitación de velocidad para la resiliencia es una lección gratuita de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Containing the Blast Radius

Circuit breakers stop calls to a broken service, but a flood of traffic to one route can still starve others. Bulkheads and rate limiting keep one busy route from sinking the whole gateway.

The Bulkhead Pattern

Named after a ship's watertight compartments, a bulkhead caps how many concurrent calls a route may have. If one service slows down, only its compartment fills, sparing the rest.

Resilience4j Bulkhead Config

Resilience4j offers a bulkhead that limits concurrent calls per instance.

resilience4j:
  bulkhead:
    instances:
      orders:
        maxConcurrentCalls: 20

Why Rate Limiting Differs

A bulkhead caps concurrency; a rate limiter caps requests over time. Together they protect both fast bursts and sustained load.

The RequestRateLimiter Filter

Spring Cloud Gateway ships a RequestRateLimiter filter backed by a Redis token bucket. It rejects excess requests with HTTP 429.

filters:
  - name: RequestRateLimiter
    args:
      redis-rate-limiter.replenishRate: 10
      redis-rate-limiter.burstCapacity: 20

Replenish Rate and Burst

replenishRate is the steady tokens per second; burstCapacity is the most that can be spent in a spike. Burst should be greater than or equal to replenish.

Choosing a KeyResolver

A KeyResolver decides what to limit by, such as user, API key, or IP. Here we limit per user from a header.

@Bean
KeyResolver userKeyResolver() {
    return exchange -> Mono.just(
        exchange.getRequest().getHeaders()
            .getFirst("X-User-Id"));
}

Redis Backing Store

The limiter needs Redis so counts are shared across gateway instances. Add the reactive Redis starter.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>

Combining Patterns

Stack resilience filters on a route: circuit breaker first, then rate limiter, so traffic is shaped before reaching a possibly fragile backend.

filters:
  - name: CircuitBreaker
    args:
      name: ordersCB
      fallbackUri: forward:/fallback/orders
  - name: RequestRateLimiter
    args:
      redis-rate-limiter.replenishRate: 10
      redis-rate-limiter.burstCapacity: 20

Graceful Rejection

When the limit is exceeded the client gets 429. You can customize the status, but always return a clear, retryable response so clients can back off.

args:
  redis-rate-limiter.replenishRate: 5
  statusCode: TOO_MANY_REQUESTS

Observing the Limits

Watch metrics for 429 counts and bulkhead rejections. Tune the numbers based on real downstream capacity, not guesses.

Quick Check

What is the core difference between a bulkhead and a rate limiter?

Recap

You added two more resilience tools:

  • Bulkheads cap concurrent calls per route
  • RequestRateLimiter uses a Redis token bucket
  • replenishRate and burstCapacity shape traffic
  • A KeyResolver defines the limiting key

Combined with circuit breakers, retries, and fallbacks, your gateway degrades gracefully under stress.

Preguntas frecuentes

¿La lección «Bulkheads y limitación de velocidad para la resiliencia» es gratis?

Sí — el texto completo de «Bulkheads y limitación de velocidad para la resiliencia» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), actualiza a CoddyKit PRO. El curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) incluye 4 lecciones en total.

¿Qué aprenderé en «Bulkheads y limitación de velocidad para la resiliencia»?

Aísle los fallos y proteja los servicios downstream mediante aislamiento bulkhead y el filtro RequestRateLimiter de la puerta de enlace. Practicas API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

No se requiere experiencia previa. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Bulkheads y limitación de velocidad para la resiliencia»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

Sí. Cada lección de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Cortocircuitos con Resilience4j
  2. Configuración de reintentos y tiempos de espera
  3. Gestión de errores y mecanismos de fallback
  4. Bulkheads y limitación de velocidad para la resiliencia
← Volver a API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)