分散トランザクション

複数の独立したノードをまたぐ一連のデータベース操作が、全て成功(コミット)するか全て失敗(ロールバック)するかをアトミックに保証するメカニズム。

CAP定理(ブリュワー、2000年): 分散システムは一貫性、可用性、分断耐性の3つのうち2つしか保証できません。

        graph LR
  Center["分散トランザクション"]:::main
  Rel_decentralized_derivatives_pricing_models["decentralized-derivatives-pricing-models"]:::related -.-> Center
  click Rel_decentralized_derivatives_pricing_models "/terms/decentralized-derivatives-pricing-models"
  Rel_transaction_sharding["transaction-sharding"]:::related -.-> Center
  click Rel_transaction_sharding "/terms/transaction-sharding"
  Rel_decentralized_exchange_dex_order_book["decentralized-exchange-dex-order-book"]:::related -.-> Center
  click Rel_decentralized_exchange_dex_order_book "/terms/decentralized-exchange-dex-order-book"
  classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
  classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
  classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
  classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
  linkStyle default stroke:#4b5563,stroke-width:2px;

      

🧒 5歳でもわかるように説明

コンサートのチケットをオンラインで購入するとします。ウェブサイトは同時に2つのことをする必要があります:(1) あなたの銀行からお金を引き落とす、(2) あなたにチケットを渡す。もし銀行のコンピュータがお金を引き落とし、チケットのコンピュータがクラッシュしたら、支払ったのに何も受け取れません。分散トランザクションはこのルールです:「両方成功するか、両方が完全に元に戻るか — 中間はない」。複数のコンピュータにまたがる全か無かの取引です。

🤓 Expert Deep Dive

2PC — ブロッキングプロトコル: コーディネーターが全てのYES票を集めた後にクラッシュすると、参加者は無限に排他的ロックを保持します。SAGAパターン: 各ステップT_iは補償トランザクションC_iを持ちます。T_3での失敗はC_2、次にC_1を実行します。SAGAは可用性のために分離性を犠牲にします。HTLC: アリスはhash(secret)でBTCをロック; ボブは同じハッシュでETHをロック。アリスがsecretを明かしてETHを受け取ると、ボブがそのsecretでBTCを受け取れます。CAP定理: ネットワーク分断時の一貫性 vs 可用性。

❓ よくある質問

What is the main problem with Two-Phase Commit (2PC)?

It is a blocking protocol. If the coordinator crashes after collecting all 'YES' votes but before sending the final COMMIT or ABORT decision, all participant nodes freeze, holding database locks indefinitely, until the coordinator recovers.

What is the SAGA pattern and why is it preferred in microservices?

A SAGA breaks a long transaction into smaller local transactions, each with a compensating transaction that undoes it. It avoids distributed locks, making services more available, but sacrifices strict isolation (intermediate states may be visible to other services).

How does a Hash Time Lock Contract (HTLC) enable trustless atomic swaps?

Both parties lock their assets using the same cryptographic secret hash. The first party reveals the secret to claim the other's asset, and this revelation automatically unlocks the secret for the second party to claim the first's asset. If either party doesn't act within the time limit, funds are refunded.

📚 出典