Skip to content
Source
Sign inSign up

Serve LFS files and assets from Europe and Asia

Site administration

Serve LFS files and assets from Europe and Asia

Object storage is in AWS us-east-1, and every LFS download and asset passes through the web Worker there. From Singapore, a 16 MiB LFS file took 2.3 s through the forge, and 0.2 s straight from object storage in Singapore. From Nuremberg it took 1.1 s, and 0.2 s from Frankfurt (measured on 2026-12-03, the median of 5). This page sets up a copy of the LFS objects and assets in Europe and in Asia, next to the git servers, and turns on the downloads from them.

5 min read

You need:

  • neonctl, signed in to the TanStack organization on Neon.
  • Wrangler, signed in to the Cloudflare account of the forge, run from apps/web.
  • psql access to the production database, as in Object storage on Neon.

1. Make the two storage projects

Each region has a Neon project of its own, with a bucket lfs on its branch main:

RegionProjectIts AWS regionS3 endpoint
eusource-objects-eu (winter-violet-53550303)eu-central-1https://br-odd-cake-bhnzwa16.storage.c-10.eu-central-1.aws.neon.tech
asiasource-objects-asia (damp-king-61214317)ap-southeast-1https://br-nameless-pond-bi4jhdsm.storage.c-5.ap-southeast-1.aws.neon.tech

The endpoints and regions are vars of the keys Worker (NEON_STORAGE_EU_ENDPOINT, NEON_STORAGE_EU_REGION, NEON_STORAGE_ASIA_ENDPOINT and NEON_STORAGE_ASIA_REGION in apps/web/wrangler.keys.jsonc). Don't use neonctl env pull on these projects: it makes the default storage key again.

2. Give the keys Worker their keys

Only the keys Worker holds the keys. Make 8 keys for each project and put them straight into the secrets NEON_STORAGE_EU_KEYS and NEON_STORAGE_ASIA_KEYS, JSON arrays of { "id", "secret" }, as step 2 of Object storage on Neon does for NEON_STORAGE_KEYS. Nothing is printed and nothing is saved in a file. Then deploy the version that the second wrangler versions secret put printed:

pnpm exec wrangler versions deploy <version id>@100% -c wrangler.keys.jsonc

Then revoke each "Default object storage credential" of the two projects (neonctl credentials list --project-id <id> and neonctl credentials revoke <id>). Revoke it only after your own keys are made: while a project has no key that writes, Neon makes the default key again.

3. Make the queue of the copies

pnpm exec wrangler queues create gitflare-storage-copies

The web Worker sends to it and consumes it (wrangler.jsonc). Its var REGIONAL_STORAGE (eu,asia) names the regions it copies to.

4. Check the copies

Once the web Worker is deployed, each new LFS object and asset reaches both regions a few seconds after its upload. At minute 0 of each hour, the web cron runs the task storage regional reconcile, which sends what a region lacks to the queue, at most 5,000 keys an hour. Its first runs copy the files from before the copies. Workers Logs show a line with diag = "storage regional reconcile": the keys that it checked (checked) and sent (sent), and the keys that only a region had (onlyInRegion), which it deleted.

The copies are done when a run sends nothing.

5. Turn on the downloads from the regions

INSERT INTO site_settings (key, value, updated_at) VALUES ('storage.regional_reads', 'true', (extract(epoch from now()) * 1000)::bigint)
ON CONFLICT (key) DO UPDATE SET value = 'true', updated_at = excluded.updated_at;

Each Worker isolate reads the settings again within 60 s. To turn it off, set the value to false.

Done

A client in Europe, Africa or the Middle East downloads from eu, and a client in the rest of Asia or in Oceania downloads from asia. Clients in the Americas download from us-east-1, as before:

  • An LFS download batch gives the client a presigned URL of its region's copy, good for 1 hour, in place of the forge's URL. Git LFS then downloads from Neon directly. A CI job always downloads from the forge.
  • A public image, video, audio file or download (any file that does not open with a type of its own) answers with a redirect to its region's copy. An SVG, a script, a style, a PDF and every hidden or private asset are served by the forge, with its sandbox.
  • A file whose copy is missing, or not yet the size of the file, comes from the forge. So does every file while the setting is off.

How it works

  • apps/web/src/server/storage/regions.ts has the copies. After a put of an LFS object (objects/) or an asset (assets/), or an upload in parts that completed, the LFS store sends the key to the queue. The consumer copies it to each region that lacks it at the same size (copyObject in storage/backup.ts, the copy of the R2 backup). A file over 100 MiB goes in parts of 64 MiB. A copy that fails is retried 5 times, then the hourly reconcile sends it again.
  • A delete in the LFS store deletes the copies in both regions before it answers. The purge of a deleted repository also deletes objects/<repo id>/ and assets/<repo id>/ in both regions.
  • The runner Worker sends nothing to the queue: what it stores reaches the regions through the hourly reconcile.
  • The region of a client comes from Cloudflare's edge data of the request (request.cf.continent and country).
  • The keys Worker signs the presigned URLs (presignStorageGet). It signs only a GET of objects/ or assets/ in the buckets lfs, lfs-eu and lfs-asia, for at most 1 hour.

Cost

Neon object storage costs $0.023 a GB-month, with no charge for requests. Each project includes 500 GB of egress a month (shared with its Postgres and Functions), then $0.09 a GB. The copies add two copies of the LFS objects and assets (about 4.3 GiB each on 2026-12-03, so about $0.20 a month), and their copy counts toward the egress of source-objects. Each download from a region counts toward the egress of that region's project.