> For the complete documentation index, see [llms.txt](https://ysfang82.gitbook.io/development-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ysfang82.gitbook.io/development-notes/aws-notes/service/storage/elasticache.md).

# ElastiCache

Introduction

* In-memory data stores on AWS.
* Types:
  * Redis
  * Memcached

Feature

* AWS takes care of the OS maintenance / patching, optimizations, setup, configuration, monitoring, failure recovery and backups.
* Using ElastiCache involves heavy application code change.
* Scenario steps:
  * Lifting load from DB
  * If data found from cache, return data.
  * If data not found from cache, read from DB. Then write it to cache.
  * Must have an invalidation strategy to avoid consistency problem.
* ElastiCache - Memcached vs Redis
  * Memcached
    * Multi-node for partitioning of data (sharding)
    * Non-persistent
    * No backup and restore
    * Multi-threaded architecture
  * Redis
    * **Can scale up / down dynamically** through CLI / console
    * Multi AZ with auto-failover
    * With Read replicas to scale with high availability
    * Persistent durability:
      * Enable Append-only file ([AOF](https://redis.io/topics/persistence)) for manual backups: logs every write operation received by the server, that will be played again at server startup, reconstructing the original dataset.

![ElastiCache - Memcached, Redis](https://3303577320-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4cDbT2F2VmcAohuhSN%2F-MEOmZykWTOnFrxsAbG8%2F-MEOrZ62iJ1r9ElweoS1%2FScreen%20Shot%202020-08-11%20at%203.34.05%20AM.png?alt=media\&token=2409c0e1-4654-4ac6-b972-891f587d6ed9)

**Handling Extreme Rates**

![Extreme rates in AWS architecture](https://3303577320-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4cDbT2F2VmcAohuhSN%2F-MEOuQ9PTj8kO_cQv04-%2F-MEOwde2ZrfW8FhL6K9M%2FScreen%20Shot%202020-08-11%20at%203.53.58%20AM.png?alt=media\&token=0fb59082-82b4-4446-a897-b183812839b0)

* The more components are used in the right, more cost would occur. Try to utilize components in the left.
