Build a self-hostable YouTube clone on Cloudflare
Open-source video pipeline on R2, D1, and Workers — $0 egress.
- Storage
- Cloudflare R2 · $0 egress
- Metadata
- D1 SQLite
- Runtime
- Workers · Assets
- Cost
- $0 to operate
What TubeForge is
TubeForge is an open-source, forkable YouTube clone implementation you can deploy directly to your own Cloudflare account. Built with Astro, Cloudflare R2, D1 SQLite, and Workers, it demonstrates how a minimal self-hosted video platform stores, indexes, and streams video files without paying per-gigabyte outbound bandwidth fees. Instead of hiding behind a managed SaaS, every route from upload to playback is small enough to read in an afternoon and adapt to your own project.
Choose where to start
Depending on whether you want to study the system design, deploy the code, or model your hosting budget, follow one of the three core guides below:
- Understand the architecture: Read the YouTube clone architecture guide to see how uploads, private storage, metadata queries, and HTTP Range playback fit together.
- Fork and deploy the code: Open the YouTube clone script walkthrough for the full route table, Wrangler bindings, D1 migration command, and deployment steps.
- Evaluate hosting economics: Check the YouTube clone cost breakdown for free-tier allowances, R2 vs. S3 egress math, and when Worker requests become the limiting factor.
Need to check how big an exported clip will be before you upload? Use the browser-based Video File Size Calculator to estimate file size from bitrate and duration locally.
Architecture Guide
Deep dive into the four system layers and key engineering tradeoffs.
Fork & Deploy Script
Step-by-step Wrangler setup, routes, and Cloudflare bindings.
Cost & Free Tier
Bandwidth economics and request quota limits on Cloudflare.
File Size Calculator
Estimate video size locally against upload caps before exporting.
Real scope, limits, and how it differs from YouTube
TubeForge is intentionally scoped as a lightweight reference implementation rather than a drop-in replacement for a full commercial video platform. Knowing the exact boundaries up front saves you from surprises when you fork it:
- Maximum scale on the default setup: Direct uploads are capped at 95 MB per file because Cloudflare Workers enforce a 100 MB request body limit on both free and paid plans. Total storage is capped at 9 GB (leaving 1 GB of headroom inside the 10 GB free R2 tier), which holds roughly 95 max-size clips or around 3.5 hours of standard 1080p footage.
- No server-side transcoding: Videos are stored and streamed exactly as uploaded (MP4 or WebM) without adaptive bitrate ladders (HLS/DASH) or background re-encoding. That keeps CPU usage inside the 10 ms Worker budget, while real YouTube runs dedicated transcoding clusters.
- Minimal access control: There is no user registration, login, or billing system. Video deletion relies on a per-upload token saved in the uploader's browser, so you should add authentication before opening a fork to untrusted public users.
- Private bucket delivery: Unlike a static CDN folder, every media read passes through a Worker proxy so nobody can scrape and hotlink raw bucket URLs.
Frequently asked questions
Is TubeForge open-source code or a hosted video service?
TubeForge is open-source reference code, not a multi-tenant hosted platform. You fork the repository, provision your own R2 bucket and D1 database, and deploy it under your own Cloudflare account using the deployment guide.
How much does it cost to run this YouTube clone?
For demos, prototypes, and low-traffic personal libraries, it can run at $0 per month within Cloudflare's free allowances. When traffic scales, Worker request volume — not storage or egress — is usually what triggers a $5/month Workers Paid upgrade, as detailed in the cost analysis.