Scaling and load
Add nodes, watch them, and run the load and chaos test.
Nodes share only Postgres and the S3 bucket. Any request, job or realtime socket can land on any node, so you scale by adding nodes behind the load balancer.
Add nodes
Start another container from the same image with CARDINAL_ROLE=web for HTTP, or worker for jobs. See Configuration.
Add web nodes to the proxy's upstreams. Point its health check at GET /health, which answers 200 ok while Postgres answers.
Check that each node reports in:
cardinal nodesEach node that serves or runs jobs upserts its row in platform.nodes every 10 seconds with its role, BEAM memory, run queue, scheduler use, pool use, realtime channels and Oban queues. A clean shutdown deletes the row. cardinal nodes marks a node silent for over 30 seconds as stale and exits 1. The scheduler's leader deletes rows not seen for a day.
What makes a node replaceable
| Concern | Where it lives |
|---|---|
| Sessions | Postgres. The cookie names a session row |
| Realtime | Each node listens on the Postgres channel cardinal_realtime and pushes to its own sockets |
| Compiled metadata | Each node's ETS, keyed by site and meta_version. A change bumps the version, so other nodes miss the old entry |
| Jobs | Oban tables in Postgres. A job a killed node held runs again after CARDINAL_JOB_RESCUE_AFTER |
| Scheduler | One leader node inserts a tick job per site each minute |
| Files | The S3 bucket |
Load and chaos test
scripts/load.sh boots a load stack from an empty database: up to four one-CPU web nodes behind a round-robin Caddy, two worker nodes and a k6 runner. Each k6 clerk logs in, lists and counts Gate Invoices, opens a new form, searches a Link, then creates, saves and submits an invoice with five rows. Listeners each hold a realtime socket.
scripts/load.sh 4 500 # 4 web nodes, 500 clerks
CHAOS=1 scripts/load.sh 4 500 # also kill a random node every 45 s
THINK=0 LISTENERS=0 scripts/load.sh 2 100 # throughput only| Variable | Default | Use |
|---|---|---|
CHAOS | 0 | 1 kills a random node every 45 s and restarts it 15 s later. Needs 2 or more web nodes |
LISTENERS | VUS | Realtime sockets |
RAMP, HOLD | 2m, 5m | Ramp-up and hold time |
THINK | 1 | Pause between a clerk's steps |
BACKLOG | 100000 | Invoices seeded before the run |
ONE_DRAFT | unset | 1 makes one draft per clerk, so no naming series writes |
CARDINAL_LOAD_POOL | 20 | Pool size per node |
CARDINAL_E2E_PORT | 8090 | Proxy port |
After the run, the script compares the invoices, submits and jobs the API acknowledged with the database, and exits non-zero if any are missing. Without chaos, k6 also fails a step whose p95 exceeds 2 s or a failure rate of 1% or more. Results go to load-results/.
First results
On one 10-CPU host, 500 clerks and 500 sockets on four web nodes ran 142 requests a second with no failures, a 139 ms p95 and 305 MiB peak memory per web node. With a node killed about every 60 seconds, 0.19% of requests failed and no acknowledged invoice, submit or job was lost. One naming series caps at about 50 inserts a second, because its counter row stays locked until commit.