Deep dive in Redis based services in AWS
I have always enjoyed trying out new AWS services and doing many labs to learn and teach my students. However, I often come across a wide variety of services with similar use cases; for this reason, I want to show you what I have seen in the Cache database services offered by AWS.
In this article, we will go through the below-mentioned points:
- Introduction to common application architectures.
- Common application architecture on AWS.
- Common application architecture on AWS with Cache layer.
- Amazon Elasticache for Redis vs Amazon MemoryDB for Redis services.
- Caching Strategies in Amazon ElastiCache.
- Caching Strategies in Amazon DynamoDB Accelerator (DAX).
- Combining layers of cache and durable storage.
1. Introduction to common architectures.
I want to explain from my point of view how we can understand the Amazon ElastiCache and Amazon MemoryDB for Redis services, but to achieve this goal, we have to think of a standard architecture of an application where we can see some components as seen in the image:
Usually, we will need a persistent database for information (Durable Storage) in architecture, whether relational or non-relational. However, as the traffic of our application increases, it makes much sense to implement an intermediate layer between the backend and the durable storage. Here is where the cache comes into play, which will help us reduce response times to the backend. With this new component, the architecture would be as follows:
2. Common application architecture on AWS
To understand how we could bring these architectures to a cloud provider like AWS, we must associate the services that could help us in each of the layers:
- Amazon API Gateway: It is a managed service to manage an API, which can be RESTful or WebSocket.
- Amazon Elastic Kubernetes Service (EKS): It is a service that enables the deployment, management, and execution of large-scale applications on Kubernetes.
- Amazon Elastic Container Service (Amazon ECS): A container orchestration service created by AWS enables the deployment, management, and execution of large-scale applications.
- AWS Lambda: It is a serverless service that allows code execution on-demand from events.
- Amazon DynamoDB: It is a serverless, non-relational key-value database that is designed for large-scale, high-performance workloads.
- Amazon DocumentDB: It is a database service based on workloads compatible with MongoDB.
3. Common application architecture on AWS with Cache layer
In our common application architecture, we add AWS cache services for databases, which will act between the backend layer and the durable storage layer.
- Amazon DynamoDB Accelerator (DAX): It is a fully managed and highly available in-memory cache for Amazon DynamoDB.
In this scenario, the cache layer acts to handle volatile or temporary data, which will be consumed by the backend. For this to happen, a caching strategy must be established.
4. Amazon Elasticache for Redis vs Amazon MemoryDB for Redis services
Below I make a comparison between the two in-memory database services with Redis that are in AWS:
5. Caching Strategies in Amazon ElastiCache
Caching Strategies Amazon ElastiCache When working with ElastiCache You must determine how the cache layer will be fed with data from durable storage.
5.1 Lazy Loading
Only the necessary data is loaded into the cache.
If the data is in the cache layer, there is a cache hit, and it responds directly to the application.
If the data is not in the cache layer, it has to fetch it from durable storage and then store it in the cache.
All data from durable storage is stored in the cache layer.
6. Caching Strategies in Amazon DynamoDB Accelerator (DAX)
5.1 Write Operations
When executing the following write operations on DynamoDB, the data is automatically written in the Dynamo table, and in DAX, they are write-through operations:
7. Combining layers of cache and durable storage
In this scenario we can combine the cache and durable storage layers, to achieve this goal we must use the Amazon MemoryDB for Redis services which will provide us with the functionality of very fast access to data and persistent storage.
In this scenario, we do not need caching strategies.
- Another essential criterion to consider is the cost of each of the services, so it is important that you can check the price of Amazon ElastiCache for Redis and Amazon MemoryDB for Redis services.
- In a key-value persistent scenario, we can combine the cache and durable storage layers.
- Before defining which database to use, you should review the Well-Architected framework in the Performance Efficiency pillar to determine the best database solution for a system based on requirements for availability, consistency, partition tolerance, latency, durability, scalability, and query capability.