ADR-002 — Media Storage Decoupling with Cloudflare R2
Status: Accepted Date: 2026-10-12 Authors: Engineering & Architecture Team
Context
Technical articles on astro-static-site contain many detailed architecture diagrams and visual assets. Storing large binaries directly in Git causes repository bloat, slow clone and build operations, and deployment quota pressure on Cloudflare Pages. Hosting images on a traditional object store such as AWS S3 introduces bandwidth egress charges. See BRD-002 and SR-002.
Two decisions were needed:
- Repository and media boundary: store media inside Git, or offload it to dedicated object storage.
- Object storage provider: AWS S3 + CloudFront, or Cloudflare R2 (zero egress fees).
This resolves the image-storage question left open in ADR-001.
Decision Drivers (FRs & NFRs)
- BR-1.2 / SR-002 SR-NF-02 — no bandwidth overage risk.
- BR-1.3 / SR-002 SR-F-03, SR-NF-01 — binaries live in object storage, not Git.
- BRD-003 BR-2.1 / SR-009 SR-NF-01 — media sits behind the same firewall, DDoS protection and rate limit as the site.
- BRD-001 BR-3.1 / SR-003 SR-F-03, SR-009 SR-F-03 — media served from the edge cache at the site’s own address.
Decision — Where media is stored and served from
Option 1 — Store all images in Git
Commit all diagrams to public/images/ inside the Astro repository.
Pros:
- Low operational overhead and no second system to manage.
- No egress cost within Pages limits.
Cons:
- The repository balloons rapidly (over 1 GB), slowing
git cloneand builds. - Build and deploy speed degrades over time.
- Deployment quota pressure on Cloudflare Pages.
Option 2 — Cloudflare Pages + AWS S3 + CloudFront
Keep the site on Cloudflare Pages and store images in AWS S3 behind a CloudFront CDN.
Pros:
- Keeps the Git repository lightweight, with fast builds.
Cons:
- AWS bandwidth (egress) fees, so a traffic surge on visual assets raises the bill.
- High operational overhead (IAM, S3 policies, CloudFront).
- A second provider alongside Cloudflare.
Option 3 — Cloudflare Pages + Cloudflare R2 (CHOSEN)
Keep code and content in Git (deployed to Cloudflare Pages) and offload architecture diagrams and heavy assets to a Cloudflare R2 bucket mapped to a custom media domain.
Pros:
- No repository bloat: the Git repository stays lightweight, keeping
git cloneand builds fast. - $0 egress fees: R2 does not charge for egress bandwidth, protecting the budget from traffic surges on visual assets.
- Unified edge management: WAF, DNS, CDN caching, Pages deployment and R2 storage live in a single Cloudflare control plane.
- Standard Markdown syntax: writers reference images with root-relative paths, e.g.
, and the build rewrites them to the media addresshttps://assets.<domain>/images/...(ADR-003).
Cons:
- Two-step authoring workflow: authors must upload images to R2 (dashboard, Wrangler CLI or any S3-compatible tool) before referencing them in Markdown.
- Storage is not free beyond the free tier: egress is free, but R2 storage above its free allowance is billed, so $0 holds only while total media stays within it.
Final Decision
Keep code and content in Git and serve media from Cloudflare R2 (Option 3). It keeps the repository small, removes egress cost and stays inside the same control plane as the site. Options 1 and 2 were rejected for repository bloat and egress fees respectively. The accepted cost is a two-step upload workflow and billed storage above the free allowance.
Implementation note: the existing image tooling (scripts/migrate-post-images.mjs, PUBLIC_IMAGE_STORAGE_BASE_URL) was built for Firebase Storage and needs retargeting to R2’s S3-compatible API. Until a bucket exists, images keep resolving to local /images/... paths.