Architecture · 10 min read · Illusion

Sharding a Minecraft world: the architecture

How Mosaic splits one Minecraft world across several servers: a coordinator, shards and a proxy, ownership by chunk claims, and leases with fencing epochs so that every chunk has exactly one writer.

The problemOne world, more players than one machine can tick in 50 ms. Folia spreads the work across cores, but every core is still in the same box.
The guaranteeEvery chunk has exactly one writer at a time. Players cross between servers without a loading screen. A crashed server's chunks come back from storage, not from guesswork.

Three moving parts

Ownership by chunk claims

By default the world is handed out in sections of 16×16 chunks, because a section is a cheap unit to lease and to move. Sections aren't a hard limit, though. A shard can claim individual chunks or carve a piece out of a section, so it can own exactly the chunks its regions tick. The coordinator places each region whole on one shard and keeps borders in idle ground, where nobody is ticking and a border costs nothing. Only a crowd too big for one shard gets cut.

Inside a shard nothing changes from Folia: only chunks near players tick, and separate groups of ticking chunks form separate regions with their own tick loops. A shard's tick time is set by its busiest region, not by the sum of everything it owns.

Leases, fencing epochs and the journal

Moving ownership is where split-brain bugs live. Two servers that both think they own a chunk will both write to it, and the world forks. Mosaic grants ownership as a lease, and every lease comes with a fencing epoch: a number that only ever goes up. Every write carries the epoch it was made under, and storage rejects any write with an older epoch than it has already seen. A shard that froze for a few seconds and woke up still believing it owns a chunk can try to write, but it can't succeed.

The journal records each grant and each saved hand-over. When a shard dies, its lease runs out, and the shards next to it take its chunks over from what was last committed to storage, under new epochs.

[CHECK: confirm this matches what the journal records in Mosaic today, and add its storage format if it's worth a paragraph.]

Moving chunks while people stand on them

When the load is uneven, the coordinator re-carves the claims and moves the chunks that changed hands. Every move runs in four steps: the current owner freezes the chunks, saves them, hands them over under a new epoch, and the new owner resumes ticking. The freeze covers only the chunks being moved, never the whole shard.

Some crowds are too dense to split by area. If a thousand players stand in one spot, no border fixes it. For that case a chunk becomes a replicated zone: players are spread across several shards, one shard ticks the blocks and mobs, and the others hold full replicas and forward player actions to it. A per-client visibility cap means each client only gets its nearest players, so a dense crowd doesn't flood everyone's connection.

Try it: set the shard slider, spawn 1,000 players at spawn, then kill a shard. Hover any chunk to see who owns it, which region ticks it, and who mirrors it.

Why not Folia, MultiPaper or a plain proxy?

FoliaParallel regions on one machine. It raises the ceiling but doesn't remove it. Mosaic runs Folia inside every shard and adds more machines on top.
Plain proxyVelocity or BungeeCord in front of several servers gives you several worlds. Moving between them means a server switch, a loading screen, and no shared border to see across.
MultiPaperThe closest prior art: it also shares one world between several servers. [YOUR REASON: what Mosaic does differently, e.g. leases and fencing, coordinator-driven balancing, replicated zones.]

Tradeoffs

A bug story

[BUG STORY: a real ownership or lease bug from building Mosaic: what broke, how it showed up in game, and the fix.]
← All writingNext: Zero-downtime handoff and ordered replication →