Bulkhead e limitazione della frequenza per la resilienza
Isoli i guasti e protegga i servizi downstream usando l'isolamento bulkhead e il filtro RequestRateLimiter del gateway.
Bulkhead e limitazione della frequenza per la resilienza è una lezione API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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: 20Why 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: 20Replenish 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: 20Graceful 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_REQUESTSObserving 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
RequestRateLimiteruses a Redis token bucketreplenishRateandburstCapacityshape traffic- A
KeyResolverdefines the limiting key
Combined with circuit breakers, retries, and fallbacks, your gateway degrades gracefully under stress.
Domande Frequenti
La lezione «Bulkhead e limitazione della frequenza per la resilienza» è gratuita?
Sì — il testo completo di «Bulkhead e limitazione della frequenza per la resilienza» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), passa a CoddyKit PRO. Il corso API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) include 4 lezioni in totale.
Cosa imparerò in «Bulkhead e limitazione della frequenza per la resilienza»?
Isoli i guasti e protegga i servizi downstream usando l'isolamento bulkhead e il filtro RequestRateLimiter del gateway. Eserciti API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?
Non è richiesta alcuna esperienza precedente. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Bulkhead e limitazione della frequenza per la resilienza»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?
Sì. Ogni lezione API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Circuit breaker con Resilience4j
- Configurazione di retry e timeout
- Gestione degli errori e fallback
- Bulkhead e limitazione della frequenza per la resilienza