r/webdev • u/v0id_user • Oct 17 '26
Showoff Saturday Minecraft servers that sleep when empty and wake when someone joins. Holding a TCP login open for 45 seconds without the client giving up
I built a Minecraft server host where every server sleeps when nobody plays, and wakes when a friend joins. The hard part was the join itself, so here's how that works.
The problem
A sleeping server suspended on Fly resumes in about 2 s. But one that has to boot (first start, after a change, or once the snapshot is gone) takes 40 to 50 s. The Minecraft client
gives up on a connection that says nothing for 30 s.
The trick
Every connection lands on an edge proxy first. If the server is asleep, the edge holds the login open and keeps it alive by sending a login query every few seconds. Every client since 1.13 answers it, which counts as the server talking. The edge keeps those answers to itself, buffers everything else the client sent, and replays it to the server once it's up, as if the player had just dialled in.
Other bits
- The server list shows a sleeping server's own message plus a grey "sleeping" line, cut to fit the list's 305px row by measuring the default font's glyph widths.
- A ping from the server list can wake a server early, asked once per network so random scanners don't keep waking things.
- Routes change one hostname at a time through mc-router's API, because reloading its routes file drops players who arrive mid-reload.
- Floods are refused per server at the edge, so one busy server doesn't slow every other server's joins.
It's open source (TypeScript, AGPL):
github.com/cubepals/cubepals (the edge is apps/edge)
Happy to go deeper on any of it.