0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · Pelajaran

Sekat Kegagalan & Pembatasan Laju untuk Ketahanan

Pisahkan kegagalan dan lindungi layanan hilir menggunakan isolasi sekat serta filter RequestRateLimiter milik gateway.

Sekat Kegagalan & Pembatasan Laju untuk Ketahanan adalah pelajaran API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

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.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Sekat Kegagalan & Pembatasan Laju untuk Ketahanan” gratis?

Ya — teks lengkap “Sekat Kegagalan & Pembatasan Laju untuk Ketahanan” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), upgrade ke CoddyKit PRO. Kursus API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Sekat Kegagalan & Pembatasan Laju untuk Ketahanan”?

Pisahkan kegagalan dan lindungi layanan hilir menggunakan isolasi sekat serta filter RequestRateLimiter milik gateway. Kamu berlatih API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?

Tidak diperlukan pengalaman sebelumnya. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.

Berapa lama pelajaran “Sekat Kegagalan & Pembatasan Laju untuk Ketahanan” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) ini?

Ya. Setiap pelajaran API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Pemutus Sirkuit dengan Resilience4j
  2. Konfigurasi Percobaan Ulang dan Batas Waktu
  3. Penanganan Kesalahan dan Mekanisme Cadangan
  4. Sekat Kegagalan & Pembatasan Laju untuk Ketahanan
← Kembali ke API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)