100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Architecture

Distributed Transactions

Distributed transactions coordinate atomic, all-or-nothing updates across multiple independent services or databases, using protocols like two-phase commit or pattern-based sagas.

Distributed Systems TheoryAdvanced10 min readJul 9, 2026
Analogies

Distributed Transactions

A distributed transaction is a set of operations spanning multiple independent nodes, databases, or services that must succeed or fail together as a single atomic unit, even though no single node has full visibility or control over the others. This is straightforward within one database thanks to ACID transaction support, but becomes genuinely hard once you split state across services — for example, debiting a wallet service and crediting an order service in a microservices architecture — because a partial failure (one side commits, the other doesn't) leaves the system in an inconsistent state that's hard to detect and even harder to repair automatically. Distributed transaction techniques exist specifically to prevent or gracefully recover from these partial-failure states, at some cost in latency, availability, or implementation complexity.

🏏

Cricket analogy: Like a single umpire easily keeping the scorebook consistent alone, but once the scorebook is split between the bowling and batting team's separate official scorers, a mid-over disagreement can leave the runs credited on one side but not the other.

Two-Phase Commit (2PC)

Two-phase commit is the classical protocol for atomic distributed transactions. In the 'prepare' (voting) phase, a coordinator asks every participant to lock the relevant resources and confirm they are able to commit; each participant replies 'yes' (ready) or 'no' (abort). Only if every participant votes 'yes' does the coordinator move to the 'commit' phase, telling everyone to make the change permanent and release locks; if any participant votes 'no,' the coordinator tells everyone to abort and roll back. 2PC guarantees atomicity across nodes, but it has a serious weakness: if the coordinator crashes after participants have voted 'yes' but before sending the final commit/abort decision, participants are left blocked, holding locks indefinitely, unable to safely decide on their own whether to commit or abort — this is why 2PC is called a blocking protocol, and it's a major reason it fell out of favor for large-scale, loosely-coupled systems.

🏏

Cricket analogy: Like a match referee polling both captains before confirming a result change — 'are you ready to accept this?' — and only finalizing if both say yes; but if the referee vanishes after both agree but before announcing it, both teams are stuck unable to update the record on their own.

The Saga Pattern

The saga pattern sidesteps 2PC's blocking problem by abandoning true atomicity in favor of a sequence of local transactions, each with a corresponding compensating action that can undo its effect if a later step fails. Instead of holding distributed locks across services for the duration of a transaction, each service commits its own local transaction immediately and publishes an event or is invoked by an orchestrator to trigger the next step; if step N fails, the saga executes compensating transactions for steps 1 through N-1 in reverse order (e.g., 'refund payment' compensates 'charge card'). Sagas can be coordinated via choreography (each service reacts to events from the previous one, with no central coordinator) or orchestration (a central saga orchestrator explicitly calls each step and handles failures) — orchestration is generally easier to reason about and debug at scale, while choreography reduces coupling but can make the overall flow harder to trace. Because each local transaction commits immediately rather than waiting on a global lock, sagas sacrifice isolation compared to ACID: other parts of the system can observe intermediate, partially-completed states before the saga finishes (e.g., inventory temporarily shows stock reserved before payment is confirmed), which must be handled explicitly through semantic locks, versioning, or read paths designed to tolerate it.

🏏

Cricket analogy: Like a tour selector committing each squad change immediately (no locked-in whole squad) and, if a later pick falls through, reversing earlier picks one by one — either via each selector reacting to news individually (choreography) or a chief selector directing every change (orchestration), with the squad list visibly incomplete mid-process.

text
Saga (orchestrated) for 'place order':

1. Orchestrator -> Payment Service: charge card    [OK]
2. Orchestrator -> Inventory Service: reserve stock [OK]
3. Orchestrator -> Shipping Service: schedule ship  [FAILS]

Compensation kicks in, running in reverse:
4. Orchestrator -> Inventory Service: release stock (compensates #2)
5. Orchestrator -> Payment Service: refund card     (compensates #1)

Result: no step ever held a distributed lock; each local
transaction committed independently, and failure triggered
explicit compensating actions instead of a global rollback.

Most large e-commerce and payments platforms (e.g., systems modeled after Uber's or Amazon's order pipelines) use saga-style orchestration rather than 2PC precisely because order fulfillment spans many independently-owned, independently-scaled services (payments, inventory, shipping, notifications) where holding a single distributed lock across all of them for the duration of an order would be a severe availability and throughput bottleneck.

Idempotency and Exactly-Once Semantics

Because distributed transactions (especially sagas, which rely on retries when a step fails or a message is delayed) can result in a step being invoked more than once, every step and every compensating action must be idempotent — applying it multiple times must produce the same result as applying it once. This is typically achieved with idempotency keys (a unique ID per logical operation that the service checks before re-applying an effect) so that network retries, at-least-once message delivery, or orchestrator restarts never cause a double-charge or a double-refund. Idempotency is not optional in distributed transaction design — without it, the retry mechanisms that make sagas resilient to partial failure become a source of new bugs.

🏏

Cricket analogy: Like a scorer using a unique ball-ID so that if a run update is resent due to a radio glitch, the same run isn't credited twice — without this, a retried transmission would double-count runs on the scoreboard.

  • Distributed transactions coordinate atomic updates across independent services or databases, where no single node has full control.
  • Two-phase commit (2PC) provides strong atomicity via a prepare/vote phase and a commit/abort phase, but blocks participants indefinitely if the coordinator crashes mid-protocol.
  • The saga pattern replaces atomic distributed locking with a sequence of local transactions plus compensating actions for rollback.
  • Sagas can be choreographed (event-driven, no central coordinator) or orchestrated (central coordinator explicitly drives each step).
  • Sagas sacrifice isolation — intermediate, partially-completed states can be visible to other parts of the system before the saga finishes.
  • Every step and compensating action in a distributed transaction must be idempotent to safely tolerate retries.

Practice what you learned

Was this page helpful?

Topics covered

#Architecture#SystemDesignStudyNotes#SoftwareEngineering#DistributedTransactions#Distributed#Transactions#Two#Phase#StudyNotes#SkillVeris

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse