Cloudflare R2

Enterprise object storage with zero egress fees and full S3 API compatibility

Understanding Object Storage in the Cloud Era

Object storage has become the foundational layer for modern web applications, content delivery systems, and data-intensive workloads. Unlike traditional file systems that organize data in hierarchical directories, object storage treats each piece of data as a discrete unit with a unique identifier, metadata, and the actual content.

Cloudflare R2 brings this proven storage paradigm to the edge, combining the durability and scalability of cloud object storage with the performance of a globally distributed network. Objects stored in R2 are automatically available from edge locations worldwide, reducing latency for users regardless of their geographic location.

The key insight driving R2's design is recognizing that egress fees--the charges incurred when moving data out of cloud storage--represent a hidden tax on innovation. For content-heavy applications that serve media to users, these fees can exceed the cost of the storage itself by orders of magnitude. R2 eliminates this friction, allowing developers to focus on building great experiences rather than optimizing data transfer patterns to minimize egress costs.

Key benefits:

  • Unlimited scalability without capacity planning
  • 300+ edge locations for global performance
  • Durable storage with automatic redundancy
  • Simple, flat namespace for easy management
Why Cloudflare R2?

The key advantages that make R2 a compelling choice for modern applications

Zero Egress Fees

No charges for data leaving R2. Serve content to users without watching the meter.

S3 Compatible

Full S3 API compatibility means existing tools and libraries work without modification.

Edge Integration

Native integration with Cloudflare Workers for compute and storage at the edge.

Predictable Pricing

Pay only for storage and operations. No surprise fees based on data transfer.

S3 Compatibility: Migration Without Rewriting

Cloudflare designed R2 with S3 API compatibility as a core principle, recognizing that the AWS S3 API has become the de facto standard for object storage. This compatibility means that applications, libraries, and tools designed for S3 can work with R2 with minimal or no modification.

Supported Operations

R2 implements the essential S3 operations that most applications require:

  • Core Operations: PutObject, GetObject, DeleteObject, ListObjects
  • Bucket Management: CreateBucket, ListBuckets, DeleteBucket
  • Multipart Upload: Full support for large file handling
  • Presigned URLs: Generate temporary access for frontend uploads and downloads

The following example shows how to configure the AWS CLI to work with R2:

# Configure AWS CLI for R2
export AWS_ACCESS_KEY_ID=your_r2_access_key
export AWS_SECRET_ACCESS_KEY=your_r2_secret
export AWS_DEFAULT_REGION=auto

# Set R2 endpoint
export AWS_EC2_METADATA_SERVICE_ENDPOINT=localhost

# List buckets using R2 endpoint
aws s3 ls --endpoint-url=https://<account-id>.r2.cloudflarestorage.com/

For JavaScript/TypeScript applications using the AWS SDK:

import { S3Client } from '@aws-sdk/client-s3';

const r2 = new S3Client({
 region: 'auto',
 endpoint: 'https://<account-id>.r2.cloudflarestorage.com',
 credentials: {
 accessKeyId: process.env.R2_ACCESS_KEY_ID,
 secretAccessKey: process.env.R2_SECRET_ACCESS_KEY,
 },
});

Migration Strategies

  1. Direct Cutover: Copy existing data to R2, update application endpoints
  2. Dual-Write: Write to both systems during transition
  3. Gradual Migration: Migrate buckets incrementally based on cost sensitivity

The AWS CLI, Terraform, and most S3-compatible tools work with R2 by simply changing the endpoint configuration. This approach dramatically reduces the migration burden for organizations considering a move from AWS S3.

The Zero Egress Advantage

The defining characteristic of Cloudflare R2 is its zero egress fee policy. Traditional object storage providers charge significant fees for data leaving the storage system--for applications serving content to users, these fees often exceed all other costs combined.

When you store data in traditional cloud object storage, you pay for the storage space consumed, the operations performed on that data, and every gigabyte of data that leaves the storage system. R2 eliminates this calculation entirely. You pay only for the storage you consume and the operations you perform.

When R2 Economics Excel

  • Content delivery and media streaming
  • Static asset hosting for web applications
  • Backup and disaster recovery
  • Data lake and analytics storage
  • Any scenario where data serves users or leaves storage

Comparison Framework

When evaluating R2 against traditional object storage providers, consider these factors:

Storage Volume: Tiered pricing with decreasing per-GB cost at scale Operation Counts: Read, write, and list operation costs vary by type Data Egress Pattern: Traditional providers charge per GB leaving storage Free Tier Allocations: Monthly allocations for development and testing Regional Consistency: No regional pricing variations

For applications where most stored data stays in storage rather than being frequently accessed, traditional providers may appear competitive. But any active use case--content delivery, API responses, media streaming, user-generated content hosting--will likely find R2's zero-egress model more economical.

Beyond direct cost, consider the architectural freedom that zero egress enables. With traditional providers, teams often implement complex caching layers, regional storage strategies, and data lifecycle policies primarily to minimize egress. R2 removes these constraints, allowing simpler architectures that serve users directly from globally distributed storage.

Migration to R2: Strategies and Considerations

Migrating to R2 from AWS S3 or other object storage providers involves several strategies, each appropriate for different scenarios and tolerance for downtime.

Migration Approaches

Direct Cutover Best for applications that can tolerate brief read-only periods during migration. Copy data to R2 using rclone or AWS CLI, update application configuration, and redirect traffic.

