10 Jun 2024 · Software Engineering

    Cut Down S3 Storage Costs with Cloudflare R2

    9 min read
    Contents

    Cloud storage has become the most popular way for businesses and developers to store data for online use. S3 is the de facto standard for cloud storage, with Amazon as the leading provider. However, the monthly bill for Amazon S3 can be steep, often amounting to thousands of dollars per month, mainly due to data transfer (egress) fees. Enter Cloudflare R2, a cost-effective cloud storage alternative that eliminates these greedy egress fees!

    In this article, you will understand what Cloudflare R2 is, how it compares to Amazon S3, how its pricing model works, and whether you can migrate your data from S3 to R2.

    Let’s dive in!

    What Is Cloudflare R2?

    R2 is a modern, efficient, S3-compatible cloud object service offered by Cloudflare. Compared to typical cloud storage services, such as Amazon S3, it is a more cost-effective solution. That is because Cloudflare R2 allows storing large amounts of unstructured data without costly egress bandwidth fees.

    Data egress fees are network fees that cloud providers typically charge for moving data out of the cloud. These, also known as data transfer fees, are usually hard to predict and add up to the fees you already need to pay for storage and cloud computing. Egress fees apply when retrieving files from cloud storage (e.g., to show images on a web page), accessing data from external analytics applications, or transferring data between different regions.

    Other scenarios where companies need to move data out of their cloud storage is when implementing hybrid cloud (a mix of two or more cloud environments) or multi-cloud (multiple clouds from more than one cloud provider) architectures. These enable businesses to use the most appropriate cloud environment for each task, improving the efficiency and flexibility of the overall IT infrastructure. In addition, having more than one cloud storage is essential for robust disaster recovery.

    By eliminating egress fees, R2 makes it more affordable for businesses and developers to adopt such robust, reliable, and efficient IT architectures. In particular, Cloudflare R2 covers several scenarios and use cases, including:

    • Cloud storage for web applications
    • Storage for multimedia files (e.g., images, podcast episodes, recordings, etc.)
    • Data lakes (e.g., for analytics and Big Data applications)
    • Storage for cloud-native applications
    • Cloud storage for large batch processes (e.g., machine learning model artifacts or datasets)

    AWS S3 vs Cloudflare R2

    Amazon S3, short for Amazon Simple Storage Service, is a scalable object storage service launched by AWS in 2006. Over the years, the S3 standard has become the go-to API for cloud storage. Its popularity has led to the emergence of several S3-compatible providers, but Amazon remains the S3 cloud storage leader.

    Cloudflare R2 is a much newer object storage solution, with its first release only in 2021. It offers similar features to Amazon S3, relying on an S3-compatible API. This makes it easy for users to migrate and integrate their existing tools and applications with this cloud system.

    The main differences between Amazon S3 and Cloudflare R2 are:

    • Cost-effectiveness: Amazon S3 charges high egress fees for moving data off the AWS network, which can significantly increase overall cloud-associated costs. In contrast, Cloudflare R2 has no egress fees. Users can move data out of storage at no additional cost, resulting in significant savings in data-intensive applications.
    • Free tier: Amazon S3 offers a limited free tier, while Cloudflare R2 comes with a generous free tier that includes millions of requests per month.
    • Global accessibility and performance: Amazon S3 provides solid performance, but only when configured correctly to optimize data transfer between regions. On the other hand, Cloudflare R2 automatically selects the optimal storage region based on the data upload location. This ensures high performance and availability without the need for complex configurations.
    • Cloud storage API: Amazon S3 is based on the original S3 standard, which is widely supported by a wide range of tools and applications. Instead, Cloudflare R2 uses an S3-compatible API, which lacks some S3 features but has others. Full compatibility with the S3 API for all features is currently underway. Monitor the status on the official docs.
    • Data security: The two solutions offer strong security features, including encryption and in-depth access control policies. Cloudflare R2 enhances security even more with undiscoverable bucket names, reducing the risk of unauthorized access.

    Cloudflare R2 Pricing Breakdown

    The Cloudflare R2 pricing model consists of two following dimensions:

    • Storage: Total volume of data stored in the cloud, per GB.
    • Operations: Operations performed on the data in the cloud. These are divided into Class A and Class B. Class A operations are more expensive and tend to change the state, while Class B operations are cheaper and tend to read the existing state. Some operations, such as deleting an object or a bucket, do not fall into these two categories and are free.

    The R2 pricing can be summarized in the table below:

    Rates
    Storage$0.015/GB
    Class A operations$4.50/million requests
    Class B operations$0.36/million requests
    Data egressFree

    All included usage is charged on a monthly basis.

    Is this actually more cost-effective than Amazon S3 storage? Let’s find it out!

    Cloudflare R2 vs Amazon S3: Price Comparison

    Take a look at the summary tables below to compare the free and paid plans offered by Cloudflare R2 and Amazon S3:

    Cloudflare R2Amazon S3
    Data storage$0.015 per GBStarts at $0.023 per GB
    Class A operations (POST)$0.0045 per 1,000 requests$0.005 per 1,000 requests
    Class B operations (GET)$0.00036 per 1,000 requests$0.0004 per 1,000 requests
    Data egressFreeStarts at $0.09 per GB

    Note that prices are up-to-date at the time of writing but may change over time. Amazon S3 prices and egress fees are based on tiered rates for S3 Standard in the US East region. For more information, visit the Amazon S3 pricing page.

    As you can see, Cloudflare R2 is cheaper in all the considered aspects when compared to Amazon S3. Time to see how these price variations translate to a couple of real-world scenarios!

    Free Tier Limits

    Both Cloudflare R2 and Amazon S3 come with free tiers, which compare as below:

    Cloudflare R2Amazon S3
    Data storage10 GB per month5 GB per month
    Class A operations (POST)1M per month2k per month
    Class B operations (GET)10M per month20k per month
    Data transferUnlimited100 GB
    ExpirationUnlimited12 months

    Notice how the biggest difference is the huge amount of free requests that R2 offers. Millions of Class A and Class B operations can meet the cloud needs of a medium-sized web application. Data storage limits are quite restrictive in both scenarios, but R2 offers twice as much monthly storage space as Amazon S3. Plus, Amazon S3’s free tier expires after 12 months, while R2’s has no time limit.

    To better understand what you can achieve with a free tier, let’s consider an example. With Cloudflare R2’s free tier, you can develop a site where users upload up to 10,000 1 MB web-optimized images per month. Suppose each web page on the site contains 5 images, this means you could have 2,000,000 monthly visits without incurring any costs. With Amazon S3, you could only have 5,000 uploaded images and 4,000 views a month.

    Usage for Video Storage

    Let’s assume that you are building a video-oriented application. Users will upload 1 million videos per month and view 100 million of these videos in this application. The average size of the video files is 5 MB, which means that users will upload 5 TB of storage per month and download 500 TB of data a month.

    To compare the cost of this application on R2 and S3, it is necessary to dig into the Amazon S3 prices. In detail, the S3 pricing model for data storage follows this table:

    S3 Data StorageCost
    First 50 TB/month$0.023 per GB
    Next 450 TB/month$0.022 per GB
    Over 500 TB/month$0.021 per GB

    Similarly, S3 data transfer fees are calculated using the following table:

    S3 Data Transfer TierCost
    First 10 TB/month$0.09 per GB
    Next 40 TB/month$0.085 per GB
    Next 100 TB/month$0.07 per GB
    Greater than 150 TB/month$0.05 per GB

    On a monthly basis, this hypothetical application requires:

    • 5 TB of storage
    • 1 million Class A operations
    • 100 million Class B operations
    • 500 TB of data transfer

    The Cloudflare R2 vs Amazon S3 price comparison table for this scenario is:

    S3 Data Transfer TierCloudflare R2Amazon S3
    Storage$75$115
    Class A operations (POST)$4.50$5
    Class B operations (GET)$36$40
    Data egress$28,800
    Total$115.5/mo$28,960/mo

    Sure, Amazon AWS offerings are quite broad and complex, and there must be a solution that better fits this particular case. However, the Cloudflare R2 plan turned out to be 99.99% cheaper than the S3 Standard plan.

    Moving From S3 to Cloudflare R2: Costs and How To Do It

    You might now be convinced to switch from your S3 provider to R2, but what about the egress fees to transfer all your data from your cloud provider to Cloudflare? That could take months and cost you several thousand dollars!

    Cloudflare is well aware of the data migration problem and has designed two solutions for that:

    • Super Slurper: Move all your data from Amazon S3 or Google Cloud Storage to R2 in a single operation. It preserves custom object metadata from the source bucket by copying it to the migrated objects, and it does not delete any objects from the source bucket. This tool is fast but requires you to pay egress fees from the source provider.
    • Sippy: Incrementally migrate from S3 providers to Cloudflare R2 without paying unnecessary egress fees. When an object is requested, it is served from your R2 bucket if it is found. Otherwise, it is simultaneously returned from the source bucket and copied to R2 to minimize data transfer fees. All other operations, including insert and delete operations, continue to work as usual.

    Both are free to use and charge only for the Class A operations that the tool needs to perform to transfer data to your R2 bucket.

    Advantages and Limitations of R2 Compared to S3

    Before blindly moving from Amazon S3 to Cloudflare R2, you must analyze in detail the pros and cons of R2 versus S3.

    👍 Pros:

    • Cheaper than Amazon S3 on data storage and operations
    • Much more generous free tier
    • No egress/data transfer fees
    • S3-compatible API
    • Easier setup, with automatic region configuration
    • Undiscoverable bucket names
    • Simple data migration with Super Slurper and Sippy

    👎 Cons:

    • Not all S3 API operations are currently supported
    • Super Slurper only works with Amazon S3 and GCS, can only transfer objects less than 1 TB, and does not guarantee the same ETags
    • More limited ecosystem compared to AWS

    Conclusion

    In this article, you explored Cloudflare R2 and compared it to Amazon S3. You now know that R2 is a cost-effective cloud storage solution with an S3-compatible API. Thanks to its no-egress fees policy, R2 can save you thousands of dollars a month. However, migrating from Cloudflare R2 to Amazon S3 would mean losing the ecosystem advantages of keeping your data within the AWS infrastructure.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Avatar
    Writen by:
    I'm a software engineer, but I prefer to call myself a Technology Bishop. Spreading knowledge through writing is my mission.
    Avatar
    Reviewed by:
    I picked up most of my skills during the years I worked at IBM. Was a DBA, developer, and cloud engineer for a time. After that, I went into freelancing, where I found the passion for writing. Now, I'm a full-time writer at Semaphore.