net_backend

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:

the trial
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):

/v1/info
{"protocol":1,"min_protocol":1,"modules":["auth","chat","files","friends","groups","leaderboards","lobbies","matchmaking","notifications","oauth","storage"]}

Keep the data and create an administrator:

shell
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 Composesystemd
Installone Compose file, one setting (DOMAIN), docker compose up -dbuild the binary, run install.sh
The server runsthe prebuilt image in a container (non-root, read-only, health-checked)as a service of a dedicated user, with systemd's sandboxing
DatabasePostgreSQL 16 or MySQL 8.4 in a containerMySQL, PostgreSQL or SQLite on the machine
Caddyin a containerCaddy's own package
Database secretsgenerated on the first start into a Docker volumegenerated by install.sh into /etc/net-backend/
Migrationsthe migrate service runs before the server startsExecStartPre=… migrate before every start
Backupsnet-backend-backup (systemd timer) dumps inside the database containerthe same timer, dumping directly
Updatesdocker compose pull + docker compose up -dbuild, 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.

Docker Compose: production in three commands

Linux server · PostgreSQL 16
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

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.

check and the first administrator
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:

systemd

MySQL, PostgreSQL or SQLite on the machine, Caddy 2.8 or newer from Caddy's apt repository, Rust from rustup.rs:

build, install, first administrator
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

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.

DatabaseHow
MySQL / MariaDBmysqldump --single-transaction (consistent, writers keep going), checked for its final "Dump completed" line
PostgreSQLpg_dump -Fc, checked with pg_restore --list
SQLitethe 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:

WhatMeasured
10 000 authenticated WebSockets over HTTPS through Caddyall 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 restartall 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 stored600 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 momentall 1000 stored in 8.6 s (MySQL), 7.4 s (PostgreSQL)
4 MiB batch saves through Caddy10 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:

WhatSQLitePostgreSQL
20 000 authenticated WebSocketsall connected, ~15 KiB per socket in the serverthe 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 time53 s, none failed61 s, none failed
Requests that read: GET /v1/account, a storage read (64 connections)4 150 / 4 750 requests/s1 300 / 1 800 requests/s
Chat, 200 members, every message stored: 50 / 200 / 400 messages per secondall delivered, p99 0.28 s / 0.79 s / 0.43 sall delivered, p99 0.24 s / 0.53 s / 0.60 s
Players saving for the first time at the same moment: 500 / 1000 / 40000.7 s / 1.2 s / 6.1 s, none failed0.7 s / 1.5 s / 5.4 s, none failed
DM burst: 100 players sending 50 messages each at once5000 of 5000, p99 3.2 s5000 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

Read the full deployment guide →