Deploy · self-hosted on your own machine or VPS
Run it yourself.
A one-command trial on your own computer, and a production install on one Linux machine (written for Ubuntu 24.04) with HTTPS and WSS through Caddy, migrations on every deploy, daily backups with a tested restore, and a hardened SSH login. This page is a summary; the deployment guide walks through every step.
Try it: one command
With Docker (Docker Desktop on Windows and macOS, Docker Engine on Linux), the same command in PowerShell, cmd, bash and zsh:
docker run --rm -p 127.0.0.1:8080:8080 ghcr.io/warmar94/net_backend_server:0.2
The image is the reference server for linux/amd64 and linux/arm64 with a configuration built in: SQLite in /data, migrations applied on start, accounts, storage, chat with a world room, a highscore leaderboard, notifications, friends, groups, the OpenID Connect module (no provider configured), lobbies, matchmaking with a duel queue, players' files in /data/files. Open http://127.0.0.1:8080/v1/info in a browser, or curl http://127.0.0.1:8080/v1/info (curl.exe in Windows PowerShell):
{"protocol":1,"min_protocol":1,"modules":["auth","chat","files","friends","groups","leaderboards","lobbies","matchmaking","notifications","oauth","storage"]}
Keep the data and create an administrator:
docker run -d --name nbs -p 127.0.0.1:8080:8080 -v nbs-data:/data ghcr.io/warmar94/net_backend_server:0.2
docker exec nbs net-backend-server user:create admin@example.com --admin
Image tags: 0.2.0, 0.2 (the newest 0.2.x release) and latest.
Production: choose the install path once
| Docker Compose | systemd | |
|---|---|---|
| Install | one Compose file, one setting (DOMAIN), docker compose up -d | build the binary, run install.sh |
| The server runs | the prebuilt image in a container (non-root, read-only, health-checked) | as a service of a dedicated user, with systemd's sandboxing |
| Database | PostgreSQL 16 or MySQL 8.4 in a container | MySQL, PostgreSQL or SQLite on the machine |
| Caddy | in a container | Caddy's own package |
| Database secrets | generated on the first start into a Docker volume | generated by install.sh into /etc/net-backend/ |
| Migrations | the migrate service runs before the server starts | ExecStartPre=… migrate before every start |
| Backups | net-backend-backup (systemd timer) dumps inside the database container | the same timer, dumping directly |
| Updates | docker compose pull + docker compose up -d | build, then install.sh again (or copy the binary + restart) |
Both paths install the reference server: the framework with every module, configured entirely from its configuration file. Your own game server has the same command line (serve, migrate, config check, user:create, …), so every file works for it.
- A machine with Ubuntu 24.04, a public address and SSH access by key (the SSH hardening guide first). 2 vCPU and 4 GB of memory are a comfortable start.
- A host name for the API (for example
api.example.com) whose DNS record points at the machine. - Open ports 80 and 443 (TCP) and 443 (UDP, HTTP/3). Nothing else: the server and the database listen on loopback or on private container networks.
Docker Compose: production in three commands
sudo mkdir -p /opt/net-backend && cd /opt/net-backend
sudo curl -fsSLo compose.yaml https://raw.githubusercontent.com/warmar94/net_backend/main/deploy/docker/compose.postgres.yaml
echo DOMAIN=api.example.com | sudo tee .env
sudo docker compose up -d
sudo mkdir -p /opt/net-backend && cd /opt/net-backend
sudo curl -fsSLo compose.yaml https://raw.githubusercontent.com/warmar94/net_backend/main/deploy/docker/compose.mysql.yaml
echo DOMAIN=api.example.com | sudo tee .env
sudo docker compose up -d
With Docker Desktop: a production-like stack on your own computer. DOMAIN=localhost gives Caddy's own local certificate (curl -k https://localhost/v1/info).
curl.exe -fsSLo compose.yaml https://raw.githubusercontent.com/warmar94/net_backend/main/deploy/docker/compose.postgres.yaml
echo DOMAIN=localhost > .env
docker compose up -d
DOMAIN is the only setting. docker compose up -d pulls the images and then, in order: init generates the database passwords and the server's connection URL into Docker volumes (existing secrets are never replaced); the database starts (the app's account is never a database administrator); migrate applies the migrations with the candidate configuration and activate puts it in place; the server starts; Caddy starts once the server is healthy and gets the certificate.
sudo docker compose ps -a # server: healthy; init, migrate and activate: exited (0)
curl https://api.example.com/v1/info
sudo docker compose exec server net-backend-server user:create admin@example.com --admin
Updates: sudo docker compose pull, then sudo docker compose up -d (migrations run first; open WebSockets get close 1001 and clients reconnect).
Your own server in Docker
Your server binary uses the same Compose file and the same Dockerfile, with three build arguments (CARGO_ARGS, BINARY, CONFIG). A project from the installer is already set up:
- SQLite:
docker compose up -d --build(the server on127.0.0.1:8080; the database and the players' files in the volumedata). - PostgreSQL / MySQL: a
.envwithDOMAIN=api.example.com, thendocker compose up -d --build(the production Compose file with Caddy, set to build the project's server with only its modules).
systemd
MySQL, PostgreSQL or SQLite on the machine, Caddy 2.8 or newer from Caddy's apt repository, Rust from rustup.rs:
cd /opt/net_backend
cargo build --release --locked -p net_backend_server --example server \
--no-default-features --features mysql,storage,chat,leaderboards,notifications,friends,groups,oauth,lobbies,matchmaking,files,smtp,steam # postgres / sqlite instead of mysql
sudo bash deploy/systemd/install.sh --db mysql --binary target/release/examples/server \
--domain api.example.com --email admin@example.com # --email is optional
sudo net-backend-cli user:create admin@example.com --admin
--db mysql|postgres|sqlite. The install creates the system user nbs, the database and its account with a random password, the service net-backend (sandboxed: NoNewPrivileges, ProtectSystem=strict, no capabilities, a system-call filter), Caddy's site and the daily backup. Running it again keeps the configuration, the secrets and the database, and installs the new binary.
HTTPS and WSS with Caddy
- HTTPS and WSS with automatic certificates; HTTP redirects to HTTPS; HTTP/3 on UDP 443. One
reverse_proxyserves the API and the WebSocket hub, and open WebSockets survive a configuration reload. - A 17 MB request limit for the whole site: the largest request is a file upload (16 MiB plus the upload's other parts).
- Logs that never contain tokens: the
AuthorizationandCookieheaders are deleted from log lines, and atokenquery parameter is removed from the logged URL. - A trusted proxy: the server believes
X-Forwarded-Foronly from Caddy, so per-address rate limits and WebSocket caps count real clients.
Backups and restore
A daily systemd timer backs up the database and keeps each backup 14 days; the database password never appears on a command line. Players' files (the files module) are a folder: /var/lib/net-backend/files or the Docker volume <project>_server_data.
| Database | How |
|---|---|
| MySQL / MariaDB | mysqldump --single-transaction (consistent, writers keep going), checked for its final "Dump completed" line |
| PostgreSQL | pg_dump -Fc, checked with pg_restore --list |
| SQLite | the online backup API (consistent while the server writes), PRAGMA integrity_check, gzip |
net-backend-restore first checks the whole backup, before anything is stopped or dropped; then it takes a safety backup of the current state, puts the backup in, runs migrate and waits until /readyz answers. A backup on the same disk does not survive the loss of the machine: copy /var/backups/net-backend/ elsewhere every day.
Measured on a small VPS
Measured on a 2 vCPU / 7.8 GiB virtual machine (Ubuntu 24.04, MySQL 8 or PostgreSQL 16 on the same machine, Caddy in front). The HTTPS rows ran load_test on that same machine, so it shared the 2 vCPU with the server, Caddy and the database:
| What | Measured |
|---|---|
| 10 000 authenticated WebSockets over HTTPS through Caddy | all connected in 56 s (TLS handshakes), none closed during the hold; server ~15 KiB per socket, Caddy ~121 KiB |
| A redeploy: 5000 sockets closed with 1001 by a restart | all 5000 reconnected (p99 17 s, bound by TLS handshakes on the shared CPUs) |
| Chat over HTTPS: 200 members, 50 senders at 1 message/s, every message stored | 600 000 of 600 000 deliveries, p99 294 ms (MySQL), 241 ms (PostgreSQL) |
| Room fan-out on loopback (one sender, 64-byte pushes) | 105 000 deliveries/s into 200 members; 149 000/s into 1000 members |
| 1000 players saving for the first time at the same moment | all 1000 stored in 8.6 s (MySQL), 7.4 s (PostgreSQL) |
| 4 MiB batch saves through Caddy | 10 of 10, median 0.97 s (MySQL), 0.47 s (PostgreSQL) |
| HTTP through Caddy, 64 connections | /v1/info ~4 500 requests/s; GET /v1/account 770 (MySQL) / 890 (PostgreSQL); a storage read 940 / 1 050 |
SQLite or PostgreSQL
Measured on the same 2 vCPU / 7.8 GiB machine with load_test on that machine, straight to the server over loopback (no Caddy), SQLite 3.51 (WAL, sqlite_synchronous = "normal", the default) and PostgreSQL 16 on the same disk, the same configuration and 20 database connections:
| What | SQLite | PostgreSQL |
|---|---|---|
| 20 000 authenticated WebSockets | all connected, ~15 KiB per socket in the server | the same |
| A restart with 5000 sockets open (every module registered) | all 5000 reconnected (p99 3.6 s) | all 5000 (p99 4.6 s) |
| 4000 registrations, 32 at a time | 53 s, none failed | 61 s, none failed |
Requests that read: GET /v1/account, a storage read (64 connections) | 4 150 / 4 750 requests/s | 1 300 / 1 800 requests/s |
| Chat, 200 members, every message stored: 50 / 200 / 400 messages per second | all delivered, p99 0.28 s / 0.79 s / 0.43 s | all delivered, p99 0.24 s / 0.53 s / 0.60 s |
| Players saving for the first time at the same moment: 500 / 1000 / 4000 | 0.7 s / 1.2 s / 6.1 s, none failed | 0.7 s / 1.5 s / 5.4 s, none failed |
| DM burst: 100 players sending 50 messages each at once | 5000 of 5000, p99 3.2 s | 5000 of 5000, p99 2.9 s |
SQLite lets one write happen at a time; with sqlite_synchronous = "normal" a commit does not wait for the disk, and on this machine it kept up with PostgreSQL in every row and read faster. Choose PostgreSQL when the server and the database should run on different machines, when you run more than one server process, or when every committed write must survive a power loss (sqlite_synchronous = "full" gives that on SQLite, at a cost: 1000 first saves at the same moment got 60 errors after the 5 s database.acquire_timeout_secs).
Memory: ~15 KiB per socket in the server plus ~120 KiB in Caddy, so roughly 1.4 GB per 10 000 connected players, on top of the database's buffer pool and the system (the default ws.max_connections = 10000 wants a 4 GB machine).
Load-test your own machine with load_test, a tool in the repository: it creates accounts, opens sockets, runs chat fan-out, DM bursts, simultaneous first saves, 4 MiB batch puts and HTTP request rates through Caddy, and prints latency percentiles. The full capacity section →
Security checklist
- SSH by key only, no root login, a firewall that opens 22 / 80 / 443 only, fail2ban (SSH hardening guide).
- Docker publishes ports past
ufw: publish nothing but Caddy's 80 / 443, as the Compose files do. - Secrets live in Docker volumes or
/etc/net-backend/, never in the configuration and never in a repository. - Tokens only in headers (
ws.query_token = false, the default). - Metrics on loopback only;
openapi.enabled = falseif the API description should not be public. - The admin role on as few accounts as possible; every admin action is in the audit log.
- Backups leave the machine, encrypted, and a restore was practised.