# Under the hood

How an app's machines are driven by a pull-only Go agent with Podman and Caddy, how pooled hosting serves a Next.js app from Rust and a sandboxed Node process, what we rejected, and what we measured.

Apps has two hosting modes. An app on its own machines is a set of ordinary compute instances,
each running a small Go agent that pulls what it should run and keeps the machine in that state;
the platform never connects in. Pooled hosting is for Next.js apps only: a Rust server on a shared
pool host answers everything that is a file itself and starts the app's own Node server, in a
gVisor sandbox restored from a checkpoint, for the rest. The decision behind both is the same:
your app runs unmodified, on a machine or in a sandbox you can reason about, and the platform's
part is a reconciler, not a scheduler.

## What runs where

An app on its own machines, as [What runs on your machines](what-runs-on-your-machines.md)
describes from the outside, looks like this from the inside:

```text
control plane (HTTPS, outbound from the machine only)
  desired state  pulled every 5 s
  status, logs (~10 s), metrics (60 s)  pushed back
        ▲
        │
   app machine (a compute instance)
     ews-agent (systemd, Restart=always)
       self-update timer, every 15 min
        │  Caddy admin API, local StatsD socket
        ▼
     Caddy :80/:443  Let's Encrypt, on-demand TLS
        │
        ▼
     Podman: app (old + new port during cutover),
       compose services on one network, release command,
       scheduled jobs (podman run --rm)

   one machine: DNS points at it
   max replicas > 1: the app's own load balancer in front
```

A deployment is one tick of the agent: it sees a newer generation, pulls what a tag needs, starts
the new container on a fresh port, waits for the health check, flips Caddy's upstream through the
admin API, then stops the old container. Kill switches are rendered into Caddy before every route
(offline answers `503`, private-only answers `403` to public sources), so they hold without
touching the app. The agent is 5,800 lines of Go on the standard library alone, a static binary
for amd64 and arm64.

Pooled hosting runs on platform-owned pool hosts. For an organization with its own hosts they are
VMs on its site; for every other organization they are the shared cloud pool, Deutsche Cloud's own
cloud servers:

```text
client ─▶ site front (443 by SNI)      client ─▶ the host's own address
            │                                     (shared cloud pool: ≥ 2 hosts,
            ▼                                      each in another data centre)
   pool host VM
     app-host, Rust: TLS, router, 256 MB file cache, proxy
     gVisor sandbox per running deployment: the app's own
       standalone server.js, restored from a checkpoint
     PostgreSQL 16, one per host

   CI: next build + export hook ─▶ bundle
       ─▶ sealed object storage
```

The Rust server applies Next's own routing order (base path, redirects and headers, rewrites,
files, dynamic routes, fallback) to a routes file exported at build time, without running any
JavaScript. A static or prerendered file is served from the deployment directory or a host-wide
RAM cache. Anything that needs Node (not GET or HEAD, a server action, draft mode, a middleware
match, a dynamic route) is proxied to the app's own server, started on demand and stopped after
300 s idle by default (60 to 3,600). Streaming responses and WebSocket upgrades are spliced through.

Pooled hosting is in the product (`hosting: pooled` on create, bundles uploaded by your CI, a
Postgres database on the pool host). The shared cloud pool keeps at least two hosts while it has
apps, each in a different data centre, and one more whenever the hosts left after losing one could
not hold every app. A host that stops reporting for two minutes is lost: its apps move at once to a
host that is already running, and the app's name follows, because our nameservers answer it with a
10-second TTL. The lost machine is deleted and a replacement started in the same minute. An app's
files come from sealed object storage, so the new host serves the first request after it has
fetched the bundle; an app's server starts there as on any wake.

## What we built, and what we did not

**On the machine we run Podman, Caddy and systemd, and wrote the agent.** Podman over Docker
because it is rootless, daemonless and driven from systemd. Caddy gives us Let's Encrypt,
on-demand TLS for wildcard custom domains (the agent answers Caddy's permission check with the
names the control plane lists) and routing we rewrite at runtime through its admin API; a
box-local proxy also means a single-machine app has no load balancer in its path. The agent pulls
rather than accepts commands because a machine that only makes outbound requests survives
control-plane downtime, NAT and reboots, and converges on its own.

**We did not put apps on Kubernetes or Nomad.** k3s and Nomad were recorded as a bigger lift to
defer until the simpler model had proved itself: an app is its own compute instances, visible,
resizable and reachable over SSH, not a pod on a shared cluster. Scaling adds machines and puts
the app's own load balancer in front at every size once its maximum is above one (we rejected
adding it only above one replica, because a DNS flip plus certificate issuance would land exactly
when load arrives), and the replica count follows request and memory numbers the agent reads from
Caddy, not the provider's balancer metrics.

