# How it's built

> What Werker is made of, how runs stay durable on Postgres, and the architectural limits that matter before you run or trust it.

Source: https://werker.cloud/docs/how-its-built (updated 2026-12-01)

Werker is two processes and one Postgres database. A web app serves
the interface and a worker executes runs; Postgres holds the data, the
work queue and the live-update signals, so there is no separate queue
or cache service to run. The main limit is that a run's durable state
is a file on the worker's own disk, so a run cannot move between
worker machines. The whole system is spike quality: it works end to
end on one machine, and Werker's own instance is live on one server.

## The two processes

A run is one execution of an agent or workflow. A workspace is one
organisation's separate set of data, users and settings.

| Process | What it is                       | What it does                                                                                                                                                                                                                                        |
| ------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Web app | SvelteKit 3 and Svelte 5 on Node | Serves the interface and sign-in. Starts runs by adding rows to Postgres. Streams live updates to the browser. It cannot open stored provider keys.                                                                                                 |
| Worker  | A Node process                   | Claims queued runs from Postgres, runs each in the Pi agent harness under Pi Durable, starts and stops sandboxes, writes run events, usage, traces and totals. Holds the install's master key, so it is the only process that can open stored keys. |

A sandbox is an isolated environment where an agent can run code and
produce files. A worker can run several runs at once. An instance
admin sets the limit per worker and per workspace in the database, and
workers re-read it without a restart.

## Postgres as database and queue

- **Workspaces:** every workspace table uses row-level security, and
  the app connects as a restricted role.
- **Queue:** a run is a row. Workers claim rows with
  `FOR UPDATE SKIP LOCKED`, so several workers can claim at once
  without taking the same run.
- **Wake-up:** a trigger sends `NOTIFY` when a run is queued, and
  workers `LISTEN`. A slow poll is the fallback, because notifications
  are not replayed if a listener was disconnected.
- **Leases:** a claimed run holds a 30 second lease, renewed every 10
  seconds. A run whose worker died can be claimed again when its lease
  expires.

## How runs stay durable

Pi Durable runs each run as a durable task and resumes it after a
crash without redoing finished work. Workflows run as one durable
task, with each step in its own child conversation. Resuming after a
crash has been tested by hand on one machine only. Durable state for a
run is kept in Postgres while the run is running or waiting for input,
and deleted when it ends. Run events, step results, usage, traces and
totals are written to Postgres too.

## Live updates in the browser

- **Lists of runs** (the runs, dashboard and decisions pages, the
  sidebar and the header) follow the database through one
  server-sent-events stream per browser tab. The server re-reads on a
  `NOTIFY`, sends only a changed result, and re-checks the session at
  most once a minute before it sends.
- **A run in progress** streams its events to its page over
  server-sent events.
- **Limit:** over HTTP/1.1 a browser allows six connections per site,
  so many open tabs can wait. Serving the app over HTTP/2, for example
  through a reverse proxy, lifts this.

## The code

The code is split into packages, each with a list of the packages it
may depend on. CI fails on an import outside that list. The packages
are in [architecture](engineering/architecture.md) and what is
enforced is in [boundary checks](engineering/guardrails.md).

It stands on Better Auth for sign-in, Pi and Pi Durable for running
agents, and gVisor over Docker, Docker Cloud Sandboxes or Daytona for
sandboxes.

## Licence

MIT. The source is at
[github.com/werker-ai/werker](https://github.com/werker-ai/werker).

## Known architectural limits

- **Runs cannot move between worker machines.** A run's durable state
  is in Postgres, but projects are folders on the worker's disk
  ([projects](projects.md)), so a worker on another machine does not
  have them. Run one worker machine until this changes.
- **The web app and worker stop when the database restarts.** A
  dropped connection ends both processes instead of reconnecting. This
  is not fixed yet.
- **Backend testing is partial.** CI runs database tests on a
  throwaway Postgres. The worker and sandboxes were tested by hand.

See also [self-hosting](self-hosting.md),
[security](https://werker.cloud/security) and [status](https://werker.cloud/status). The
detail is in the [engineering docs](engineering/architecture.md).
