AlgoViz

A transfer crosses two shards

medium 6 min

An allocation moves credits between two accounts on different shards.

Video lesson · Chapter 1 of 5

A ticket spans two accounts

0:00 / 3:52

Both shards said ready. Is the transfer committed?

1:14Reel

Theory

Read or listen first. About 1 min.

What it is

Moving credits involves a local question at each shard and a shared question across them. Is the debit valid against the current balance? Will both shards finalize the same transfer outcome? Replicating each shard helps it survive a machine failure. A cross-shard transaction also needs agreement on whether this particular operation committed.

A prepared participant waits for the decision

Shard ACoordinatorShard BPrepareReadyPrepareReadyA prepared shard cannot choose its own outcome.
Both shards durably prepare and promise that they can commit. Their reserved changes stay pending until a decision arrives.

Why it exists

In a prepare-and-commit protocol, a participant that promises it can commit must retain enough durable state to honor the eventual decision. If the decision is temporarily unavailable, independently guessing an outcome can leave one account debited and the other uncredited.

View diagram · Commit decision
Client → Coordinator (T17); Coordinator → Decision log (record outcome); Coordinator → Debit shard (prepare or finish); Coordinator → Credit shard (prepare or finish)
Retrying the same intent must resolve its existing outcome.
Full size

Words to know

Atomic commit
Participants agree on one outcome for all parts of a transaction.
Prepared state
A durable promise that a participant can commit if instructed.

How it works

Step through the idea, or press Play.

Step 1 of 3

Separate replication and commit. Consensus orders changes within a replica group. Atomic commit coordinates the outcome across participating groups. A quorum on one shard says nothing about whether the other shard debited its account.

Understand it

Start here

Follow transfer T17

Track receipt T17 as forty credits move from A to B. Watch the account values and the receipt separately: the money can move even when the client never receives the reply.

Follow transfer T17
Move 40 credits with receipt T17Shard A100 creditsT17openedShard B0 creditsStart with 100 credits in total

Check the original transaction identity.

Structure

Commit decision

Commit decision

Client → Coordinator (T17); Coordinator → Decision log (record outcome); Coordinator → Debit shard (prepare or finish); Coordinator → Credit shard (prepare or finish)
Retrying the same intent must resolve its existing outcome.

One missing acknowledgment

Debit 40 credits on shard A and credit 40 on B. Drop the reply immediately after a durable commit. Replay the same logical transfer. Check both account histories and the total across accounts: there should be one movement of 40, with the total unchanged.

One outcome across participants

Follow transfer T17

ObservationWhat the client knowsSafe next step
Validation rejects debitNo transfer was acceptedReport insufficient credits
Both participants prepareResources are reserved for the decisionAwait a durable outcome
Coordinator commits, reply dropsClient sees a timeoutLook up T17
Lookup returns committedThe transfer succeededReturn its existing receipt

Why uncertainty becomes expensive

Prepared work can occupy locks or other resources while the outcome is resolved. Long network paths and slow participants extend that interval. Place strongly related data together when the common operation needs a single commit boundary. If the data must span shards, monitor time spent prepared and the oldest unresolved transactions.

When intermediate states are acceptable

A travel itinerary can sometimes expose a flight reservation while a hotel request is pending, then cancel the flight if the hotel fails. That choice requires customer-visible states, a durable workflow, and a plan for failed compensation. Account balances that promise atomic movement impose a different contract. Choose the contract before choosing the protocol.

Resolve T17

  • Check the original transaction identity.

Create a new transfer

  • An unknown outcome can become a duplicate movement.

Balance after one transfer

(100−40)+(0+40)=100(100-40)+(0+40)=100
Check transfer history as well: a second balanced transfer would also preserve the total.

Summary

The whole topic in one minute.

A missing reply is an observation about transport. Recover the durable outcome of the original operation before initiating another movement.

Sources