1 00:00:00,270 --> 00:00:02,490 ‫Let's talk about Amazon ElastiCache. 2 00:00:02,490 --> 00:00:04,320 ‫So the same way you get RDS 3 00:00:04,320 --> 00:00:06,870 ‫to have managed relational databases, 4 00:00:06,870 --> 00:00:08,820 ‫ElastiCache is going to help you get 5 00:00:08,820 --> 00:00:11,160 ‫managed Redis or Memcached 6 00:00:11,160 --> 00:00:12,870 ‫which are cache technologies. 7 00:00:12,870 --> 00:00:13,740 ‫So what are caches? 8 00:00:13,740 --> 00:00:16,260 ‫Well, they are in-memory databases 9 00:00:16,260 --> 00:00:19,740 ‫with really high performance and low latency. 10 00:00:19,740 --> 00:00:21,690 ‫And what the cache will help you with is 11 00:00:21,690 --> 00:00:24,990 ‫to help reduce the load off of databases 12 00:00:24,990 --> 00:00:27,720 ‫for read intensive workloads. 13 00:00:27,720 --> 00:00:30,420 ‫The idea is that the common queries are going to be cache, 14 00:00:30,420 --> 00:00:33,420 ‫and therefore your database will not be queried every time. 15 00:00:33,420 --> 00:00:34,710 ‫Just your cache can be used 16 00:00:34,710 --> 00:00:37,920 ‫to retrieve the results of these queries. 17 00:00:37,920 --> 00:00:39,600 ‫What this also helps you do is 18 00:00:39,600 --> 00:00:41,190 ‫makes your application stateless 19 00:00:41,190 --> 00:00:43,470 ‫by putting the state of your application 20 00:00:43,470 --> 00:00:45,450 ‫into Amazon ElastiCache. 21 00:00:45,450 --> 00:00:48,477 ‫And because we have the same benefits our RDS, 22 00:00:48,477 --> 00:00:51,120 ‫AWS will take the same maintenance 23 00:00:51,120 --> 00:00:53,190 ‫of the operating system, the patching, 24 00:00:53,190 --> 00:00:55,080 ‫the optimization the setup, configuration, 25 00:00:55,080 --> 00:00:58,320 ‫monitoring, failure recovery and backups. 26 00:00:58,320 --> 00:01:00,210 ‫Now, if you use Amazon ElastiCache 27 00:01:00,210 --> 00:01:02,340 ‫just so you know that it will require you 28 00:01:02,340 --> 00:01:05,460 ‫to do some heavy application code changes 29 00:01:05,460 --> 00:01:07,290 ‫for your application. 30 00:01:07,290 --> 00:01:08,700 ‫This is not something just enable 31 00:01:08,700 --> 00:01:10,080 ‫and off you go, you have a cache. 32 00:01:10,080 --> 00:01:13,020 ‫You need to change your application to query the cache 33 00:01:13,020 --> 00:01:15,090 ‫before or after querying the database. 34 00:01:15,090 --> 00:01:17,140 ‫And we'll see the strategies in a minute. 35 00:01:18,210 --> 00:01:19,650 ‫So now let's talk about 36 00:01:19,650 --> 00:01:23,130 ‫the architecture for using ElastiCache. 37 00:01:23,130 --> 00:01:25,260 ‫And there can be many, but I'm just giving you an example. 38 00:01:25,260 --> 00:01:27,390 ‫So, let's say we have Amazon ElastiCache 39 00:01:27,390 --> 00:01:29,970 ‫and RDS database and your application. 40 00:01:29,970 --> 00:01:32,730 ‫The application will query ElastiCache 41 00:01:32,730 --> 00:01:35,100 ‫to see if the queries are already being made. 42 00:01:35,100 --> 00:01:37,140 ‫And if it has already been made, 43 00:01:37,140 --> 00:01:38,670 ‫and it is stored in ElastiCache, 44 00:01:38,670 --> 00:01:40,110 ‫then it's called a cache hit. 45 00:01:40,110 --> 00:01:41,370 ‫And then it just gets the answer 46 00:01:41,370 --> 00:01:43,050 ‫straight from Amazon ElastiCache. 47 00:01:43,050 --> 00:01:45,300 ‫And we were saving a trip 48 00:01:45,300 --> 00:01:47,490 ‫to the database to do the query. 49 00:01:47,490 --> 00:01:49,440 ‫Now, in case of a cache miss, 50 00:01:49,440 --> 00:01:52,050 ‫then we need to fetch the data from the database. 51 00:01:52,050 --> 00:01:53,970 ‫So we're going to read it from the database. 52 00:01:53,970 --> 00:01:57,180 ‫And then for other application or other instances 53 00:01:57,180 --> 00:01:59,010 ‫where the same query will be made 54 00:01:59,010 --> 00:02:02,250 ‫we can write the data back into the cache 55 00:02:02,250 --> 00:02:04,620 ‫so that such as the same query next time 56 00:02:04,620 --> 00:02:07,050 ‫will result in a cache hit. 57 00:02:07,050 --> 00:02:09,540 ‫The idea is that it will help relieve load 58 00:02:09,540 --> 00:02:11,130 ‫from your RDS database. 59 00:02:11,130 --> 00:02:13,440 ‫And because you're storing data in the cache 60 00:02:13,440 --> 00:02:16,620 ‫there must be a cache invalidation strategy 61 00:02:16,620 --> 00:02:19,140 ‫to make sure that only the most current data 62 00:02:19,140 --> 00:02:20,160 ‫is used in there. 63 00:02:20,160 --> 00:02:21,930 ‫And this is the whole difficulty 64 00:02:21,930 --> 00:02:24,360 ‫around using caching technologies. 65 00:02:24,360 --> 00:02:27,990 ‫Another architecture is around storing the user session 66 00:02:27,990 --> 00:02:29,790 ‫to make your application stateless. 67 00:02:29,790 --> 00:02:31,920 ‫So the idea is that your user will do a login 68 00:02:31,920 --> 00:02:34,170 ‫into any kind of your applications, 69 00:02:34,170 --> 00:02:36,540 ‫and then the application will write the session data 70 00:02:36,540 --> 00:02:38,340 ‫into Amazon ElastiCache. 71 00:02:38,340 --> 00:02:40,200 ‫Now, if your user is redirected 72 00:02:40,200 --> 00:02:42,660 ‫to another instance of your application 73 00:02:42,660 --> 00:02:45,090 ‫then your application can retrieve the session cache, 74 00:02:45,090 --> 00:02:47,460 ‫the session directly from the Amazon ElastiCache 75 00:02:47,460 --> 00:02:49,740 ‫And therefore your user is still logged in, 76 00:02:49,740 --> 00:02:52,410 ‫and doesn't need to log in one more time. 77 00:02:52,410 --> 00:02:53,280 ‫And so the idea is that 78 00:02:53,280 --> 00:02:55,080 ‫now you made your application stateless 79 00:02:55,080 --> 00:02:56,460 ‫by writing the session data 80 00:02:56,460 --> 00:02:59,430 ‫of your user into Amazon ElastiCache. 81 00:02:59,430 --> 00:03:03,180 ‫So if we compare Redis and Memcached, what do we have? 82 00:03:03,180 --> 00:03:07,170 ‫Well, for Redis, we have Multi AZ with Auto-Failover, 83 00:03:07,170 --> 00:03:09,900 ‫and we have Read Replicas if you wanted to scale the reads 84 00:03:09,900 --> 00:03:11,940 ‫and have high availability. 85 00:03:11,940 --> 00:03:14,610 ‫So this looks a lot like RDS. 86 00:03:14,610 --> 00:03:18,540 ‫We have data durability using AOF persistence, 87 00:03:18,540 --> 00:03:20,760 ‫and we have backup and restore features. 88 00:03:20,760 --> 00:03:23,760 ‫So again, Redis is all about data durability. 89 00:03:23,760 --> 00:03:25,530 ‫And feature wise as a cache, 90 00:03:25,530 --> 00:03:28,230 ‫it supports sets and sorted sets 91 00:03:28,230 --> 00:03:31,740 ‫which are keywords you can also look for at the exam. 92 00:03:31,740 --> 00:03:33,900 ‫So here I'd like to show Redis 93 00:03:33,900 --> 00:03:36,360 ‫as a cache that gets replicated 94 00:03:36,360 --> 00:03:38,850 ‫that is highly available and durable. 95 00:03:38,850 --> 00:03:42,570 ‫Whereas Memcached is using multi-node 96 00:03:42,570 --> 00:03:43,650 ‫for partitioning of data. 97 00:03:43,650 --> 00:03:44,700 ‫So it's called sharding. 98 00:03:44,700 --> 00:03:46,500 ‫There is no high availability, 99 00:03:46,500 --> 00:03:48,270 ‫there's no replication happening. 100 00:03:48,270 --> 00:03:49,980 ‫It's not a persistent cache. 101 00:03:49,980 --> 00:03:51,960 ‫There is no backup and restore. 102 00:03:51,960 --> 00:03:54,660 ‫And this is a multi-threaded architecture. 103 00:03:54,660 --> 00:03:56,880 ‫So we have multiple instances altogether 104 00:03:56,880 --> 00:03:59,100 ‫working in Memcached with some sharding. 105 00:03:59,100 --> 00:04:00,960 ‫So the idea here that you need to remember 106 00:04:00,960 --> 00:04:02,970 ‫is that Redis really is here 107 00:04:02,970 --> 00:04:05,880 ‫for high availability, backup, read replicas, 108 00:04:05,880 --> 00:04:06,720 ‫this kind of stuff. 109 00:04:06,720 --> 00:04:09,120 ‫Whereas Memcached is a pure cache that's distributed 110 00:04:09,120 --> 00:04:10,227 ‫where you can afford to lose the- 111 00:04:10,227 --> 00:04:12,690 ‫You lose your data, there's no high availability, 112 00:04:12,690 --> 00:04:13,860 ‫and there's no backup and restores. 113 00:04:13,860 --> 00:04:16,170 ‫So these are the main differences that you're going to have 114 00:04:16,170 --> 00:04:17,610 ‫between the two technology. 115 00:04:17,610 --> 00:04:18,570 ‫So that's it. 116 00:04:18,570 --> 00:04:19,403 ‫I hope you liked it, 117 00:04:19,403 --> 00:04:21,270 ‫and I will see you in the next lecture.