Dual-Write Pattern For applications requiring continuous availability. Write to both old storage and R2 simultaneously while copying historical data. Once verified, redirect reads to R2.

Cloudflare Super Slurper Bulk data migration tool provided by Cloudflare for moving existing S3-compatible storage to R2 efficiently.

Pre-Migration Checklist

  • Review application S3 API usage patterns and verify R2 compatibility
  • Test S3 features your application relies on against R2 documentation
  • Generate R2 API tokens through Cloudflare dashboard
  • Update credential storage (configuration files, secret management systems)
  • Configure network and firewall rules for R2 endpoints
  • Test with non-production workloads before production migration
  • Establish rollback strategy and verify it works
  • Update monitoring and alerting for R2-specific metrics

Before beginning a migration, verify that your applications and workflows will function correctly with R2's implementation of the S3 API. While R2 supports the vast majority of S3 operations, some less commonly used features have different behavior or are not implemented.

Integration with Cloudflare Workers

Cloudflare Workers provide serverless execution at the edge, running JavaScript and WebAssembly code in Cloudflare's global network. R2 integrates natively with Workers, creating a powerful combination where compute and storage exist at the edge.

When you bind an R2 bucket to a Worker, the Worker gains direct access without additional network hops or authentication complexity. Objects in the bucket can be read, written, and manipulated using the Workers API, which follows familiar patterns for developers experienced with S3 SDKs but optimized for edge execution.

Use Cases

  • Edge Image Processing: Transform and resize images on-the-fly
  • Access Control: Gate access to private objects with custom logic
  • Dynamic Content Generation: Combine stored assets with dynamic responses
  • Upload Processing: Validate and sanitize uploads before persistence

The practical implications are significant for latency-sensitive applications. Rather than round-tripping to a centralized storage region, requests to a Worker can access R2 objects from the same edge location. For frequently accessed objects, the Worker can implement caching strategies that reduce both latency and R2 operations costs. This combination of edge computing and object storage creates powerful opportunities for globally distributed applications.

Example: Worker with R2 Binding

export default {
 async fetch(request, env) {
 const url = new URL(request.url);
 const objectKey = url.pathname.slice(1);

 try {
 // Read object from R2 bucket
 const object = await env.MY_BUCKET.get(objectKey);

 if (object) {
 return new Response(object.body, {
 headers: {
 'Content-Type': object.httpMetadata.contentType || 'application/octet-stream',
 'Cache-Control': 'public, max-age=31536000',
 },
 });
 }

 return new Response('Object not found', { status: 404 });
 } catch (error) {
 return new Response('Error retrieving object', { status: 500 });
 }
 },
};

To configure this in wrangler.toml:

name = "r2-worker"
main = "src/index.ts"
compatibility_date = "2025-01-01"

[[r2_buckets]]
 binding = "MY_BUCKET"
 bucket_name = "my-assets-bucket"
Worker with R2 Binding
1export default {2 async fetch(request, env) {3 const url = new URL(request.url);4 5 // Read object from R26 const object = await env.ASSETS.get(url.pathname.slice(1));7 if (object) {8 return new Response(object.body, {9 headers: { 'Content-Type': object.httpMetadata.contentType }10 });11 }12 13 return new Response('Not Found', { status: 404 });14 }15};

Use Cases Where R2 Excels

R2's combination of S3 compatibility, zero egress fees, and edge integration makes it particularly well-suited for specific categories of applications.

Ideal Use Cases

Media Hosting and Content Delivery Any application serving images, videos, audio, or documents to users benefits directly from zero egress fees. Traditional architectures often implement elaborate caching strategies specifically to minimize egress; with R2, you can serve content directly from edge-proximal storage without those concerns. This approach is particularly valuable for SEO-focused content delivery where fast, reliable asset delivery impacts search rankings.

Static Asset Hosting Web application assets, site images, downloadable content, and static resources work excellently with R2. When combined with Cloudflare Pages or any static hosting solution, R2 provides durable storage for assets that might change less frequently than the site content itself.

Backup and Disaster Recovery Predictable costs independent of restore volumes make R2 attractive for backup storage and recovery testing. Traditional backup storage pricing often creates anxiety around recovery testing--every gigabyte restored during testing adds to the bill. R2's zero-egress model means you can restore entire datasets for testing without worrying about the meter's running.

Data Lake and Analytics Store analytical outputs and make insights available without worrying about transfer costs. When insights generated from stored data need to reach dashboards, reports, or downstream systems, R2 ensures those transfers don't carry unexpected costs.

When to Consider Alternatives

  • Highly specialized S3 features R2 doesn't implement
  • Extreme performance requirements beyond typical object storage
  • Multi-cloud strategies requiring vendor distribution
  • Applications depending on specific S3 features like advanced replication configurations
Getting Started with R2

Create an R2 Bucket

In the Cloudflare dashboard, navigate to R2 and create a bucket with a unique name. Configure access settings and object locking preferences.

Generate API Credentials

Create API tokens with appropriate permissions for your use case. Store credentials securely for your applications.

Configure Your Tools

Update AWS CLI, SDKs, or application code to use R2 endpoints. Test with sample operations.

Verify and Test

Run test operations to confirm everything works correctly. Set up monitoring for usage tracking.

Frequently Asked Questions

Ready to Eliminate Egress Fees?

Cloudflare R2 provides enterprise object storage with zero egress fees and full S3 compatibility. Build globally distributed applications without the hidden costs of traditional cloud storage.