# Under the hood

How Container registry is built, why we wrote our own OCI Distribution server instead of running one, what we measured against the reference registry and where the limits are.

Container registry is our own implementation of the OCI Distribution v2 API: manifests, tags and
scan results in Postgres, layer bytes in the platform's object store, our own token flow, and IAM
enforced per repository by the same engine as every other service. There is no CNCF Distribution,
Harbor or other registry underneath. The decision that matters most is that one: the registry is
a content-addressed blob store with a JSON index, and owning it is what lets a repository's
permissions, audit and billing be ordinary Deutsche Cloud permissions, audit and billing.

## What runs where

```text
docker ──TLS 443──▶ Caddy (<org>.ecr host)
                      │  session affinity on ?_u
                      ▼
   web or web-b (Node.js)
     GET  /v2/        ─▶ 401, Bearer realm
     POST /v2/token   ─▶ IAM eval ─▶ 1 h bearer
     HEAD blob        ─▶ Postgres only
     POST uploads/    ─▶ multipart upload + session row
     PATCH            ─▶ 16 MiB parts, SHA-256 in memory
     PUT ?digest=     ─▶ complete; digest must match
     PUT manifest     ─▶ parse, check blobs, tag rules
                         ─▶ Postgres; scan queued
                      │
                      ▼
   object store (one key per blob)

   pull: token ─▶ manifest from Postgres
               ─▶ ranged GET streamed from the store
   scanner (Trivy) pulls by digest through the public
     registry host
```

Each organization has its own registry host, and the organization is resolved from the `Host`
header before any token is checked; a token's organization must match. A push starts with a
multipart upload in the object store and a session row; every `PATCH` is streamed into 16 MiB
parts while a SHA-256 runs in the replica's memory, so memory per upload is one part plus a
socket chunk whatever the layer's size. The upload's `Location` carries a session id, and Caddy
hashes on it so every request of one session reaches the replica holding the hash; if the replica
set changes mid-session the finalising step re-reads the blob to verify it. The final `PUT` with
`?digest=` must equal the in-flight hash, and a blob already held by the organization is
deduplicated. A manifest is parsed, every blob it names must be held by the repository, tag rules
are applied, and the row is written; the scan is queued.

A pull takes the manifest from Postgres and streams the blob from the store with ranged GETs that
resume if the store fails mid-transfer. We do not redirect blob GETs to presigned store URLs, as
many registries do: that hands the client the store's failures directly, makes the bucket
public-facing and bypasses per-pull audit. The scanner is the Trivy CLI behind a small Go front of
ours in its own container, on a network shared only with the web replicas and one background
worker: read-only root
filesystem, all capabilities dropped, no new privileges, an unprivileged user and a 64 MB tmpfs.

## What we built, and what we did not

**The server is ours.** The reasoning we recorded: OCI Distribution is "a dumb content-addressed
blob store with a JSON index. Immutable objects, no negotiation, no concurrency on mutable state
beyond a tag pointer." That is small enough to own, and owning it gives one token flow and one IAM
engine for registry, Git and everything else; the shape (bytes in the object store, pointers in
Postgres) later became the template for the [Git service](/docs/git/guide/under-the-hood). We did
not record a point-by-point evaluation of Harbor, Zot, Quay or CNCF Distribution before building;
Harbor served as a feature benchmark afterwards and CNCF Distribution as the performance reference
below.

**Hashing: native `node:crypto`, not hash-wasm, not Rust.** The first version hashed with
hash-wasm so the SHA-256 state could be serialised across requests and replicas. It capped push
throughput, so we moved to native `node:crypto` kept in replica memory plus the session affinity
above. We did not move to Rust: the runtime is not the limit.

**Scanner: Trivy CLI, not Trivy server mode, not a second scanner.** Trivy's server mode, given
only an image name, analysed nothing and returned an empty list, so every image showed clean; the
Go front runs the CLI per request instead. Trivy is pinned by image digest since the March 2026
Trivy supply-chain compromise (CVE-2026-33634). A second scanner (Grype) was deferred: it doubles
the supply-chain surface and needs result deduplication; osv-scanner is weaker on OS packages.

**Lifecycle policies are AWS ECR JSON, verbatim,** so a policy written for ECR can be pasted in.

**Retries are ours, with jitter, not the SDK's `maxAttempts`;** a throttled store call is tried
six times over 11.5 to 23 s and then answered `503` with `Retry-After: 10`. A small final part
under the store's 5 MiB minimum is kept as a short last part rather than written as a separate
tail object. Our own deploys run images by digest and skip pulling a digest already on the
machine. Every answer carries `Content-Length`, because containerd refused manifest `HEAD`
answers without it.

