All work

Backend

Rewriting CubeCraft's leaderboards in Rust, behind shadow reads

How I rebuilt Rocket's leaderboards as an in-memory Rust gRPC service and checked it against the old Java and PostgreSQL path on live traffic first.

Ziax · CubeCraft and Rocket · 2026

The problem

Leaderboards are one of the most-read things on CubeCraft, a network with millions of players a month. Every read went through Java to PostgreSQL. I wanted them faster and cheaper to serve, but leaderboards are also very visible. If a player’s rank jumps around or a board comes back wrong, people notice fast.

The hard part was switching to it without anyone noticing.

What I built

  1. Game serverasks for a board page
  2. Java serviceanswers from PostgreSQL
  3. Shadow samplesame read sent to Rust in the background
  4. Comparemismatch and latency metrics
Shadow reads: players keep getting the old answer while the new service is checked against it.
  1. Read request
  2. Flag on?per board
  3. Rust servicein-memory board
  4. FallbackPostgreSQL when cold, loading or erroring
The cutover: the flag moves reads, and the old path catches anything the new one can't answer yet.

How a read works

A sketch of the idea, not the production code.

fn read_page(board, offset, limit):
    if not flag_enabled("leaderboards.rust", board):
        return postgres.page(board, offset, limit)

    match rust.page(board, offset, limit):
        Ok(page)                  -> return page
        Err(Cold | Loading | _)   -> return postgres.page(board, offset, limit)

fn shadow(board, offset, limit, served_page):
    if random() > SAMPLE_RATE: return
    spawn_detached:                       # not tied to the caller's request
        started = now()
        candidate = rust.page(board, offset, limit)
        metrics.latency("rust", now() - started)
        if not equivalent(served_page, candidate):
            metrics.mismatch(board, classify(served_page, candidate))

What the comparison caught

Both are counted apart from real mismatches now, so a genuine bug can’t hide behind them. The comparison also caught one of mine: shadow reads were being cancelled along with the incoming gRPC call, which quietly skewed the sample. Moving them onto a detached task fixed it.

Why it matters

Moving reads over is a flag flip backed by live data. The old path still answers whenever the new service errors or a board is cold or still loading, and sampled shadow reads flag disagreements in the metrics.

Stack