Replication · 11 min read · Illusion

Zero-downtime handoff and ordered replication

What happens when a player walks from one shard to another: swapping their backend mid-session, replaying their input, and keeping each shard's mirror of its neighbour in exactly the order things happened.

The problemMoving a player between servers normally means a disconnect and a loading screen. Showing two servers' worlds to each other means they disagree about what happened when.
The guaranteeA player crosses a border without disconnecting or losing input. Each shard's mirror applies its neighbour's changes in the order they were made, and is caught up before it takes a player over.

Part 1 · Handoff

Every player connects through Velocity, so the proxy is the one place that can move them without the client knowing. When a player crosses into another shard's chunks, the old shard keeps simulating them until the new one is ready. Then the proxy swaps the player's backend mid-session. The client keeps one connection the whole time.

The swap isn't instant, and the client keeps sending moves while it happens. Those moves are buffered and replayed on the new shard once it takes over, so nothing the player did is lost.

Bug story · the one-move-per-tick kick

The first version replayed every buffered move as soon as the new shard took over, all in the same tick. On 26.3 that got the player kicked: the server accepts one move per tick from a client, and a burst of buffered moves looks exactly like a cheating client. The fix was to replay at the rate a real client sends, one move per tick, until the buffer is empty.

[DETAIL: the exact kick message, and how you tracked it down.]

Part 2 · Mirror streams

Each shard keeps a read-only copy of a band of its neighbour's chunks. That copy is fed by a mirror stream: a snapshot to start from, then a numbered sequence of changes. The numbers matter. Applying change #46 before #45 isn't "slightly late"; it's a different world.

Bug story · the redstone clock that died at the border

A redstone clock built right on a shard border stopped after a few pulses. The neighbour updates were going over a separate path from the block changes, so the other shard sometimes got told "your neighbour changed" before the change itself had arrived. It re-evaluated the wire against a stale clock, saw nothing new, and never updated again. Moving neighbour updates into the mirror stream fixed it, because they can no longer overtake the change they describe.

[DETAIL: confirm this is the mechanism, and add how you found it.]

Scrub through one handoff. Tick either "first version" box to bring back the bug it caused.

Tradeoffs

← Sharding a Minecraft world: the architectureAll writing →