Skip to content

Scale the server ​

The server keeps nothing that matters in its own memory: sessions are signed cookies, and queues, leases, waits and accounts are in Redis and PostgreSQL. So it scales by running more instances behind a load balancer, with no sticky sessions. This page is how; Capacity is how many, and what to size beside them.

Drawing the diagram…

Every instance answers every request. Work that must run once is done by the instance that holds its lease in Redis, here instance 2 for alert notifications.

When to add an instance ​

  • For availability. Two instances let you replace one without an outage, and survive one dying.
  • For gateway throughput. SDK workers and producers make HTTP calls to the server. Add an instance when the instances are out of CPU while Redis is not. Measure first: more worker processes are usually the cheaper step (Scale workers).

More instances do not make Redis faster. If Redis is the limit, see Capacity.

Add instances ​

Every instance needs the same three things:

  1. The same /data volume. It holds the licence, the connections and the generated secrets; instances with different session secrets would sign each other's users out.
  2. The same PostgreSQL and Redis.
  3. A load balancer in front that checks GET /readyz and overwrites the client address header: see TLS and proxies.

In the Compose file that is one line in deploy/.env, once setup is finished:

sh
JOOBQUI_SELF_HOSTED_REPLICAS=3

Elsewhere, start more containers with the volume mounted. Instances that start together do not race: the first takes the migration lock in PostgreSQL and the others wait for it.

Replicas must share the volume. Each volume is its own installation on the licence, and each would generate its own secrets: see Several instances of one server.

What runs once ​

Some work must not be done twice. One instance at a time does it, holding a lease in Redis:

WorkDone by
Sending alert notificationsone instance (every instance evaluates the rules)
Purging the audit logone instance, once a day
Purging dead letters and pruning finished workflowsone instance per pass, one pass at a time
Firing job scheduleswhichever instance claims the tick first; a tick is never fired twice
Firing workflow schedulesone instance among those with JOOBQUI_WORKFLOW_SCHEDULER=true

A holder that dies is replaced within 30 seconds. An orderly shutdown (SIGTERM) hands its leases over at once, which is why a rolling replacement loses nothing. JOOBQUI_ALERT_NOTIFICATIONS=off keeps an instance from sending alerts.

What stays per instance ​

  • Alert state: what is firing and who acknowledged it. An acknowledgement sent to another instance answers 404.
  • The console's telemetry history and the request metrics (joobqui_api_requests_total).
  • The workflow archive, if you use one: it is a directory on the instance that ran the retention pass. Mount shared storage or run retention on one instance: see Backups and retention.

If the first two matter to you, send console traffic to one instance and let workers use them all. Scrape /metrics on every instance.

Check it worked ​

text
sum(joobqui_leader{role="alerts"})    # exactly 1 across all instances
count(joobqui_build_info)             # the number of instances you expect

Stop one instance with SIGTERM: the sum stays 1, and workers keep polling the others.