Amazon ElastiCache

Learn via video courses
Topics Covered

Overview

Amazon ElastiCache is a cache-as-a-service (CaaS) that is created and distributed by AWS (Amazon Web Services). It is a web service that we use to deploy, operate, and scale a distributed in-memory cache or data store in the cloud. ElastiCache service boosts web application performance by allowing users to access data from quick, managed in-memory data stores rather than only using slower disk-based databases.

What is ElastiCache?

Amazon ElastiCache is a cache-as-a-service created by AWS that can deploy, operate, and scale a distributed data store or in-memory cache in the cloud. In other words, it deals with the complexity of establishing and maintaining a distributed cache environment. The system itself is designed to enhance the speed of web-based applications by reducing database load through fast data retrieval from data stores.

Now, let's understand as a beginner with the real-life example of caching. Suppose you have to prepare tea and require milk (data) for it. You will first check if there's any milk in the fridge (ElastiCache). If yes, you can easily use it to prepare tea. But if there's no milk in the fridge (data not present) or the milk is old (stale data which cannot be used), you need to go to a nearby shop and buy a packet of milk from there (analogous to fetching data from a database).

  • ElastiCache provides a high-performance, cost-effective, and scalable caching solution.
  • It is a distributed in-memory cache environment in the Amazon Web Services (AWS) Cloud.
  • Amazon ElastiCache supports two open-source in-memory engines : Redis and Memcached engines.
    • Redis : is an in-memory data structure store that offers a rich set of features. It is useful as a cache, queue, database, and message broker.
    • Memcached : is a distributed memory caching system that is designed for ease of use and simplicity and well suited for use as a cache or session store.

Global Datastore in Amazon ElastiCache for Redis provides fast, fully managed, reliable, and secure cross-region replication. Global Datastore enables low-latency reads and disaster recovery across regions by allowing you to write to your ElastiCache for the Redis cluster in one region and have the data available to be read from two other cross-region replica clusters.

An in-memory cache is a data storage layer placed between applications and databases to deliver responses quickly by storing data from previous requests or data that has been directly fetched from databases.

Components of ElastiCache

The following important components are available in the ElastiCache provided by AWS :

  • ElastiCache nodes :
    A network-attached, fixed-size chunk of secure RAM is referred to as a node. It is the smallest building block of an ElastiCache where each node has its DNS ( Domain Name System ) and port.
  • ElastiCache for Redis shards :
    A Redis shard is a group of 1 to 6 similar nodes. A Redis cluster can only have one shard. Redis clusters with the "cluster mode enabled" can have up to 500 shards, with your data partitioned among them.
  • ElastiCache for Redis clusters :
    It is the logical grouping of more than one ElastiCache. Data is divided into shards in a Redis cluster.
  • ElastiCache for Redis replication :
    2 to 6 nodes are grouped to implement replication in a shard. All the nodes are read-only replica nodes except one which is the primary node and supports both read/write operations.
  • ElastiCache for Redis Endpoints :
    The unique address your application uses to connect to an ElastiCache node or cluster is known as an endpoint.
  • ElastiCache parameter groups :
    Parameters are used to control item sizes, eviction policies, memory usage, and more. You can apply this collection of engine-specific parameters to a cluster as an ElastiCache parameter group.
  • ElastiCache for Redis security :
    ElastiCache for Redis node access is limited to applications executing on the Amazon EC2 instances that you allow for enhanced security.
  • AWS Regions and availability zones :
    We can create the cache and use it anywhere that meets our business needs. There are many AWS regions worldwide where Amazon ElastiCache is available.

How Does ElastiCache Work?

The user first hits the application server, then the Application server tries to fetch the updated data from the Amazon ElastiCache. If the updated data is present in ElastiCache, the application server will fetch the data from there. Otherwise, it will read from the actual database (Amazon RDS) and return to the application server. Now the application server has read the most updated data and it will now write the data to ElastiCache to avoid the hassle of reading that particular data from the Amazon RDS again.

how-does-elasticache-work

ElastiCache works as a real-time application in social media, gaming, ride-hailing, and media streaming, all of which require quick access. The data is also stored in a database that is used by the message broker, cash register, queue, and database. Ephemeral data can also be stored in memory by the user for response times under one millisecond.

