‫Let's talk about Amazon ElastiCache.
‫So the same way you get RDS
‫to have managed relational databases,
‫ElastiCache is going to help you get
‫managed Redis or Memcached
‫which are cache technologies.
‫So what are caches?
‫Well, they are in-memory databases
‫with really high performance and low latency.
‫And what the cache will help you with is
‫to help reduce the load off of databases
‫for read intensive workloads.
‫The idea is that the common queries are going to be cache,
‫and therefore your database will not be queried every time.
‫Just your cache can be used
‫to retrieve the results of these queries.
‫What this also helps you do is
‫makes your application stateless
‫by putting the state of your application
‫into Amazon ElastiCache.
‫And because we have the same benefits our RDS,
‫AWS will take the same maintenance
‫of the operating system, the patching,
‫the optimization the setup, configuration,
‫monitoring, failure recovery and backups.
‫Now, if you use Amazon ElastiCache
‫just so you know that it will require you
‫to do some heavy application code changes
‫for your application.
‫This is not something just enable
‫and off you go, you have a cache.
‫You need to change your application to query the cache
‫before or after querying the database.
‫And we'll see the strategies in a minute.
‫So now let's talk about
‫the architecture for using ElastiCache.
‫And there can be many, but I'm just giving you an example.
‫So, let's say we have Amazon ElastiCache
‫and RDS database and your application.
‫The application will query ElastiCache
‫to see if the queries are already being made.
‫And if it has already been made,
‫and it is stored in ElastiCache,
‫then it's called a cache hit.
‫And then it just gets the answer
‫straight from Amazon ElastiCache.
‫And we were saving a trip
‫to the database to do the query.
‫Now, in case of a cache miss,
‫then we need to fetch the data from the database.
‫So we're going to read it from the database.
‫And then for other application or other instances
‫where the same query will be made
‫we can write the data back into the cache
‫so that such as the same query next time
‫will result in a cache hit.
‫The idea is that it will help relieve load
‫from your RDS database.
‫And because you're storing data in the cache
‫there must be a cache invalidation strategy
‫to make sure that only the most current data
‫is used in there.
‫And this is the whole difficulty
‫around using caching technologies.
‫Another architecture is around storing the user session
‫to make your application stateless.
‫So the idea is that your user will do a login
‫into any kind of your applications,
‫and then the application will write the session data
‫into Amazon ElastiCache.
‫Now, if your user is redirected
‫to another instance of your application
‫then your application can retrieve the session cache,
‫the session directly from the Amazon ElastiCache
‫And therefore your user is still logged in,
‫and doesn't need to log in one more time.
‫And so the idea is that
‫now you made your application stateless
‫by writing the session data
‫of your user into Amazon ElastiCache.
‫So if we compare Redis and Memcached, what do we have?
‫Well, for Redis, we have Multi AZ with Auto-Failover,
‫and we have Read Replicas if you wanted to scale the reads
‫and have high availability.
‫So this looks a lot like RDS.
‫We have data durability using AOF persistence,
‫and we have backup and restore features.
‫So again, Redis is all about data durability.
‫And feature wise as a cache,
‫it supports sets and sorted sets
‫which are keywords you can also look for at the exam.
‫So here I'd like to show Redis
‫as a cache that gets replicated
‫that is highly available and durable.
‫Whereas Memcached is using multi-node
‫for partitioning of data.
‫So it's called sharding.
‫There is no high availability,
‫there's no replication happening.
‫It's not a persistent cache.
‫There is no backup and restore.
‫And this is a multi-threaded architecture.
‫So we have multiple instances altogether
‫working in Memcached with some sharding.
‫So the idea here that you need to remember
‫is that Redis really is here
‫for high availability, backup, read replicas,
‫this kind of stuff.
‫Whereas Memcached is a pure cache that's distributed
‫where you can afford to lose the-
‫You lose your data, there's no high availability,
‫and there's no backup and restores.
‫So these are the main differences that you're going to have
‫between the two technology.
‫So that's it.
‫I hope you liked it,
‫and I will see you in the next lecture.