Linux Networking & TCP/IP for Developers · レッスン

レジリエンスパターン:サーキットブレーカー、リトライ、タイムアウト

タイムアウト、バックオフ付きの回数制限リトライ、連鎖的な停止を防ぐサーキットブレーカーパターンによって、障害発生時にも分散システムを健全に保つ方法を学びます。

レッスン 4/413 ステップ

「レジリエンスパターン:サーキットブレーカー、リトライ、タイムアウト」はCoddyKit上の無料Linux Networking & TCP/IP for Developersレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLinux Networking & TCP/IP for Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Linux Networking & TCP/IP for Developersコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Failure Is Normal

In a microservices network, calls cross machines and links that will fail. Resilience patterns keep one slow or broken service from dragging down the whole system.

Always Set Timeouts

A call with no timeout can hang forever, exhausting threads and connections. Every remote call must have a deadline.

import requests
r = requests.get('http://orders/api', timeout=2.0)

The Danger of Naive Retries

Retrying immediately after a failure can amplify an outage — a struggling service gets hit even harder. Retries must be bounded and spaced.

Exponential Backoff

Increase the wait between attempts exponentially so a recovering service gets breathing room.

for attempt in range(5):
    try:
        return call()
    except Exception:
        wait = 2 ** attempt
        time.sleep(wait)

Adding Jitter

If many clients back off on the same schedule they retry in sync, creating a thundering herd. Add random jitter to spread the load.

import random
wait = (2 ** attempt) + random.uniform(0, 1)

Retry Only Idempotent Operations

Retrying a non-idempotent write (like 'charge card') can double-execute it. Only retry safe operations, or use idempotency keys to make writes safe.

The Circuit Breaker

A circuit breaker tracks failures to a dependency. After too many, it opens and fails fast instead of waiting on a dead service.

This stops resources from piling up on a doomed call.

Breaker States

A circuit breaker has three states:

  • Closed — calls flow normally
  • Open — calls fail immediately
  • Half-Open — a few test calls probe recovery

Breaker in Code

A minimal breaker counts failures and trips after a threshold, refusing calls until a cooldown elapses.

if breaker.is_open():
    raise CircuitOpenError()
try:
    result = call()
    breaker.record_success()
except Exception:
    breaker.record_failure()
    raise

Fallbacks and Graceful Degradation

When a breaker is open, return a sensible fallback: cached data, a default value, or a reduced feature set. A degraded response beats a total failure.

Bulkheads

The bulkhead pattern isolates resources (thread pools, connection pools) per dependency, so one saturated dependency cannot starve the others.

Quick Check

Test your resilience knowledge.

Recap

You can now build resilient service calls:

  • Always set timeouts
  • Bounded retries with exponential backoff + jitter
  • Retry only idempotent operations
  • Circuit breakers (closed/open/half-open) to fail fast
  • Fallbacks and bulkheads for graceful degradation

This complements your load balancing, service mesh, and API gateway lessons.

無料で開始

AI チューターと学ぶ Linux Networking & TCP/IP for Developers — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
12
レッスン
48

よくある質問

「レジリエンスパターン:サーキットブレーカー、リトライ、タイムアウト」レッスンは無料ですか?

はい。「レジリエンスパターン:サーキットブレーカー、リトライ、タイムアウト」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Networking & TCP/IP for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Networking & TCP/IP for Developersコースには全4レッスンが含まれています。

「レジリエンスパターン:サーキットブレーカー、リトライ、タイムアウト」で何を学びますか?

タイムアウト、バックオフ付きの回数制限リトライ、連鎖的な停止を防ぐサーキットブレーカーパターンによって、障害発生時にも分散システムを健全に保つ方法を学びます。 ブラウザで直接実行するハンズオンコードでLinux Networking & TCP/IP for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Linux Networking & TCP/IP for Developersを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのLinux Networking & TCP/IP for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「レジリエンスパターン:サーキットブレーカー、リトライ、タイムアウト」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このLinux Networking & TCP/IP for Developersレッスンでコードを書いて実行できますか?

はい。すべてのLinux Networking & TCP/IP for Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ロードバランシング戦略
  2. サービスメッシュアーキテクチャ(Istio/Linkerd)
  3. API Gatewayとエッジルーティング
  4. レジリエンスパターン:サーキットブレーカー、リトライ、タイムアウト
← Linux Networking & TCP/IP for Developersに戻る