Production Deployment

A production deployment needs your application, one or more Waymark nodes, and Postgres. The nodes run workflows and the scheduler; Postgres holds shared state. You can restart app and node containers independently, but version upgrades require downtime and a specific startup order.

Topology

  • Your app queues workflows from a web service, script, or cron job. Its language-specific SDK starts waymark-bridge; the Python SDK starts a singleton on first use. Give it the same main database and observability-store settings as the nodes. The bridge doesn't read migration URLs or change the schema; its database role only needs to read and write rows. Budget its pool sizes separately from the nodes' pools (see Database connections).
  • The node is one container running waymark-executor. It runs your workflows, dispatches their actions to a pool of worker processes, and persists every step in Postgres. It also runs the scheduler and, if you enable it, serves the HTTP API and the webapp.
  • Postgres is the only stateful piece. Anything 14+ works, including the managed instance you already have.

Your app and the nodes coordinate purely through Postgres, so they don't need to reach each other over the network. Scale them and restart them independently; only an upgrade needs an order.

Migrations and upgrades

Nodes migrate the database schema at startup. With HTTP enabled, /healthz becomes available after migration finishes.

The bridge checks the schema only at startup. It waits up to WAYMARK_MIGRATIONS_STATEMENT_TIMEOUT_MS for an in-progress migration, then refuses to start unless the schema exactly matches its own migrations. An older node also refuses a newer schema. The bridge checks the observability store in the same way, using WAYMARK_OBSERVABILITY_POSTGRES_MIGRATIONS_STATEMENT_TIMEOUT_MS.

On a new database, start the app once a node is healthy. Until then, your app's workflow calls fail with unable to boot waymark server, and each call tries again. The same error shows when the app and the nodes run releases with different migrations.

