분산 트랜잭션
여러 독립적인 노드에 걸쳐 있는 데이터베이스 작업 집합이 모두 성공(커밋)하거나 모두 실패(롤백)하도록 원자적으로 보장하는 메커니즘.
CAP 정리(브루어, 2000): 분산 시스템은 일관성, 가용성, 파티션 허용성 세 가지 중 두 가지만 보장할 수 있습니다.
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살도 이해할 수 있게 설명
온라인으로 콘서트 티켓을 구매한다고 상상해 보세요. 웹사이트는 동시에 두 가지를 해야 합니다: (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.