**Smaller decisions, as recorded.** Compose apps publish several services through the machine's
own Caddy; we rejected one app per public service (loses the shared network and volumes) and a
platform proxy in front (an extra hop and failure domain). Images run by digest: a digest-pinned
reference already on the machine is neither pulled nor logged in for; we rejected an expected
digest per service, skipping only user-pinned digests, and falling back to a stale local tag. Kill
switches overlay desired state rather than edit the app, because an edit is undone by the next
deploy or Terraform apply. Preview environments are apps of their own, not extra containers on the
parent's machines.

**For pooled hosting we run gVisor, Node, PostgreSQL 16 and Incus VMs, and wrote the server.** We
compared: the app's unmodified standalone Node server in a pooled sandbox, started on request and
stopped when idle (chosen: every Next feature keeps working); static and prerendered output from
our own cache in front (chosen, in Rust); OpenNext-style public adapters (not used); V8 isolates in
the Cloudflare style (ruled out: a JavaScript engine in our host, and broken Node APIs). We read the
build through Next's Adapters API with a hook of about 20 lines that exports routing data and
nothing else, because the build manifests changed shape between 15.5 and 16.4 without a version
bump; a customer installs nothing.

The isolation choice was the real one. runc is no tenant boundary, so plain containers were out.
Firecracker needs KVM, which the cloud VMs we rent do not expose, and a VM per app costs 2 to 4 s
to start and at least 0.43 GB idle. Fly Machines are the right model (suspend what is idle) at the
wrong granularity: a VM snapshot is memory-sized and lost on every deploy, while a gVisor
checkpoint is the process only, 47 MB (12 MB compressed), one per deployment. So each running
deployment is a gVisor sandbox (`runsc`, systrap) in its own network namespace with a read-only
root, uid 65534 and cgroup limits; the pool host is itself a VM, so an escape lands in a VM holding
only pool workloads. Every restore of one checkpoint would start with identical OpenSSL and
`Math.random` state, so a preload reseeds both before the server takes traffic, and a sandbox whose
reseed failed never gets a request. Sandboxes reach the internet only: not the host (except its
Postgres port), not each other, no private ranges, no IPv6. The one private exception is a cloud
pool host's link to managed Postgres: a sandbox may reach the link address and port of a database
its own app is bound to, and nothing else on that network; the database node itself admits only the
pool hosts' addresses, and only on Postgres and its pooler, since the provider's firewall does not
filter private networks. The host Postgres is also archived continuously (every write-ahead log
file about once a minute, a base backup daily, sealed per file under the platform key bound to the
host), which gives a restore to any second of the last 7 days and a failover that loses a minute
or two.

The host Postgres (one cluster per host, a database and role per app, dumps as backups) won over
porting managed Postgres to own hosts (weeks) and over managed Postgres in the cloud (cross-site
latency). Bundles, data and backups are sealed with AES-256-GCM; the host receives a per-object
data key, never a wrapping key.

## Benchmarks

**How to rerun these.** The autocannon, `runsc` and `curl` commands below reproduce the file
table, the bare restore and checkpoint, the client-side wake and the redeploy. The one-app,
30-app, burst and memory figures were run with an internal tool, not published. The app-host
timings on the same VM (route handler, PGlite wake, first `initdb`) were taken by hand and their
commands not kept.

Pooled-hosting numbers are from 2026-11-18 on one `performance-4` VM (4 shared AMD vCPU, 8 GB,
x86) with gVisor release-20261109.0 and a Next 16.4.6 app (a small probe app for the bare `runsc`
rows, a template app with a PGlite guestbook for the app-host rows), unless stated. Raw output was
not kept for any of them; the conditions were recorded with each run.

**Files: Rust versus Node.** autocannon 8 on the same VM, 50 connections, 15 s:

| `GET`                   | app-host (Rust)                  | the app's `node server.js`  |
| ----------------------- | -------------------------------- | --------------------------- |
| prerendered `/`         | 33,300 req/s, p50 1 ms, p99 4 ms | 2,980 req/s, p50 14, p99 37 |
| 112 KB JavaScript chunk | 3,900 req/s (440 MB/s)           | 2,990 req/s                 |

```sh
npx autocannon@8 -c 50 -d 15 -H 'Host: app1.local' http://127.0.0.1:8080/
```

The chunk row is limited by the load generator, which shared the four vCPUs. Loopback, one
machine: it shows the cost of serving a file through Node, not what a client sees.

**Waking a sleeping app.** The headline "about 90 ms" is the bare `runsc restore` of a warmed
server. Inside app-host, with the reseed and the network namespace, a wake costs more, and the
number to plan with is the one from a real pool host:

