How we cut video infrastructure costs 80% by moving off AWS MediaConvert and CloudFront
Cutting production VOD spend from $5,000 to $1,000/month (~$48K/yr) using Cloudflare R2, Modal serverless GPUs, Workers edge auth, and ClickHouse.
Our production video infrastructure bill hit $5,000 a month on AWS MediaConvert and CloudFront, and most of that spend was moving bytes rather than encoding them. By moving object storage and delivery to Cloudflare R2 with edge token checks, shifting transcoding to Modal serverless GPUs, and offloading viewer metrics to ClickHouse, monthly spend dropped 80% to roughly $1,000 a month.
That is about $48,000 a year in gross margin recovered without touching product features. Here is how the cost breakdown actually worked, the architecture we moved to, and the cases where staying on a managed service is still the smarter call.
Why AWS MediaConvert and CloudFront bills compound silently
Video products rarely get expensive because of database rows or REST endpoints. They get expensive in three places: per-minute managed transcoding, CDN egress per gigabyte delivered, and API servers wasting memory proxying uploads.
On an edtech and healthcare video platform with growing course libraries, CloudFront egress and MediaConvert job pricing scale linearly with every watch-through and every re-encode. Even worse, if your application server accepts video uploads before forwarding them to S3, every slow mobile upload pins worker memory and forces horizontal scaling you would never need for normal API traffic.
| Cost driver | Legacy AWS setup ($5,000/mo total) | Target R2 + Modal setup ($1,000/mo total) | Why it changed |
|---|---|---|---|
| Storage | Amazon S3 standard storage | Cloudflare R2 ($0.015/GB-month after 10 GB free) | Comparable storage rate |
| Video egress & delivery | CloudFront metered bandwidth | Cloudflare R2 ($0 egress) + Workers edge auth | Eliminated per-GB egress charges |
| Transcoding compute | AWS MediaConvert per-minute pricing | Modal serverless GPUs (pay-per-second, $30/mo starter credit) | Only pay for active GPU seconds |
| Job dispatch & limits | Polling / tightly coupled workers | QStash + Upstash Redis + faster-whisper | CPU and GPU jobs scale separately |
| Viewer analytics | Expensive OLAP add-ons or slow Postgres scans | ClickHouse watch-time & drop-off tables | Fast aggregations without locking OLTP |
The biggest lever in that table is zero-egress storage. When learners or patients replay the same 1080p lesson twenty times a month, removing per-gigabyte delivery fees changes the unit economics immediately.
The R2, Modal, and Cloudflare Workers architecture
To keep the request path small and the bill predictable, four components sit behind a thin control plane API:
Browser ──(1. upload token + presigned PUT parts)──▶ Cloudflare R2 (raw bucket)
│ │
│ (2. complete + HEAD size check) │
▼ ▼
Control Plane API ──(3. Postgres lease + QStash)──▶ Modal GPU Worker (FFmpeg / Shaka)
│ │
│ (4. JWT playback token) ▼
└──────────────▶ Cloudflare Worker ◀────────── Cloudflare R2 (HLS/DASH bucket)
│
└──▶ ClickHouse (watch time & drop-off events)
In our open-source reference implementation (ClipMux), the API is control-plane only and never carries video bytes. A browser asks for an upload token, fetches presigned multipart URLs in small windows so URLs do not expire mid-upload, and pushes chunks straight to the raw R2 bucket.
Once parts finish, the browser hits the completion endpoint. Because the API never saw the upload stream, it cannot trust the client's word that the file is intact: it runs a HEAD check against R2 to verify object existence and exact byte size before dispatching any GPU container.
Decoupling CPU, GPU, and edge playback authorization
Sending video processing straight from an HTTP handler is how API latency spikes and timeouts trigger duplicate encodes. Instead, we split responsibilities across three layers:
- Claim before dispatch in Postgres: Completion flips the video row from
uploadingtoprocessingwith a conditional update, records an attempt ID and a 20-minute lease, and only then dispatches the job. If the GPU request times out, a background sweeper retries the same attempt ID after the lease expires rather than spawning a duplicate container. - Separate CPU and GPU queues: Audio transcription (
faster-whisper) and HLS/DASH packaging run on Modal serverless GPUs, while webhook notifications and status updates run through QStash with dead-letter retries. - Edge-authorized playback without database lookups: When a viewer hits play, the API signs an HS256 JWT containing the video ID, organization, a coarse browser-family hash, an optional domain allowlist, and an expiry. The Cloudflare Worker in front of the transcoded R2 bucket validates that signature, checks playback policy stored in R2 custom metadata, and rewrites the HLS manifest so segment URIs carry the token.
That last detail matters for latency and cost. Because the edge Worker verifies tokens statelessly without opening a Postgres connection per .ts or .m4s segment, playback stays fast even under sudden traffic spikes.
Honest tradeoffs: signed playback is not DRM
Cutting 80% off an infrastructure bill is not free magic. Moving away from a managed pipeline shifts three specific responsibilities back onto your engineering team:
- You own CORS and multipart edge cases: Browser-direct uploads to R2 require exposing the
ETagheader in bucket CORS rules, plus a cleanup job for abandoned multipart uploads that never completed. - Signed URLs are bearer credentials, not Widevine DRM: Rewriting HLS manifests with an edge JWT stops casual link hotlinking and domain embedding, and we explicitly block attaching tokens to foreign-host URLs. However, anyone holding an unexpired manifest URL can download segments until expiry, and deleting a video takes effect only once the R2 bytes are removed because the edge Worker does not query Postgres.
- Modal GPU spend still needs guardrails: On Modal, an L4 GPU bills around $0.000222 per second (~$0.80/hour). That makes 1080p ladders very cheap, but running unrestricted 4K ladders and Whisper transcription on every user upload can burn through credits quickly without per-tenant presets and concurrency limits.
When you should NOT migrate off AWS or Mux
Not every team should run their own video stack. Stay on Mux or AWS MediaConvert if:
- Your total monthly video spend is under $500. A few hundred dollars a month will not pay back the engineering time spent maintaining CORS, FFmpeg ladders, and sweeper jobs.
- Your contracts legally require hardware-backed DRM (Widevine, FairPlay, PlayReady) rather than edge-signed HLS/DASH playback.
- You have zero backend engineers available to own upgrades and monitoring.
If you are spending $3,000+ a month on egress and transcoding and want the exact architecture patterns, you can read the full ClipMux case study or look at my cloud and video cost optimization service.
Frequently asked questions
How much storage and bandwidth does Cloudflare R2 include for free?
Cloudflare R2 charges $0 for egress at any volume. Its free tier covers the first 10 GB of storage, 1 million Class A operations, and 10 million Class B operations each month, with storage billed at $0.015 per GB-month beyond that.
How do you stop duplicate GPU transcodes when a webhook or API request times out?
Claim the transcode atomically in PostgreSQL using a conditional UPDATE with a unique attempt ID and a lease timestamp before calling Modal. Timeouts leave the claim intact so a sweeper retries the same attempt ID idempotently instead of launching a second GPU job.
Do we lose viewer analytics when leaving a managed video provider?
No. Edge Workers or lightweight client player beacons stream playback heartbeats directly into ClickHouse, giving product teams watch time, completion rate, and drop-off curves per video without overloading PostgreSQL.
How long does an AWS MediaConvert and CloudFront migration usually take?
A scoped cost audit takes 5 to 7 days to validate exact dollar savings, and a zero-downtime dual-bucket migration for uploads, transcoding, and signed playback typically ships in 2 to 4 weeks.