Use Cases of ElastiCache

With the help of Amazon ElastiCache, in-memory data stores in the cloud can be set up, managed, and scaled to power real-time transactional and analytical processing use cases like caching, session storing, machine learning, and real-time analytics.

Caching

Amazon ElastiCache can be used as a highly accessible in-memory cache to reduce access latency, boost throughput, and lighten the stress on your relational or NoSQL database with response times of under a millisecond for either the Redis or Memcached engines. ElastiCache for Redis also provides full caching, continuous session caching, and query results caching.

caching

Real-time Analytics

To ingest, process, and analyze real-time data with sub-millisecond latency, combine Amazon ElastiCache for Redis with streaming services like Apache Kafka and Amazon Kinesis. ElastiCache can be utilized for real-time analytics use cases including time-series data analytics, social media, ad targeting, personalization, and IoT.

real-time-analytics

When users shop online, product recommendations must be generated right away while they are still browsing the catalog. This requires the customer's previously selected items to be cached and evaluated in real-time to suggest the next set of products.

Message Management

When a message is sent to subscribers through a particular network, there is constantly a fluctuation in the number of subscribers joining and canceling their subscriptions. Without a caching mechanism, there is a chance that messages will be delayed and possibly missed or lost. ElastiCache helps in maintaining the subscription status up to date and accurate.

message-management

Session Store

Redis and Memcached's session data can be managed using Amazon ElastiCache as session storage. This session management is commonly required for online applications, including games, social media platforms, and e-commerce websites.

session-store

Leaderboards (Redis Sorted Sets)

In the gaming business, the number of points that players have acquired and their place on the leaderboard is constantly updated. To be able to present the changing leadership positions continuously, there need to be continuous updates, therefore caching is crucial. Leaderboards' computational complexity is passed from your application to your Redis cluster through Redis sorted sets.

In Redis, sorted sets are a data type similar to sets in that both are nonrepeating groups of strings. The only difference is that each member is associated with a score, a floating-point number that provides a sorting order for the Sorted Set. Members are always sorted from the smallest score to the largest.

leaderboards

Amazon ElastiCache Pricing

  • You simply pay for the amount of Amazon ElastiCache that you use. As you scale up, this billing system raises your service costs.
  • When you use on-demand nodes, you only pay for memory capacity by the hour with no long-term commitments. You are billed hourly from the time a node is launched until it is terminated. The price depends on whether you are using Standard Cache Nodes or Memory Optimized Cache Nodes as well as the region.
  • For each node you wish to reserve for a term of one or three years, you can do so with Reserved Nodes by paying a small, upfront fee. In exchange, you get a substantial discount off the Node(s) you reserve's ongoing hourly usage rate depending upon the region and node type.
  • There are multiple payment options available with Reserved nodes. You can pay low hourly charges with no upfront payment or make a one-time, partial upfront payment with lower hourly charges or you can just pay all upfront for even lower hourly charges.
  • For each active ElastiCache for the Redis cluster, ElastiCache provides free storage space for one snapshot. There is a monthly fee of $0.085 per GB for additional backup storage.
  • When transferring data between an EC2 instance and an ElastiCache Node in different Availability Zones of the same Region, EC2 Regional Data Transfer fees of $0.01 per GB in/out are charged.
  • Data Transfer OUT from Amazon ElastiCache Global Datastore is charged at the rate of $0.02 per GB of data.
  • You can get started with Amazon ElastiCache for free as part of the AWS Free Tier and receive 750 hours of free cache.t2.micro or cache.t3.micro node usage for 12 months.

Advantages and Disadvantages of ElastiCache