| Where measured                                            | Wake time                                  |
| --------------------------------------------------------- | ------------------------------------------ |
| bare `runsc restore`, same VM, 5 runs, to first response  | 86–92 ms (37–45 ms inside `runsc`)         |
| app-host on the same VM, route handler, end to end        | 165–187 ms (restore+reseed 141–150)        |
| app-host, one app woken 5 times                           | 157 ms (restore 133 ms)                    |
| pool host in our test installation, app-host's own timing | 208–225 ms (restore 116–123, reseed 39–55) |
| same, from a client about 70 ms away, two series          | 348–403 ms, 414–419 ms                     |

The pool host in our test installation was a 16 GB VM running nested on one of our own hosts.

```sh
runsc --platform systrap --network sandbox checkpoint -image-path /tmp/ckpt <sandbox-id>
time runsc --platform systrap --network sandbox restore -detach -image-path /tmp/ckpt \
  -bundle <bundle> <sandbox-id>
curl -o /dev/null -s -w '%{time_starttransfer}\n' https://<app hostname>/api/hello
```

A checkpoint takes 54 ms. An app with an open PGlite database is never checkpointed and wakes in
0.67 to 0.77 s; its first-ever start runs `initdb` and takes 4.7 s.

**Bursts and memory** (internal tool, not published). Restores are CPU-bound, about 0.2
vCPU-seconds each: 1, 4, 8, 16 and 32
restores started at once completed in 217, 283, 419, 781 and 1,649 ms of wall time, which is why
app-host caps concurrent starts at the host's vCPU count. 30 apps woken at once all answered `200`
within 1.84 s (p50 1.0 s). An idle restored app with no open database costs 58 MB of host memory
(30 apps took the host from 452 to 2,202 MB), one with PGlite open 172 MB, a stopped one 0 MB. We
have not measured a full-size pool host; any "apps per host" figure is arithmetic on these per-app
numbers, not a measurement.

**Redeploy latency on a machine.** In our test installation on 2026-11-19, one `performance-2`
machine (2 shared AMD vCPU, 4 GB), a two-service compose app, raw output not kept: an
environment-only redeploy took 9.9 to 11.8 s from "machine runs release" to the release starting
before images were pinned by digest, 2.6 to 5.8 s after; created to live went from 25.9 to 26.7 s
to 21.0 to 21.9 s. With the registry cut off, the same redeploy failed after 485 s before and went
live in 16.9 s after.

```sh
curl -X PUT -H "Authorization: EWS-ACCESS-KEY $KEY" -H 'content-type: application/json' \
  -d '{"redeploy":true}' https://<console host>/deploy/api/apps/<app id>/env
```

There is no throughput, density or memory benchmark of the agent itself.

## Known limits

- The agent and the control plane's deployment step each poll every 5 s, which can add up to about
  10 s to every deployment; long polling is not built.
- A tag such as `postgres:17` is still pulled on every rollout, and a redeploy re-resolves the tags
  of a pinned compose file.
- A machine ignores new fields (routes, kill switches) until its agent self-updates, up to 15 min.
- Pooled hosting: one host per app at a time. On the shared cloud pool a lost host's apps move to
  another host once it has been silent for two minutes; on an own-hosts site with one pool host a host loss is
  downtime. The host Postgres is a single node: after a host loss its database comes back from
  the WAL archive after five minutes (about a minute of data lost) or, if the archive is stale, the newest daily dump.
- A route with Partial Prerendering or Cache Components holes goes to Node whole. A Next version
  the hook does not know falls back to "files, and everything else to Node".
- `revalidatePath` and `revalidateTag` reach only the running instance's memory; a shared cache
  handler is not built, nor is a Rust image optimizer for `/_next/image`.
- A gVisor upgrade invalidates every checkpoint; the next wake boots the server (about 1
  vCPU-second).
- A wake storm beyond the vCPU count holds requests 10 s, then answers `503` with `Retry-After: 2`.
- A long-open WebSocket keeps the app running, and billed; WebSockets are proxied but not
  measured. Pooled usage costs 0,008 € per GB-hour of reserved memory while the server runs (idle
  is free), one invoice line per app; where pooled charging has not started yet it is metered,
  not charged yet.
- Kill switches on a pooled app cover hostnames only (answered `404`); there is no private-only switch.
- An autoscaled app's load balancer is not metered yet.

## Related

- [What runs on your machines](what-runs-on-your-machines.md)
- [Use a database on the pool host](use-a-pool-host-database.md)
- [Autoscale an app](autoscale-an-app.md)
- [Publish several services](publish-several-services.md)
- [Pull a kill switch](pull-a-kill-switch.md)
- [Under the hood: the site front](/docs/ec2/guide/under-the-hood)