## Benchmarks

### Against `registry:3` and Zot on the same storage, 21 November 2026, raw output kept

Our `arm-16` test box (16 Neoverse-N1 cores, 30 GB, arm64), shared with other work (load 3 to 30).
Ours: the production build as one replica behind Caddy, Postgres 17, SeaweedFS 4.54 as the S3
store. References on the same SeaweedFS: CNCF `registry:3` (Distribution 3.1.2), also with blob
redirects on, and Zot 2.1.23 (dedupe off). Plain HTTP over loopback, so no TLS cost in any figure.
Clients speak the Distribution API the way containerd does (one streaming `PATCH` per layer, all
layers pulled at once, every byte hashed); parallel pulls run one process per client.

Five 1 GiB random layers, MB/s ("redirect": `registry:3` answering blob `GET`s with a redirect to
the store):

| Step            | Deutsche Cloud | `registry:3` | redirect    | Zot         |
| --------------- | ----------- | ------------ | ----------- | ----------- |
| push, 1 client  | 221–228     | 258          | 261–269     | 240–256     |
| pull, 1 client  | 252–260     | 451–565      | 428–502     | 451–551     |
| pull, 8 clients | 244–249     | 2,158–2,321  | 2,775–2,887 | 2,080–2,271 |

Real `docker push` and `docker pull` (Docker 29.10) of a 2.04 GB image in 12 layers:

| Step                     | Deutsche Cloud | `registry:3` | Zot    |
| ------------------------ | ----------- | ------------ | ------ |
| push, cold               | 9.2 s       | 8.7 s        | 9.2 s  |
| pull, cold (with unpack) | 15.2 s      | 10.5 s       | 10.1 s |
| push or pull, warm       | 0.2–0.4 s   | 0.2–0.6 s    | 0.8 s  |

Metadata, in a repository of 500 tags: median latency at one client, then requests a second at 32.

| Request        | Deutsche Cloud   | `registry:3`   | Zot            |
| -------------- | ------------- | -------------- | -------------- |
| manifest `GET` | 9.8 ms / 228  | 7.8 ms / 959   | 17.4 ms / 704  |
| blob `HEAD`    | 14.8 ms / 183 | 1.4 ms / 5,228 | 3.3 ms / 2,144 |
| tag list       | 14 ms / 174   | 166 ms / 21    | 13 ms / 701    |

What it shows: push is level. A replica moves blob bytes on one core, about 250 MB/s however many
clients pull, where the Go registries scale with clients; a cold `docker pull` takes about 45 %
longer. Metadata answers are a few milliseconds from the reference at one client but take about
5 ms of CPU each; tag listing is the fastest of the three, from a Postgres index rather than a
bucket walk. As a pull-through cache of a 586 MB image from GHCR, ours serves a layer only after
storing and verifying all of it: 20 s cold against 11 s for `registry:3`, which streams through,
when the upstream is fast.

Because the registry shares a replica with the console, a saturated replica used to delay every
other request: the health check rose from 7 ms to a median of 1.05 s and a worst case of 4.4 s
during 16 parallel pulls. Since 21 November byte streams step aside while the replica's event loop
falls behind; the same test now gives a median of 189 ms (worst 472 ms), and a single pull or push
runs at the same speed as before (pull 278–288 MB/s, push 215–220 MB/s).

**How to rerun this one.** Run `registry:3` and Zot against an S3 bucket of your own and push the
same random layers to each with any Distribution client: one `POST /v2/<repo>/blobs/uploads/`,
one streaming `PATCH`, `PUT ?digest=` per layer, then `GET` every layer at once from one or
several processes, hashing what arrives. For the `docker` rows, build an image from random tar
layers (`crane append`), `docker load` it, and time `docker push`, then `docker rmi` and time
`docker pull`; a second push or pull gives the warm row. Our own scripts for all of it are
internal.

**How to rerun the earlier runs.** The push-and-pull and native-hashing tables were run with an
internal tool, not published; the method (one streaming `PATCH` per layer, parallel pulls hashed on
the client) can be repeated with `crane` or any registry client, and `openssl speed` gives the
native hashing figure. The SHA-256 micro-benchmark's tool and the manual `docker push` commands
were not kept; the 1,152 MiB figure comes from an internal test. No raw output of those runs was
kept; each figure is printed with its dated record of conditions.

### Push and pull of 5 × 1 GiB against CNCF Distribution, 12 November 2026