Advantages

  1. Fully-managed :
    The cloud-based ElastiCache solution is fully managed. As a result, you can take advantage of the advanced caching features without having to worry about backups, setups, monitoring, configuration, software patching, failure recovery, or hardware requirements. All of that will be taken care of while the service continuously monitors your clusters to keep Redis running smoothly.
  2. Highly available :
    AWS ElastiCache uses automatic failover detection and mitigation, in addition to running in both cluster and non-cluster modes, to achieve high availability. For example, standby replicas immediately take over when a primary node fails. Similar rules apply to reading operations, if the primary replica is busy, the read replicas step in to serve the data and keep your application operating smoothly.
  3. Easily scalable :
    With Amazon ElastiCache, you can start small and gradually expand your functionalities as the application grows. For instance, you can increase the size of your Redis cluster to up to 500 shards, 500 nodes, and perhaps even 340TB of in-memory data. Then, without any type of downtime, you can easily scale down the resources if you need to lower costs.
  4. Improves application performance :
    ElastiCache offers in-memory data stores that significantly lower the overall response times, whereas a disk-based database would require your applications to make time-consuming roundtrips to retrieve information. The improvement is so meaningful that typically read or write operations now take less than a millisecond. This means you should be able to comfortably run demanding web applications that require quick real-time responses.

Disadvantages

  1. Expensive :
    Although the pricing structure for AWS ElastiCache is pretty flexible and only charges you for what you use, the costs can quickly mount over time. After using it for about a year, a medium-sized business might find itself paying thousands of dollars each month.
  2. Learning curve :
    Beginners on Amazon ElastiCache might need some time to get the hang of things. The user interface is not very user-friendly, and when you first start using it, all the options may seem a little overwhelming.
  3. Limited to Amazon-Hosted Services :
    ElastiCache doesn't have many integration options because it is an AWS service. It is only compatible with databases and programs that are hosted by Amazon.

ElastiCache vs. Redis, CloudFront, And DynamoDB

Redis, CloudFront, and DynamoDB are sometimes confused with ElastiCache. Even though they each exist separately, it may be difficult to tell their differences apart because they are all somehow related to cloud caching. The truth is that ElastiCache is very different from each of these services. Here is a comparison of them.

AWS ElastiCache vs. Redis

Amazon ElastiCache can deploy, operate, and scale a distributed in-memory cache or data stored in the cloud. It deals with the complexity of establishing and maintaining a distributed cache environment and enhances the speed of web-based applications by reducing database load through fast data retrieval from data stores.

Redis ( Remote Dictionary Server ), on the other hand, is a quick, in-memory, open-source, BSD-licensed key-value data store. It is frequently used as a database, cache, message broker, and queue. ElastiCache has support for Redis.

AWS ElastiCache vs. CloudFront

Although both AWS ElastiCache and AWS CloudFront are caching solutions, there are major differences between their strategies and overall frameworks.

ElastiCache improves web application performance by quickly collecting data from fully-managed data stores. It makes use of Memcached and Redis and significantly shortens the time it would otherwise take for your applications to read the data from a disk-based database.

On the other hand, CloudFront also seeks to enhance web applications’ performance but contradictory to ElastiCache, it acts as a CDN ( Content Delivery Network ), which increases the delivery of web-based assets through the endpoint caches placed near the traffic source (edge locations). In simple words, instead of entirely relying on the original hosting server, your web users load content from the nearest caching server.

AWS ElastiCache vs. AWS DynamoDB

AWS DynamoDB is a completely managed NoSQL database service from Amazon. Administrators have avoided the hassle of establishing, managing, and scaling expensive distributed database clusters because DynamoDB is fully managed by AWS. AWS DynamoDB holds its data items in Solid State Drives (SSDs), which are then cloned across three availability zones for increased reliability and availability.

ElastiCache is Amazon's specialized "Caching-as-a-Service" since it provides a fully-managed in-memory cache that works with Redis and Memcached, whereas DynamoDB can be classified in the "NoSQL Database-as-a-Service" category.

Conclusion

  • Amazon ElastiCache is a cache-as-a-service that is hosted and managed by AWS.
  • ElastiCache is a web service that we use to deploy, operate, and scale a distributed data cache in the cloud.
  • ElastiCache service boosts web application performance by allowing users to access data from quick, managed data stores rather than only using slower disk-based databases.
  • Amazon ElastiCache deals with the complexity of maintaining a distributed cache environment and enhances the speed of web-based applications by reducing database load.
  • Amazon ElastiCache works as an in-memory data store and cache to handle the most demanding applications that demand sub-millisecond response times.
  • Some use cases of ElastiCache include caching, session storing, machine learning, and real-time analytics.