---
title: "Requirements"
description: "Hardware, dependency versions and network prerequisites for a self-hosted Pug deployment."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.pug.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Requirements

Backing services, toolchains, ports, and sizing for self-hosting Pug.

## Toolchains

What you need depends on whether you build from source or run prebuilt container images.

| Tool | Version | Needed for | Why |
|------|---------|-----------|-----|
| Go | >= 1.27.2 | Building the backend | Compiles the `pug` server, workers, and CLI. `go.mod` pins `1.27.2`. |
| Bun | >= 1.3 | Building the dashboard | Installs deps and builds the React SPA. The dashboard's CI builds with `1.3.14`. |
| Docker | Any recent release | Local infra **or** container builds | Runs the four backing services locally, and builds the backend images. |

If you deploy the backend from its [published container images](/self-hosting/deployment#published-images), you need **no Go** - only a container runtime. The dashboard has no image: its backend URL is compiled in, so you always build it with Bun ([Dashboard](/self-hosting/dashboard)).

```bash
git clone https://github.com/pug-sh/pug.git  # backend: server, workers, pug CLI
cd pug
```

The dashboard lives in a separate repo (`pug-sh/app`) and is covered in [Dashboard](/self-hosting/dashboard).

## Backing services

The backend requires four backing services: **PostgreSQL**, **ClickHouse**, **NATS**, and **Dragonfly**. The versions below are the ones the dev Docker Compose runs; you may run managed equivalents (e.g. Amazon RDS for Postgres, ClickHouse Cloud) at compatible versions. The Pug server itself appears in the table only for its listening port.

| Component | Image / Version | Container port(s) | Role |
|-----------|----------------|-------------------|------|
| PostgreSQL | `postgres:18` | `5432` | Auth, orgs, projects, dashboards, and config. Dev host mapping: `5433->5432`. |
| ClickHouse | `clickhouse/clickhouse-server:26.5` | `8123` (HTTP / `/ping`), `9000` (native), `9009` (interserver) | Analytics event storage and queries. Requires `ulimits.nofile` >= 262144. |
| NATS | `nats:2.14-alpine` | `4222` (client), `6222` (cluster), `8222` (monitoring) | JetStream message queue. Must be started with `--jetstream`. |
| Dragonfly | `docker.dragonflydb.io/dragonflydb/dragonfly:v1.38.1` | `6379` | Redis-compatible store for caches, the cookieless salt and session stitching. Needs Redis >= 7.0 and no persistence - see below. Dev host mapping: `6380->6379`. |
| Pug server | - | `3000` | The Connect RPC API server. Override with `PUG_SERVER_PORT`. |

> **NATS JetStream is required.** Start NATS with `--jetstream` (and `--store_dir` for a durable volume). The monitoring server (`-m 8222`) exposes `/healthz` on port 8222. Without JetStream, event ingestion will not function.

> **PostgreSQL 15 or later.** Pug v0.0.26's migration 022 uses a foreign-key action that PostgreSQL 14 and older lack, so `pug postgres migrate` fails on them. The first migration also runs `create extension if not exists moddatetime`, so the role that runs it must be allowed to create extensions - or create `moddatetime` in the database beforehand.

> **Dragonfly / Redis: version 7.0 or later, and nothing on disk.** Any Redis-compatible store (Dragonfly, Valkey, Redis) works if it reports version 7.0 or later: cookieless session stitching uses `SET ... NX GET`, which 6.x rejects. On 6.x every cookieless session silently collapses into one per visitor per day while ingestion looks healthy. The store must also be **ephemeral** - no RDB/AOF snapshots, no replica, no volume backup. It holds the daily salt behind cookieless visitor IDs, and deleting that salt every day is the privacy guarantee: a salt that survives on disk lets the IDs be brute-forced back to IP and user agent. Start Dragonfly with `--dbfilename=` (by default it saves a snapshot on every graceful shutdown), and check a managed service's persistence settings before you use one.

For how the dev Compose file wires these up locally (health checks, volumes, and the observability overlay), see [Development](/self-hosting/development).

## Ports summary

Only the Pug server (and your static dashboard host) need to be reachable from outside your private network. All backing services should be kept on an internal network:

| Port | Service | Exposure |
|------|---------|----------|
| `3000` | Pug server (Connect RPC) | Public: behind a TLS terminator |
| `8090` | Worker health / readiness | Internal only: probes (configurable via `PUG_WORKER_HEALTH_ADDR`) |
| `5432` | PostgreSQL | Internal only |
| `4222` | NATS client | Internal only |
| `8123` / `9000` | ClickHouse HTTP / native | Internal only |
| `6379` | Dragonfly | Internal only |

## Sizing guidance

These are **starting-point ballparks, not hard requirements**. Actual resource needs depend heavily on event volume and retention.

### Development / staging

| Component | CPU | RAM | Disk |
|-----------|-----|-----|------|
| Pug server + workers | 2 vCPU | 2 GB | - |
| PostgreSQL | 1 vCPU | 2 GB | 20 GB |
| ClickHouse | 2 vCPU | 4 GB | 50 GB |
| NATS | 1 vCPU | 1 GB | 10 GB (JetStream store) |
| Dragonfly | 1 vCPU | 1 GB | - |

### Production (small - up to ~1 k events/s)

| Component | CPU | RAM | Disk |
|-----------|-----|-----|------|
| Pug server | 2 vCPU | 2 GB | - |
| Workers (per type) | 2 vCPU | 2 GB | - |
| PostgreSQL | 2 vCPU | 8 GB | 100 GB SSD |
| ClickHouse | 4 vCPU | 16 GB | 500 GB SSD |
| NATS | 2 vCPU | 2 GB | 20 GB SSD |
| Dragonfly | 1 vCPU | 2 GB | - |

The dashboard is static files - it needs no compute of its own, only a web server or CDN.

### Production (larger workloads)

Scale the **events worker** horizontally for higher ingest throughput - replicas share one durable JetStream consumer, so they split the stream between them. Give ClickHouse more CPU, RAM, and disk as event volume and retention grow. NATS benefits from a 3-node cluster for JetStream HA.

## Optional: geo enrichment (Cloudflare)

Geo auto-properties (`$country`, `$region`, `$city`, `$continent`, and related fields) are resolved **at ingestion by the server** - it reads them from **Cloudflare proxy headers** (`CF-IPCountry`, `CF-Region`, `CF-IPCity`, `CF-IPContinent`, etc.) on the inbound request. So this needs Cloudflare (or a proxy that sets the same headers) in front of the server; the visitor IP itself is never persisted. Because the values come from the inbound request, they describe the client that sent the event - see [Events sent from your own backend](#events-sent-from-your-own-backend) below.

- `CF-IPCountry` is added automatically when Cloudflare IP Geolocation is enabled on your zone.
- `CF-Region`, `CF-IPCity`, and the remaining location headers require the **"Add visitor location headers"** [Managed Transform](https://developers.cloudflare.com/rules/transform/managed-transforms/reference/) to be enabled.

### Events sent from your own backend

Those headers describe **whoever opened the connection to Pug**, which is the visitor only when the event comes from their browser. An event your backend sends is located at your backend, and forwarding headers cannot change that: Cloudflare sets `CF-Connecting-IP` and the `CF-IP*` headers itself from the connecting address and overwrites whatever a client sent for them. `X-Forwarded-For` does survive - Cloudflare appends to it rather than replacing it - but Pug consults `CF-Connecting-IP` first, so behind Cloudflare the forwarded value is never read.

Send the location on the event instead. A request authenticated with a **private** (`prv_`) API key is your own server, so Pug skips geo enrichment there entirely - it keeps the location the event carries and adds none of its own:

```json
"autoProperties": {
  "$country": { "stringValue": "DE" },
  "$city": { "stringValue": "Berlin" }
}
```

From `@pug-sh/node` 0.0.6+ and the Ruby SDK this is `track`'s `location` option ([Node](/sdks/node#visitor-location), [Ruby](/sdks/ruby#visitor-location)), and from the Go SDK [`pug.WithLocation`](/sdks/go#visitor-location), rather than hand-written `autoProperties`, which none of them otherwise lets you set:

```ts
pug.track('user-123', 'order.completed', { amount: 49 }, {
  location: { country: 'DE', city: 'Berlin' },
})
```

Because nothing is merged, your `$city` is never paired with the edge's `$country` - and an event that carries **no** location stores none. Pug will not fall back to the headers, since your backend's city is not your visitor's. Send `$country` as an ISO 3166-1 alpha-2 code: Pug stores what you give it without normalizing, so `USA` or `us` becomes a breakdown value of its own and will not render on the map. The SDK's `location` option checks the code and fixes its case before sending, so that one only bites hand-written payloads.

This applies to private keys only - a **public** (`pub_`) key ships inside client apps where anyone can copy it, so geo on those requests stays server-derived. `$ip` is stripped from every event either way.

Geo lookup sits behind a small `Provider` interface (`internal/geo`), and Cloudflare headers are the **only implementation today**. The interface is designed to also accept a local database lookup, e.g. MaxMind (MMDB), from the client IP in a future release. Until then, if Pug runs behind a different proxy or without these headers, geo auto-properties are simply absent from events; there's no built-in GeoIP database yet.

## Further reading

- [Configuration](/self-hosting/configuration): environment variables and secrets
- [Deployment](/self-hosting/deployment): production deployment guide
- [Development](/self-hosting/development): local dev stack setup

Source: https://docs.pug.sh/self-hosting/requirements/index.mdx
