It's a complex topic in itself. Sometimes even seasoned professionals misunderstand.
▢ 𝟮𝗣𝗖 - atomic but blocking, commit or abort in two steps.
▢ 𝟯𝗣𝗖 - splits commit into two, reduces blocking and handles partial failures.
▢ 𝗦𝗮𝗴𝗮 - a sequence of local transactions that breaks a transaction into multiple steps.
𝗪𝗵𝗲𝗻 𝘁𝗼 𝘂𝘀𝗲 𝟮-𝗣𝗵𝗮𝘀𝗲 𝗖𝗼𝗺𝗺𝗶𝘁
→ When strict consistency is needed, all participants commit or abort.
→ For simple, low-latency systems with minimal crash risk.
𝗘𝘅𝗮𝗺𝗽𝗹𝗲: 𝗕𝗮𝗻𝗸 𝗙𝘂𝗻𝗱 𝗧𝗿𝗮𝗻𝘀𝗳𝗲𝗿 𝗕𝗲𝘁𝘄𝗲𝗲𝗻 𝗔𝗰𝗰𝗼𝘂𝗻𝘁𝘀 𝗶𝗻 𝘁𝗵𝗲 𝗦𝗮𝗺𝗲 𝗕𝗮𝗻𝗸
• Transfer involves debiting one account and crediting another.
• If one fails, the entire transaction must rollback.
• Atomicity is a must, and latency is acceptable.
𝗪𝗵𝗲𝗻 𝘁𝗼 𝘂𝘀𝗲 𝟯-𝗣𝗵𝗮𝘀𝗲 𝗖𝗼𝗺𝗺𝗶𝘁
→ When minimizing blocking is key, and partial failures must be avoided.
→ Where fault tolerance takes priority over message overhead and complexity.
𝗘𝘅𝗮𝗺𝗽𝗹𝗲: 𝗖𝗿𝗼𝘀𝘀-𝗥𝗲𝗴𝗶𝗼𝗻 𝗟𝗲𝗱𝗴𝗲𝗿 𝗦𝘆𝗻𝗰𝗵𝗿𝗼𝗻𝗶𝘇𝗮𝘁𝗶𝗼𝗻
Synchronizing transaction records between European and Asian data centers.
• Each region prepares and pre-commits.
• Final commit is sent when all regions are ready.
• Handles network partition or coordinator crash more gracefully than 2PC.
𝗪𝗵𝗲𝗻 𝘁𝗼 𝘂𝘀𝗲 𝗦𝗮𝗴𝗮
→ Performance matter more than strict consistency
→ Long-running distributed transactions where full rollback isn't practical
𝗘𝘅𝗮𝗺𝗽𝗹𝗲: 𝗜𝗻𝘁𝗲𝗿𝗻𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝗙𝘂𝗻𝗱 𝗧𝗿𝗮𝗻𝘀𝗳𝗲𝗿 (𝗦𝗪𝗜𝗙𝗧)
Transferring funds from a bank in Germany to one in Singapore via SWIFT or similar clearing systems.
• Debit sender → Local transaction
• Notify intermediary → Local transaction
• Credit receiver → Local transaction
• If the final step fails, compensation (e.g., refund sender) is triggered.