Struggling with caching? Make it Serverless!

Flavio Maggi
Storm Reply
Published in
8 min readAug 8, 2024

In today’s fast-paced digital world, businesses need high-performance, scalable solutions to handle their growing data needs. That’s where Amazon ElastiCache comes in — a managed caching service that speeds up application performance. Recently, Amazon Web Services (AWS) has taken this offering a step further with the introduction of ElastiCache Serverless, an innovation that promises to simplify cache management and optimize resource usage.

In this article, we will start by giving you an overview on the caching concept and main examples, then we’ll talk a bit about Redis, a widely adopted in-memory data store for use as cache, and finally we will delve into the AWS world talking about the core features of ElastiCache Serverless for Redis.

Join us as we look at the future of serverless caching and see how Amazon ElastiCache Serverless can take your application’s performance to the next level.

Okay cool but what do you mean with “caching”?

There are only two hard things in Computer Science: cache invalidation and naming things.

— Phil Karlton

Caching is a technique used in computing to store copies of data or computations in a temporary storage location, called a cache, so that future requests for that data can be served faster.

Caching is important for several reasons, primarily centred around performance optimisation, efficiency, and user experience that have a significant impact on applications, making the concept of caching a central topic in system development and design. Here are the key reasons why caching is essential:

1. Performance Improvement

  • Reduced Latency: Caching stores frequently accessed data in a temporary storage closer to the user or application, significantly reducing the time it takes to retrieve data.
  • Improved Throughput: By offloading repeated data retrieval tasks to the cache, the system can handle more requests per second, enhancing overall throughput.

2. Resource Efficiency

  • Reduced Backend Load: Caching reduces the load on primary data sources such as databases and APIs. This enhances the performance of these systems but also reduces the need for frequent scaling.

3. Cost Savings

  • Scalability without high costs: Caching allows systems to scale efficiently without a corresponding increase in cost. By serving many requests from the cache, fewer expensive compute resources are needed.

4. Enhanced User Experience

  • Faster Load Times: For web applications, faster data retrieval translates directly into quicker page load times, improving the user experience and satisfaction.
  • Smooth Performance: Consistent and fast performance, even under high load, ensures a smoother and more reliable user experience.

5. Availability and Reliability

  • Offline Access: In some scenarios, cached data can be accessed even when the primary data source is unavailable, ensuring continuous service availability.
  • Failure Resilience: Caching can provide a buffer against backend service failures. If the primary source goes down, the cached data can still be served, improving system reliability.

Examples

  • Database caching

Database caching allows you to dramatically increase throughput and lower the data retrieval latency associated with backend databases, which as a result, improves the overall performance of your applications. The cache acts as an adjacent data access layer to your database that your applications can utilise in order to improve performance.

  • Session Management

HTTP sessions contain the user data exchanged between your site users and your web applications such as login information, shopping cart lists, previously viewed items and so on. Utilising a centralized session management data store is the ideal solution for a number of reasons including providing consistent user experiences across all web servers, better session durability when your fleet of web servers is elastic and higher availability when session data is replicated across cache servers.

  • Web Caching

When delivering web content to your viewers, much of the latency involved with retrieving web assets such as images, html documents, video, etc. can be greatly reduced by caching those artifacts and eliminating disk reads and server load.

  • Content Delivery Network (CDN)

When your web traffic is geo-dispersed, it’s not always feasible and certainly not cost effective to replicate your entire infrastructure across the globe. A CDN provides you the ability to utilise its global network of edge locations to deliver a cached copy of web content such as videos, webpages, images and so on to your customers. To reduce response time, the CDN utilises the nearest edge location to the customer or originating request location in order to reduce the response time.

Who’s this guy named Redis?

Redis is an in-memory data store known for its speed and versatility. It stores data in a key-value format, allowing for rapid data retrieval. Redis supports various data structures like strings, lists, sets, hashes, and sorted sets, making it flexible for different use cases. It also provides features such as persistence, replication, and high availability through clustering. Additionally, Redis is often used for caching, session management, real-time analytics, and messaging due to its low latency and high throughput.

Fun fact: Did you know that Redis means Remote Dictionary Server and that was an italian guy named Salvatore Sanfilippo, nicknamed antirez, that started the Redis project?

How can AWS help? Elasticache Overview

Amazon ElastiCache is a fully managed in-memory data store and caching service provided by Amazon Web Services (AWS). It is designed to improve the performance of web applications (and beyond) by enabling rapid retrieval of data from a fast, managed, in-memory cache.
ElastiCache supports two popular open-source caching engines: Redis and Memcached.

