welcome back to back space Academy in this lesson I'm going to go through the 2
elasticache service. We do also have two labs on elasticache and they do go into 3
quite significant amount of detail on how to use elasticache at the 4
management console and the command-line interface and we have another lab there 5
for developers who would like to know how to program the ElastiCache 6
Redis engine using the AWS JavaScript software development kit. So this lesson 7
will be preparing you for those labs. So first of all we'll go through exactly 8
what is elasticache and the two different options that we have for a 9
caching engine being a memcached and Redis and then we'll look at the ways in 10
which we can enable caching on for example a data source or a data base 11
ElastiCache is a managed in-memory cache service it is a key value store and 12
provides ultra-fast sub-millisecond latency access to your cache data. There 13
are two options available for that data store one being elasticache Redis and 14
the other being memcached. It is primarily used, but not always used, to 15
reduce load on a database. So in a similar way so you would use Cloud 16
front to front and cache an Amazon s3 bucket or a 17
website on an Amazon s3 bucket, in the same way that you would use cloud front 18
in that situation you would use elasticache as a cache in front of your 19
database and that would reduce the load on your database it would reduce the 20
latency on any request to that database. It provides multi AZ capability and you 21
would use it in situations where there is a high request rate required. So if 22
you need very fast access to your data and there is a high request rate for 23
that data, you had a lot of users and the volume of data is quite low but it's 24
regularly accessed and you require a low latency to that 25
data. The first option available to us is the 26
memcached engine. So memcached, it's a free and open source project and 27
provides high performance distributed memory object caching system it only 28
supports simple data types and the data structure is a string or an object up to 29
one megabyte the data volume maximum you can have in a memcache cache is 4.7 TB 30
bytes and there is no persistence of data, if data is lost inside a cache it 31
cannot be recovered, but that is not such a bad thing because this is a caching 32
engine and you would normally use it in front of a database, so if you lost the 33
data in your cache you can always retrieve that data back from your 34
original data source being at the data base behind that cache. It provides 35
simple scaling by adding or removing nodes and the data is distributed across 36
those nodes it is suitable for simple data 37
structures for large nodes with multiple cores or threads and in situations where 38
you require elasticity, where you require a scaling in and out by adding and 39
removing nodes according to demand and you require partitioning of data across 40
multiple shards and it's very suitable for caching data bases. 41
The next option available to us is redis. Redis is a little bit 42
more of an advanced caching engine it's again it's a free and open source 43
project and it's a in-memory data structure store similar to memcache but 44
more advanced. It supports far more advanced data structures strings hashes 45
lists sets sorted sets with range queries bitmaps hyper logs and it also 46
supports geospatial indexes with radius queries which is great if you've got a 47
mobile application for example that needs geospatial information it needs a 48
location information and you just search an information really good you can do 49
that in very low latency the key/value size can 50
be up to 512 megabytes so much more than the memcache one megabyte and the 51
maximum data volume is slightly lesser memcached at 3.5 gigabyte 52
the data is persistent so lost data can be recovered and we also have read 53
replicas for elasticache Redis so this is good if you want to use Redis on its 54
own as a standalone a standalone key value store without a database behind it 55
it has a very large command set available so that combined with the 56
advanced data structures that are available you can have very complex 57
queries of that data and enables you to have very good very advanced 58
applications using the elasticache Redis engine, it supports notification or 59
notifications from the Redis pub/sub channel. So you can set up a pub sub 60
channel and users can subscribe to that channel and receive notifications 61
through the Redis engine, for changes to that to that cache so you would use it 62
over memcached obviously where you require that advanced data type where 63
you will require auto sorting of data where you would require pub sub 64
capabilities where you require high availability and failover you want 65
persistent data so that is where you would use Redis. it's a more 66
advanced version of memcached but memcached is still very good if you're 67
if you don't require all the bells bells and whistles of Redis and certainly if 68
you have got a no SQL database for example and you want to put a key value 69
store in front of it and memcached is great for doing that. In order for our 70
caching engine to be useful it needs to be updated on a regular basis or updated 71
on an event-driven basis, so when data changes we need to have some way for 72
example and we need to have a data base trigger to update that data. So dynamodb 73
has database triggers and mysql there's a 74
mysql.lambda procedure that can trigger a lambda function. 75
MongoDB also has built-in triggers for its databases 76
so if our database supports triggers we can use that to update elasticache 77
using a Lambda function or using a separate ec2 instance to copy that 78
that data over to our elasticache engine. We could also use our application 79
itself to update elasticache so when our application has a read request to to 80
the database it can also update elasticache at the same time., There are 81
a couple of caching strategies that we can look at for loading our data 82
initially into our elasticache and also for updating that data when it changes. 83
The first one being lazy loading and that will load data into the cache on a 84
cache miss so what that means is that if a request comes in to elasticache and 85
that data is not available, then our application will go back to the data 86
source, it will retrieve that data load it into elasticache and then also at the 87
same time return that data back to the requester. It will require a time to live 88
to be put on that data otherwise the data will grow and it will become not 89
manageable so when data is not accessed regularly we need a TTL on that to 90
remove it from the case because a case is only there for accessing regularly 91
accessed data. The downside of lazy loading is that it 92
requires three trips on occasion if so we need to we need to first of all go 93
back to the data source if it's if the data is not in our case then we need to 94
retrieve that data put it into elasticache and then return it back to 95
requester. The other strategy there is write through and that is where our 96
application or if we're using database triggers, a trigger event, will update the 97
cache when data is written to the database or 98
the database is updated so this again requires a TTL for to make sure that 99
style data doesn't build up the downside of right through is that it caches in 100
frequently accessed data so unlike lazy loading that will cache it only on on 101
occasion is this case is that whether or not it has been requested 102
so that does require more more resources volume of data to be stored in the cache 103
and so it is definitely does require a TTI to get rid of any style data more so 104
than in lazy loading adding a TTL so memcache to and Redis both have the 105
option there to through a set command to specify an expire parameter in memcache 106
its in seconds and in Redis it is in either seconds or milliseconds so in 107
there set command we have an ex parameter which is the expire timing 108
seconds and the px which is expire time if in milliseconds. If you wanted to 109
expire very quickly so when that expire time is up then it is that data that key 110
value is removed from the cache. So that brings us to the end of our lecture on 111
elasticache. There are a couple of labs coming up the first one being using 112
elasticache which is for solutions architects and sysops administrators and 113
you will go through using the Amazon console and using that to create and 114
elasticache Redis cache and at the same time accessing that through the Command 115
Line. The other lab is for developers where we are using the software 116
development kit the JavaScript software development kit to program elasticache 117
Redis. So that brings us to the end and I'll see you in our next lecture