AWS ElastiCache for Redis

Michael Weeks
4 min readDec 10, 2019

ElastiCache for Redis is quite interesting when you understand the real world use cases for it. If you’ve ever done anything in SEO, you’ve come to the realization that your web pages need to load incredibly fast. Think about it. You’re on a third party website trying to buy a lamp and it takes forever to load. What do you do? You probably open up Amazon.com and buy a lamp on there in about 3 steps with incredibly fast load times.

How is this possible? This is where ElastiCache for Redis can help out. It can help out with delivering the latest news, a top-10 leaderboard (think iTunes or an Amazon top-selling product list), a product catalog, or selling tickets to an event. All of these things require immense speed. What does this mean for a business? The success of your business (especially ecommerce) is dependent on the speed at which you can deliver content.

To give you some perspective, the New York Times wrote an article on how the time of an eye blink is too long to wait for impatient web users. The human body can detect a 250 millisecond (¼ second) difference between loading various websites.

Amazon actually tested this and cited in a study that for every 100 milliseconds (1/10 second) increase in load time, sales decrease by 1%

This raises questions to a new level of can you afford to not cache your web pages to deliver them as quickly as possible (by way of the shortest latency). ElastiCache is used in the following ways to improve the overall performance of your application:

  • In-Memory Data Store
  • Gaming Leaderboards (Redis Sorted Sets)
  • Messaging (Redis Pub/Sub)
  • Recommendation Data (Redis Hashes)
  • Other Redis Uses

It’s important to know the above uses for Redis for the CSAA exam. Next we’ll walk through examples of each use case to paint a bigger picture.

In-Memory Data Store

An in-memory key-value store provides ultrafast (submillisecond-latency) and inexpensive access to copies of data. A common pattern in data stores is that they have data that’s frequently accessed but seldom updated (perfect for an in-memory data store). Alternatively, querying a database will always be slower and more expensive than locating a key in a key-value pair cache.

Database queries can be expensive to perform especially if they involve joins across multiple tables or queries with intensive calculations. By caching these query results, you only pay the price of the query once. Since the data is cached, there’s no need to re-execute the query. An analogy might look something like placing a take-out order for food so that when you go to pick it up, you don’t have to wait. The food is ready to go (or cached).

Leaderboards (Redis Sorted Sets)

Leaderboards are computationally complex for things like gaming and Amazon’s top sellers list. Amazon actually uses ElastiCache for that feature to populate the lists. Redis sorted sets remove the computational complexity of leaderboards from your application to your Redis cluster.

Complexity is added to these computations when there are a large number of concurrent players and constantly changing scores. Redis guarantees both uniqueness and element ordering with sorted sets. Each time a new element is added to a set, the set is reranked in real time. After that, it’s added to the set in correct numerical order.

AWS Documentation

Messaging (Redis Pub/Sub)

Think about when you send an email directly to one or more people. In the pub/sub paradigm, you actually send a message to a channel not knowing if anyone receives it. The recipients of the message are the subscribers to the channel.

Redis pub/sub functionality has no relation to key space so it doesn’t interfere on any level. Below is an illustration of ElastiCache for Redis.

Subscription is straightforward using Redis pub/sub. You can subscribe to a single channel, multiple channels, or all channels that match a pattern. To cancel a subscription, you simply unsubscribe.

Recommendation Data (Redis Hashes)

Redis uses INCR or DECR to make compiling recommendations simple. Each time a user ‘likes’ your product, you increment an item:productID:like counter and vice-versa with a dislike. Additionally, by using Redis hashes, you can maintain a list of everyone who liked/disliked a product.

Below is an example of using ElastiCache for Redis for a real-time analytics store.

Here are some customer testimonials of how customers use ElastiCache in their businesses.

--

--