advanced26 min studyLesson 266 in Engineering

Deterministic transaction ordering

Move agreement before execution while preserving access-set, replay, and nondeterminism assumptions.

On this page

What you’ll understand

  • Explain why agreeing on inputs before execution changes coordination.
  • Identify nondeterministic inputs that replicas must not invent independently.
  • Separate a planned serial order from unnecessary global serial execution.

Two transactions compete for a small remaining GPU quota. A conventional system may execute both and later coordinate conflicts. A deterministic design first agrees on the relevant transaction inputs and order, then arranges execution so replicas make the same decisions. The potential saving comes from moving and restructuring coordination, not from abolishing agreement or assuming that all programs naturally replay identically.

Agree on the work before acquiring its resources

Calvin’s design replicates an ordered transaction input stream and uses deterministic scheduling to avoid a conventional distributed commit agreement phase for its supported execution model. Participants can know which conflicting transaction should precede another before holding the transaction’s locks. This changes the contention footprint. It does not mean a partitioned machine can ignore the agreed plan, or that a node failure authorizes a new outcome. Recovery and replay must follow the same input and ordering commitments.

Execution need not be globally single-threaded. Nonconflicting transactions can overlap, and separate shards can perform their portions while preserving the required conflict order. Distinguish the order of logical effects from wall-clock instruction interleaving. If two transactions touch independent records, forcing one to finish entirely before the other starts can waste parallel capacity. The scheduler needs enough information to identify their accesses and coordinate dependencies, rather than granting unlimited parallelism and hoping the final outputs match.

Si+1=F(Si,Ii)S_{i+1}=F(S_i,I_i)
S_i is the relevant database state and I_i the agreed input at logical position i. Deterministic replay requires the same specified transition function F and inputs; this notation does not establish safe concurrent implementation or durability by itself.↔ Scroll wide equations horizontally.

Make every decision input reproducible

Wall-clock reads, random choices, external API results, unordered iteration, and application-version changes can all create different outcomes from apparently identical requests. A deterministic design must eliminate such differences, record them as agreed inputs, or provide a supported mechanism to resolve them consistently. Replaying an external payment call is especially dangerous because deterministic arguments about database state do not make the outside service idempotent. Define which effects belong to the replicated transaction and which need a separate delivery protocol.

Calvin’s scheduling depends on obtaining transaction read and write sets in advance. Data-dependent access can require a reconnaissance or planning mechanism and validation of what it discovered; it is not free support for arbitrary interactive transactions. Preserve the distinction between a business rule that deterministically declines a request and a system-level abort caused by execution uncertainty. A replay must reproduce the authorized logical behavior, while failures and membership changes follow the surrounding replication and recovery rules.

W(Ti)∩(R(Tj)∪W(Tj))=∅W(T_i)\cap\bigl(R(T_j)\cup W(T_j)\bigr)=\varnothing
For i before j, this absence removes one direction of record-level conflict. Independence also needs the reverse read-write check and complete access/predicate information. R and W are sets, and this one expression alone is not a complete parallel-scheduling test.↔ Scroll wide equations horizontally.

Unique order survives finite labels and restarts

An ordering position needs a stable identity across epochs, replay, and log compaction. A small wrapping slot number cannot identify an unlimited history by itself. Keep the epoch, sequence, or other protocol context that distinguishes reused positions. Observe ordering latency separately from execution and dependency waiting: a fast execution engine can still queue behind a saturated input-ordering service. Evaluate recovery time and access-planning overhead as well as steady-state throughput under the workloads the design actually supports.

The modular lab makes the label-reuse issue concrete. Reset, set modulus to 4 and additive step to 1, predict when the displayed residue returns to zero, then Step four times. For a fresh comparison, Reset and explicitly set modulus to 5 and additive step to 1, predict, then Step five times. Each Step advances one addition. This is a finite additive orbit, not Calvin’s sequencer or a transaction log; explain why returning to label zero does not mean the previous operation at zero is the same operation.

Order two quota reservations

Quota starts at 10 units. Request A reserves 7 units if enough remain; request B reserves 5 under the same rule. Both inputs and the conditional rule are deterministic. Compare agreed order A then B with order B then A.

  1. With A first, the state changes from 10 to 3 units. B then sees only 3, so its 5-unit reservation is declined and the final state remains 3.

  2. With B first, quota becomes 5. A needs 7 and is declined, leaving 5. Both histories preserve nonnegative quota but serve different requests.

  3. Replicas must use the same agreed order and rule to reproduce the same accepted request and final state. Identical initial data alone is insufficient when the operations do not commute.

The result

Ordering is an application-visible choice. Deterministic execution must reproduce both successful mutations and business-rule declines.

Explore the model

Interactive lab

Interactive lab · modular

A finite slot is not a unique history position

Reset, set modulus m = 4 and additive step a = 1, predict the return to zero, then Step four times. Compare a fresh Reset with both m = 5 and a = 1 before five Steps. This finite arithmetic orbit illustrates label reuse, not transaction ordering or log recovery.

A finite slot is not a unique history positionAddition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Current readings: Residue r0: 0; Orbit period · m/gcd(m,a): 12; Distinct residues visited: 1 of 12. All parameters are adjustable with the labeled controls below.Repeated addition modulo 12: the current residue is 0, and the orbit period is 12.01234567891011+ 5mod 12An additive orbitn = 0rₙ = 0Period = 12Cycle starts at 0:0 → 5 → 10 → 3 →8 → 1 → 6 → 11 →4 → 9 → 2 → 7 → 0Exact residues · two additions per second
Additive orbitCurrent residue / next edge
Residue r0
0
Orbit period · m/gcd(m,a)
12
Distinct residues visited
1 of 12
t = 0 s

Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA wrapping position needs protocol context to distinguish different operations occupying the same label.

Check your understanding

Two replicas replay the same ordered transaction requests but call a local random generator independently inside each transaction. What additional requirement is missing?

Try it yourself

Starting from quota 12, A conditionally reserves 8 and B conditionally reserves 6. Compute both serial orders. Name one implementation detail that can break replica agreement even if they agree on order.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Apply the capacity test against the current state after each earlier accepted request.

Compare with the solution

A then B accepts A, leaves 4, and declines B. B then A accepts B, leaves 6, and declines A. Replicas following one agreed order should match. A local time-based policy, unrecorded external lookup, random choice, or inconsistent application version can still make them diverge, so the replay contract must cover those inputs and code semantics.

Take it with you

  • Deterministic systems coordinate inputs and order before executing supported transactions.
  • Parallel execution remains possible when required conflict ordering is preserved.
  • Access planning, nondeterministic inputs, and stable history identity are explicit obligations.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.