0Pricing
Microservices Communication Patterns (Saga, Circuit Breaker) · レッスン

冪等性とメッセージ重複排除

冪等なハンドラーを設計し、分散システムでメッセージの重複を排除して、マイクロサービスの処理を安全に再試行できるようにします。

「冪等性とメッセージ重複排除」はCoddyKit上の無料Microservices Communication Patterns (Saga, Circuit Breaker)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMicroservices Communication Patterns (Saga, Circuit Breaker)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Microservices Communication Patterns (Saga, Circuit Breaker)コースには全4レッスンが含まれています。

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

Retries Cause Duplicates

Distributed systems deliver messages at least once. A timeout or retry can make the same request arrive twice — and charge a card or create an order twice.

What Idempotency Means

An operation is idempotent if doing it many times has the same effect as doing it once. Repeating it changes nothing beyond the first application.

Naturally Idempotent Operations

Some operations are idempotent by nature — absolute SET, HTTP PUT and DELETE. Others, like balance = balance + 10, double-apply on a retry.

The Idempotency Key

The standard fix is an idempotency key: the client generates a unique id per operation and resends it on every retry, so the server processes it only once.

POST /payments
Idempotency-Key: 9f1c-7a22-...
{ "amount": 4999 }

Storing Processed Keys

The server records each processed key. If the same key reappears, it returns the stored result instead of re-running the work.

if (store.exists(key)) return store.result(key);
Result r = process(request);
store.save(key, r);
return r;

Deduplication at the Consumer

For queues, the consumer does deduplication: it tracks message ids it has already handled and silently skips any repeats.

if (seen.contains(msg.id())) { ack(msg); return; }
handle(msg);
seen.add(msg.id());
ack(msg);

Atomicity Matters

Recording the key and doing the work must be atomic. If they are separate, a crash between them reopens the duplicate window — use a transaction or unique constraint.

INSERT INTO processed(key) VALUES (?) -- unique constraint
-- if it fails, the work already ran

Expiring the Dedup Store

You cannot store keys forever. Give the dedup store a TTL sized to your max retry window — Redis with expiry is a common choice.

redis.set("idem:" + key, result, "EX", 86400, "NX");

Idempotency vs Exactly-Once

True exactly-once delivery is extremely hard. The practical pattern is at-least-once delivery plus idempotent processing, giving effectively-once behavior.

Designing Idempotent Events

Make event handlers idempotent: include a unique event id, prefer absolute state changes, and guard side effects so a redelivered event never repeats them.

Where to Apply It

Apply idempotency at every retry boundary — API gateways, queue consumers, saga steps, webhooks. Anywhere a message can arrive twice needs a dedup strategy.

Quick Check

The same message just arrived twice — does your design still do the right thing? Check your idempotency grasp.

Recap

You made operations retry-safe: at-least-once causes duplicates, idempotent operations repeat harmlessly, use keys and dedup, keep record-and-process atomic with a TTL.

よくある質問

「冪等性とメッセージ重複排除」レッスンは無料ですか?

はい。「冪等性とメッセージ重複排除」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Microservices Communication Patterns (Saga, Circuit Breaker)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Microservices Communication Patterns (Saga, Circuit Breaker)コースには全4レッスンが含まれています。

「冪等性とメッセージ重複排除」で何を学びますか?

冪等なハンドラーを設計し、分散システムでメッセージの重複を排除して、マイクロサービスの処理を安全に再試行できるようにします。 ブラウザで直接実行するハンズオンコードでMicroservices Communication Patterns (Saga, Circuit Breaker)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Microservices Communication Patterns (Saga, Circuit Breaker)を始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのMicroservices Communication Patterns (Saga, Circuit Breaker)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「冪等性とメッセージ重複排除」レッスンにはどのくらい時間がかかりますか?

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

このMicroservices Communication Patterns (Saga, Circuit Breaker)レッスンでコードを書いて実行できますか?

はい。すべてのMicroservices Communication Patterns (Saga, Circuit Breaker)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

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

  1. 同期通信と非同期通信の比較
  2. 分散システムの課題
  3. API Gatewayとサービスディスカバリ
  4. 冪等性とメッセージ重複排除
← Microservices Communication Patterns (Saga, Circuit Breaker)に戻る