On an `arm-16` test host (16 Ampere Altra cores, 32 GB) shared with other work, with SeaweedFS as
the S3 store for both registries. Ours: the production build behind Caddy. Reference: CNCF
`registry:3` (Go) with its S3 driver, 16 MiB chunks, no proxy. Five 1 GiB incompressible layers
pushed in parallel, each as one streaming `PATCH`, then pulled in parallel and hashed on the
client; nothing touches disk. The same can be done with `crane` or any client that issues
`POST /v2/<repo>/blobs/uploads/`, one `PATCH`, `PUT ?digest=`, and parallel
`GET /v2/<repo>/blobs/<digest>`. Memory and CPU from `docker stats`. (Raw output not kept.)

| Registry                      | Push 5.37 GB     | Pull 5.37 GB     | Peak RSS |
| ----------------------------- | ---------------- | ---------------- | -------- |
| Deutsche Cloud, hash-wasm, run 1 | 49.8 s, 108 MB/s | 20.5 s, 262 MB/s | 365 MB   |
| Deutsche Cloud, hash-wasm, run 2 | 48.4 s, 111 MB/s | 23.2 s, 231 MB/s | 537 MB   |
| CNCF `registry:3`             | 21.8 s, 246 MB/s | 13.7 s, 391 MB/s | 220 MB   |

Keeping two store parts in flight per upload changed nothing (111 vs 108 MB/s) and was not
shipped. A SHA-256 micro-benchmark on the same host gave 243 MiB/s for hash-wasm and 1,770 MiB/s
for `node:crypto`; `openssl speed -evp sha256` gives the native figure on any machine.

### Native hashing, same day, same method

| Where                                                | Build     | Push 5.37 GB     | Pull 5.37 GB     |
| ---------------------------------------------------- | --------- | ---------------- | ---------------- |
| lab, one replica, SeaweedFS                          | hash-wasm | 46.8 s, 115 MB/s | 19.0 s, 283 MB/s |
| lab, one replica, SeaweedFS                          | native    | 23.7 s, 226 MB/s | 18.5 s, 290 MB/s |
| test installation, two replicas, zone store over TLS | hash-wasm | 44.6 s, 120 MB/s | 36.7 s, 146 MB/s |
| test installation, two replicas, zone store over TLS | native    | 33.5 s, 160 MB/s | 22.9 s, 234 MB/s |

Push doubled in the lab and sits within 8 % of the Go reference; in the test installation the
object store across the network is now the limit, with both replicas near 190 % CPU. Pull was not
re-measured against the reference after this change. The lab record does not restate the machine.
(Raw output not kept.)

### What a real `docker push` costs in memory, 26 October 2026

On a developer laptop (the machine was not recorded), one 3.3 GB layer of random bytes pushed from
`docker:dind` through Caddy to a web container with a 1 GB memory limit, against our own Postgres
and SeaweedFS: 121 s, container memory 124 to 199 MiB
at peak, no out-of-memory kill. An automated test pushes 1,152 MiB and asserts the resident-memory
growth stays under 256 MiB; it measured 6.4 MiB. (Raw output not kept.)

## Known limits

- Blob throughput per replica is one core's worth, about 250 MB/s in the lab, flat from one client
  to eight; CNCF Distribution and Zot reach 2.1 to 2.9 GB/s with eight (21 November 2026).
- A pull-through cache serves a layer only once it has stored and verified all of it.
- A single request body is capped at 10 GiB at the edge. The upload design allows a blob of 160
  GiB (16 MiB × 10,000 parts), but a client that sends a layer as one `PATCH`, as Docker does,
  cannot push a layer above 10 GiB.
- An upload session expires after 24 h; a replica keeps at most 10,000 in-flight hashes and 64 MiB
  of parked short-part bytes for 10 minutes.
- A session that crosses replicas is finalised by re-reading the blob, which is slower; a chunked
  client that carried a short part across replicas gets `416`.
- A chunked client that dies while overwriting its short part fails the push; it never stores
  wrong bytes.
- Store throttling that lasts beyond about 20 s surfaces as `503` with `Retry-After: 10`.
- Manifests are capped at 4 MiB, the same as the reference implementation; bearer tokens last 1 h.
- Only `sha256` digests; one region, no replication; the rest is in
  [Not supported](not-supported.md).
- The blob store is a third-party object store whose outages surface as registry failures; the
  mitigations are retries, resuming ranged GETs and digest-pinned deploys. Moving registry blobs
  onto our own storage cluster is not built.

## Related

- [What runs on your machines](what-runs-on-your-machines.md)
- [Storage and cleanup](storage-and-cleanup.md)
- [Quotas](quotas.md)
- [Security in Container registry](security.md)
