Transakcje Rozproszone
Mechanizmy gwarantujące, że zestaw operacji na bazie danych rozproszonych między wieloma niezależnymi węzłami albo w pełni się wykona (commit), albo w pełni się cofnie (rollback) — atomowo.
Twierdzenie CAP (Brewer, 2000): rozproszony system może gwarantować tylko dwie z trzech właściwości — Spójność, Dostępność, Odporność na partycje.
graph LR
Center["Transakcje Rozproszone"]:::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;
🧒 Wyjaśnij jak 5-latkowi
Wyobraź sobie, że kupujesz bilet na koncert online. Strona musi zrobić dwie rzeczy jednocześnie: (1) pobrać pieniądze z twojego konta, (2) dać ci bilet. Jeśli komputer banku pobierze pieniądze, ale komputer z biletami ulegnie awarii — zapłaciłeś i nic nie dostałeś. Transakcja rozproszona to reguła: 'Albo obie operacje się udają, albo obie są całkowicie cofnięte, jakby nic się nie stało.' Wszystko albo nic na wielu komputerach.
🤓 Expert Deep Dive
2PC — Protokół Blokujący: Jeśli koordynator ulega awarii po zebraniu wszystkich głosów YES, uczestnicy utrzymują wyłączne blokady w nieskończoność. SAGA: Każdy krok T_i ma transakcję kompensacyjną C_i. Błąd T_3 uruchamia C_2, potem C_1. SAGA poświęca Izolację dla dostępności. HTLC: Alicja blokuje BTC z hash(secret); Bob blokuje ETH tym samym hashem. Ujawnienie secret przez Alicję odblokowuje BTC dla Boba. Twierdzenie CAP: Spójność kontra Dostępność przy partycjach sieci.
❓ Częste pytania
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.