How is "Target Groups" different from "Auto-Scaling Groups" in AWS?
Asked Answered
L

5

67

I'm a little too confused on the terms and its usage. Can you please help me understand how are these used with Load Balancers?

I referred the aws-doc in vain for this :(

Luwian answered 30/1, 2018 at 19:26 Comment(0)
C
89

Target groups are just a group of Ec2 instances. Target groups are closely associated with ELB and not ASG.

  • ELB -> TG - > Group of Instances

We can just use ELB and Target groups to route requests to EC2 instances. With this setup, there is no autoscaling which means instances cannot be added or removed when your load increases/decreases.

  • ELB -> TG - > ASG -> Group of Instances

If you want autoscaling, you can attach a TG to ASG which in turn gets associated to ELB. Now with this setup, you get request routing and autoscaling together. Real world usecases follow this pattern. If you detach the target group from the Auto Scaling group, the instances are automatically deregistered from the target group

Hope this helps.

Chetnik answered 15/11, 2018 at 15:15 Comment(4)
I think this is not quite the correct way to put it. It's not that the TG points to the ASG, but the other way around: the ASG points to the TG. That way, when the ASG scales, it automatically adds or removes its instances from the TG, thus making them available for load balancing. You can also directly add instances to the TG, but I think that's not usually done: just let the ASG take care of it.High
Very good explanation. It would be much better if someone annotate official documentation related this topic though.Hydromancy
I think @High is right.Business
Or to add to what @High said: From a configuration standpoint it's ELB -> TG <- ASG. Neither ELB nor ASG can point to the other directly. This is true for Application LB, though it could have been different with the Classic LB.Cumshaw
W
27

What is a target group?

A target group contains EC2 instances to which a load balancer distributes workload.

A load balancer paired with a target group does NOT yet have auto scaling capability.

What is an Auto Scaling Group (ASG)?

This is where auto scaling comes in. An auto scaling group (ASG) can be attached to a load balancer.

We can attach auto scaling rules to an ASG. Then, when thresholds are met (e.g. CPU utilization), the number of instances will be adjusted programatically.

How to attach an ASG to a load balancer?

  • For Classic load balancer, link ASG with the load balancer directly
  • For Application load balancer, link ASG with the target group (which itself is attached to the load balancer)
Warder answered 17/9, 2018 at 8:57 Comment(0)
O
25

Auto Scaling Group is just a group of identical instances that AWS can scale out (add a new one) or in (remove) automatically based on some configurations you've specified. You use this to ensure at any point in time, there is the specific number of instances running your application, and when a threshold is reached (like CPU utilization), it scales up or down.

Target Group is a way of getting network traffic routed via specified protocols and ports to specified instances. It's basically load balancing on a port level. This is used mostly to allow accessing many applications running on different ports but the same instance.

Then there are the classical Load Balancers where network traffic is routed between instances.

The doc you referred to is about attaching load balancers (either classical or target group) to an auto-scaling group. This is done so scaling instances can be auto-managed (by the auto scaling group) while still having network traffic routed to these instances based on the load balancer.

Orientalism answered 30/1, 2018 at 23:42 Comment(0)
L
6

Target groups

They listen to HTTP/S request from a Load Balancer

Are the Load Balancer's targets which will be available to handle an HTTP/S request from any kind of clients (Browser, Mobile, Lambda, Etc). A target has a specific purpose like Mobile API processing, Web App processing, Etc. Further, these target groups could contain instances with any kind of characteristics.

AWS Docs

Each target group is used to route requests to one or more registered targets. When you create each listener rule, you specify a target group and conditions. When a rule condition is met, traffic is forwarded to the corresponding target group. You can create different target groups for different types of requests. For example, create one target group for general requests and other target groups for requests to the microservices for your application. Reference

So, a Target Group provides a set of instances to process specific HTTP/S requests.

AutoScaling groups

They are a set of instances who were started up to handle a specific workload, i.e: HTTP requests, SQS' message, Jobs to process any kind of tasks, Etc.

On this side, these groups are a set of instances who were started up by a metric which exceeded a specific threshold and triggered an alarm. The main difference is that Autoscaling groups' instances are temporary and they are available to process anything, from HTTP/S requests until SQS' messages. Further, the instances here are temporary and can be terminated at any time according to the configured metric. Likewise , the Autoscaling groups share the same characteristics because the follow something called Launch Configuration.

AWS Docs

An Auto Scaling group contains a collection of EC2 instances that share similar characteristics and are treated as a logical grouping for the purposes of instance scaling and management. For example, if a single application operates across multiple instances, you might want to increase the number of instances in that group to improve the performance of the application or decrease the number of instances to reduce costs when demand is low. Reference

So, an Autoscaling group not only will be able to process HTTP/S requests but also can process backend stuff, like Jobs to send emails, jobs to process tasks, Etc.

Levite answered 31/1, 2018 at 0:4 Comment(0)
R
1

As I understand it, Target Groups is a connection between ELB and EC2 instances. Some kind of a service discovery rules. This layer allows to Target Groups for ECS Services for instance when it's possible to have more than one container per instance.

Auto-Scaling Groups is an abstraction for aggregation of EC2 metrics and taking some actions based on that data.

Also, bear in mind, that the possibility of attaching of Auto-Scaling Groups to ELB comes from the previous generation of ELBs. You may compare the first generation and the second one in the CloudFormation docs.

Rat answered 30/1, 2018 at 19:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.