Under the hood

How the Git service is built, why we dropped a Forgejo per organization for stock git over object storage and Postgres, what we measured and where the limits are.

Last updated 21 November 2026View as Markdown

The Git service is stock git running inside the control plane, with the repository's truth split in two: packfiles in object storage, refs in Postgres. Local disk is only a cache, and any node can rebuild a repository from packs and refs. Nothing is provisioned per organization or repository. The decision that matters most is where we drew the line: we did not reimplement the pack protocol, delta compression or reachability, which is exactly where a reimplementation silently corrupts repositories; we own everything above it.

What runs where

git push ──HTTPS──▶ Caddy (git host) ──▶ git serving replica (Rust)
git push ──SSH────▶ ssh container (ssh2)
                      │  either one runs
                      ▼
                    git receive-pack
                      │  pre-receive ──▶ policy callback
  1 auth (token or access key) + IAM git:PushRepository
    (404 if missing or forbidden)
  2 spool the request body to local disk, no lock held
  3 lock the repository (a lease row in Postgres)
    (60 s wait, then 503)
  4 hydrate: missing packs from object storage,
    refs from Postgres
  5 receive-pack (quarantine ─▶ pre-receive ─▶ move in)
  6 upload new pack + idx ─▶ object storage;
    replace refs in one transaction, NOTIFY
  7 answer the client; webhooks, CI, push mirrors,
    dependency scan queued

Packfiles with their indexes are immutable and self-checksummed, so they go to object storage under one platform bucket with a prefix per repository. Refs are mutable and small, so they live in a Postgres table, replaced as a whole in one transaction that also bumps a per-repository version and notifies every process holding that repository. LFS objects go to the same store under their own prefix, and so do the files git derives from a pack set (the commit-graph and the reachability bitmap), so each is computed once rather than on every server. Packs are uploaded and recorded before the refs are replaced, so a crash in between leaves an unreferenced pack, never a ref pointing at missing objects.

Over HTTPS there is one fixed host and the organization is the first path segment; Caddy sends each repository's requests to one git serving replica (a small Rust server, apart from the console), which runs git upload-pack or git receive-pack --stateless-rpc. Clone generation goes through a memory budget, a per-repository limit and a cache of identical packs, and a replica with no room answers 503 with Retry-After instead of running out of memory. Protocol v2 is negotiated through the Git-Protocol header, and partial clones (--filter) are allowed. Over SSH a separate container built on the ssh2 library accepts public keys only and exactly two commands, git-upload-pack and git-receive-pack. It checks the key and IAM, then hands a fetch to the same git serving replica as HTTPS, so clones over either protocol share one budget and one pack cache; a push over SSH runs git receive-pack in the ssh container itself. The host key is stored encrypted so every node presents one identity; it is RSA-4096 because ssh2 cannot parse a PKCS#8 ed25519 key. In TypeScript: routing, auth, IAM, branch protection, webhooks, pack storage, hydration, ref sync and maintenance. In Rust: admission, the clone memory budget, the pack cache and moving the bytes. In C: the pack protocol, delta search, compression and checks. The only bytes TypeScript touches on the hot path are an SSH fetch relayed between the encrypted channel and the git serving replica.

On the read side a process remembers each repository's refs version, live-pack set and directory inode (up to 500 repositories); if nothing changed, a read costs one indexed row, a pack list and one stat. Packs of 48 MiB and more are hydrated as eight parallel ranged GETs of 32 MiB. A commit-graph with changed-path Bloom filters is written in the background. Every 20 minutes a worker repacks a repository with 12 or more live packs (git repack -a -d --keep-unreachable) under the repository lock, uploads the new pack, marks the old ones superseded and deletes them an hour later. Git's own automatic maintenance is turned off: its detached maintenance run --auto once merged a just-received pack away before it was uploaded, so the objects existed on one replica only.

What we built, and what we did not

We dropped a Forgejo per organization. The first version ran one Forgejo virtual machine per organization with the control plane holding an admin token and bridging users lazily; it was removed on 24 August 2026. The reasons we recorded: Forgejo is lock-in and cannot speak Deutsche Cloud's permissions, actions or budgets. "Git the tool is already the open-source component. Forgejo is a product layer on top of it, and that product layer is the lock-in." GitLab draws the same line (Gitaly is an RPC service that shells out to git), and Gitea and Forgejo do too for much of their work. The precedent was Container registry, our own OCI server over the store and Postgres; git is harder on the protocol axis (stateful want/have negotiation, delta packfiles, reachability), hence the line above. Owning the service also meters storage per organization natively; Forgejo has no concept of usage records.

Stock git, not a reimplementation, not Rust. Every measured second and failure sits inside git's C (index-pack, pack-objects); Node's share is copying at about 2.5 ms of CPU per MB. A Rust transport would spawn the same git.

