Partitioning, Transactions and Durable Workflows

Scaling ownership and coordinating effects create different failure windows. This stage connects partition movement, isolation and workflow recovery to an explicit business invariant.

Section 6 of 9 · 14 units · about 58 hours

0/14

By the end you can Rebalance without violating ownership, reproduce and prevent the selected isolation anomaly, and preserve one cross-service invariant through duplicate delivery, partial failure, coordinator death and reconciliation.

Units

Build it

Mini project · about 18 to 24 hours

Fenced shard movement and recoverable transaction workflows

Extend loglab from a replicated group to versioned shard ownership and durable cross-shard work on your machine. Build reduced isolation, atomic-commit and saga fixtures over the existing log, comparing their guarantees and recovery costs without treating compensation as rollback or routing versions as revocation.

  1. 1Build shard/ placement for range, hash, weighted virtual-node rings and rendezvous routing. Compare joins, leaves and scans with exhaustive placement and access-pattern oracles; retain key/byte movement and fan-out predictions. Check replica placement against independently enumerated failure-domain losses rather than counting virtual nodes as independent replicas.
  2. 2Implement atomic versioned maps, refresh-and-retry routing and fenced freeze/install/delete movement while unaffected shards serve. Check ownership and retained writes against a sequential oracle across stale routes, delayed migration RPCs and controller restart from durable current/next configurations; retain traces. Optionally run MIT 6.5840 Lab 5A/5B.
  3. 3Build shared/exclusive locking with growing/shrinking phases, commit-held locks, predicate protection and wait-for-cycle aborts in txn/. Check anomaly fixtures against Berenson's definitions and transaction results against independent serial-order enumeration, including real-time constraints; retain deadlock, phantom, retry and serializable-but-not-strictly-serializable regressions.
  4. 4Add MVCC version selection, safe reclamation and shared-timestamp reads across shards, waiting for each safe time including unresolved prepares. Check against a version-history oracle; retain pinned-snapshot and lagging-shard regressions. Compare per-shard/global index queries and CDC-fed updates with full scans, preserving postings/fetch/merge costs and staleness evidence.
  5. 5Implement durable prepare, tentative writes, lock recovery and coordinator decisions using the Building Distributed Systems two-phase-commit and coordinator-failure drills as protocol checks. Restart at each persistence boundary and duplicate decisions; compare recovered results with an independent atomic-outcome oracle, preserving in-doubt blocking and timeout-after-commit histories.
  6. 6Build txn/'s durable saga with outbox/inbox transactions, ordered relaying and atomic processed-ID/effect storage. Inject coordinator death, ambiguous replies, duplicates and failed compensation; compare paused per-business ledgers with independent invariants. Retain fenced recovery, bounded retries/escalation, irreversible-pivot policy and pending-versus-terminal verdicts.
  7. 7After deterministic gates, run repeated matched baseline/fault comparisons, validating extraction against hand-counted histories. Retain versions, workloads, latency distributions, skew, hot-key split/read-fan-out, scatter-gather tails, moved keys/bytes, cutover availability, abort/compensation denominators, suppressed deliveries versus duplicate effects, goodput, recovery predicates and invariant verdicts; include unresolved and negative regimes.
What you hand in
  • The shard/ routing and recoverable movement fixture plus txn/ isolation, atomic-commit, saga, outbox and inbox implementations.
  • Independent placement, version-history, serial-order and business-ledger checks with deterministic crash, stale-owner, deadlock and compensation regressions in tests/ and faults/.
  • Raw histories and repeated matched cost reports in reports/, with explicit atomic boundaries, irreversible steps, pending work and recovery assumptions.
How to check it
How it's graded

Placement and ownership

Pass: Your placement oracle checks movement and failure-domain survival; sequential-model tests preserve acknowledged writes and exclusive serving authority across stale routes, movement crashes and controller recovery.

Great: Interrupted transitions resume without silent drops; per-event evidence distinguishes map publication, source fencing and destination activation while unaffected shards continue serving.

Isolation and atomicity

Pass: Your independent serial-order and version-history oracles validate locking and snapshot fixtures. Atomic-outcome checks cover durable prepare, decisions, recovered locks and duplicate decisions without treating timeout as abort permission.

Great: Negative controls expose phantoms, write skew, premature version reclamation and inconsistent shard snapshots; recovery evidence explains permitted blocking separately from isolation or atomicity violations.

Workflow recovery evidence

Pass: Your paused per-business ledger oracle catches false terminal status and duplicate effects; outbox/inbox recovery handles ambiguous replies and failed compensation. Hand-counted metrics validate repeated matched runs with named versions and workloads.

Great: Reconciliation preserves unresolved irreversible effects and retry escalation; measured skew, movement, tails, aborts and recovery costs retain negative regimes without weakening invariants or hiding pending work.

