bene : studio is a global consultancy, helping startups, enterprises and HealthTech companies to have better product

Static caching based on cloud services

Static Caching

At bene : studio, we love knowledge sharing to help the community of professionals. With 10+ years and over 100 projects behind us, we have a vast amount of experience. This is why we have launched a knowledge base on our blog with regular updates of tutorials, best practices, and open source solutions.

These materials come from our internal workshops with our team of developers and engineers.

Pardon the interruption, we have an important message!

We are looking to expand our team with talented developers. Check out our open positions and apply.

Introduction

Caching is the process of storing data in a temporary storage referred to as a cache. A cache is a short-term computer memory that stores information for fast and easy retrieval.  In our previous article “How Can Caching Improve your Health App?” we described a caching strategy for computed data of our health apps.  But what if we are looking for a solution to improve the load time of static content? Yes, they are usually pictures, but you can think of any other static content. This article will look at the current Cloud static caching services, also known as Content Delivery Networks (CDNs).

Main caching targets

Optimal targets for caching are large-size items and pieces of content that never change, which are supplied by our server. If we can handle the request by not reaching the server at all, we can reduce our server-side requirements by a significant amount. Also, we can improve our load times in regions that are physically far from our server location (depending on caching service setup). But actually, any deterministic response— a response that does not change over time —   can be a good target for caching. For example, a response of our REST API is usually not deterministic over time. It can (and will) change based on many factors. But we can use caching for our API if we can identify a deterministic part of our service. 

Caching services

All major cloud services usually offer caching services. Therefore if you already use a cloud service provider, the easiest way to add caching services is just to use your current cloud provider. These services are usually well documented, but we will introduce them briefly in the following sections.

AWS CloudFront

CloudFront is a CDN service that works in collaboration with other AWS services.It delivers content through a worldwide network of data centers called edge locations. You can put Cloudfront before many of your AWS resources easily. Also, you can use Cloudfront before your http(s) resources outside of AWS as well. However, there are some tricks you need to be aware of. 

AWS puts Cloudfront automatically before some of AWS services. For example, you will reach API Gateway through Cloudfront automatically. There are some services where you can opt-in for Cloudfront. The most common situation is using it with static S3 content and making frequent S3 resource calls very fast. Interesting fact: you can’t put Cloudfront directly before your EC2 instance. So how to proceed if you want to have Cloudfront caching before EC2? You can put Load Balancer before your EC2 since Load Balancer can use Cloudfront. Also, you can use simple http(s) origin caching, but in this case, your EC2 http(s) port needs to be public-facing to the internet or update EC2 access based on the public Cloudfront IP address list. Using a custom SSL certificate is possible, and it can be super easy if you use AWS’s own certificate manager ACM.

Cloudfront setup is relatively straightforward, as you can see on the settings sample screenshot below.

Cloudfront pricing is based on the number of requests, transferred data amount, and Edge location.

Google Cloud CDN

Google Cloud CDN uses Google’s global edge network to serve content. It works with external HTTP(S) Load Balancing to deliver content to end-users. Like AWS, you can easily choose many different origins located inside Google Cloud, such as server instance groups, serverless network groups, and storage buckets. Note that you can’t specify sources, called Backend Services, outside Google Cloud for CDN. This means that Google Cloud CDN can be used only with other Google Cloud products. You can see an example Backend configuration which is using static Buckets as a source below:

Azure CDN

Azure Content Delivery Network is the CDN offered by Microsoft. As usually seen with Cloud providers, it is very well integrated with its own services like Storages, Static websites, and Web applications. It also supports a Custom origin (domain name or IP address). Azure CDN can also accelerate dynamic content, which cannot be cached, by leveraging various network optimizations, for example, route optimization. When selecting Pricing Tier, you can figure out that Azure CDN contains several types of sub-products, like

  • Azure CDN Standard from Microsoft
  • Azure CDN Standard from Akamai
  • Azure CDN Standard from Verizon
  • Azure CDN Premium from Verizon

They have some slight differences in features, but it can be a little bit confusing that so many options exist for a single service. Pricing is based on the transferred data and the Zone where the data is being transferred. Also, you need to pay a flat rate for Rules Engine separately.

Cloudflare CDN

Cloudflare has gained a reputation as a distributed-denial-of-service (DDoS) mitigation tool, and as such it has a proven capability to have a highly available content delivery network. The main idea of Cloudflare is that if you use their Domain Name Server (DNS), they will do some extra (hidden) tricks and don’t just let all requests reach your origin. This is how they mitigate DDoS attacks: if they think the actual request is not a valid request, just an attack, they will not forward it to your infrastructure. Also this setup ensures that they can solve caching easily, without any additional setup. You can exercise some control over how your content is cached, but the settings are much less detailed than its competitors (see screenshot below). This can be a good choice if you don’t use any other cloud service.

Conclusion

We walked through the most popular Content Delivery Networks in this article. There are many good services in the market, with slightly different capabilities. The rule of thumb is that if you already use a cloud service, you will probably find the CDN service there, and it will be the most effective solution to use. However, if you are trying to find a CDN for your actual custom origin, your options are limited, and you need to carefully check which service can offer the solution you are looking for.

Have a question? Send them to partner@benestudio.co and we are happy to set up a talk with our engineers.

Looking for a partner for your next project? Check out our services page to see what we do and let’s set up a free consultation.

Join Our Engineering Team, We Are Hiring!

Static Caching

Let bene : studio enhance
your digital product!