You're reading the docs for dotwire 0.4. The latest release is 0.5. Upgrading? See Upgrading to 0.5.
Deployment
dotwire needs three things: the dotwire binary or image, PostgreSQL with the Timescale extension, and NATS with JetStream enabled. The repository ships two Compose files: compose.yaml for a single node and compose.multinode.yaml for a split deployment.
The published image is ghcr.io/pasztor-mark/dotwire:<version>, for linux/amd64 and linux/arm64. The Compose files pin it through DOTWIRE_VERSION, which defaults to 0.4.3.
Single node
compose.yaml runs three services:
dotwirein the defaultAllrole, listening on port 8080. Compose publishes it on127.0.0.1:8080only.postgres, fromtimescale/timescaledb:2.31.0-pg17.nats, fromnats:2.15.1-alpine, started with JetStream (-js) and file storage on a volume. It runs as an unprivileged user, so a short-livednats-initcontainer hands the volume to that user first and then exits.
See the Quickstart for the .env values it needs.
The dotwire service is hardened by default: it runs as a non-root user with a read-only filesystem, drops all Linux capabilities, sets no-new-privileges, and raises the open-file limit to 65,536. It also turns on server GC with dynamic adaptation (DOTNET_gcServer=1, DOTNET_GCDynamicAdaptationMode=1), which suits connection-dense workloads. Keep these settings when you write your own deployment.
Required settings
| Setting | What it's for |
|---|---|
ConnectionStrings__PostgresMigrator | The owner role (dotwire) that runs migrations |
ConnectionStrings__PostgresWrite | The runtime role (dotwire_app) for writes |
ConnectionStrings__PostgresRead | The runtime role for reads. Point it at a replica to move reads off the primary. |
Postgres__AppRolePassword | The password dotwire sets for dotwire_app when it runs migrations |
Dotwire__Encryption__ActiveKeyId, Dotwire__Encryption__Keys__<id> | At-rest encryption key. See Encryption and retention. |
Auth__Issuer, Auth__Audience, and Auth__Keys__<kid> or Auth__JwksUrl | Host token verification. See Auth. |
Nats__Url | NATS server URL. Separate several URLs with commas. |
Every option is listed in the configuration reference.
Migrations
With Postgres__Migrate=true (the default), dotwire runs its embedded SQL migrations at startup through the migrator connection, then sets the dotwire_app password from Postgres__AppRolePassword. With Nats__Enabled=true (the default), it also provisions its JetStream streams at startup.
The runtime role holds only the grants it needs. In particular, it can't update or delete audit rows. See Audit log.
Health check
GET /healthz returns 200 on every node role, and the sample HAProxy config checks it. The image has no shell or wget, so the Compose healthchecks run the binary itself: /app/dotwire --healthcheck calls /healthz on the local node and exits 0 on success. Use the same command in your own container healthchecks.
Node roles
Set Dotwire__Role to All, Api, or Gateway. See Node roles for what each one serves.
- Run the Postgres writer and audit writer on
ApiorAllnodes.Gatewaynodes don't run them. - Run migrations from one node.
compose.multinode.yamlsetsPostgres__Migratetotrueon the API node andfalseon gateways. - Only one audit writer is active at a time. Additional
Apinodes wait in standby. See Audit log. - Retention set with
Dotwire__Retention__MessagesDaysis applied by the node that runs migrations. - On startup, each node opens
Minimum Pool Sizeread connections fromConnectionStrings__PostgresRead, waiting up to 5 seconds.compose.yamlsets 20 minimum and 100 maximum. Keep the maximum times the node count under Postgresmax_connections, together with the write pool.
Multiple nodes
compose.multinode.yaml is a reference topology:
- two
Gatewaynodes that hold WebSocket and SSE connections, - one
Apinode that serves REST and admin traffic and runs migrations, - a three-node NATS cluster with JetStream,
- a Postgres primary for writes and a streaming replica for reads,
- HAProxy in front, configured by
haproxy.cfg, with its stats page on127.0.0.1:8404behind a password.
It needs these values in .env, and refuses to start without them:
| Variable | What it's for |
|---|---|
NATS_USER, NATS_PASSWORD | NATS client authentication. Every dotwire node connects with them. |
POSTGRES_REPLICATION_PASSWORD | The replicator role the read replica streams from. |
HAPROXY_STATS_PASSWORD | The HAProxy stats page, user admin. |
Use URL-safe values without quotes, because the NATS credentials end up inside Nats__Url.
Routing
Gateway nodes serve the hub (/hub/rooms) and SSE (/rooms/{roomId}/events). Api nodes serve everything else. Route requests to match. With Dotwire__HubSend__Enabled=true, gateways also publish member sends to JetStream, and the presend and postsend webhooks run there, so gateways need to reach your webhook URLs too.
The sample haproxy.cfg sends WebSocket upgrades, /hub/rooms, and /rooms/{roomId}/events to the gateways, and everything else to the API node.
Load balancer
Connections are WebSockets only, with negotiation skipped, so you don't need sticky sessions. An L4 (TCP passthrough) load balancer adds the least per-connection overhead. The sample haproxy.cfg runs in HTTP mode only because it serves both roles from one listener and routes by path. If you give each role its own listener or hostname, a plain TCP proxy works.
Terminate TLS at your load balancer or ingress. dotwire listens on plain HTTP on port 8080, and both Compose files publish it on 127.0.0.1 only.
Before you expose dotwire:
- Put TLS in front of it. Tokens travel in
?access_token=on WebSocket and SSE connects, and they end up in proxy logs over plain HTTP. - Set
Cors__AllowedOrigins__0(and__1, and so on) to your real browser origins. An empty list allows any origin. - Set
AllowedHoststo your real host names. - Keep
ConnectionStrings__PostgresMigratoron the node that runs migrations only. - Point the host SDKs at an
httpsbaseUrl. - Supply connection strings from your secret store. Values in a Compose
environment:block are visible throughdocker inspect.
Capacity
In the v0.4 benchmarks, one 0.4.1 node in the All role, on 8 dedicated vCPUs and 32 GB RAM, handled:
- 5,000 msg/s at 22.5–26.9 ms p99, with no lost messages, in all 3 runs. Offered 10,000 msg/s, the node saturates: it accepts ~7,300–7,700 msg/s and p99 climbs to 1.5–3.6 s.
- 50,000 concurrent connections, opened at 500/s, with no failed connects in 3 runs.
dotwire is CPU-bound: the host was ~75–80% busy at 5,000 msg/s with no iowait, so add cores or Gateway nodes before you buy faster disks. These numbers use the NATS settings from compose.yaml, where JetStream flushes to disk periodically, not on every write. For connection bursts, raise net.core.somaxconn and net.ipv4.tcp_max_syn_backlog, as the benchmark hosts did (65,535). The kernel caps dotwire's listen backlog at somaxconn.
Rate limits across nodes
Rate limits are enforced in each process and nodes don't share counters. With N nodes behind a load balancer, a user's effective limit is N times the configured value. The same goes for Dotwire__MaxConnectionsPerUser, which caps connections per node. The Unauthenticated bucket is keyed by client IP, so behind a proxy every client shares the proxy's IP. See Rate limits.
Securing NATS
Anyone who can connect to NATS can bypass dotwire's token and membership checks at the broker: read ciphertext and metadata, publish forged events, or administer JetStream. Treat NATS as an internal service.
- Don't publish NATS ports outside your private network.
compose.yamlbinds4222(clients) and8222(monitoring) to127.0.0.1only, andcompose.multinode.yamldoesn't publish4222at all. - Turn on NATS authentication anywhere other machines share the network.
compose.multinode.yamldoes, withNATS_USERandNATS_PASSWORD.compose.yamlruns NATS without it, for local use.
To connect to an authenticated NATS server, put the credentials in the URL:
Nats__Url=nats://<user>:<password>@nats:4222
A URL with only a user part, nats://<token>@nats:4222, sends it as a token. With a cluster, list every server, comma-separated, with the same credentials in each URL. A wrong or missing password fails at startup.
dotwire has no settings for NATS client certificates, NKeys, or credential files.
The same applies to Postgres: compose.yaml binds 5432 to 127.0.0.1.
Before you go further
dotwire v0.4 is an early release and isn't production-hardened. If you deploy it anyway:
- Keep the encryption key in a secret store and back it up. Losing it makes history unreadable.
- Archive
audit_checkpointsrows to independent storage on a regular schedule. - Back up and encrypt Postgres and the NATS volumes. dotwire's at-rest encryption covers message content, not your backup storage.
- Review the shared responsibility matrix.