HostForGames | From Checkout to a Running Game Server
The architecture behind HostForGames, a game-server hosting side project with 100+ users: PayPal checkout as a state machine, automatic provisioning on Pterodactyl, a cron-driven lifecycle and deploys that roll themselves back.
4 min readsveltekit · pterodactyl · docker · devops
Some people unwind with a game after work. I unwind by hosting other people's games. HostForGames is a side project a few of us run: you pick a game and a plan, pay, and shortly after your Minecraft or Arma Reforger server is up. More than 100 users rent servers from us.
The landing page is the easy part. The interesting part is everything between the Pay button and a server you can join, with nobody awake at 3 a.m. to click things.
The shape of it
One SvelteKit app does the web, the API and the scheduled jobs. It runs in Docker next to its SQLite database (WAL mode, versioned SQL migrations), behind Cloudflare. Game servers don't live there: Pterodactyl runs them on separate nodes, one container per server.
Checkout is a state machine
Money is the one thing you can't retry casually, so checkout has two halves.
Create order. The browser never decides the price. The server reloads the plans, applies discounts, credits or upgrade proration itself, checks that a node has room for a new server, and only then creates the PayPal order and stores ours as pending.
Capture. This is where money actually moves, so it's built to survive retries and double clicks. The capture is idempotent, the amount and currency PayPal took must match what we priced, and every order walks through three recorded states: not captured, captured but not delivered yet, delivered. The middle one is the point of no return: once we hold the money, every retry moves forward and nobody pays twice. Only after the database transaction commits (subscription, discounts and credits: all or nothing) do we touch the panel.
Provisioning: let the panel do the heavy lifting
Pterodactyl gives customers the hard UI for free: console, files, backups, start and stop. Each game is an egg: a Docker image, a startup command and its variables. Our job is the glue:
- Find the customer's panel account by email, or create it.
- For each plan bought: pick a node with capacity and take a provisioning lock, so two checkouts can't claim the same room.
- Allocate ports, read the egg, create the server with the plan's CPU, RAM and disk limits.
- Store the server ID against the subscription.
An upgrade patches the server's build limits. A renewal unsuspends it. If a step fails after the payment, the order falls back to manual provisioning instead of failing silently. Add-ons like a MariaDB database or a Discord bot are eggs too, generated by scripts in the repo.
A lifecycle that runs itself
Subscriptions are monthly, and a cron job walks every one through the same states. Each run takes a lock in the database, so two overlapping runs never suspend the same server twice.
Renewing while suspended pushes the end date forward and unsuspends the server, so nobody loses their world over a late payment.
Deploys that undo themselves
Every pull request runs type checks, unit and integration tests, the migrations against a copy of the database, the build and a dependency audit. A merge to the main branch ships it:
- The release is packed into an archive and copied to the server over SSH.
- A lock makes sure only one deploy runs at a time.
- The database gets an online backup, and the running image is kept as the rollback.
- The new image builds while the old container keeps serving, then the new one starts and has to pass a health check.
- If it doesn't, the previous code and image come back, without rebuilding. The database is never restored automatically: migrations are additive, and a restore would throw away whatever customers wrote in between.
DDoS is part of the job
Game servers attract DDoS like nothing else. Somebody loses a match, somebody rents a botnet. The website sits behind Cloudflare, and signup and login go through Turnstile so bots don't farm free servers. Game traffic is raw TCP and UDP to the nodes, so it can't hide behind an HTTP proxy: it needs mitigation at the network level.
What I'd steal from it
- Treat payment capture as a state machine with a point of no return.
- Let a battle-tested panel own the hard UI. Own the glue.
- Make deploys boring: backup, health check, automatic rollback.
- Write your failure modes down before your customers find them.
Running a hosting business on the side means a server can go down while I'm in a meeting about servers going down. Engineering, but recursive.