DEV Community

Rahul
Rahul

Posted on

How to build caching service with 10% of your Redis, DynamoDB costs

Learn how to utilise FREE cloud services and cache like Redis, DynamoDB with 10x reduction in costs

Before we dive in, this is just a theory. No one has implemented it till now. So, use it only if you understand the numbers.

So recently, I was reading a blog saying that S3 isn’t more expensive than DynamoDB, if you afford the extra latency.

Then I got an idea of why not use some cloud providers’ FREE services and build a caching service.

Limitations

  • Latency of 100ms.
  • No custom invalidation.

Services

  1. Backblaze

    • Similar to S3
    • 10 GB of FREE storage
  2. Cloudflare

    • Service is completely FREE
    • Provide edge caching.

Here’s are the steps

  • Create a storage bucket in Backblaze.
  • Connect your Cloudflare DNS with above bucket via some route.
  • Enable Cloudflare edge caching to this route.
  • Now you can upload to bucket with filename as key and file data as value.
  • Get/serve your value/file from Cloudflare route, to act as cache.

Cost Estimation

Let’s take an example of 10 billion entries of 1KB each with 100 billion reads (I know it’s massive)

DynamoDB

  1. On-demand pricing of DynamoDB
    • $0.25 per GB of storage
    • $1.25 per million write requests
    • $0.25 per million read requests
  2. Calculations
    • 10 billion * 1 KB = 10 TB of storage * $0.25 per GB => $2,500
    • 10 billion inserts * $1.25 per million inserts => $12,500
    • 100 billions reads * $0.25 per million reads => $25,000

Total = $2,500 + $12,500 + $25,000 = $40,000

Backblaze + Cloudflare

  1. Backblaze cloud storage

    • $5 per TB of storage
    • Unlimited FREE inserts/uploads
    • $0.004 for 10k reads
  2. Considerations

    • Cloudflare DNS and edge caching is completely FREE
    • 90% of reads will be from Cloudflare cache, which is FREE. So only 10% will hit Backblaze bucket and get charged
    • Cloudflare, Backblaze are in bandwidth alliance, which gives us zero egrees fees for these files.
  3. Calculations

    • 10 billion * 1 KB = 10 TB of storage * $5 per TB => $50
    • 10 billion inserts * Unlimited FREE inserts => $0
    • 100 billions reads * $0.004 per 10k reads * 0.1 (10% of reads) => $4,000

Total = $50 + $0 + $4,000 = $4,050

$40,000 => $4,000

10x decrease 🤯


In Conclusion…

I know this is completely theoretical. And also I didn’t take into account many things while calculating numbers, provisioned capacity, FREE tiers and etc.

But I would say, if you would leave it aside, and if you can afford little higher latency, and some caveats, then I think this can work as cache, alternative to DynamoDB, Redis.


That’s it! Please let me know about your views and comment below for any clarifications.

If you found value in reading this, please consider sharing it with your friends and also on social media 🙏

Also, to be notified about my upcoming articles, subscribe to my newsletter below (I’ll not spam you 😂)

Blog of Codes | Rahul | Substack

Articles about cloud architecture and programming. Click to read Blog of Codes, by Rahul, a Substack publication. Launched a month ago.

favicon blogofcodes.substack.com

You can find me on Twitter and LinkedIn ✌️

Top comments (0)