# Building a Serverless Docker Registry on Cloudflare Workers, Containers, and R2

> How we bisected Harbor into a scale-to-zero OCI registry on Cloudflare Workers, Durable Objects, Containers, and R2 — with $0 egress and 64 GB layers.

Published: 2026-11-30
Author: Max
Tags: docker, oci, harbor, cloudflare, r2, serverless, architecture

## Why build a serverless OCI registry?

Every engineering team hits the same container registry wall eventually. Either you pay hyperscaler egress taxes ($0.09–$0.12/GB every time a CI runner, bare-metal build node, or cross-cloud Kubernetes cluster pulls a layer), or you self-host [Harbor](https://goharbor.io/) and inherit an 11-container stateful Kubernetes footprint — PostgreSQL, Redis, Nginx, Portal, Core, Registry, RegistryCtl, Jobservice, Trivy, Notary, and log collectors — that burns compute 24/7 even when nobody is pushing an image.

We built **Trylle Container Yard** (`docker.direct`) to get out of that trade-off. We wanted Harbor's full enterprise surface — projects, RBAC, robot accounts, OIDC trusted publishing, quotas, garbage collection, and per-repository visibility inside private organizations — running **scale-to-zero on Cloudflare Workers, Durable Objects, Workers KV, Cloudflare Containers, PlanetScale PostgreSQL, and Cloudflare R2**, with **$0.00/TB egress** and support for **multi-dozen-gigabyte single layers** (VM snapshots, AI model weights, and dense CI runner rootfs images).

Getting there was not a lift-and-shift deploy. It required bisecting Harbor's 11 services down to a single stateless control container, replacing Redis with consistency-split edge primitives, and — after our stress tests exposed both a subtle streaming bug and a hidden `$25/TB` container egress trap — moving the entire OCI blob upload data plane out of containers and straight into Cloudflare Workers.

---

## How images flow through the serverless architecture

Before walking through each component, here is the complete lifecycle of a `docker push` and `docker pull` inside Trylle Container Yard (`v3.1+`). The key architectural invariant is **strict separation between control plane and data plane**: containers handle RBAC, quotas, tokens, and PostgreSQL metadata, while **zero layer bytes ever traverse a container** on either push or pull.

<figure>
  <img src="/blog/serverless-docker-registry/image-lifecycle-animated.svg" alt="Animated diagram of push and pull data flows through Cloudflare Edge Workers, R2, HarborState Durable Object, HarborContainer pool, and PlanetScale PostgreSQL" />
  <figcaption>Figure 1 — Animated OCI image lifecycle in Trylle Container Yard. On push, the Edge Worker streams 64 MiB chunks directly to an R2 multipart upload via FixedLengthStream while checkpointing resumable SHA-256 state in HarborState DO. On pull, HarborContainer presigns an HTTP 307 redirect so clients pull layers directly from Cloudflare R2 at line rate ($0/TB egress).</figcaption>
</figure>

### Push path (`docker push`)

1. **Session init & RBAC (`POST /v2/<repo>/blobs/uploads/`):** The Edge Worker forwards the empty `POST` to one of 8 warm `HarborContainer` slots (`harbor-enam-0..7`). Harbor Core enforces project membership, robot scopes, and storage quotas, then delegates to local `distribution` which returns `HTTP 202` with a `Docker-Upload-UUID`.
2. **Edge takeover (`maybeInitDirectR2Upload`):** On the `202` response, the Edge Worker intercepts the UUID, opens a native Cloudflare R2 multipart upload (`env.HARBOR_R2.createMultipartUpload`), and persists an initial `R2UploadSession` (offset `0`, empty parts array, and initialized FIPS 180-4 SHA-256 state) in the strongly consistent `HarborState` SQLite Durable Object.
3. **Direct edge streaming (`PATCH /v2/<repo>/blobs/uploads/<uuid>`):** Every subsequent `PATCH` chunk bypasses `HarborContainer` completely. The Worker verifies the RS256 Bearer JWT locally using `node:crypto` against the Harbor token public key, validates `Content-Range`, and pumps the request body through a `FixedLengthStream(64 MiB)` directly into `mp.uploadPart()` while updating our resumable SHA-256 hasher. Peak Worker memory stays **under 1 MiB**, regardless of whether the layer is 50 MB or 64 GB.
4. **Idempotent commit (`PUT /v2/<repo>/blobs/uploads/<uuid>?digest=sha256:...`):** Once all bytes arrive, the Worker verifies the final SHA-256 digest against the requested `digest`, completes the R2 multipart upload, executes a parallel server-side R2 `UploadPartCopy` into the content-addressable path `docker/registry/v2/blobs/sha256/<xx>/<hex>/data`, writes the repository `_layers` link, and sends a ~120-byte JSON call to `POST /api/internal/blobs/register` on `HarborContainer` so Harbor's PostgreSQL `blob` and `project_blob` tables stay 100% consistent.
5. **Manifest persistence (`PUT /v2/<repo>/manifests/<ref>`):** Small JSON manifests (~4–64 KiB) go through `HarborContainer`, which verifies all referenced blobs exist, updates artifact metadata and quotas in PlanetScale PostgreSQL, and commits the manifest to R2.

### Pull path (`docker pull`)

1. **Edge cache fast-path:** Unauthenticated `GET /v2/<repo>/manifests/sha256:<digest>` requests for public immutable digests are served straight from Cloudflare's `caches.default` (`Cache-Control: public, max-age=86400, immutable`) without waking a container.
2. **Presigned redirect (`GET /v2/<repo>/blobs/sha256:<hex>`):** Authenticated or tag-based requests route to `HarborContainer`, where `distribution v3.0.0` returns an `HTTP 307` redirect to a short-lived presigned Cloudflare R2 URL (median ~159 ms end-to-end).
3. **Line-rate object storage download:** The OCI client follows the `307` and pulls every layer in parallel straight from Cloudflare R2's global edge network. Neither the Edge Worker nor `HarborContainer` touches a single byte of the blob download, keeping egress cost at **$0.00/TB**.

---

## Bisecting Harbor: 11 stateful containers to 1 serverless control plane

Upstream Harbor assumes a long-lived cluster with local networking between 11 containers. To run Harbor cleanly inside Cloudflare Workers + Containers — where instances scale to zero after 10 minutes of inactivity and every network hop has real latency and billing implications — we bisected Harbor component by component.

<figure>
  <img src="/blog/serverless-docker-registry/architecture-overview.svg" alt="Architecture diagram mapping upstream Harbor's 11 stateful containers to Trylle Container Yard's serverless Cloudflare Workers, Durable Objects, KV, unified Container pool, R2, and PlanetScale Postgres topology" />
  <figcaption>Figure 2 — Component-by-component bisection of upstream Harbor into Trylle Container Yard's serverless topology.</figcaption>
</figure>

| Upstream Harbor Component | What it did | Trylle Container Yard Replacement | Why |
|---|---|---|---|
| `harbor-portal` | Angular UI served by Nginx | **Workers Static Assets (`env.ASSETS`)** + Global CDN | Zero container compute for UI or Swagger docs (`/devcenter-api-2.0`). |
| `nginx` | TLS termination, reverse proxy, path rewrites | **Cloudflare Edge Worker (`index.ts`)** | Global Anycast TLS, edge auth rate-limiting, `/api/v2.0/bots` alias, cold-slot failover, and Direct R2 uploads. |
| `harbor-core` + `registry` (`distribution v3`) + `harbor-registryctl` | 3 separate pods talking over cluster DNS | **1 unified `standard-4` Cloudflare Container** (pool of 8, 10m idle scale-to-zero) | `entrypoint.sh` supervises `harbor_core :8080`, `distribution :5000`, and `registryctl :8081` over `127.0.0.1` — zero inter-pod RTT. |
| `redis` | Sessions, OIDC PKCE state, upload tracking, metadata cache, connection limits | **Split across `HarborState` SQLite DO + Workers KV** via `interceptOutboundHttp` | Strong consistency where required (auth/sessions/uploads); async non-blocking cache writes elsewhere. |
| `harbor-db` (PostgreSQL) | Projects, repos, artifacts, blobs, quotas, audit logs | **PlanetScale PostgreSQL** via PgBouncer (`:6432`, `simple_protocol=true`) | Serverless-friendly transaction pooling; capped at `16` max open connections per container slot. |
| `harbor-jobservice` | Persistent Redis worker pool for GC, replication, scans | **Disabled (`HARBOR_DISABLE_JOBSERVICE=true`)** + Cloudflare Cron (`0 4 * * *`) | Daily cron wakes a dedicated `harbor-gc` container and calls `POST /api/internal/gc` against PlanetScale & R2. |
| `trivy`, `notary`, `harbor-log` | Sidecar scanners, legacy signing, syslog forwarder | **Removed from hot path; native OTLP to SigNoz** | Keeps cold-start footprint lean and exports distributed traces from both `harbor_core` and `distribution` at `TRACE_SAMPLE_RATE=0.1`. |

### Replacing Redis without rewriting Harbor: `interceptOutboundHttp`

Harbor expects Redis for three completely different workloads: Beego UI/OIDC sessions, short-lived registry/upload coordination state, and a read-heavy repository/artifact cache layer. Instead of paying for an always-on managed Redis cluster or tearing out Harbor's internal cache abstractions, we added two lightweight URL schemes (`cfdo://` and `cfkv://`) backed by Cloudflare Containers' **`container.interceptOutboundHttp`** hook:

```ts
await container.interceptOutboundHttp("harbor.state", this.ctx.exports.HarborStateGateway);
await container.interceptOutboundHttp("harbor.cache", this.ctx.exports.HarborCacheGateway);
```

Inside the container, `entrypoint.sh` simply points Harbor's standard environment variables at those virtual hosts:

```bash
export _REDIS_URL_CORE="cfdo://harbor.state/session"
export _REDIS_URL_HARBOR="cfdo://harbor.state/state"
export _REDIS_URL_CACHE_LAYER="cfkv://harbor.cache/layer"
```

- **`HarborState` (SQLite Durable Object, ENAM):** Stores sessions, OIDC PKCE verifiers, direct-R2 upload checkpoints, connection limits, and auth rate-limit windows in embedded SQLite (`kv_items`, `conn_limits`, `rate_limits`) with a self-scheduling 5-minute `alarm()` to purge expired rows. Strongly consistent, zero cold-connection overhead.
- **`HarborCacheGateway` (Workers KV):** Serves Harbor's read-heavy metadata cache. Critically, `PUT` and `DELETE` calls flush to KV inside `ctx.waitUntil(...)` after invalidating the container-local L1 cache synchronously — preventing multi-key invalidations during `PUT /manifests/` from stalling for ~400–600 ms waiting on global KV propagation.

### Pool affinity and cold-slot failover

A single Cloudflare Container instance runs `standard-4` (4 vCPU, 12 GiB RAM, 20 GB disk), and we pool `HARBOR_POOL_SIZE=8` slots (`harbor-enam-0..7`, `max_instances=10`). Browser sessions stick by `sid` cookie and legacy upload sessions stick by upload UUID to avoid unnecessary cold starts.

During deploys or container recycling, a single slot can briefly return `HTTP 503` while booting (~2–4 seconds). In `v3.1.1`, `fetchContainerPool()` automatically detects `503` or connection errors on idempotent/bodyless requests (`GET`, `HEAD`, `DELETE`, and empty `POST /blobs/uploads/`) and fails over to `(slot + 1) % poolSize` across up to 3 warm slots — turning container restarts into zero-error events for clients.

---

## Inside the upload data plane: why we bypassed container streaming

Our initial `v3.0` deployment worked on small images, so we threw a brutal multi-terabyte stress suite at it: 64 GB single layers and 128 × 1 GB layers across three regions. Two serious issues surfaced immediately — neither of which would ever appear in a 50 MB smoke test.

<figure>
  <img src="/blog/serverless-docker-registry/upload-dataplane-evolution.svg" alt="Diagram comparing v3.0 container-proxied uploads (port.fetch block-reordering corruption and $25/TB container txBytes billing) against v3.1+ Direct Edge Worker to R2 uploads (0% corruption, $0/TB egress, 640 GiB max layer)" />
  <figcaption>Figure 3 — Moving PATCH/PUT blob ingestion from HarborContainer into the Edge Worker eliminated both port.fetch() stream block-reordering and $0.025/GB container egress billing.</figcaption>
</figure>

### Finding #1: A 40 KiB block-reordering bug inside `port.fetch()`

Under multi-gigabyte uploads, ~10–15% of layers failed at commit with `HTTP 400 DIGEST_INVALID`, even though every single `PATCH` returned `HTTP 202` and the total byte count matched to the exact byte.

We wrote a forensic byte-diff probe that pushed a deterministic 1 GiB pattern and downloaded the staged R2 object back to diff it byte-for-byte. Every corrupted upload showed the exact same signature: **zero bytes lost, zero bytes added, and a single 40 KiB window where an 8 KiB block had been reordered ahead of the preceding 32 KiB block** (`got_offset - want_offset = +32768`). Both `distribution`'s internal SHA-256 hashstate and the final R2 object agreed bit-for-bit on the swapped digest, proving the corruption occurred in Cloudflare Containers' `port.fetch()` TCP proxy *before* bytes reached `distribution`.

### Finding #2: The `$25/TB` container `txBytes` billing trap

When we audited our Cloudflare GraphQL billing telemetry after ingesting ~506 GB during production migration, we found `341.39 GB` logged under `containersUsageAdaptiveGroups.txBytes`. Because Cloudflare Containers bills outbound container traffic at **`$0.025/GB` (`$25/TB`)** in North America/Europe above the 1 TB monthly allowance, every gigabyte uploaded from `distribution` inside the container to R2 was quietly accruing container egress charges — even though R2 itself has zero egress fees.

### The `v3.1` fix: Direct Edge Worker → R2 streaming

Moving `PATCH`/`PUT`/`GET`/`DELETE /v2/<repo>/blobs/uploads/<uuid>` into `r2-upload.ts` solved both problems permanently:

1. **Zero-copy 64 MiB multipart streaming (`FixedLengthStream`):** Cloudflare R2 requires all non-trailing multipart parts to have identical sizes (up to 10,000 parts per object). By setting `R2_PART_SIZE = 64 MiB` and piping incoming `PATCH` streams through `new FixedLengthStream(64 MiB)` directly into `mp.uploadPart()`, the Worker never buffers a chunk in heap (`<1 MiB` RAM) and supports **up to 640 GiB per individual layer**. Sub-64 MiB tails spill cleanly into a temporary `r2tail` object and merge seamlessly on the next `PATCH` or final `PUT`.
2. **Resumable FIPS 180-4 SHA-256 (`sha256.ts`):** WebCrypto's `crypto.subtle.digest` cannot suspend and serialize mid-stream across separate HTTP `PATCH` invocations. We implemented a compact resumable SHA-256 engine whose 8×32-bit state vector, bit counter, and `<64`-byte remainder serialize to ~180 bytes of JSON in `HarborState` DO between chunks.
3. **Adaptive parallel server-side R2 copy (`s3-copy.ts`):** Because OCI blobs are staged under `_uploads/<uuid>/r2data` and only move to `blobs/sha256/<xx>/<hex>/data` once the digest is verified, single-threaded R2 `CopyObject` runs at ~48 MB/s (~21 seconds for 1 GB, and >20 minutes for 64 GB — guaranteed to hit Cloudflare's 100-second `524` gateway timeout). Our AWS SigV4 helper runs parallel `UploadPartCopy` directly inside R2 with size-adaptive parameters:
   - `<= 128 MiB`: single `CopyObject`
   - `128 MiB – 2 GiB`: `64 MiB` chunks × `12` parallel workers (~6–15s for 1 GB)
   - `2 GiB – 8 GiB`: `512 MiB` chunks × `16` parallel workers
   - `> 8 GiB` (e.g., 64 GB layers): `1 GiB` chunks × `24` parallel workers (`60` parts → ~3 waves, committing 64 GB safely under the 100-second edge timeout)
4. **100% idempotent `PUT` commits, 64-way Go `r2copy`, and per-UUID regional upload DOs (`v3.1.1` → `v3.2.1`):**
   - **Idempotent commits (`v3.1.1`):** Early in our `128 × 1 GB` stress test, a transient R2 `10001` internal error hit during `PUT` commit on layer 121. In `v3.1.1`, `PUT` retains `r2tail` and `r2data` until PostgreSQL registration succeeds across multi-slot failover, caches a 15-minute `committedDigest` record, and uses a single-flight lock (`copyStartedAt`) so retries never race. On the very next stress run, a live R2 `10001` error recovered automatically on attempt 2 with 0 failed layers.
   - **Bypassing Workers' 6-socket limit for mega-layers (`v3.2.0`):** Cloudflare Workers caps concurrent outbound `fetch()` sockets at 6 per invocation, which pushed a `64 GB` R2 `UploadPartCopy` to ~110–130s (just past Cloudflare's 100s edge timeout). In `v3.2.0`, blobs `>2 GiB` delegate *only* the server-side `UploadPartCopy` metadata calls (~30 KiB of S3 headers, **$0.00 data-plane egress**) to `POST /api/internal/blobs/r2copy` inside `harbor_core`, which fans out **64 concurrent Go goroutines** (`256 MiB` chunks) and commits 64 GB layers in **50.9–71.1 seconds** on Attempt 1.
   - **Per-UUID regional upload DOs + R2 Local Uploads (`v3.2.1`):** Sharding upload sessions into `r2upload:<uuid>` Durable Objects with no `locationHint` keeps upload coordination local to the uploader's region and eliminates single-DO serialization across concurrent streams — cutting `64 MiB` `PATCH` median latency by **24–44%** across both NYC and Frankfurt.

---

## Per-repository visibility and OIDC trusted publishing

Two operational capabilities mattered deeply for Trylle's own infrastructure:

- **Public repositories inside private organizations:** Upstream Harbor ties pull visibility strictly to the project level — either the whole org/project is public or every image in it is private. That breaks a common pattern where an engineering org keeps internal app builds private while exposing a handful of base images or VM snapshot images (`ci-runner-boxd-ubuntu-*`, `magic-sessions-boxd`) for anonymous pull by ephemeral cloud VMs. We extended Harbor Core + the Trylle Dashboard with per-repository public-pull overrides so teams can flip individual repositories public without exposing the parent project.
- **OIDC trusted publishing:** CI workflows never store static registry passwords. Trylle CI issues short-lived OIDC JWTs exchanged directly at `docker.direct` for repo-scoped Harbor robot credentials, eliminating long-lived secrets from build pipelines.

---

## Are we CNCF / OCI conformant? (And how to get officially graded)

This is worth answering plainly, because "CNCF compatible" gets tossed around loosely in container marketing.

First, a quick taxonomy distinction: **Harbor** is a **CNCF Graduated project**, and `distribution/distribution` (the Go registry engine inside our container) is a **CNCF project**. However, the wire-protocol compliance standard for container registries is formally governed by the **Open Container Initiative (OCI)** — a Linux Foundation project alongside CNCF — under the **[OCI Distribution Specification](https://github.com/opencontainers/distribution-spec)**.

### Where Trylle Container Yard stands today

- **Pull, Content Discovery (tag listing, referrers), and Content Management (manifest/blob deletes):** Served directly by upstream **CNCF `distribution` v3.0.0** + **Harbor Core**, which are already OCI Distribution v1.1 conformant.
- **Push (blob upload sessions):** Handled at the edge by `r2-upload.ts`, which implements the OCI Distribution v1.1 chunked and monolithic blob upload protocol (`202` + `Location` + `Range` + `Docker-Upload-UUID` + `OCI-Chunk-Min/Max-Length`, `416` on out-of-order `Content-Range`, `400 DIGEST_INVALID` on digest mismatch, `204` on `GET` status and `DELETE` abort, `201` + `Docker-Content-Digest` on `PUT`), while automatically delegating cross-repo blob mounts (`?mount=...&from=...`) and single-request uploads (`?digest=...`) back to `distribution`.
- **Certification status:** Trylle Container Yard is **wire-compatible with OCI Distribution v1.1 in production today**, but it is **not yet officially listed** on [conformance.opencontainers.org](https://conformance.opencontainers.org/) until we publish formal test artifacts from our live `v3.1+` edge upload path.

### How to earn official OCI Conformance certification

Official certification is open, transparent, and artifact-driven — there is no opaque paywall, only passing tests and public review by the OCI Conformance Working Group:

1. **Build the official conformance binary** from `opencontainers/distribution-spec`:
   ```bash
   git clone https://github.com/opencontainers/distribution-spec.git
   cd distribution-spec
   go test -c ./conformance
   ```
2. **Run all four mandatory OCI workflow suites** against a dedicated test namespace on the live production endpoint:
   ```bash
   export OCI_ROOT_URL="https://docker.direct"
   export OCI_NAMESPACE="ocitest/conformance"
   export OCI_USERNAME="<robot-user>"
   export OCI_PASSWORD="<robot-token>"
   export OCI_TEST_PULL=1
   export OCI_TEST_PUSH=1
   export OCI_TEST_CONTENT_DISCOVERY=1
   export OCI_TEST_CONTENT_MANAGEMENT=1
   ./conformance.test
   ```
3. **Verify 100% pass across all mandatory assertions** and archive the generated HTML/JSON conformance report (`report.html` / `junit.xml`).
4. **Fork [`opencontainers/oci-conformance`](https://github.com/opencontainers/oci-conformance)**, complete the OCI Participation / Certification form (organization, product name, version `v3.1.x`, specification version), and commit your test logs in the repository's required directory layout.
5. **Open a Pull Request** to `opencontainers/oci-conformance`. Once the OCI Conformance Working Group validates the test artifacts and merges the PR, the registry is officially listed as an **OCI-Conformant Distribution Implementation** on `conformance.opencontainers.org`.

We plan to wire `conformance.test` directly into our release pipeline so every `trylle-harbor` Worker tag is verified against the official OCI Distribution Spec suite before deployment, and then submit our `v3.1.x` certification PR.

---

## Performance & stress-test benchmarks

We put `docker.direct` through a multi-region, multi-terabyte torture suite across three hosts — `trylle-us` (Virginia, 32 vCPU), `bench-nyc` (NYC, 16 vCPU `boxd`), and `bench-fra` (Frankfurt, 16 vCPU `boxd`) — followed by a head-to-head comparison against Docker Hub (`registry-1.docker.io`), a **101-VM extreme pull-concurrency burn**, and a controlled **R2 Local Uploads + Regional DO A/B experiment**. Over 3 days, **`22.33 TB`** (`10.79 TB` upload + `11.53 TB` download) flowed through R2.

### Test methodology

To eliminate synthetic caching and local disk bottlenecks, our Go streaming OCI harness generates unique, uncompressible GNU-tar layers on the fly using `xoshiro256**` (unique per cycle → zero deduplication), uploads them over standard OCI v2 chunked `64 MiB` `PATCH`/`PUT` streams, pulls every layer back in parallel while computing full SHA-256 verification on every byte, and deletes the manifest via OCI `DELETE`.

### 30-cycle stress test on `docker.direct` (`15 × 128×1GB` + `15 × 2×64GB` = 7.68 TB)

All **30 / 30 baseline cycles** completed with **0 errors** and **1,950 / 1,950 layers SHA-256 verified bit-for-bit**:

| Stage | Runner (Region) | Cycles OK | Avg / Peak Push (MB/s) | `PUT` Commit p50 | Avg / Peak Pull (MB/s) | Peak Pull (Gbps) | SHA-256 Verified | Errors |
|---|---|---:|---:|---:|---:|---:|---:|---:|
| **`128 × 1 GB`** | `bench-nyc` (`nyc`) | **5 / 5** | `141.7` / **162.5** | `14.5 s` | **1,029.5** / **1,075.6** | **8.60 Gbps** | **640 / 640** | **0** |
| **`128 × 1 GB`** | `trylle-us` (`us-va`) | **5 / 5** | `135.8` / **146.4** | `16.0 s` | **931.8** / **1,052.5** | **8.42 Gbps** | **640 / 640** | **0** |
| **`128 × 1 GB`** | `bench-fra` (`fra`) | **5 / 5** | `103.6` / **111.5** | `21.5 s` | **763.0** / **823.4** | **6.59 Gbps** | **640 / 640** | **0** |
| **`2 × 64 GB`** | `bench-nyc` (`nyc`) | **5 / 5** | `28.7` / **34.8** | `69.5 s` | `166.9` / **239.2** | **1.91 Gbps** | **10 / 10** | **0** |
| **`2 × 64 GB`** | `trylle-us` (`us-va`) | **5 / 5** | `23.8` / **27.4** | `56.9 s` | `181.8` / **237.0** | **1.90 Gbps** | **10 / 10** | **0** |
| **`2 × 64 GB`** | `bench-fra` (`fra`) | **5 / 5** | `23.3` / **35.0** | `71.1 s` | `116.1` / **144.0** | **1.15 Gbps** | **10 / 10** | **0** |

During Stage 2 Cycle 2, `bench-nyc` (`8.60 Gbps`) and `trylle-us` (`8.42 Gbps`) pulled simultaneously at **17.02 Gbps combined** straight off R2 presigned URLs.

### Head-to-head vs. Docker Hub (`128 × 1 GB` and `12 × 10 GB` max-layer cap)

Because Docker Hub caps single layers at **10 GB** (vs. our **640 GiB** ceiling / 64 GB tested), we ran identical `128 × 1 GB` workloads alongside Docker Hub's max-layer `12 × 10 GB` (`120 GB`) across all three regions:

| Stage & Region | `docker.direct` Push | Docker Hub Push | `docker.direct` Pull | Docker Hub Pull | Takeaway |
|---|---:|---:|---:|---:|---|
| **`128 × 1 GB` — NYC** | `141.7 MB/s` (`147.6` `v3.2.1`) | **582.7 MB/s** | **1,029.5 MB/s** | `947.3 MB/s` | **`docker.direct` +8.7% faster pulls** |
| **`128 × 1 GB` — US-VA** | `135.8 MB/s` | **340.4 MB/s** | `931.8 MB/s` | **1,160.5 MB/s** | Docker Hub leads Ashburn S3 ingest/pull |
| **`128 × 1 GB` — FRA (EU)** | `103.6 MB/s` | **148.4 MB/s** | **763.0 MB/s** (**1,043.8** Local ON) | `421.9 MB/s` | **`docker.direct` 1.81×–2.47× faster EU pulls** |
| **Mega-Layers (64 GB vs. 10 GB)** | `23.3–39.2 MB/s` *(64 GB)* | `60.8–212.4 MB/s` *(10 GB cap)* | `116–248 MB/s` *(2 streams)* | `120–301 MB/s` *(4 streams)* | **`docker.direct` supports 6.4× larger layers** |

### Extreme pull concurrency burn (`256 MB`, 10 layers — 10 VMs → 101 parallel VMs)

To find real-world pull ceilings and rate-limit cliffs, we scaled from 10 to **101 parallel `boxd` VMs (`50 nyc` + `51 fra`)** pulling an identical `256 MB` (10-layer) image concurrently against both registries:

| Scenario (101 Parallel VMs) | Active Concurrency | Pulls OK | Pulls Failed | Success Rate | Agg. Throughput | HTTP `429`s | First `429` |
|---|---:|---:|---:|---:|---:|---:|---|
| **`docker.direct` (`reuse`)** | **186** | **1,712** | **0** | **100.0%** | **44.46 Gbps** (`21.7 pulls/s`) | **0** | Never |
| **`docker.direct` (`reuse`, 4w)** | **360** | **1,998** | `14,904`* | — | **50.52 Gbps** (`24.7 pulls/s`) | `14,904`* | *Own `120/min` NAT-IP auth cap; **0 container/R2 errors*** |
| **Docker Hub (`fresh` PAT)** | **194** | `1,927` | **10,162** | **15.9%** | `53.02 Gbps` *(burst then walled)* | **12,934** | **`t = 0.74s`** (`RateLimit-Limit: 1500;w=60`) |
| **Docker Hub (`reuse` PAT)** | **188** | `1,969` | **8,989** | **18.0%** | `56.86 Gbps` *(burst then walled)* | **13,607** | **`t = 1.25s`** (`RateLimit-Limit: 1500;w=60`) |
| **Docker Hub (`anon`, 10 VMs)** | **40** | `382` | **2,064** | **15.6%** | `17.22 Gbps` *(burst then walled)* | **2,064** | **`t = 14.04s`** (`RateLimit-Limit: 100;w=3600`) |

Docker Hub hard-throttled authenticated PAT pulls at **`1,500 requests / 60 seconds`** (`25 req/s` across the entire fleet), failing **82–84%** of pulls within 1.25 seconds even with token reuse. Meanwhile, `docker.direct`'s container pool + R2 sustained **100% pull reliability at 44.46 Gbps** and peaked at **50.52 Gbps** with **zero container or R2 errors** (the only `429`s at 360 concurrent pulls came from our own configurable `AUTH_RATE_LIMIT_PER_MIN=120`/IP edge guard on shared regional NAT IPs — which we immediately fixed in **`v3.2.2`** by removing rate limits on authenticated `/service/token` identities and raising the unauthenticated per-IP limit to **`5,000/min`**).

### R2 Local Uploads + `v3.2.1` Per-UUID Regional DO A/B experiment

Enabling **R2 Local Uploads** alongside `v3.2.1`'s per-UUID regional upload DOs produced two clear engineering findings:

- **Per-UUID DO sharding (`v3.2.1`) is an unconditional win (kept ON in production):** Eliminating single `"global"` DO serialization cut `64 MiB` `PATCH` p50 latency by **-24% to -30%** even inside ENAM, pushing `bench-nyc` `2 × 64 GB` push throughput to an all-time high of **39.2 MB/s** (`54.4 min`, **+36.6%** faster) and pull to **248.5 MB/s (1.99 Gbps)**.
- **R2 Local Uploads trade-off for OCI staging (turned OFF in production):** From Frankfurt, Local Uploads slashed `PATCH` p50 by **-44.3%** (`6,696 ms → 3,729 ms`) and boosted immediate `128 × 1 GB` pulls by **+36.8%** to **1,043.8 MB/s (8.35 Gbps — matching NYC)**. However, when 16 × 1 GB layers finish quickly in Frankfurt and immediately trigger `UploadPartCopy` into ENAM, `commit_p50` jumped `2.5×` (`21.5s → 53.1s`) while WEUR→ENAM replication caught up. Because faster EU image submission matters more to us than immediate same-second EU re-pulls, we kept **per-UUID DO sharding ON** and turned **R2 Local Uploads OFF** on `docker-direct-next`.

### Verified Cloudflare billing delta (`v3.2+` proof)

On `2026-12-01` (pure `v3.2.0`/`v3.2.1`, spanning our final 64 GB cycles, 101-VM burn, and Local Uploads A/B):
- **R2 Bandwidth:** **`1,253.7 GB`** uploaded + **`2,778.6 GB`** downloaded = **`4.03 TB`** transferred at **`$0.00` egress**.
- **Cloudflare Workers:** `87,620` invocations with **`0` errors**.
- **Cloudflare Containers `txBytes`:** **`0.146 GB` (`0.0036%` of 4.03 TB = `$0.0036`)**, empirically confirming our Direct Edge Worker → R2 upload engine eliminated the `$25/TB` container egress bill.
- Across the full 3-day migration + stress test (**`22.33 TB`** total R2 I/O), R2 Class A (`321k`), Class B (`159k`), DO (`299k`), and KV (`104k`) all stayed **100% inside Workers Paid free allowances (`$0.00`)**.

---

## Limits and cost comparison: Trylle Container Yard vs. cloud registries

Below is a direct comparison of hard technical limits, pull quotas, egress costs, and storage pricing across **Trylle Container Yard (`docker.direct`)**, **GitHub Container Registry (GHCR)**, **AWS ECR**, **Google Artifact Registry** (the successor to GCR), and **Cloudflare's managed container registry (`registry.cloudflare.com`)**.

| Dimension | Trylle Container Yard (`docker.direct`) | GitHub Container Registry (GHCR) | AWS ECR | Google Artifact Registry (GCR) | Cloudflare Managed Registry (`registry.cloudflare.com`) |
|---|---|---|---|---|---|
| **Max layers per image** | **No registry cap** *(4 MiB OCI manifest / 127 runtime overlayfs limit; tested live at **128 layers × 1 GB**)* | No hard registry cap *(4 MiB manifest / 127 runtime limit)* | **127 layers** *(4 MiB manifest; ECS/EKS runtime bound)* | No hard registry cap *(4 MiB manifest / 127 runtime limit)* | Container-instance bound *(internal CF Containers deployment registry only)* |
| **Max size per layer** | **640 GiB** *(10,000 × 64 MiB R2 MPU parts via Edge Worker; tested live at **64 GB/layer**)* | **10 GB** hard cap *(+ 10-minute upload timeout)* | **200 GB** via `docker push` *(50 GB via `UploadLayerPart` API)* | Up to **5 TB** *(monolithic uploads only — **no chunked `PATCH`**; 60-min OAuth token expiry)* | **≤ 20 GB** *(bounded by max `standard-4` disk; Worker request limits on non-chunked hops)* |
| **Max total image size** | **Practically unlimited** *(multi-TB; 640 GiB × layers on R2)* | No hard total cap *(constrained by 10 GB/layer + 10-min timeout)* | No hard total cap *(200 GB/layer × 127 layers; 100k images/repo)* | **5 TB** per image/artifact | **20 GB** max image *(**50 GB total account storage cap**)* |
| **Pull rate limits (sec / min / hr)** | **Unlimited authenticated `/service/token` & blob pulls** (`5,000/min/IP` unauthenticated auth limit in `v3.2.2`); verified live at **50.52 Gbps** across 101 parallel VMs | **No published pull-rate limit** for public or authenticated private pulls *(subject to abuse limits)* | **`BatchGetImage`: 2,000 req/s** (`120k/min`); **`GetDownloadUrlForLayer`: 3,000 req/s** (`180k/min`); **`GetAuthorizationToken`: 500 req/s** *(soft quotas)* | **60,000 total req/min** (`1,000 req/s`) per project/region; `18,000` writes/min (`HTTP 429` above quota) | Internal Cloudflare Containers scheduling only *(not a general external pull registry; account API 1,200 req/5 min)* |
| **Price of egress** | **$0.00 / GB** *(global R2 presigned 307 pulls & direct Worker uploads — free to any cloud, CI, or bare metal)* | **$0.00 / GB currently** *(exempt from GitHub Packages' `$0.50/GB` rate with 30-day notice guarantee; free inside GitHub Actions)* | **$0.00** same-region AWS; **~$0.09 / GB** Internet (first 10 TB) & cross-region | **$0.00** same-region GCP; **$0.12 / GB** Internet (0–1 TB), **$0.11 / GB** (1–10 TB), **$0.08 / GB** (10 TB+); $0.01–$0.15/GiB inter-region | **$0.00** for internal CF Container image boot *(container runtime egress: `$0.025/GB` NA/EU above 1 TB; `$0.05/GB` APAC)* |
| **Storage price (per GB / month)** | **$0.015 / GB-mo** underlying R2 *(first 10 GB free + `$5/mo` Workers Paid base + minimal scale-to-zero control compute)* | **$0.00 / GB-mo currently** *(standard GitHub Packages overage rate if enforced later: `$0.25 / GB-mo`)* | **$0.10 / GB-mo** Standard *(`$0.04 / GB-mo` Archive w/ 90-day min + `$0.03/GB` restore)* | **$0.10 / GiB-mo** *(first 0.5 GiB free per billing account)* | Included in **$5/mo** Workers Paid up to **50 GB account cap** *(cannot scale beyond 50 GB)* |

### Real-world monthly bill: 1 TB stored + 20 TB/month external CI & multi-cloud pulls

To make those unit prices concrete, consider an engineering organization storing **1 TB** of container images and pulling **20 TB/month** across external CI runners, bare-metal clusters, developer laptops, and multi-region compute:

| Registry | Storage (1 TB) | Egress (20 TB external) | Control Plane / Base | Estimated Monthly Total |
|---|---:|---:|---:|---:|
| **Trylle Container Yard (underlying CF cost)** | **$14.85** *(R2)* | **$0.00** | ~$10–$30 *(Workers Paid + scale-to-zero DO/Containers)* | **~$25 – $45 / mo** |
| **AWS ECR** | $100.00 | ~$1,750.00 *(tiered ~$0.09/$0.085)* | $0.00 | **~$1,850 / mo** |
| **Google Artifact Registry** | $100.00 | ~$1,920.00 *(tiered $0.12/$0.11/$0.08)* | $0.00 | **~$2,020 / mo** |
| **GHCR** | $0.00 *(currently exempt)* | $0.00 *(currently exempt)* | $0.00 | **$0 / mo today** *(10 GB layer cap; `$10,250/mo` if standard Packages rates activate)* |
| **Cloudflare Managed (`registry.cloudflare.com`)** | N/A *(50 GB account cap)* | N/A *(internal CF Containers only)* | $5.00 | **Not applicable** |

### Why Cloudflare's own `registry.cloudflare.com` wasn't enough

A natural question is why we didn't just use Cloudflare's managed registry directly. `registry.cloudflare.com` is purpose-built for scheduling Cloudflare Workers Containers — it is capped at **50 GB total storage per account**, limits images to **20 GB** (the largest `standard-4` container disk), and is not designed as a multi-tenant public/private OCI registry with projects, OIDC trusted publishing, robot accounts, per-repository public toggles, or external bare-metal/Kubernetes pull workflows. Building our serverless Harbor architecture *on top of* Cloudflare Workers, Durable Objects, Containers, and R2 removes those caps entirely while keeping the exact same zero-egress R2 economics.

---

## What's next

With 30/30 multi-region mega-layer stress cycles, head-to-head Docker Hub comparisons, a 101-VM pull burn at **50.52 Gbps**, our R2 Local Uploads + Regional DO A/B runs, and **`v3.2.2`** live in production (unlimited authenticated `/service/token` pulls + `5,000/min/IP` unauthenticated edge limit), next on the roadmap is wiring `opencontainers/distribution-spec`'s official `conformance.test` suite into CI for every `trylle-harbor` release and submitting our `v3.2.x` certification PR to `opencontainers/oci-conformance`.

---

Canonical: https://blog.trylle.com/serverless-docker-registry-old
