AWS Elasticache – What is Elasticache and Why should we use it on AWS?
- Tram Ho
## Introduction Hi guys, in today’s post we’re going to learn about Elasticache, we’ll learn what it is and why we should use it when we’re already working on the AWS system.  *
* From the name you probably know that Elasticache is used for cache, before starting to learn about Elasticache, we will take a look at why we need cache. ## Why do we need cache? ### Problem For example, we have a case as follows, we have a leaderboard page that displays the user’s score and rank, and we often have to query the database to get data related to the rank to display for the user. user.  However, this leaderboard page information rarely changes, but the number of users accessing this page is very large leads to our database being overloaded.  ### Resolve Then to solve the above problem we can use cache. It will be an intermediate layer between the user and the database, instead of having to query the database directly to get the data, we will access the cache to get the data out. The most commonly used implementation of the cache is that we request the data in the cache, if there is no data we need, we will query down the database to get the data, then save the data in the cache, next time. When we request, our data is already in the cache.  ### Popular cache database The two most popular cache technologies currently are Memcached and Redis. .  Compare Memcached and Redis. | | Memcached | Redis| | — | — | — | | Data | Simple | Complex | | Command line | 12 | 125 | | Server-side scripting | No | Yes (Lua) | | Transactions | no | yes | | Multi-threaded | yes | no |
So what is ElastiCache and what does it have to do with mencached and redis? ## ElastiCache ElastiCache is an AWS service that allows you to create Memcached or Redis clusters easily instead of having to install and configure many things yourself.  AWS ElastiCache will cover the following things: + Installation: when you create an ElastiCache, AWS will automatically install the necessary things for Memcached and Redis under it, we just need to wait for it to finish installing and use. + Administration: the problems related to the work of the system admin for an ElastiCache, we do not need to care, AWS does it for us. Monitoring: ElastiCache will push its metrics on CloudWatch. + Backups: AWS has an option for us to automatically backup cache data (redis only). ## Why should we use it on AWS? There is a question that if we have worked on AWS environment, why should we use ElastiCache? To answer this question, I will have a follow-up example as follows. Usually when deploying applications using cache we will install redis or memcached on our server. If our application is simple then this will still work fine.  But if our app expands, then our redis needs to expand too to accommodate applicable application. So far, no problem at all.  But if our application needs to scale a lot more, then our redis will also need to expand accordingly. This is when we will run into problems, at this point redis has taken up all the resources of the server and cannot expand any further.  **The above is just an example server 2 CPU 2 GB RAM, even if our server has is 32 CPU 32 GB RAM, we will have this problem sooner or later.** To solve the above problem, we have to use redis cluster. Cluster will help us solve the redis scale problem. We will create a redis replica on another server and configure the redis on the old server to become the master, and enable the master to sync data to the replica.  So to set up such a redis cluster is a job that is not too difficult but also not simple. simple, and most importantly, when we do this, it takes a lot of time. So when we are already working with AWS we should use Elasticache, instead of having to create multiple EC2 children and then build a redis cluster on top of it. **With Elasticache we only need a few simple steps on the Console to get a Redis Cluster.** ## Create Elasticache Memcached To create an Elasticache cluster we first need to create a subnet group for it, we do the following steps: following: 1. Access the Elasticache Console [https://console.aws.amazon.com/elasticache/home](https://console.aws.amazon.com/elasticache/home). 2. Select **Subnet Groups**, click Create Subnet Group. 3. Enter Name and Description. 4. Select **VPC ID** => Select **Availability Zone** => Select **Subnet ID** that we want Elasticache Node to be deployed to. 5. Enter tags and click Create.
After creating Subnet Groups, we will create Elasticache Memcached, we do the following: 1. In Elasticache Console, select Memcached menu, click Create. 2. **Cluster engine** select Memcached. 3. **Location** we choose Amazon Cloud. 4. **Memcached settings** we enter the Name, the remaining parameters you can choose or leave the default. 5. Open the **Advanced Memcached settings** section and we will see that the **Subnet Group** that we just created has been selected. 6. Click Create. Oke, we have created an Elasticache Memcached ?. ## Conclusion So we have learned the basics of Elasticache. If you have any questions or need more clarification, you can ask in the comment section below. In the next article we will learn about **Cache Deployment Options** in Elasticache. ## Team search section Currently, my company, Hoang Phuc International, has more than 30 years of experience in the fashion field. And is the largest fashion e-commerce site in Vietnam. HPI’s technology team is looking for teammates for positions such as: + Senior Backend Engineer (Java). Link JD: https://tuyendung.hoang-phuc.com/job/senior-backend-engineer-1022 + Senior Front-end Engineer (VueJS). https://tuyendung.hoang-phuc.com/job/senior-frontend-engineer-1021 + Junior Backend Engineer (Java). https://tuyendung.hoang-phuc.com/job/junior-backend-engineer-1067 + Junior Front-end Engineer (VueJS). https://tuyendung.hoang-phuc.com/careers/job/1068 + App (Flutter). https://tuyendung.hoang-phuc.com/job/mobile-app-engineer-flutter-1239 + Senior Data Engineer. https://tuyendung.hoang-phuc.com/job/seniorjunior-data-engineer-1221 With the goal within the next 5 years in the technology field are: + There will be a website in the top 10 fastest websites in Vietnam with 20 million visits per month. + 5 million loyal customers and more than 10 million transactions per year. The team is building a very large system with a lot of problems to solve, and there will be a lot of interesting problems for you. If you are interested in building a large, flexible, scalable, and high-performance system with microservices architecture, then join us. If you are interested, please send your CV on the recruitment page of Hoang Phuc International or via my email hmquan08011996@gmail.com
. Thank you for reading.
Source : Viblo