# Deploy a self-hosted server

> Deploy pushq in production: one SQLite node with systemd, or Postgres replicas with docker-compose, behind nginx or Caddy, with blue/green deploys.

Source: https://pushqueue.dev/docs/self-hosting/deploy/

pushq is one static binary with the dashboard included. It runs in one of two shapes:

| Shape | Use it when |
|---|---|
| **Single node + SQLite** | You want zero dependencies: one box, one file. Plan for up to about 500 sustained dispatches per second. |
| **Several replicas + Postgres** | You need high availability or more throughput. Every replica serves the API; a Postgres advisory lock elects one replica to run the dispatcher. |

Both shapes run the same binary; only the `db` setting changes. See the [server configuration reference](https://pushqueue.dev/docs/self-hosting/configuration/) for every setting.


**systemd**

```bash
# Single node, SQLite: install the unit and config below, then
sudo systemctl enable --now pushq
```

**docker-compose**

```bash
# Two replicas on Postgres: save the compose file below, then
docker compose up -d
```

## Deploy a single node with systemd and SQLite

Use this when one machine is enough and you don't want to run a database server.

```ini
# /etc/systemd/system/pushq.service
[Unit]
Description=pushq task queue
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/bin/pushq serve -c /etc/pushq/pushq.yaml
Restart=always
RestartSec=2
User=pushq
StateDirectory=pushq
# SIGTERM starts a graceful drain: in-flight deliveries get up to
# dispatcher.drain_timeout (default 30s) to finish.
TimeoutStopSec=45

[Install]
WantedBy=multi-user.target
```

```yaml
# /etc/pushq/pushq.yaml
db: sqlite:/var/lib/pushq/pushq.db
listen: 127.0.0.1:8080          # a reverse proxy in front terminates TLS
log: { format: json }
```

```bash
sudo useradd --system --no-create-home pushq
sudo systemctl daemon-reload
sudo systemctl enable --now pushq
journalctl -u pushq -f
```

`StateDirectory=pushq` creates `/var/lib/pushq` owned by the `pushq` user. SQLite runs in WAL mode, so you'll see `pushq.db-wal` and `pushq.db-shm` next to the database file.

Keep `TimeoutStopSec` above `drain_timeout` plus a few seconds, or systemd will kill the process before in-flight deliveries finish.

:::caution
Create the admin account in the dashboard **before** exposing the server. Until then, a server without `api_keys` accepts anonymous requests. See [create the first admin account](https://pushqueue.dev/docs/self-hosting/install/#create-the-first-admin-account).
:::

## Run multiple replicas with docker-compose and Postgres

Use this when you need the API to stay up through a crash or a deploy. All replicas serve the API; one at a time runs the dispatcher.

```yaml
# docker-compose.yml
services:
  db:
    image: postgres:16
    environment: { POSTGRES_USER: pushq, POSTGRES_PASSWORD: pushq, POSTGRES_DB: pushq }
    volumes: [pgdata:/var/lib/postgresql/data]
    healthcheck: { test: ["CMD-SHELL", "pg_isready -U pushq"], interval: 2s, retries: 30 }

  pushq-a: &pushq
    image: ghcr.io/blissfulrays/pushq:1.0.0   # pin a version
    command: serve
    environment:
      PUSHQ_DB: postgres://pushq:pushq@db/pushq?sslmode=disable
      PUSHQ_LISTEN: ":8080"
      PUSHQ_LOG_FORMAT: json
      PUSHQ_API_KEYS: "admin:pq_admin_<generate>,writer:pq_writer_<generate>"
    depends_on: { db: { condition: service_healthy } }
    ports: ["8081:8080"]

  pushq-b:
    <<: *pushq
    ports: ["8082:8080"]

volumes:
  pgdata:
```

Generate real keys (for example `echo "pq_$(openssl rand -hex 24)"`) instead of the placeholders.

Load-balance across the replicas however you like. `GET /readyz` reports which replica currently runs the dispatcher (`"role": "leader"`); the others report `"follower"` and still serve every API request. See [high availability and leader election](https://pushqueue.dev/docs/self-hosting/operations/#high-availability-and-leader-election).

## Put pushq behind a reverse proxy

Run pushq on a private address and put a TLS-terminating proxy in front. Two things matter.

### Forward encoded queue names unmodified

Queue names can contain `/` (folders, e.g. `user/instagram`). In URLs the whole name travels as one encoded segment: `/v1/queues/user%2Finstagram`. Your proxy must pass `%2F` through as-is. If it decodes `%2F` into `/`, pushq sees a different path and answers `404 not_found`.

- **Caddy** forwards the path unmodified by default.
- **nginx**: write `proxy_pass http://127.0.0.1:8080;` with **no** URI part. A trailing slash (`proxy_pass http://127.0.0.1:8080/;`) makes nginx normalize the path and decode `%2F`.

### Set X-Forwarded-Proto for TLS

pushq marks the dashboard session cookie `Secure` only when the request arrived over TLS or carries `X-Forwarded-Proto: https`. In SaaS mode the same check picks the scheme of the default WorkOS redirect URI. Behind a TLS-terminating proxy, forward that header. Caddy sets `X-Forwarded-Proto` and gets certificates on its own; with nginx, set it yourself.


**nginx**

```nginx
server {
    listen 443 ssl;
    server_name pushq.example.com;
    # ssl_certificate / ssl_certificate_key ...

    client_max_body_size 10m;   # batch enqueue bodies can be up to 8 MiB

    location / {
        proxy_pass http://127.0.0.1:8080;          # no trailing slash
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 60s;
    }
}
```

**Caddy**

```text
pushq.example.com {
    reverse_proxy 127.0.0.1:8080
}
```

pushq rate-limits password sign-in attempts per client IP. Behind a proxy every client shares the proxy's address, which still caps brute-force attempts but means one noisy client can briefly lock out others.

## Zero-downtime blue/green deploys

You can run the old and new versions side by side against the same Postgres database:

1. Start the new instance. It serves the API immediately; its dispatcher role is `follower`.
2. Send `SIGTERM` to the old instance. It releases dispatcher leadership at once, stops accepting new connections, then drains in-flight deliveries for up to `dispatcher.drain_timeout` (default 30s).
3. The new instance takes leadership within about 5 seconds (followers retry the lock every 5s) and continues from where the old one left off.

Correctness never depends on the lock: each delivery's result is recorded only if the task's lease token still matches, so overlapping instances can't both complete the same attempt. As with any at-least-once queue, a task whose lease expires mid-delivery is retried, so keep handlers idempotent. See [at-least-once delivery](https://pushqueue.dev/docs/concepts/delivery/).

New versions apply their database migrations on startup. To apply them before switching traffic, run `pushq migrate` with the new binary first.

## Deploy on Coolify or another Docker PaaS

The image works on any platform that runs a container image. A typical setup on Coolify or a similar Docker PaaS:

1. Create a Postgres database on a private network.
2. Create an app from the Docker image `ghcr.io/blissfulrays/pushq:<version>`, or `:latest` to follow stable releases.
3. Expose port `8080` and attach your domain. The platform's proxy terminates TLS and should send `X-Forwarded-Proto`.
4. Set environment variables: `PUSHQ_DB=postgres://USER:PASS@<db-host>:5432/<db>?sslmode=disable`, plus `PUSHQ_API_KEYS` or the [SaaS mode](https://pushqueue.dev/docs/self-hosting/saas-mode/) variables if you need them. Use the platform's secret storage for passwords and keys.
5. Turn off the platform's in-container health check, or point it at the HTTP endpoint from outside: the image is distroless, so a check that runs `curl` or `wget` inside the container fails.

To redeploy automatically on every release, run the app on `:latest` and trigger the platform's deploy webhook when a new image is published. With SQLite instead of Postgres, mount a persistent volume at `/data` (the image defaults to `PUSHQ_DB=sqlite:/data/pushq.db`).

## Sizing and performance

- **Memory**: the ceiling is roughly `dispatcher.global_concurrency × limits.max_body_bytes` (defaults: 512 × 1 MiB = 512 MiB worst case), plus a few MB per 10,000 active queues.
- **SQLite** (pure-Go driver, one writer): plan for about 500 sustained dispatches per second with headroom. Beyond that, or for high availability, use Postgres.
- **Postgres**: each replica opens up to 16 pooled connections, plus a dedicated connection for the leader lock and one for `LISTEN`/`NOTIFY`. If you put PgBouncer in front, use **session** mode: `LISTEN`/`NOTIFY` and advisory locks need real sessions.

### Throughput benchmark

Smoke benchmark from the repository (`PUSHQ_LOAD=1 go test ./test/load`): one laptop, a local receiver that answers instantly, 1,000 dynamic queues and 50,000 tasks.

| Backend | Queue creation | Enqueue | End-to-end dispatch |
|---|---|---|---|
| SQLite | 1,000 in 0.2s | ~11,000/s | ~2,300 tasks/s |
| Postgres 15 | 1,000 in 0.6s | ~2,600/s (batched) | ~3,600 tasks/s |

Treat these as upper-bound smoke numbers, not guarantees. In production, throughput is usually bounded by your receivers and by each queue's rate limits.

## Read more

- [Install a self-hosted server](https://pushqueue.dev/docs/self-hosting/install/): binaries, Docker image and first-time setup.
- [Server configuration reference](https://pushqueue.dev/docs/self-hosting/configuration/): every setting and environment variable.
- [Monitoring, backups and upgrades](https://pushqueue.dev/docs/self-hosting/operations/): health checks, metrics and leader election.
- [SaaS mode with WorkOS](https://pushqueue.dev/docs/self-hosting/saas-mode/): multi-team sign-in.
- [How delivery works](https://pushqueue.dev/docs/concepts/delivery/): at-least-once delivery and signatures.
