Skip to content

Architecture

Video: How a session flows (1:19).

Hearth is five programs written in Rust, a Redis (Valkey) for shared state and an S3-compatible store for artifacts. Only the gateway and the operator hold Redis and storage credentials.

flowchart TB
    runners["Playwright / Selenium / Appium runners<br/>and people in the web UI"]
    gw["hearth-gateway<br/>(stateless, any number of replicas)"]
    redis[("Redis / Valkey<br/>sessions, queue, pods, devices, key hashes")]
    s3[("S3-compatible store<br/>videos, device logs, apps")]
    op["hearth-operator<br/>(one replica)"]
    k8s["Kubernetes API<br/>BrowserPool, DevicePool, Team, Secrets"]
    subgraph cluster["Pods the operator runs"]
        bp["browser pods<br/>hearth-node + Playwright server or WebDriver<br/>one session each, no farm credentials"]
        ep["emulator pods (optional)<br/>Android emulator + Appium + hearth-agent"]
    end
    hosts["hosts outside the cluster<br/>hearth-agent + simulators or emulators + Appium"]

    runners -- "one URL, API key" --> gw
    gw <--> redis
    gw <--> s3
    gw -- "WebSocket / HTTP proxy" --> bp
    bp -- "register, heartbeat, upload video<br/>(pod token, /internal/node)" --> gw
    gw -- "prepare, release, live view,<br/>Appium commands (via the agent)" --> ep
    gw -- "prepare, release, live view,<br/>Appium commands (via the agent)" --> hosts
    ep -- "heartbeats, artifacts" --> gw
    hosts -- "heartbeats, app downloads, artifacts<br/>(agent token, /internal/agent)" --> gw
    op -- "watch resources, create and delete pods" --> k8s
    op -- "publish pools, teams, key and token hashes" --> redis

The parts

hearth-gateway is the only thing clients talk to. It checks the API key, picks a pool, queues the request if no browser is free, claims a browser pod or a device, and then proxies the session: it splices Playwright and CDP WebSockets straight through to the pod, and forwards Selenium and Appium HTTP commands. It also serves the web UI, the JSON API, live view, take control, artifact downloads and /metrics, and it is the only way browser pods and device agents reach the farm's state and storage. All state is in Redis, so any replica can serve any session and replicas can come and go.

hearth-operator runs one reconcile loop every 3 seconds. Each pass it:

  1. Publishes every Team's session limit, the SHA-256 hashes of the API keys in Secrets labelled hearth.testzeus.com/team, and the hashes of agent tokens in Secrets labelled hearth.testzeus.com/agent.
  2. Publishes every BrowserPool and DevicePool for the gateway.
  3. Sizes each browser pool (and each DevicePool with cluster: set): deletes finished pods, creates pods to cover the warm count plus the queue, removes idle pods above it after a delay, replaces idle pods made from an older template, and removes pods that never register. Each new browser pod gets its own name and a random token (HEARTH_POD_TOKEN), whose hash it records. See Pools and scaling.
  4. Fails sessions whose browser pod or emulator pod disappeared, and frees their team slots.
  5. Writes ready, busy, starting and queued counts into each pool's status.

The loop is safe to restart at any point: every decision is made from what Kubernetes and Redis say at that moment.

hearth-node runs inside every browser pod. On start it brings up a virtual screen (Xvfb) and either playwright run-server or a WebDriver (chromedriver or geckodriver), then registers the pod with the gateway (/internal/node/register, with its pod token) and heartbeats every 2 seconds. It serves exactly one session: it records the screen with ffmpeg while the client works, uploads the video through the gateway when the session ends, and exits. It holds no Redis or storage credentials.

hearth-agent runs next to devices: on a Mac with iOS simulators, on a Linux or macOS host with Android emulators, or inside an in-cluster emulator pod. It reports its devices to the gateway by heartbeat, prepares a device for a session (installs the app, starts recording), forwards the session's Appium commands to the device's Appium on its own host, and resets the device afterwards. See Device agents on hosts.

