Docs menu

You're reading the docs for dotwire 0.3. The latest release is 0.5. Upgrading? See Upgrading to 0.4.

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.3.0.

Single node

compose.yaml runs three services:

  • dotwire in the default All role, listening on port 8080. Compose publishes it on 127.0.0.1:8080 only.
  • postgres, from timescale/timescaledb:2.31.0-pg17.
  • nats, from nats:2.15.1-alpine, started with JetStream (-js) and file storage on a volume. It runs as an unprivileged user, so a short-lived nats-init container 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

SettingWhat it's for
ConnectionStrings__PostgresMigratorThe owner role (dotwire) that runs migrations
ConnectionStrings__PostgresWriteThe runtime role (dotwire_app) for writes
ConnectionStrings__PostgresReadThe runtime role for reads. Point it at a replica to move reads off the primary.
Postgres__AppRolePasswordThe 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__JwksUrlHost token verification. See Auth.
Nats__UrlNATS 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 Api or All nodes. Gateway nodes don't run them.
  • Run migrations from one node. compose.multinode.yaml sets Postgres__Migrate to true on the API node and false on gateways.
  • Only one audit writer is active at a time. Additional Api nodes wait in standby. See Audit log.
  • Retention set with Dotwire__Retention__MessagesDays is applied by the node that runs migrations.

Multiple nodes

compose.multinode.yaml is a reference topology:

  • two Gateway nodes that hold WebSocket and SSE connections,
  • one Api node 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 on 127.0.0.1:8404 behind a password.

It needs these values in .env, and refuses to start without them:

VariableWhat it's for
NATS_USER, NATS_PASSWORDNATS client authentication. Every dotwire node connects with them.
POSTGRES_REPLICATION_PASSWORDThe replicator role the read replica streams from.
HAPROXY_STATS_PASSWORDThe 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.

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 AllowedHosts to your real host names.
  • Keep ConnectionStrings__PostgresMigrator on the node that runs migrations only.
  • Point the host SDKs at an https baseUrl.
  • Supply connection strings from your secret store. Values in a Compose environment: block are visible through docker inspect.

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.yaml binds 4222 (clients) and 8222 (monitoring) to 127.0.0.1 only, and compose.multinode.yaml doesn't publish 4222 at all.
  • Turn on NATS authentication anywhere other machines share the network. compose.multinode.yaml does, with NATS_USER and NATS_PASSWORD. compose.yaml runs 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.3 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_checkpoints rows 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.