0Pricing
Serverless AWS Lambda Development · レッスン

分散トランザクションのSagaパターン

分散トランザクションを使わずに、Sagaパターンと補償アクションで複数のサービスにまたがるデータ変更を調整する方法を学びます。

「分散トランザクションのSagaパターン」はCoddyKit上の無料Serverless AWS Lambda Developmentレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはServerless AWS Lambda Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Serverless AWS Lambda Developmentコースには全4レッスンが含まれています。

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

The Distributed Data Problem

In event-driven systems each service owns its own data. A single business operation may span several services, but there is no shared transaction to roll them all back.

What is a Saga?

A saga breaks one big transaction into a sequence of local transactions. If a step fails, earlier steps are undone with compensating actions.

A Worked Example

Placing an order: reserve inventory, charge payment, create shipment. If payment fails, you must release the reserved inventory.

Compensating Actions

Every forward step needs a matching undo. Reserve has Release; Charge has Refund. Compensations make the system eventually consistent.

steps = [
  ('reserveInventory', 'releaseInventory'),
  ('chargePayment', 'refundPayment'),
  ('createShipment', 'cancelShipment')
]

Choreography Style

In choreography, each service reacts to events and emits the next event. There is no central coordinator, but the flow is implicit and harder to follow.

Orchestration Style

In orchestration, a coordinator (often AWS Step Functions) explicitly drives each step and triggers compensations on failure. The flow is centralized and visible.

Step Functions Fits Sagas

Step Functions supports a Catch on each task to invoke a compensation, making it a natural home for orchestrated sagas.

{
  "ChargePayment": {
    "Type": "Task",
    "Resource": "arn:...:chargePayment",
    "Catch": [{"ErrorEquals": ["States.ALL"], "Next": "ReleaseInventory"}],
    "Next": "CreateShipment"
  }
}

Idempotency is Essential

Saga steps and compensations may be retried, so each must be idempotent. Use a unique transaction id to detect and ignore duplicates.

Eventual Consistency

During a saga the system is temporarily inconsistent. Design the UI and downstream consumers to tolerate states like "payment pending".

Semantic Locks

To avoid conflicts mid-saga, mark records with a pending status (a semantic lock) so other operations know the data is in flight.

When to Use a Saga

Use sagas when a workflow truly spans services. If everything lives in one service or one database, a normal local transaction is simpler and safer.

Quick Check

Test your saga knowledge.

Recap

You learned the saga pattern: split a distributed operation into local steps with compensating undos, choose choreography or orchestration, and keep steps idempotent.

よくある質問

「分散トランザクションのSagaパターン」レッスンは無料ですか?

はい。「分散トランザクションのSagaパターン」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Serverless AWS Lambda Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Serverless AWS Lambda Developmentコースには全4レッスンが含まれています。

「分散トランザクションのSagaパターン」で何を学びますか?

分散トランザクションを使わずに、Sagaパターンと補償アクションで複数のサービスにまたがるデータ変更を調整する方法を学びます。 ブラウザで直接実行するハンズオンコードでServerless AWS Lambda Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Serverless AWS Lambda Developmentを始めるのに経験は必要ですか?

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

「分散トランザクションのSagaパターン」レッスンにはどのくらい時間がかかりますか?

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

このServerless AWS Lambda Developmentレッスンでコードを書いて実行できますか?

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

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

  1. イベント駆動マイクロサービスの構築
  2. Amazon EventBridgeとの統合
  3. Kinesisによるリアルタイム処理
  4. 分散トランザクションのSagaパターン
← Serverless AWS Lambda Developmentに戻る