Implementing Redis Cache within AWS Lambda Function for better response latency: Part 1 — Overview

Pranab Sarkar
2 min readMar 19, 2021

--

AWS ElastiCache for Redis

In this post, we will discuss a simple use-case where we can improve the latency of any real-time application which depends upon any external data source.

Here, we will be using AWS ElastiCache with a Redis Cluster, API Gateway, Lambda Function to create the system architecture.

Overview

Why we are using Redis?

Redis is a fast in-memory data store that enables any real-time applications to achieve sub-millisecond latency to serve its users for any key requests.

What is the major challenge with an external data-dependent service?

During the down-time of the external data service, the real-time application can’t serve requests to its users.

What application we are going to build?

In this application, users can request to check the list of all available banks present in the queried zip-code using Cache Lazy-Loading Strategy.

Architecture

System Architecture for this Banking Application

Below are the steps where we have summarized the functionality of this application using different AWS services-

  1. The Website User requests the API Gateway endpoint to get the list of banks present in a particular zip-code.
  2. API Gateway triggers the lambda function to process the request and respond. Lambda checks the key (zip-code) in its in-memory Redis Cluster and there could be two scenarios — a. Cache Miss: If the key is not present inside the Redis Cluster, then Lambda Function will query the same from the External Data Source. Once the Lambda Function has successfully queried the data, the Redis Cluster will be updated with user-defined TTL and returned to the API Gateway. b. Cache Hit: Redis Cluster will return the values to the Lambda Function, then Lambda will pass it back to the API Gateway.
  3. API Gateway will return the response to the Website User.

Advantages of using Redis

  1. We can achieve sub-millisecond latency.
  2. Reduces the dependency on external data-source.
  3. It supports multiple data types and available with proper API documentation.
  4. It is open source and has decent developer community support.

Notes

In the next part as a continuation of this post, we will be discussing the setup, development, and deployment of this sample banking application using the AWS Serverless Application Model (SAM).

--

--