Self-hosting

Scaling api and worker replicas

How many api and worker replicas to run, the knobs that raise throughput, what really limits sending, and how to stop the engine safely.

Edit on GitHub

The api and worker roles scale on their own, and several replicas of each are safe. Read this page when you size a deployment or when a queue falls behind.

Settingapiworker
Replicas1 to N; scale on CPU or request rate1 to N; scale on queue depth or oldest-due lag
Resources to start500 mCPU, 512 MB500 mCPU, 512 MB
Port 8080public, behind TLSprivate: health only
On SIGTERMstops accepting, finishes in-flight requests, exitsstops reading queues, waits up to 30 s for in-flight messages, exits

The whole shutdown is capped at 35 seconds, after which the process exits with code 1. Give the platform a grace period of at least 40 seconds. Work left unfinished reappears when its visibility timeout ends.

Replicas are safe

Two workers never send the same step twice:

  • The planner claims due enrollments with FOR UPDATE SKIP LOCKED, so two planners never take the same one.
  • An executor owns a run while it works on it (the enrollment's owner_run_id), and every write re-checks state under a row lock.
  • Each scheduler job takes a lease row in seq.job_locks before it runs, so one replica at a time runs a given job.

The API is stateless apart from one per-replica cache: the rate-limit counter.

The knobs

KnobDefaultRaise it when
SEQ_CONCURRENCY8 messages in flight per queue per replica (max 64)queues have depth and the database has headroom
worker replicas1the same, or for availability
SEQ_DB_POOL10 connections per process (max 100)you raise SEQ_CONCURRENCY: the pool serves the in-flight messages and the scheduler
planner claim50 per sender, 500 per tick, every 5 secondsthousands of enrollments come due in the same second. These are engine constants, not variables
SEQ_QUEUE=redispostgresthe queue table itself is hot, with many thousands of messages a minute. Most installs never need it

What really limits throughput

Usually not the engine. Thirty sequences with about 500 active contacts and a step every one to three days is 5,000 to 15,000 steps a day, a few hundred an hour at peak. One worker and one Postgres handle that easily.

The binding limits are outside: each sender's email daily_limit (30 by default, with a 60-second gap between sends), the SMS daily_limit (100 by default), and your SMS carrier registration. More capacity means more senders or higher caps, not more replicas.

Measure the lag

Queue depth comes from the health endpoints (GET /v1/admin/engine/health). Oldest-due lag, how long enrollments wait past their next_run_at, has no endpoint yet; read it from the database:

select now() - min(next_run_at) as oldest_due_lag
from seq.enrollments
where status = 'active' and owner_run_id is null and next_run_at <= now();

Keep it under 2 minutes. If it grows while queues are empty, the planner is not running: check the plan job in the health output.

Stopping the engine

ActionEffect
Scale the worker to zerohard stop. Steps, signals and deliveries wait in the tables and resume when a worker returns. Nothing is lost
SEQ_PAUSED=1 on the workersthe planner claims nothing and executors defer every send by 5 minutes. Signals are still recorded and webhooks still delivered. Needs a restart to change
SEQ_DISABLED_CHANNELS=sms on the workersexecutors defer every send on that channel by 5 minutes; the planner keeps going. Needs a restart
project flag global offexecutors defer that project's sends by 5 minutes, with no restart: PUT /v1/engine/flags/global with { "value": false }. channel:sms does the same for one channel

On this page