Resources

  • DDIA 2e - Chapters 7 and 8 Sharding and TransactionsMartin Kleppmann and Chris Riccomini

    Read both chapters completely. Build a decision table connecting access pattern, partition key, isolation, atomicity, failure and recovery before implementing either the partition map or workflow.

  • A Critique of ANSI SQL Isolation Levels (Berenson et al., 1995)arXiv (Microsoft Research report)

    Read the phenomena P0 to P3, the snapshot-isolation anomalies A5A (read skew) and A5B (write skew) and the summary tables. Cite these definitions, not the SQL-92 prose they correct.

  • Sagas (Garcia-Molina and Salem, 1987)Cornell course copy

    Read the whole paper: a saga is a sequence of transactions with compensating transactions, and compensation is application-defined. Name the steps whose effects cannot be compensated.

  • CMU 15-445 - Concurrency Control, Logging and RecoveryCarnegie Mellon Database Group

    Follow Fall 2025 lectures 17 to 22, the transactions homework and the concurrency-control project where available. Reproduce lost update and write skew outside the project before claiming an isolation level.

  • PostgreSQL 18 Documentation - Transaction Isolation and Explicit LockingPostgreSQL Global Development Group

    Read Section 13.2 (Read Committed, Repeatable Read and Serializable with its serialization failures) and 13.3 (row locks and deadlocks). Reproduce write skew under Repeatable Read and its rejection under Serializable in the postgres:18 image.

  • MIT 6.5840 - Distributed Transactions and Lab 5 Sharded KVMIT PDOS

    Use lecture 11 and Lab 5 for coordinator failure, shard ownership and migration. Treat the lab as the integrated advanced path; a smaller deterministic partition map is sufficient for the compulsory gate if time is constrained.

  • HLD Handbook - Sharding, Distributed Transactions and IdempotencyHLD Handbook

    Read Part 2 database sharding, then Part 3 distributed transactions, idempotency and consistent hashing. Use Part 5 event patterns only for the chosen workflow design.

  • Weak Consistency: A Generalized Theory and Optimistic Implementations for Distributed Transactions (Adya, 1999)MIT LCS

    Read the dependency-graph definitions of G0, G1 (a, b and c) and G2 and the levels PL-1 to PL-3 they define. They are the anomalies Elle checks on recorded histories.

  • Serializable Snapshot Isolation in PostgreSQL (Ports and Grittner, 2012)arXiv

    Read the dangerous-structure rule (two adjacent read-write antidependencies) from Cahill et al. and how PostgreSQL implements and limits it. False positives abort transactions, so measure abort rates.

  • Spanner: Google's Globally-Distributed Database (Corbett et al., 2012)Google (author copy)

    Read TrueTime and the concurrency-control section (timestamps, commit wait, read-write and read-only transactions, two-phase commit over Paxos groups). TrueTime needs clock hardware, so emulate bounded uncertainty in simulation.

  • Large-scale Incremental Processing Using Distributed Transactions and Notifications (Peng and Dabek, 2010)USENIX OSDI

    Read the snapshot-isolation transaction protocol over Bigtable (primary lock, timestamp oracle) and notifications. Snapshot isolation still admits write skew.

  • The Internals of PostgreSQL - Concurrency ControlHironobu Suzuki

    Read Chapter 5 Sections 5.5 to 5.9 (snapshots, visibility rules, preventing lost updates and serializable snapshot isolation) to see one real engine implement the anomalies and isolation levels you reproduce. Note the date you read it.

  • DSLabs - Lab 4 Sharded Store and TransactionsUniversity of Washington (Ellis Michael)

    Labs are Java 21 message-passing state machines tested on an emulated network and by model-checking search tests that print a minimal violating trace; run them with the run-tests.py script and its --lab and --part options. Lab 4 adds a shard master, shard movement and multi-key transactions across groups with two-phase commit and locking (Part 3): use it for the commit protocol across groups, which MIT Lab 5 does not exercise.

  • Gossip Glomers - Totally Available TransactionsFly.io and Jepsen

    Each challenge runs locally under Maelstrom (v0.2.4; the pages were tested on 0.2.3) with its checker and, where the page says so, the partition nemesis; keep the run directory as the history. Do 6a to 6c (read-uncommitted, then read-committed transactions under partition). The 6b page says the checker cannot detect G0 anomalies, so a pass is weaker than its label.

  • AlgoMaster System Design - Selected Sharding and Transaction ProblemsAlgoMaster

    Use the sharding, consistent hashing, ACID, saga, idempotency and outbox lessons as vocabulary, and the problems Calculate Hash Shard Load, Count Keys Moved by Resharding, Merge Cross-Shard Top-K Results, Analyze Transaction Serializability, Build a Saga Compensation Order and Consume Outbox Events Idempotently and in Order as drills. The capstone must supply real persistence, fault history and load evidence.

  • Replicated Log and Stream Processor - Partition and Workflow SliceRoadmap-Final

    Add partition routing, ownership epochs, rebalance, one cross-partition invariant and a durable transaction or saga path. Inject stale routes, coordinator death, duplicate steps and failed compensation.

  • Building Distributed Systems - The Sharder and The CoordinatorBuild Distributed Systems

    Only the first three tasks of each track are free: in The Sharder, a shard controller, consistent hashing and configuration change; in The Coordinator, two-phase commit, coordinator failure and three-phase commit. Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.