Docs

Scaling

What can move to other machines, how gateways work, and where one federation's ceiling is.

By default a federation writes to its database from one process, and scaling means taking load off that writer. Primaries started with --writers=many write the same database together, each serving the presence of its own connections; each call runs on the primary where it started, and devices on any primary take part in it. Each background job is served by one of them at a time. A gateway keeps each connection on one primary. The mode is experimental, so keep it off in production until it has run under load on several primaries; a call ends when its primary stops. How many resources your number of people needs: the calculator.

Profiles

ProfileWhat runsFor
SServer, PostgreSQL and media on one machine (the ready-made stack)Most installations
MPrimary server, gateways, NATS, a shared media volumeMany concurrent connections. Still a lab profile: rehearsed by tools/mlab-stack.py, no ready-made stack

Profile S does not survive the loss of its only machine beyond the last backup. Profile M promises no high availability either: there is one writer.

What to move out first

  • Media to a separate disk: --media-dir. It is the fastest-growing volume.
  • PostgreSQL to another machine or a managed PostgreSQL 17 service: the server gets its connection string from --postgres-conninfo-file. Keep the latency to the database minimal: every message is a transaction.
  • SFU and TURN to a machine with a good uplink. All call traffic goes through them, and the federation server needs only the address of their control API (sfu_url) and the secrets. TURN must stay in the SFU's network namespace (calls).
  • Speech recognition to a machine with a GPU (voice transcription).

Gateways

A gateway (comon_federation_gateway) accepts the apps' WebSockets, holds the Noise encryption and send queues, and passes requests to the primary server over NATS. It gets live updates from the same bus. A gateway opens no database and holds no locks; calls, presence and background jobs stay on the primary.

apps ──WSS /comon──▶ proxy ──┬──▶ gateway 1 ──┐
                             └──▶ gateway 2 ──┼── NATS ──▶ primary server ──▶ PostgreSQL
everything else (sign-in, links, Bot API) ────┼──────────▶ primary server
                                              └── shared media volume

What it takes:

  1. The primary with --live=nats --live-nats=<host>:<port> --live-nats-token-file=<file> --media-volume=shared or --media-volume=s3. With a node-local media directory nats does not start.
  2. NATS that allows messages of 2.1 MB or more (max_payload), with a token.
  3. Gateways with --federation-id, --noise-key-file (a read-only copy of the primary's noise-server-key), the same NATS options and --behind-tls-proxy.
  4. The proxy sends only /comon to the gateways, everything else to the primary.

Every gateway option is in the reference.

What happens on failures

EventWhat happens
One gateway failsIts apps reconnect through another.
NATS stopsGateways become unready; when the bus returns they reconcile sessions with the primary and catch up.
The primary stopsGateways refuse requests until it returns. Nobody else can write.
One of several primaries stops (--writers=many)Gateways close the connections it served; the apps reconnect to another primary. Its calls end.
A second primary starts on the same databaseWithout --writers=many on both it does not start; the first keeps serving.

Media in S3 (MinIO)

With --media-volume=s3 the ready media lives in an S3-compatible bucket (MinIO on your own machines, or a cloud S3) instead of a shared disk. Each primary receives uploads in its own --media-dir, checks them there and puts the finished files into the bucket; every download is read from the bucket. The bucket belongs to one federation: the first start writes its mark (comon-media-volume.json) into it, and a start on another bucket fails.

--media-volume=s3 --media-bucket-endpoint=http://minio:9000 --media-bucket=comon-media \
--media-bucket-credentials-file=/run/secrets/s3.json

The credentials file is {"access_key_id": "...", "secret_access_key": "..."}. The key needs to read, write, delete and list objects of that bucket.

An existing federation moves its media from the disk into the bucket while stopped:

  1. Stop every server process of the federation.
  2. Run federation_admin --data=... --postgres-conninfo-file=... --media-dir=<the media disk> --media-volume=s3 --media-bucket...=... media-to-s3. It copies what the bucket lacks, so a run cut short is simply run again.
  3. Start the servers with the S3 options. Keep the old disk until you have checked that pictures, files and voice messages open.

Back up the bucket along with the database (backups).

Where the ceiling is

One federation's limits are in limits: up to 10,000 profiles, up to 1 TiB of media. For more people, run several independent federations. Federations cannot talk to each other, but a person can belong to several at once (federations).

On this page