All work

Backend

Making game server writes safe to retry

Fixing player progress and XP being counted twice when a CubeCraft game server retried a write, with write IDs recorded atomically in Redis.

Ziax · CubeCraft and Rocket · 2026

The problem

Game servers send a steady stream of writes to Rocket, like progress and XP. When one times out, the server does the sensible thing and sends it again. But a timeout doesn’t mean the first write failed. Sometimes it landed and only the response got lost, so the retry counted it a second time. Players got XP they didn’t earn, or progress jumped ahead.

What I built

  1. Game serverwrite with ID w-123
  2. Rocketforwards to the script
  3. Redis Luaseen w-123?
  4. First timeapply, record ID with TTL
  5. Seen beforereturn the stored result
One round trip, atomic in Redis, so a retry inside the dedupe window can't double count.

The idea in pseudocode

A sketch of the idea, not the production code.

-- runs inside Redis, atomically
function apply_once(write_id, key, delta, ttl):
    existing = GET "write:" .. write_id
    if existing then                          -- a missing key comes back as false
        return existing                      -- a retry: same answer, no change
    end
    new_value = INCRBY key delta
    SET "write:" .. write_id new_value EX ttl
    return new_value

A sketch of the idea, not the production code.

// the game server side
id = new_write_id()
retry(max = 3, on = Timeout):
    rocket.add_xp(player, amount, write_id = id)   // same id every attempt

Why it matters

Retrying is the right call on a flaky network, and now it’s safe. Inside the dedupe window, game servers can retry a timed-out write without counting it twice, and nobody has to guess whether it went through.

Stack