One platform bucket with a prefix per repository, not a bucket per repository. Buckets are a quota-limited resource at every S3 provider, and a bucket per repository would put a provisioning step and a credential on the create path.

Branch protection in a pre-receive hook that posts the ref updates back to the service, gated by a repository-scoped HMAC token with a 10-minute lifetime: the same approach as Gitea. Merges use git merge-tree --write-tree.

SSH in-process with ssh2, rather than a gitolite-style authorized_keys file with a forced command. Fronting it with OpenSSH sshd and AuthorizedKeysCommand, which would give post-quantum key exchange, is an open alternative, not done.

A refs-version column instead of fingerprinting refs on every read: counting and taking the maximum over 14,600 ref rows cost 2.8 ms per read; one indexed row costs almost nothing.

Benchmarks

How to rerun these. The Linux-sized repository and repository-page tables come with the commands that produced them. The multi-pack-index bitmap run, the cause timings under the page table and the ranged downloads were done by hand and their commands not kept; the aws s3api line is a stand-in. The concurrency runs used an internal tool, not published. The Forgejo comparison lists its client commands; the harness that serves our transport code and starts both servers is internal.

Each figure is printed with its dated record of conditions; raw output was kept only for the Forgejo comparison.

Against Forgejo, 21 November 2026

One Arm test host (16 Neoverse-N1 cores, 32 GB, shared with other jobs), client on the same host. Both servers in a container with the production web replica's limits: 2 CPUs, 1 GB, pack.threads 2. Deutsche Cloud's transport code with Postgres for refs and SeaweedFS for packs; Forgejo 14.0.5 with its repositories on local disk and the same Postgres. Repositories: expressjs/express (11 MB, 329 refs) and kubernetes/kubernetes (1.33 GiB pack, 1.85 million objects, 1,319 refs). Raw output kept.

git clone --bare https://github.com/kubernetes/kubernetes k8s.git
git -C k8s.git push https://git.example.com/my-org/k8s.git 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'
git clone --bare https://git.example.com/my-org/k8s.git             # full clone
git clone --depth 1 --branch master https://git.example.com/my-org/k8s.git
git push https://git.example.com/my-org/k8s.git <commit>:refs/heads/bench   # 30 in a row
Operation (median) Deutsche Cloud Forgejo
Push all of Kubernetes in one push 395 s, 501 MB 400 s, 375 MB
Full clone, Kubernetes 99 s, 740 MB 97 s, 628 MB
--depth 1 clone, Kubernetes 11.5 s 11.5 s
Full clone, express 0.89 s 0.83 s
Fetch with nothing new, express 0.08 s 0.06 s
Push one commit, express / Kubernetes 0.48 s / 0.74 s 0.80 s / 1.14 s
Pull request merge, express / Kubernetes 0.46 s / 0.44 s 0.97 s / 2.44 s
30 concurrent clones of express 10.4 s 9.7 s
4 concurrent full clones of Kubernetes 4 of 4, one after another, in 256 s 1 of 4 finishes
Clone with the repository on no replica 109 s (packs fetched from the store) —

Merges are faster because they are written in place in the cached repository rather than in a temporary clone; pushes, because no hook process runs per ref. Before the fixes of that day, the whole-history push of Kubernetes ran the web replica out of memory (the push check held the list of every pushed object in memory), and a push whose pack could not be stored was still reported as accepted to git. Four concurrent full clones of Kubernetes ran the replica out of memory and the kernel stopped the server process, so none finished; now git processes are the kernel's first choice when memory runs out, and full clones of large repositories wait for each other within a memory budget per replica.

A Linux-sized repository, 12 November 2026

One dedicated-8 machine (8 dedicated AMD vCPU, 32 GB, 240 GB local disk) with client and server on the same host, so loopback, no network. Production compose with Postgres, SeaweedFS standing in for the object store, and the web replica at its production limits of 2 CPUs, 1 GB and pack.threads 2. Repository: torvalds/linux, one 6.1 GB pack, 1,506,298 commits, 953 tags. Baseline: plain git upload-pack (git 2.54.1) over a pipe in a container with the same limits. (Raw output not kept.)

