FileDummy Logo
FileDummy
Lưu Trữ Đám Mây & CDN

So Sánh Cloudflare R2 vs AWS S3: Tiết Kiệm Chi Phí Băng Thông Egress

Phân tích kiến trúc và chi phí lưu trữ tệp giữa Cloudflare R2 và Amazon S3. Tại sao chính sách miễn phí 100% egress của R2 lại vượt trội.

14 tháng 9, 202613 phút đọc1,420 lượt xem
cloudflare-r2aws-s3cloud-storageobject-storagecomparison

Amazon S3 has long been the dominant cloud object storage solution, but its data egress (bandwidth) fees remain a significant cost pain point for high-traffic download platforms. Cloudflare R2 entered the market with full S3 API compatibility and zero egress fees. Here is an architectural and financial breakdown.

Core Architectural Differences

FeatureAWS S3 StandardCloudflare R2
S3 API CompatibilityNative99% Compatible (SigV4)
Egress Fees$0.09 / GB (US/EU)$0.00 / GB (Free)
Storage Cost$0.023 / GB / month$0.015 / GB / month
Global Edge IntegrationRequires CloudFront ($)Direct Cloudflare CDN integration
Minimum Storage DurationNone on Standard (90d on Glacier)None
Verified Test Asset.pdf

Test low-latency downloads served directly from Cloudflare R2 edge object storage.

Tải File Mẫu 100MB PDF →

Code Migration: Connecting to R2 with AWS SDK v3

Migrating from S3 to R2 requires changing only the client endpoint:

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

const r2Client = new S3Client({
  region: 'auto',
  endpoint: `https://${process.env.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
  credentials: {
    accessKeyId: process.env.R2_ACCESS_KEY_ID!,
    secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
  },
});

export async function uploadToR2(bucket: string, key: string, data: Buffer) {
  return await r2Client.send(
    new PutObjectCommand({
      Bucket: bucket,
      Key: key,
      Body: data,
    })
  );
}

When to Choose Which?

  • Choose Cloudflare R2: For public file distributions, software releases, game patchers, and video assets where download egress dominates your AWS bill.
  • Choose AWS S3: If your application relies deeply on AWS services like Athena, SageMaker, or fine-grained IAM resource tagging.
NDL

Nguyễn Đại Long

Tác Giả

Backend Lead • Chuyên gia Kiến trúc Hệ thống Phân tán & Lưu trữ Đám mây

Hơn 4 năm kinh nghiệm thiết kế các hệ thống xử lý tệp tải lên thông lượng lớn, tối ưu hóa cơ sở dữ liệu và hạ tầng phân tán Cloudflare R2 / AWS S3. Người sáng lập FileDummy và Mạng lưới Hệ sinh thái NDL.

Bài viết này có hữu ích không?

Bấm Thích để ủng hộ tác giả và giúp bài viết lan tỏa tới cộng đồng lập trình viên.

Thảo Luận Kỹ Thuật & Đóng Góp Ý Kiến (0)

Chia sẻ kết quả benchmark, phản hồi các trường hợp biên hoặc đặt câu hỏi chuyên môn.

0/3000

Chưa có bình luận nào. Hãy là lập trình viên đầu tiên bắt đầu cuộc thảo luận!

Câu Hỏi Thường Gặp (FAQ)

What is Cloudflare R2's biggest advantage over AWS S3?

Zero egress fees. AWS S3 charges $0.09 per GB for data transfer out to the internet. Cloudflare R2 charges $0. For high-download-volume applications, this eliminates 70–90% of the monthly storage bill.

Is Cloudflare R2 fully S3 API compatible?

R2 implements the S3-compatible API — the AWS SDK v3 works by changing the endpoint URL. However R2 lacks some S3 features: no object versioning, no S3 replication, no S3 Select, and limited lifecycle policy support as of 2026.

Which is faster for global file distribution: R2 or S3?

For global downloads, Cloudflare R2 with Workers CDN is generally faster due to Cloudflare's 300+ edge locations and zero-egress economics making CDN caching more viable. For uploads, both are comparable depending on your region relative to the bucket.

Bài Viết Liên Quan