hearth is the command line: hearth up local and hearth down for a local farm on kind, hearth status for pools and queues, hearth key and hearth agent-token to print a team's key or a host's token, and hearth app upload for device apps.

How a Playwright session flows

sequenceDiagram
    participant C as Playwright client
    participant G as gateway
    participant R as Redis
    participant N as browser pod (hearth-node)
    C->>G: WebSocket upgrade /playwright/chromium?token=KEY
    G->>R: key hash -> team; reserve a team slot
    G->>G: pick the pool from engine + client version (User-Agent)
    G->>R: join the pool's queue; claim a ready pod
    Note over G,R: no ready pod: poll every 250 ms until one is free<br/>or the queue timeout passes (HTTP 429)
    G->>N: WebSocket /session/ID with the pod's secret token
    N->>N: start recording, launch the browser via Playwright's server
    G-->>C: 101 Switching Protocols (spliced to the pod)
    C->>N: Playwright protocol, end to end
    C->>G: close
    N->>G: upload video.mp4, report the outcome (pod token)
    N->>N: exit
    Note over N: the operator deletes the pod and a fresh one replaces it
  1. The gateway reads the key (bearer token, basic-auth password, x-hearth-key header or ?token=), finds the team and reserves one of its session slots.
  2. It picks the pool: the engine comes from the path, the Playwright major.minor from the client's User-Agent (or ?version=). A version with no pool is refused before the WebSocket upgrade, with a message that lists what the farm runs.
  3. It joins the pool's queue, oldest request first, and claims a ready pod with one atomic Redis script, and marks the pod as used so it can never register as ready again. If none is free it keeps the client's upgrade request open and retries every 250 ms. A request that gives up loses its place within a few seconds; one whose gateway died is failed after 20 minutes.
  4. It opens a WebSocket to the pod, presenting the pod's own secret, and splices the two together. From here the client speaks Playwright's protocol with the pod.
  5. When the client disconnects, the session reaches its maximum duration, or someone presses Stop in the UI, the pod stops recording, uploads the video through the gateway, reports the outcome (which gives back the team slot) and exits. The operator deletes it and creates a fresh one if the pool needs it.

Selenium follows the same steps over HTTP: POST /wd/hub/session claims a WebDriver pod, and every later command for that session id is forwarded to it. Appium sessions claim a device instead of a pod: the gateway asks the device's agent to prepare it, then sends the new-session request and every later command to the agent, which forwards them to the device's Appium. See Mobile devices.

Why one session per pod

Some farms pack several browser contexts into one long-lived browser server. That is dense, but clients then share a browser: they cannot freely call newContext, one tenant's crash hits another, and the farm has to count slots per server.

Hearth gives each session a pod from a warm pool of pods that already booted:

  • The client gets a whole browser. newContext, extensions, close() and CDP just work.
  • Isolation is the pod boundary, with its own resource limits and NetworkPolicy.
  • Video for every engine comes from one place: the virtual screen and ffmpeg.
  • Allocation is "claim a ready pod", one atomic step in Redis.
  • A pod is never reused, so nothing leaks from one session to the next.

The cost is density and a cold start when the warm pool runs dry: a few seconds for a pod on a node that has the image, longer if the cluster must add a node.

Device pools differ: emulators and simulators are slow to boot, so devices are reused and reset between sessions by their agent.

Where state lives

State Where Lifetime
Sessions, queue, pod and device registrations, pod token hashes, team counters, UI sign-ins Redis, under a prefix (hearth by default) Session records 7 days; the rest is live state
Pools, teams BrowserPool, DevicePool, Team resources Until you delete them
API keys, agent tokens Secrets labelled hearth.testzeus.com/team or hearth.testzeus.com/agent Kept even if the chart is uninstalled
Videos, device artifacts, uploaded apps The S3-compatible bucket Until you delete them

The bundled Valkey keeps nothing on disk. Losing it ends running sessions and clears the session list; pools, teams and keys are published again by the operator within seconds, and agents report their devices again on their next heartbeat. See Operations for how browser pods recover.