Amazon ElastiCache for Redis
Overview
AWS ElastiCache is a fully managed caching solution that works with Redis and Memcached. Redis (Remote Dictionary Server) is a distributed, in-memory key-value database, cache, and message broker with configurable persistence. Strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices are among the abstract data structures supported by Redis.
ElastiCache is a fully managed Redis platform that makes it simple to build, manage, and scale high-productivity distributed in-memory central data clusters.
What is Redis?
Redis, Remote Dictionary Server, is a key-value data store that is quick, open source, and in-memory. Salvatore Sanfilippo, the original Redis developer, began the project to increase the scalability of his Italian firm. He went on to create Redis, which is used as a database, cache, message broker, and queue today.
Redis provides sub-millisecond response speeds, allowing millions of queries per second for real-time applications in gaming, advertising, finance, healthcare, and IoT. Redis is now one of the most popular open-source engines, having been selected as the "Most Loved" database by Stack Overflow for five years.
Redis is a popular choice for caching, session management, games, scoreboards, real-time analysis, geolocation, ride-hailing, messaging, video streaming, and other applications because of its quick speed.
AWS provides two fully managed Redis services. Amazon MemoryDB for Redis is a Redis-compatible, long-lasting in-memory database service with lightning-fast performance. Amazon ElastiCache for Redis is a fully managed caching solution that provides microsecond latency data access from main databases and data storage. In addition, ElastiCache supports Memcached, another famous open-source caching engine.
Introduction to Amazon ElastiCache for Redis
Amazon ElastiCache for Redis is an in-memory data structure service that is Redis-compatible and may be used as a data store or cache. It combines Redis's ease of use and power with its reliability, stability, and portability to run the most demanding applications.
The service is fully managed, scalable, and secure, making it an excellent choice for powering high-performance use cases, including Websites, Mobile Applications, Pharmaceutical Apps, Banking Apps, Entertainment, Ad-Tech, and the Internet of Things (IoT). Deployment, patching, backups, restoration, fault diagnosis, and maintenance are no longer time-consuming procedures.
The service automatically identifies and recovers from node failure or engine breakdowns. ElastiCache for Redis enables you to deploy replica nodes across different AWS Availability Zones for maximum availability by utilizing Multi-AZ with automated failover. If a primary node fails, it will fail over to one of up to five read replicas.
With a few clicks, you may rapidly launch and set up a Cache Cluster or Replication Group in the AWS Management Console. We have a variety of node sizes available, as well as push-button vertical scaling - you may start with 555 MiB of RAM and scale up to 635.61 GiB of RAM.
How does it Work?
A cluster is the foundation of ElastiCache for Redis. It consists of one or more cache nodes collectively running the Redis cache engine. When you build a cluster, you provide the engine and version that all nodes will use. A cluster may be created and modified using the AWS CLI, the API, or Management Console.
Each ElastiCache for Redis cluster employs a different Redis engine version. Each Redis engine version supports different functionality. Furthermore, each Redis engine version has a set of settings in a parameter group that governs the performance of the managed clusters.
A cluster's instance or node type determines its computing and memory capacity. You can choose the node type that best matches your requirements. You can alter node types as your needs evolve.
You may also use data tiering when assessing your node type requirements. Data tiering is a feature that stores some of the least often used data on disk to alleviate memory constraints on applications that can accept higher delay when data on SSD (solid state drives) is accessed.
Terminologies
Amazon ElastiCache implemented the capability for dividing your data into up to 500 shards at a time. AWS extended the API version operations to incorporate the new Redis capabilities to maintain compatibility with earlier versions.
At the same time, AWS began using terminology in the ElastiCache console that is commonly used across the industry. These changes mean that at some points, the terminology used in the API and CLI might be different from the terminology used in the console. The following list identifies terms that might differ between the API and CLI and console.
Node vs. Node Cache Cluster
- There is a one-to-one relationship between a node and a cache cluster when there are no replica nodes. Thus, the ElastiCache console often used the terms interchangeably. The console now uses the term node throughout. The one exception is the Create Cluster button, which launches the process to create a cluster with or without replica nodes.
- The ElastiCache API and AWS CLI continue to use the terms as they have in the past.
Replication Group vs. Cluster
The console now refers to all ElastiCache for Redis clusters as clusters. In all of these cases, the console uses the word cluster:
- When the cluster consists of a single node of Redis.
- When the cluster is a Redis cluster (cluster mode deactivated) that permits replication inside a single shard (in the API and CLI, called a node group).
- Whenever the cluster is a Redis cluster with replication capabilities for shards or up to 500 with an increase in the limit through user requests.
The diagram below shows the various configurations of ElastiCache for Redis clusters, as seen from the console.
The ElastiCache API and AWS CLI actions continue to differentiate between single-node ElastiCache for Redis clusters and multi-node replication groups. The graphic below depicts the different ElastiCache for Redis topologies as seen using the ElastiCache API and AWS CLI.
Global Datastore vs. Replication Group
A global datastore is a group of one or more clusters replicating each other across AWS regions. In contrast, a replication group replicates data across many shards in a cluster mode-enabled cluster. A global data store is made up of the following components:
- A primary (active) cluster accepts updates replicated to every cluster in the global data store. The primary cluster allows reading requests as well.
- A secondary (passive) cluster accepts only reads requests and replicates data changes from a primary cluster. A secondary cluster must be located in a separate Amazon Web Services region from the parent cluster.
Features of Amazon ElastiCache for Redis
-
Simpleness of Use:
It's simple to get started using Amazon ElastiCache for Redis. Simply use the AWS Management Console or a single API request to create a new Cache Cluster or Replication Group. Cache Parameter Groups offer granular management and fine-tuning of your Redis environment, and resources are pre-configured with the relevant parameters and settings. Without further preparation, you may launch a Redis resource and connect your application in minutes. -
Redis is Completely Managed:
Redis automates time-consuming administration chores like software patch management, failure detection, and recovery so you can focus on higher-value application development. You still have native access to the underlying Redis in-memory database environment, which makes it simple to utilize Amazon ElastiCache for Redis alongside your existing Redis tools and apps. -
Metrics and Monitoring:
Amazon CloudWatch metrics give free visibility into your Redis resources. Using the AWS Management Console, you can examine over 20 critical operational data for your Redis instances, including compute, used memory, cache hit ratio, active connections, Redis replication, and Redis commands. -
Notifications of Events:
Important events such as snapshot completion and scheduled node replacements can be alerted through email or SMS. You may subscribe to various events connected with your Redis resources using the AWS Management Console or APIs. -
Tagging:
Use the option to tag your Cache Clusters and Redis snapshots for tracking and billing. The Cost Explorer may be used to assign costs to resources, and Resource Groups can be used to simply build and manage groupings of resources with similar tags. -
Several Availability Zones:
Utilize Multi-AZ with an automated failover feature to increase availability. To increase availability and grow beyond the read capacity restrictions of a single node, you can use several AWS Availability Zones.
Amazon ElastiCache for Redis Use Cases
Cache, messaging, game scoreboards, geolocation, ML, media streaming, queuing, real-time analysis, and session storage are all excellent uses for Amazon ElastiCache for Redis.
-
Caching:
Amazon ElastiCache for Redis is a fantastic option for creating a highly available, scalable, and secured in-memory cache to minimize access time, increase throughput, and relieve pressure on relational applications and NoSQL databases. ElastiCache may provide frequently requested items in milliseconds and helps you to rapidly scale for larger loads without increasing the much more costly backend storage. ElastiCache for Redis is commonly used for SQL queries output caches, continuous session caching, and comprehensive caching. -
Messaging and Chatting:
AWS ElastiCache for Redis handles the PUB/SUB standard with pattern matching. This enables ElastiCache for Redis to help with high-performance chat rooms, factual statement streaming, and server interconnectivity. PUB/SUB can also be utilized to take actions based on events that have been published.
-
Leaderboards in Gaming:
Amazon ElastiCache for Redis simplifies the creation of real-time gaming leaderboards. Simply utilize the Redis Sorted Set data structure to maintain element uniqueness while sorting the list by their scores. To generate a real-time ranked list, just alter a user's rank each moment it changes. Sorted sets may also handle time series information by assigning a score based on timestamps. -
Geospatial:
Amazon ElastiCache for Redis provides in-memory data structures and operators that are purpose-built for managing real-time geospatial data at speed and scale. ElastiCache for Redis may offer location-based capabilities to your apps, such as driving duration, drive distance, and places of interest.
Amazon ElastiCache for Redis Pricing
With AWS ElastiCache, you just pay for what you consume, and there is no minimum price. You are charged hourly depending on the number of nodes, the kind of node, and your chosen price plan.
ElastiCache offers both on-demand and reserved nodes. On-demand nodes allow you to pay by the hour with no long-term obligations, while reserved nodes give discounts to clients who commit to one-year or three-year periods. You may also have to pay for backup storage, data transfer within or between regions, or the usage of AWS Outposts.
Free Tier:
-
Amazon ElastiCache is available for free as part of the AWS Free Tier. New AWS users receive 750 hours of ElastiCache cache.t2.micro or cache.t3.micro node usage for free for up to a year when they sign up.
-
AWS Free Tier applies to participate services across the global regions. Your free usage under the AWS Free Tier is calculated each month across all regions and automatically applied to your bill – free usage does not accumulate.
Nodes on Demand:
On-demand nodes are charged for memory capacity by the hour with no long-term obligations. This strategy relieves you of the expenses and hassles of designing, procuring, and maintaining hardware, as well as assists in transforming high, fixed expenditures into smaller variable costs. You are charged hourly for on-demand nodes from the moment they are launched until they are stopped.
Reserved Nodes:
Reserved Nodes substantially reduce the hourly use fee for the node(s) you reserve for one or three years. You have the option with reserved nodes to:
- Pay modest hourly rates with no up-front fees.
- Make a one-time, partial advance payment in exchange for decreased hourly rates.
- Pay everything up ahead for significantly reduced hourly rates.
Storage for Backups:
The storage associated with automatic and user-initiated snapshots is known as backup storage. Amazon ElastiCache offers free storage for one snapshot for each active ElastiCache for the Redis cluster. Extra backup storage costs $0.085 per GB per month. The data transmission for making and restoring snapshots is free. Only ElastiCache for Redis offers backup storage.
Getting Started with Amazon ElastiCache for Redis
Step - 1: Create an AWS Environment
Before using the Amazon ElastiCache Redis service, you must create an AWS environment. Here's a brief tour of how to accomplish that:
-
Firstly, set up an EC2 instance that will execute an application on the Redis cluster. For simplicity, we will use the AWS default VPC for instance and cluster.
-
When the EC2 instance has started running, go to its information and get the "Public IPv4" address as shown below, which will be used afterward to access the site.
-
The security group assigned to the EC2 instance should permit two custom TCP inbound rules: one for the Redis port range 6379 and a second for the application on the TCP port range 5000.
Step - 2: Set Up Amazon ElastiCache from AWS Management Console
- Click the "Get Started Now" button as shown below. Use the same AWS Region as the EC2 instance for the Redis cluster, as shown in the upper right corner.
- To start, choose "Redis" as the Cluster Engine.
- Provide a name to the Redis Cluster and use the default AWS Cloud region.
- From the various ElastiCache instance types, choose your preferred type.
- Now, after selecting your various choices for the Redis settings, move ahead, as shown below.
- Under "Advanced Redis settings", provide a meaningful name to the subnet group as shown below.
- Now select the already created security group, that was provided to the AWS EC2 instance, in the Security panel area.
- After reviewing all the selected parameters, click on the "Create" button.
- After ensuring that the AWS Redis Cluster is operational, copy the primary endpoint URL, which will be utilized by the Website later. Now you have learned how to set up AWS ElastiCache for Redis and create a Redis cluster.
How to Use the AWS Redis Service?
When storing and maintaining the session data of users is required, scalable web applications frequently employ Redis as a session store. In this example, we will use a simple web application that enables visitors to log in and log out and uses Redis to store their session data.
-
To install the relevant tools and dependencies for the application, open an interactive remote SSH connection to the EC2 instance you previously deployed and perform the following commands:
-
Set the environment variables for Redis URL, Flask application, and secret key for the application. The value of the Redis URL will be the Primary Endpoint value already created. The Python file of the web application example should be the target of the FLASK_APP variable. Since the sample application uses the SECRET_KEY value as a seed to generate the session, it may be set to any arbitrary text.
-
Use the following command to launch the sample web application: flask run -h <custom TCP dns> -p <custom TCP port no.> --reload
-
Just use the Public Domain Name Server (DNS) name of the AWS EC2 instance to connect to the web application while the application is running in the background.
-
Log in to the application using the /login endpoint using any random credentials and refresh the page a few times. You will notice that the number of visits will increment every time the same user visits, and if you allow 10 seconds to elapse without refreshing the page, the counter will be reset to 1.
-
Under the hood, logging into the application generates a unique token that represents the Redis key under which the user session data will be stored in the cluster. Every user's access to the web page will increment the counter in Redis with the number of visits. Since the web application sets a Time to Live (TTL) of 10 seconds for the user data stored in Redis, the session and user counter will be automatically reset after the time elapses.
Benefits
-
Superior Performance:
The most demanding apps needing response speeds under a millisecond can be supported using Amazon ElastiCache for Redis, which functions as in-memory data storage. In-memory data stores handle data in memory, which is an order of magnitude quicker than disk-based databases, where most operations require a roundtrip to the disk. -
Secure:
ElastiCache allows you to create and manage users and user groups that may be used to set up Role-Based Access Control (RBAC) for AWS Redis commands, as of Amazon ElastiCache for Redis version 6. Now you can manage groups more effectively while preserving security boundaries in your design, thanks to granular access control. -
Fully Managed and Hardened:
ElastiCache for Redis from Amazon is an entirely managed service. Management chores are no longer required, including configuring, patch management, installation, installation, management, failure restoration, and archiving. ElastiCache keeps an eye on your clusters to keep Redis up and running, allowing you to concentrate on developing higher-value applications. -
Redis Compatible:
Redis is a well-adopted in-memory data store that may be used as a leaderboard, message broker, queue, database, cache, and session store. The open-source Redis data formats, Redis APIs, and Redis clients continue to be compatible with Amazon ElastiCache for Redis. Without changing any code, you may move your independently managed Redis workloads to ElastiCache for Redis.
-
Highly Accessible and Reliable:
Amazon ElastiCache supports both cluster and non-cluster modes for Redis, which also offers high availability via support for automated failover by identifying primary node failures and quickly promoting a replica to be primary. -
Scalability:
You may start small and scale your Redis data effortlessly with Amazon ElastiCache for Redis as your application expands, all the way to the top to a cluster with 310 TiB of in-memory data or 982 TiB when employing clusters with data tiering. Your Redis Cluster setup may be scaled up to 500 nodes and 500 shards using this.
Conclusion
-
Redis is a key-value database, cache, and message broker that runs in memory and has adjustable persistence. Redis supports abstract data structures such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices.
-
ElastiCache for Redis is a fully managed platform that makes it simple to create, maintain, and grow a high-performance distributed in-memory data store cluster. These features have the potential to drastically reduce the operational overhead associated with machine maintenance, software patching, monitoring, failure recovery, and backups.
-
Implementing a caching solution may greatly improve the performance of your cloud-native apps while lowering the expenses associated with data access latency and general inefficiencies.
-
You can take advantage of managed Redis' speed and ease of use along with customizations, with AWS ElastiCache for Redis.
-
With cluster mode enabled, Amazon ElastiCache for Redis provides online cluster scaling, allowing you to expand and scale the Redis clusters without latency and respond to changing demand.
-
Your operational overhead may be reduced while improving performance and user experience using a tool like AWS ElastiCache for Redis.