Self-hosting / Cluster mode
Cluster mode
Spread the checks over several workers. The job queue lives in PostgreSQL, so no extra service is needed.
In cluster mode, the main image serves the web interface and the API, and workers run the checks. The workers share a job queue stored in PostgreSQL, so no extra service is needed.
Set up the application
Run the uptime-kotlin image with SCHEDULER_STRATEGY: none. It no longer runs checks itself, and it can be replicated behind a load balancer.
Add workers
Add one service per worker with the worker image:
uptime-kotlin-worker:
image: ghcr.io/theomeunier/uptime-kotlin/worker:latest
container_name: uptime_kotlin_worker
restart: unless-stopped
environment:
TZ: Europe/Paris
SCHEDULER_STRATEGY: database
SCHEDULER_WORKER_NAME: worker-primary
SCHEDULER_WORKER_CONCURRENCY: '4'
QUARKUS_DATASOURCE_USERNAME: uptime-kotlin
QUARKUS_DATASOURCE_PASSWORD: change-me
QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://postgres:5432/uptime-kotlin
ENCRYPTION_MASTER_KEY: change-me-32-characters-minimum-0
depends_on:
- uptime-kotlinGive each worker its own SCHEDULER_WORKER_NAME. It identifies the worker in the logs and the metrics, and a retry runs on the next worker still alive, so a failure seen from one machine is confirmed from another.
The workers must use the same ENCRYPTION_MASTER_KEY as the application, and the same maintenance and notification settings (see Configuration).
When a worker stops
Each worker sends a heartbeat to PostgreSQL and leases the checks it runs for 2 minutes, renewing the lease every 30 seconds while a check is in progress.
- Checks waiting for a stopped worker are taken by the others once it has sent no heartbeat for 30 seconds.
- Checks it was running come back to the queue when their lease expires, at most 2 minutes after the worker stopped, and another worker runs them.
- On a clean stop, for example
docker compose stopor a redeployment, the worker claims no new check and lets the running ones finish for up to 30 seconds. The checks still running after that go straight back to the queue, and another worker picks them up without waiting for the lease to expire.
Lease times are computed by PostgreSQL, not by each machine, so a small clock drift between your servers does not matter.
No duplicate checks
Every worker schedules the checks that are due, but only one of them does it at a time: they share a PostgreSQL lock. A monitor also never has more than one check waiting or running, so adding workers never checks a monitor twice for the same run, and Check now on a monitor whose check is already running leaves that check alone.
- Job claimed
- Check and answer
- Result saved
- Stopped worker
The application stops running checks
With SCHEDULER_STRATEGY set to none, the main image only serves the interface and the API. When a check is due, it waits as a job in a queue stored in PostgreSQL.
To watch the workers, their heartbeats and the job queue, see Prometheus metrics.
