Cloudflare R2 Object Storage
S3-compatible object storage with zero egress fees, ideal for media, backups, and large datasets.
Why
R2 charges $0.015/GB/month storage but $0 egress — S3 charges $0.09/GB egress. For a 100GB site serving 1TB/month egress, R2 saves $90/mo.
S3 API compatibility means drop-in replacement.
When
Use R2 for user uploads, video/images served to users, database backups, and ML datasets. Avoid as primary DB or for objects needing frequent strong consistency writes.
How
Example
Common Problems
- ⚠R2 eventual consistency on overwrite — reads may return stale object right after PUT
- ⚠No bucket-level public access — must serve through Worker or custom domain, unlike S3 website endpoint
- ⚠Multipart upload >5GB needs S3 API — wrangler CLI doesn't support multipart yet
Best Practices
- ✓Serve media through Worker with Cache API — edge caching makes R2 reads nearly free
- ✓Use lifecycle rules for backups — auto-tier to delete after 90 days, avoid manual cleanup
- ✓Generate presigned URLs for uploads — clients upload directly to R2, save Worker CPU
FAQ
What is Cloudflare R2 Object Storage and what problem does it solve?
S3-compatible object storage with zero egress fees, ideal for media, backups, and large datasets. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.
How do I get started with Cloudflare R2 Object Storage in 5 minutes?
Two steps to run it: (1) Create bucket — wrangler r2 bucket create my-bucket (or dashboard); (2) S3 API — generate API token, use endpoint https://<account>.r2.cloudflarestorage.com. Validate on the free tier first, then wire into production.
What is the #1 pitfall with Cloudflare R2 Object Storage?
The most frequent issue is: R2 eventual consistency on overwrite — reads may return stale object right after PUT. Run a pre-launch checklist item by item, and add policy/config scanning in CI.
What are the best practices for Cloudflare R2 Object Storage?
Best practices for Cloudflare R2 Object Storage include: Serve media through Worker with Cache API — edge caching makes R2 reads nearly free; Use lifecycle rules for backups — auto-tier to delete after 90 days, avoid manual cleanup; Generate presigned URLs for uploads — clients upload directly to R2, save Worker CPU. The first one — "Serve media through Worker with Cache API — edge caching makes R2 reads nearly free" — should be a team default baked into your IaC templates.
How do I control cost and avoid bill surprises with Cloudflare R2 Object Storage?
Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most Cloudflare R2 Object Storage options offer a free tier — validate within free quota before scaling.