A workflow call waits about 5 seconds for the bridge the SDK starts. While a migration is in progress, the call fails with that error even though the bridge itself keeps waiting for the migration. The bridge the SDK starts keeps no logs, so the error does not say why the bridge did not start (#820); to see the reason, run waymark-bridge by hand with the app's environment.

Plan downtime for the whole upgrade. Running bridges and nodes don't recheck the schema, so a rolling update is not supported.

  1. Snapshot the database. The old version refuses the migrated schema, so you cannot roll back by restarting the old containers.
  2. Stop every app container, bridge, and node. The SDK starts the bridge as a separate process that can outlive the app; stop those processes too.
  3. Start the nodes on the new version and wait for a healthy node.
  4. Start the app on the same version.

Share an image

Build one image containing your application and Waymark's support for its language (the waymark package for Python). Both the app and the node need the same workflow and action definitions; use a different startup command for each service.

Run the node as a second container from your app's image, with waymark-executor as its command. If you don't have a Dockerfile yet, use this one:

FROM python:3.12-slim

RUN pip install uv

WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev
COPY src ./src

ENV PATH="/app/.venv/bin:${PATH}"

# The default command serves the app; `waymark-executor`
# overrides it.
CMD ["uvicorn", "yourapp.web:app", "--host", "0.0.0.0", "--port", "8000"]

Compose the services

The same shape works in Docker Compose, Kubernetes, or anything that runs containers. In Compose:

services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: app
      POSTGRES_USER: app
      POSTGRES_PASSWORD: app
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app"]
      interval: 5s
    volumes:
      - postgres-data:/var/lib/postgresql/data

  executor:
    build: .
    command: ["waymark-executor"]
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      WAYMARK_DATABASE_URL: postgresql://app:app@postgres:5432/app
      WAYMARK_USER_MODULE: yourapp.workflows
      WAYMARK_HTTP_ENABLED: "true"
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:24119/healthz')"]
      interval: 5s
      start_period: 60s
    ports:
      - "24119:24119"

  app:
    build: .
    depends_on:
      executor:
        condition: service_healthy
    environment:
      WAYMARK_DATABASE_URL: postgresql://app:app@postgres:5432/app
    ports:
      - "8000:8000"

volumes:
  postgres-data: {}

Production settings

Start with the single-host defaults. Adjust these settings as you measure worker utilization and queued work:

VariableWhat it controls
WAYMARK_WORKER_COUNTWorker processes per node. Defaults to the CPUs available to the node, container CPU limits included, so the workers can saturate each core.
WAYMARK_CONCURRENT_PER_WORKERConcurrent actions per worker. Raise it for I/O-bound actions such as API requests.
WAYMARK_MAX_CONCURRENT_INSTANCESWorkflow instances one node holds at once.
RUST_LOGThe node's log filter, e.g. info or warn.

If a third-party library leaks memory inside your actions, set WAYMARK_MAX_ACTION_LIFECYCLE to recycle workers after a fixed number of actions. Today the old worker is stopped with its in-flight actions, which fail with ActionExecutionLost (#727); a retry policy that lists it retries them.

Every other variable, the workload pinning lease and the scheduler interval among them, is documented in Configuration.

Database connections

Budget your Postgres connections per process:

  • Each node opens up to 25 connections for its main pool (WAYMARK_DATABASE_MAX_CONNECTIONS), plus up to 4 + 4 for the observability store's write and read pools - 33 in total, since the observability store shares the main database by default. At startup it also opens one connection for the main migrations and one for the observability migrations; each is closed before the pools of its database open, so neither adds to the 33.
  • Each app container, pod or host (whatever shares one localhost) that queues workflows runs one singleton bridge, shared by its processes, with up to 10 connections (WAYMARK_DATABASE_MAX_CONNECTIONS, the same variable as the node's, with a default of its own), plus up to 4 for its own observability write pool - 14 in total. At startup it also opens one connection to check the main schema and one to check the observability schema; each is closed before the pool of its database opens, so neither adds to the 14.

The observability store holds events and node load samples, kept for seven days by default. On a busy deployment you can move it off the main database by pointing WAYMARK_OBSERVABILITY_DATABASE_URL at another Postgres, and its reads at a replica with WAYMARK_OBSERVABILITY_READ_DATABASE_URL; the node's own connection count stays the same. Every host that boots the bridge, the SDK's included, then carries the same WAYMARK_OBSERVABILITY_DATABASE_URL: without it the bridge looks for the store in the main database and refuses to start. Once the nodes run on the new store, drop the old observability schema from the main database: a bridge still pointed at it would find a store at the right migrations, pass its check, and write where nothing reads. See Configuration.

Logs, metrics and the webapp

The node logs to standard output, filtered by RUST_LOG. It always serves /metrics in Prometheus format on port 9118 (METRICS_ADDR). That port's /health endpoint responds before migrations run: it checks liveness, not readiness.

Set WAYMARK_HTTP_ENABLED=true to serve the HTTP API, webapp, and /healthz on port 24119. Use /healthz for readiness checks.

Scaling out

To add capacity, run another node. Each node claims workflow instances through leases in Postgres and refreshes those leases while it works. After a crashed node's lease expires (15 seconds by default), another node can resume its instances from their last saved state. The app tier can scale independently; it queues workflows through Postgres.

When a node container is killed mid-run, its instances resume on another node. Version upgrades still require the shutdown order above. An action call that was in flight on the killed node fails with ActionExecutionLost after the node's lock on it lapses (WAYMARK_ACTION_EFFECT_RECONCILER_LOCK_TTL_MS, 15 seconds by default), reported to the workflow by the node that resumed it. A worker process dying or being recycled on a live node is the other case: the calls it was running fail with ActionExecutionLost too, or ActionExecutionNotStarted if it provably never started. ActionExecutionLost derives from BaseException, because the attempt may have run partway, so only a retry policy that lists it retries the call, and an action retried that way must be safe to run again; ActionExecutionNotStarted is retried like any other exception. Without a matching policy, the exception propagates like any other, for a try/except in the workflow to handle.

On a termination request to the node process (SIGTERM, what docker stop and Kubernetes send, or SIGINT), a node shuts down gracefully: it lets its in-flight action calls finish, releases its workflows for another node to resume, then exits. Nothing inside the node bounds how long that takes; your orchestrator's grace period does (stop_grace_period in Compose, terminationGracePeriodSeconds in Kubernetes), and a node it kills once that runs out is picked up as described above. On Linux and macOS, further shutdown requests while the node is shutting down do nothing today; this may change.

A Ctrl+C typed in the terminal running waymark-executor reaches its worker processes too, and they stop at once: their in-flight action calls fail with ActionExecutionLost (#827). On Windows, a second Ctrl+C during the shutdown terminates the node at once (#826), and closing its console, logging off or shutting Windows down terminates it after the system's own timeout, or at once during a shutdown already under way.

If queue latency grows, check Postgres load as well as worker capacity. A dedicated Postgres instance can separate Waymark's writes from application queries. For Postgres configuration help, see Autopg.