0Pricing
WebSockets & Realtime Systems Programming · レッスン

メッセージ確認と配信保証

確認応答、リトライ、冪等性を追加し、メッセージが気付かないまま失われるのを防いで、信頼性の高い配信を実現します。

「メッセージ確認と配信保証」はCoddyKit上の無料WebSockets & Realtime Systems Programmingレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWebSockets & Realtime Systems Programming学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 WebSockets & Realtime Systems Programmingコースには全4レッスンが含まれています。

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

Messages Can Vanish

A message can be lost if the socket drops mid-send, the server crashes, or the client reloads before processing. Without acknowledgements, neither side knows it happened.

Delivery Guarantee Levels

Three common guarantees:

  • At-most-once: may lose, never duplicate
  • At-least-once: never lose, may duplicate
  • Exactly-once: never lose, never duplicate (hardest)

Application-Level Acks

WebSockets only confirm transport delivery, not processing. To know a message was handled, the receiver must send an explicit ack back.

Adding a Message Id

Tag each message with a unique id so acks can reference it.

const msg = { id: crypto.randomUUID(), type: 'order', data };
ws.send(JSON.stringify(msg));

Sending the Ack

The receiver replies with an ack carrying the original id once it has safely processed the message.

ws.send(JSON.stringify({ type: 'ack', id: msg.id }));

Tracking Unacked Messages

The sender keeps a map of in-flight messages until their ack arrives.

const pending = new Map();
pending.set(msg.id, msg);

Retrying on Timeout

If no ack arrives within a timeout, resend the message. This is how at-least-once delivery is achieved.

setTimeout(() => {
  if (pending.has(msg.id)) ws.send(JSON.stringify(msg));
}, 3000);

The Duplicate Problem

Retries can deliver the same message twice (e.g. the ack was lost, not the message). At-least-once therefore implies the receiver may see duplicates.

Idempotency to the Rescue

Make processing idempotent: handling the same id twice has the same effect as once. Track seen ids and ignore repeats.

const seen = new Set();
if (seen.has(msg.id)) return;
seen.add(msg.id);
process(msg);

Approaching Exactly-Once

True exactly-once is impossible to guarantee end-to-end, but at-least-once delivery plus idempotent handling gives the same practical result, which is what most systems use.

Best Practices

Build reliable delivery:

  • Tag messages with unique ids
  • Require application-level acks
  • Retry unacked messages with a timeout
  • Make processing idempotent to absorb duplicates

Quick Check

Test your delivery knowledge.

Recap

You added delivery guarantees to realtime messaging:

  • Understand at-most/at-least/exactly-once
  • Use message ids and application-level acks
  • Retry unacked messages
  • Combine at-least-once with idempotency

Your system no longer silently loses messages.

よくある質問

「メッセージ確認と配信保証」レッスンは無料ですか?

はい。「メッセージ確認と配信保証」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、WebSockets & Realtime Systems Programmingコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 WebSockets & Realtime Systems Programmingコースには全4レッスンが含まれています。

「メッセージ確認と配信保証」で何を学びますか?

確認応答、リトライ、冪等性を追加し、メッセージが気付かないまま失われるのを防いで、信頼性の高い配信を実現します。 ブラウザで直接実行するハンズオンコードでWebSockets & Realtime Systems Programmingを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

WebSockets & Realtime Systems Programmingを始めるのに経験は必要ですか?

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

「メッセージ確認と配信保証」レッスンにはどのくらい時間がかかりますか?

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

このWebSockets & Realtime Systems Programmingレッスンでコードを書いて実行できますか?

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

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

  1. 切断と再接続への対応
  2. 堅牢なエラー伝播と復旧
  3. ハートビートとキープアライブ
  4. メッセージ確認と配信保証
← WebSockets & Realtime Systems Programmingに戻る