git clone --mirror https://github.com/torvalds/linux
git push origin v2.6.20:refs/heads/step1      # then later tags, then --tags
/usr/bin/time -v git clone https://git.example.com/my-org/linux.git
/usr/bin/time -v git clone --depth 1 https://git.example.com/my-org/linux.git
docker run --cpus 2 --memory 1g alpine/git clone --no-local file:///repo   # baseline (equivalent)
Test Result
Whole history in one push refused after 228 s: HTTP 413 at the 2 GiB cap
Push in 10 steps plus tags 11 pushes, 1,305 s in all, web CPU 1,136 s (index-pack)
Full clone, baseline, 2 CPU / 1 GB fails, pack-objects killed at 1 GB after 27 s
Full clone, baseline, 8 CPU / 24 GB 400 s, peak 2.64 GB, server CPU 181 s
Full clone through Deutsche Cloud, production limits fails, out of memory in the web replica
Cold start: hydrate 11 packs from the store 5.9 GB in about 16 s, Node CPU 15 s (loopback SeaweedFS)
--depth 1, baseline, 2 CPU / 1 GB 48 s, 286 MB, server CPU 64 s
--depth 1 through Deutsche Cloud, warm cache 78 s, web CPU 81 s (protocol v0, before that night's fix)
4 concurrent --depth 1 through Deutsche Cloud 45 s for all four, web CPU 82 s
Push one small commit onto it 0.8 s

A multi-pack-index bitmap on a copy of the eleven packs did not rescue the 1 GB clone; at 3 GB it took 468 s against 408 s without, with peak memory 1.76 GB against 3.04 GB.

Repository pages, 18 November 2026

In our test installation: an import of github.com/prometheus/prometheus (one 946 MB pack, 14,622 refs, 500 pull requests), full HTML fetched with curl and a session cookie from a client about 5 ms away, 12 runs before and 20 after the read-path work, both replicas warm. (Raw output not kept.)

curl -s -o /dev/null -b "$COOKIE" -w '%{time_total}\n' https://console.example.com/git/my-org/prometheus
Page Before p50 (p95) After p50 (p95)
Code 1,014 (1,231) ms 111 (155) ms
Directory 737 (834) 91 (102)
File 375 (502) 97 (109)
Commits 368 (507) 94 (154)
Branches 404 (571) 171 (277)
Insights 816 (876) 98 (118)

The causes: a path-limited git log -1 -- path fell from about 200 ms to 25 ms with the commit-graph and changed-path Bloom filters, rev-list --count from 230 ms to 16 ms, and git itself needs 4 to 7 ms for ls-tree and 5 ms for cat-file. A cold view, with the repository on no replica's disk, fell from 19.7 s to 10 to 13 s with the read-path work, then to 8.4 to 9.6 s with parallel ranged hydration, and to 0.23 s once the notification-driven prefetch had run. Ten commits read back six times each, alternating replicas: 60 reads, 0 stale.

Ranged downloads from the object store, 18 November 2026

A 304 MB pack fetched by a web container of our test installation from the zone object store in de1a (Falkenstein), as one stream and as parallel ranged GETs: one stream 74 to 82 MB/s, 8 × 32 MiB 224 MB/s. Variance between runs is large; a 936 MB pack once took 4.7 s and, a minute later, 88 s as one stream. Any S3 endpoint can be tried with aws s3api get-object --range bytes=… in eight processes against one aws s3 cp. (Raw output not kept.)

Concurrency, 11 November 2026

On an arm-16 test host (16 Ampere Altra cores, 32 GB) shared with other work, production compose with SeaweedFS as the store: 30 concurrent clones of a 25 MB repository finished in 4.5 s with the web replica at 195 % CPU, and console pages went from a p50 of 7 ms to 2.3 s while 30 clients cloned one repository and 40 pulled an image. 12 concurrent pushes to separate branches of one repository: 4 answered 500 before a shared temporary file was fixed, 0 after. A lock leak seen in 29 of 40 push cycles was 0 of 200 after the fix. (Internal tool, not published; raw output not kept.)

Known limits

  • A push is at most 2 GiB per request over HTTPS and SSH; a Linux-sized history must be pushed in steps. Imports have no such limit.
  • A full clone of a Linux-sized repository is refused: pack-objects needs about 3 GB (2 GB with a bitmap), more than a git serving replica's 700 MB clone budget. A Kubernetes-sized repository (1.3 GiB) clones. Clones that do not fit the budget at the moment wait for it and are then refused with remote: Fetch not started: … Try again in a minute.; identical clones (CI jobs checking out one commit) are generated once and served from the pack cache.
  • The maintenance repack runs in 512 MB and cannot consolidate a repository above about 1 GB that has gathered 12 or more packs; such a repository keeps its packs.
  • If object storage or the database fails while a push is being stored, the push is refused ([remote rejected] … not stored) and has to be repeated.
  • The first view of a large repository that no replica holds is network-bound: about 8 to 12 s for a 946 MB pack.
  • Pushes to one repository are serialised: 60 s wait for the lock, then 503.
  • SSH has no post-quantum key exchange and an RSA host key; there is no known_hosts endpoint, so compare the fingerprint by hand.
  • Repack runs at 12 live packs, every 20 minutes; superseded packs are kept for an hour.
  • Unreachable objects survive a repack but are not fetchable by hash.
  • LFS objects are at most 5 GiB, over HTTPS only, without locking.
  • Anonymous reads of public repositories: a burst of 30, then one per second per address.
Did this page help you?