Everything about AWS-3:Features of EC2 instances
Features of EC2 instances:
- Auto Scaling
- Elastic Load Balancing
- Messaging and Queuing
Auto Scaling:
If one EC2 instance fails suddenly, we would require another instance to take up the job. Often we come across websites which wouldn’t load properly, that can be because the website might have received more requests than it was able to handle. In such a scenario, another EC2 instance will get added automatically. Let us consider sales like Big Billion day or Christmas, traffic can be huge due to several offers, during such time more instances will get added to handle large traffic, once the rush ends, automatically the added instances will get removed. This is the concept of Scaling.
Elastic Load Balancing:
Now that we know during high traffic number of instances will get added, how will a web traffic understand which instance to approach when may be 3 instances are performing the same job? In this situation, a host will be helpful who can assist to route the traffic and check on even distribution of workload across all instances. This is the work of a Load Balancer or Elastic Load Balancer(ELB) in AWS.
ELB -
- Automatically scalable: If the traffic increases, ELB can handle the increased throughput
- No added cost: With increased traffic, there’s no added cost on ELB
- When an EC2 instance gets added, it lets the ELB know and starts operating.
- Once the traffic reduces, ELB waits for existing requests to complete and auto scaling engine to reduce the number of instances without any disruption.
- ELB works at a regional level. Let us consider there’s 4 client servers in frontend and 4 EC2 instances in the backend. Now with an added instance, it doesn’t have to inform each server working in the frontend, but will only let the ELB know and the ELB will automatically divide the workload and start sending requests to the new instance without any server even learning about it. This is also known as decoupled architecture.
Messaging and Queuing:
Now, there can be situations when the client and the server are not in sync, a buffer might come handy then. Eg: Let us consider in an eatery there’re 15 people and 4 cooks to prepare their food. Now if these 15 people rush and provide their orders directly to the cooks, it might cause disruption. Hence, we have waiters who take the orders and provide them to the cooks in a queue. Whoever goes first, will be served first. People need to wait before they’re served. People don’t need to know about the cooks, they only interact with the waiter to provide the order and their jobs are done. Similarly cooks don’t need to know whose order it is, they prepare it and hand it over to the waiter to complete their jobs. Now when the cooks will have their lunch, the waiter won’t stop taking orders. These orders will wait in a queue until the cook is back on his job and start preparing food again.
This is exactly what happens in a Messaging and Queuing service in a loosely coupled architecture. When two components (frontend and backend) are loosely coupled, they have a buffer which is called queue. If backend server fails, the client(frontend) will still be able to send requests to it (just like the waiter accepting orders even when the cooks were away) and those will wait in a queue until the server is up and running once again (cooks were back from lunch break to fulfill the orders to be served that were waiting in a queue) to accept these requests from the queue and process them.
In case of managing and scaling microservices AWS provides SQS and SNS services.
- Amazon Simple Queue Service(SQS)-This is the Amazon message queuing service that helps to send, store and receive messages amongst various software components(microservices). The data contained in a message is called Payload and is protected till its delivered. An application sends a message in the queue(SQS queues) and the service accepts, processes and deletes it from the queue.
- Amazon Simple Notification Service(SNS)-This is the Amazon publish/subscribe (pub/sub) service where along with messages we can also deliver notifications to the end user after completion of an action. End users can be other AWS services too along with mobile push, emails, etc.
Conclusion:
Stay tuned to learn more on other features of AWS that I will cover in Part 4.