As a managed service, ElastiCache automates key tasks such as provisioning, patching, and maintenance, freeing developers to concentrate on their applications.
It also integrates with Amazon CloudWatch for real-time monitoring and performance metrics, providing valuable insights into cache health and usage.

One of the primary advantages of ElastiCache is its ability to deliver high performance with low latency, offering sub-millisecond response times and high throughput suitable for applications requiring fast, concurrent data access.
The service supports horizontal scaling, allowing users to add or remove nodes easily and use sharding (in Redis) to distribute data across multiple nodes. It also offers read replicas to improve read scalability.

ElastiCache ensures reliability and availability through features like Multi-AZ (Availability Zone) replication for Redis, which provides automatic failover in case of node failures.
Automated backups and point-in-time recovery for Redis further enhance data durability and protection against data loss.

Security is a crucial aspect of ElastiCache, with support for deployment within an Amazon Virtual Private Cloud (VPC), encryption of data at rest and in transit, and fine-grained access control using IAM policies and security groups.

Amazon ElastiCache is a robust, high-performance caching service that integrates seamlessly with AWS’s suite of services. Whether using Redis for its advanced data structures and persistence capabilities or Memcached for its simplicity and high-speed operations, ElastiCache offers a flexible and powerful solution to meet diverse caching needs.

Elasticache became Serverless! Let’s set-up together!

You can choose to design your own Redis cache cluster by choosing the EC2 node family, size, number of nodes, and placement across Availability Zones. When self-designing your cluster, you pay per hour for each cache node depending on the node-size and Region.

Or…You can stop focusing on the design of your cluster and just use it!
How? Make it serverless!

Starting from 27 November 2023, AWS offers ElastiCache for Redis Serverless a service that enables you to create a cache without worrying about capacity planning, hardware management, or cluster design. You simply provide a name for your cache and you receive a single endpoint that you can configure in your Redis client to begin accessing your cache.

Key Benefits:

  • No capacity planning: ElastiCache Serverless continuously monitors the memory, compute, and network bandwidth utilization of your cache and scales both vertically and horizontally. It scales without downtime or performance degradation to the application by allowing the cache to scale up and initiating a scale-out in parallel to meet capacity needs just in time.
  • Pay-per-use: With ElastiCache Serverless, you pay for the data stored and compute utilized by your workload on the cache. You pay for cached data in GB-hours, ECPUs consumed, and Snapshot storage in GB-months. No more paying in advance!
  • High-availability: ElastiCache Serverless automatically replicates your data across multiple Availability Zones (AZ) for high-availability. It automatically monitors the underlying cache nodes and replaces them in case of failures. It offers a 99.99% availability SLA for every cache.
  • Automatic software upgrades: ElastiCache Serverless automatically upgrades your cache to the latest minor and patch software version without any availability impact to your application. When a new Redis major version is available, ElastiCache will send you a notification.
  • Security: Serverless always encrypts data in transit and at rest. You can use a service managed key or use your own Customer Managed Key to encrypt data at rest.

Let’s see how to build it right from the AWS Console!

Spoiler: you will need less than 10 clicks!

Let’s start from the Elasticache service main page. As said before, we’ll focus on a Redis-based cluster (but the procedure you’ll see can be applied also to a Memcached-based cluster!)

Amazon Elasticache service homepage

You can choose if you want to create the cluster by yourself (Design your own cache) or choose the Serverless version.

Of course, we are going to choose the Serverless one!

The you can choose to use the default settings to create a cache in your default VPC, Availability Zones, service-owned encryption key, and security groups.

If you want to customize default settings, you can set your own security groups, or enable automatic backups. You can also set maximum limits for your compute and memory usage to ensure your cache doesn’t grow beyond a certain size. When your cache reaches the memory limit, keys with a time to live (TTL) are evicted according to the least recently used (LRU) logic.

And… That’s it!

Click the create button and you’re done!
You have your new cluster fresh out of the oven!

Conclusion

In short, caching is a game-changer for boosting app performance and efficiency by speeding up data retrieval and easing the load on backend systems. Amazon ElastiCache makes caching easy by managing everything for you. ElastiCache Serverless takes it a step further by removing the hassle of managing server infrastructure.

By using ElastiCache and ElastiCache Serverless, your apps can handle growing demands smoothly and keep users happy with quick, reliable performance.

Thank you very much for getting this far, I hope you found this article useful and inspiring!

Happy building!

--

--