To get the high performance, we generally cache the most frequent data in memory, Application developers can improve the performance of the application response when the most frequent data is saved in memory.
This features is provided by Amazon with the help of Amazon ElastiCache service.
It is the Web service that setup management of distributed in-memory caching environment for cloud based application. With the use of Amazon ElastiCache in your application, it helps to speed the deployment of cache clusters.
With the use of Amazon ElastiCache, large number of caching pattern can be implemented. The most common pattern is the cache-aside pattern shown in figure:
In this app servers check the cache first to check if the data available is in cache or not , and if required data is not in cache node , then it query to the database and write the query results to cache , now when next user want to read the data , they directly access form cache instead of querying database.
There are two types of Amazon ElastiCache which allow you to quickly deploy clusters: Memcached and Redis.
Memcached: It allow you to write and read object into in-memory Key/value data stores. With this you can elastically grow and shrink a cluster of Memcached nodes to meet your demands. Memcached data can be referenced as object and these objects can be accessed by a unique key. There are following version of Memcached starts from 1.4.5 to 1.4.24 which Amazon Elasticache supports.
Redis: Amazon ElastiCache supports to deploy Redis Clusters from version 2.8.24 to older versions. Redis supports rich set of data type’s likes strings, Lists, and sets. Redis has ability to persist in-memory data on to disk, which further helps to create snapshots that backup your data and then recover or replicate from backups. Redis clusters supports up to 5 read replicas to offload read requests. In case of failure of primary node, read replica can be promoted and become new master using Multi-AZ replication groups.
Node & Clusters:
When we deploy the Amazon ElastiCache, we generally deploy one or more nodes in cluster. A single Memcached cluster contains up to 20 nodes whereas Redis cluster always contains single node and multiple clusters can be grouped in to Redis replication group.
Individual nodes can be made from Amazon EC2 instance families like t2, m3, and r3 and depends upon your needs you can choose to have few large nodes or many smaller nodes in your cluster or replication groups.
Memcached Auto Discovery:
Amazon ElastiCache supports Auto Discovery which simplifies your application code in a such a way that it no longer need to be aware of the infrastructure topology of the cache cluster in application layer.
The Auto Discovery client gives your applications the ability to identify automatically all of the nodes in a cache cluster and to initiate and maintain connections to all of these nodes. The Auto Discovery client is available for .NET, Java, and PHP platforms.
Amazon ElastiCache allow you to scale in and scale out cache nodes based on your requirements. Scaling of cache nodes can be done horizontally to meet higher level of read and write performance. Where cache nodes can be scaled vertically of cache nodes.
Horizontal Scaling: In horizontally scaling with Memcached, you can partitioned your data and scale horizontally to 20 nodes or more. And with Redis , cluster consist of single node that is handling read and write transactions, additional clusters can be added and grouped in to Redis replication group. In this you can only have one nodes handling write commands, you can have up to 5 read replicas which only handles read requests.
Replication and Multi-AZ
Amazon Elasticache clusters running redis supports rapid recovery in event of node failure and also serves high volumes of read queries. Where as in Memcached they are standalone in-memory services without any redundant data protection services.
Clusters running Redis supports concepts of replication group which consists up to six clusters in which five of them are designated for read replicas. This allow you to scale horizontally by writing code in application to offload reads to one of the five clones.
Multi-AZ Replication Groups:
This replication groups is created to increase the data availability and minimize the loss of data. When a primary nodes fails it helps in replacement of failure nodes by selecting and promoting the read replicas to become primary and new nodes is provisioned to replace the failed one. Amazon ElastiCache will then update the DNS entry of new Primary node to allow application to continue processing without any configuration change.
Backup and Recovery:
Amazon ElastiCache clusters running Redis allow you to persist your data from in-memory to disk and create a snapshot. Each snapshot is a full clone of the data that can be used to recover to a specific point in time or to create a copy for other purposes. Snapshots cannot be created for clusters using the Memcached engine because it is a purely in-memory key/value store and always starts empty. Amazon ElastiCache uses the native backup capabilities of Redis and will generate a standard Redis database backup file that gets stored in Amazon Simple Storage Service (Amazon S3).