From one Minecraft server to a network

Minebox v1 crashed past 150 players on one server. How we rebuilt it as a network of Minecraft servers, proxies and services, and the problems we solved.

contents

Minebox v1 launched in 2022 and couldn't hold more than about 150 players. We spent a year rebuilding it as a network, by hand, before AI coding tools. Minebox has since reached 1,000 concurrent players.

This post explains the problems you hit when one Minecraft server becomes a network of servers, and how we solved each of them.

One server, one thread

A Minecraft server updates its world 20 times per second. Each update, called a tick, runs on a single thread: one CPU core does the work for every player, mob and block. When a tick takes longer than its twentieth of a second, the game slows down for everyone. Paper, the server software we use, moves some work like chunk loading to other threads, but the game itself stays on one. More cores don't help.

Minebox v1 ran everything on one server: the spawn and every player's island. Nothing in it could be split across servers. Past about 150 players the server fell behind, slowed down more as players kept joining, and eventually crashed, taking the spawn and every island down with it.

The only way past that limit was to run the game on many servers.

Why not Folia

Folia is a version of Paper that splits a world into regions and updates them in parallel on several cores. For some servers it's a good alternative to a network. It wasn't one for us:

  • It didn't exist when we started building the network in 2022. It came out in 2023, when our system was almost done.
  • Plugins have to be adapted for it, because it removes the single thread they're written for. Its own README says to expect almost no Paper plugins to work, and many of ours didn't.
  • It's still one server on one machine. PaperMC's sizing advice for Folia comes from a test server with a few hundred players, and a crash still takes everyone down. A network grows by adding machines.

The shape of the network

                            players
                               │
                  ┌────────────┴────────────┐
                  ▼                         ▼
              ┌───────┐                 ┌───────┐
              │proxy 1│                 │proxy 2│
              └───┬───┘                 └───┬───┘
                  └────────────┬────────────┘
                               ▼
  ┌────────────────────────────────────────────────────────┐
  │ game servers                                           │
  │ spawn · islands · PvP · raids · events                 │
  └────────────────────────────┬───────────────────────────┘
                               │ gRPC, both ways
  ┌────────────────────────────┴───────────────────────────┐
  │ services                                               │
  │ server registry · players · islands · social · market  │
  └────────────────────────────┬───────────────────────────┘
                               │
  ┌────────────────────────────┴───────────────────────────┐
  │ database · cache · object storage                      │
  └────────────────────────────────────────────────────────┘

The network has four layers:

  • Proxies are where players connect. A proxy, Velocity in our case, moves players between game servers without disconnecting them. We run two.
  • Game servers run the game. Each one has a type: spawn, islands, PvP, raids or events. Each type runs as many copies as it needs, and most of our fleet is island servers.
  • Services are programs we wrote in Go. They own everything shared across the network: player data, islands, chat, friends, guilds, the market, and the list of running servers.
  • Storage is a database (PostgreSQL) for structured data, object storage for large files like player data and island worlds, and a cache (Redis) for short-lived data that has to be fast.

Every game server and proxy runs the same plugin, mbcore, which connects it to the services.

Splitting the game

In v1, the spawn and the islands were on the same server, so they could only grow together. In the network, the game is split by role into server types, and each type grows on its own.

Islands needed the biggest change. Each island is its own world, stored outside the servers. When a player visits an island, it's loaded on an island server with free capacity, and unloaded when nobody is left. If the island is already loaded somewhere, the player is sent to that server. An island is locked while it's loaded, so two servers can never load the same one.

No island belongs to a server. To hold more players, we add island servers.

Game servers don't own shared data

On one server, everything shared lives in memory: a player's inventory, their island, their friends, chat, the economy. On a network, each server only sees its own players, so it can't be the owner of anything shared.

The rule: game servers run the game, services own the data. A server loads what it needs from the services and saves it back. Chat, friends, parties and guilds are services, so they work the same whatever server or proxy players are on. The market is a service too, so every server sees the same listings.

Because servers don't keep anything that isn't saved, any server can be restarted, replaced or added. That's also what lets us deploy updates without disconnecting players, covered in Scaling a Minecraft server with Kubernetes.

Talking across the network

Minecraft servers usually talk to each other with plugin messages, sent through the proxy. A plugin message travels on a player's connection: it needs a player on the sending server, and it only reaches the proxy that player is connected to. With two proxies, half the network can't receive it.

We use gRPC instead, a standard way for programs to call each other over the network:

  • Game servers and proxies call the services.
  • Each game server and proxy also accepts calls, so services can reach them: deliver a chat message, save a player, load an island.

There's no message broker in between. Services know where every player is, so they call the right server directly.

More than one proxy

One proxy is one process. It has a capacity limit, and restarting it disconnects everyone. So we run several. That breaks things a single proxy handled on its own, because each proxy only knows its own players:

  • Is my friend online, and on which server?
  • How do I move a player who is connected to another proxy?
  • How do I stop the same account from logging in twice, through two different proxies?

The fix is to keep that knowledge outside the proxies. The server each player is on is stored in the database, so any service can find any player. A second login of the same account is refused. To move a player, the network asks the proxies, and the one the player is connected to moves them.

Knowing which servers exist

Servers come and go: they restart, crash, and get added as the network grows. A service called server_manager keeps the list. How it runs and stays available is in Scaling a Minecraft server with Kubernetes. Each server registers when it starts, then reports regularly with its state, player count and tick rate. server_manager uses that list to decide where players go and where islands load, and removes servers that stop reporting.

One writer per player

The worst bugs in a network come from two servers writing the same player's data. When a player moves from server A to server B, A might still be saving while B has already loaded the player. The result is a duplicated item, or progress rolled back.

So only one server can write a player's data at a time:

  • A lock. Each player's data has a lock in the database naming the one server allowed to save it.
  • A handoff. When B loads a player, the network asks A to save and release them first. Only then does B get the lock.
  • A cache. A's last save is kept in the cache for a short time, so B doesn't wait for it to reach object storage.
  • An epoch. The lock carries a number that goes up at every handoff, and every save must carry the current number. A server that froze and comes back later still has an old number, so its saves are rejected. This technique is called a fencing token.

When a server crashes

A crashed server stops reporting. server_manager removes it and releases the locks it held on players and islands. Those players lose what happened since their last save. Everyone on other servers keeps playing. If the crashed server comes back, the epoch stops its old saves from overwriting anything.

What we'd tell anyone making the same move

  • Decide what's shared and move it out of the game servers first. Everything else depends on it.
  • Split the game by role, and make the parts that grow, like islands, loadable on any server.
  • Don't route anything through the proxy if you want more than one.
  • Make every handoff explicit: one writer at a time, with a lock and an epoch.

Questions, or a different approach? I'm @imevlad on X.