Target groups concept in AWS - Time & Space Complexity
When working with AWS target groups, it's important to understand how the number of targets affects the time it takes to register or check their health.
We want to know how the work grows as we add more targets to a group.
Analyze the time complexity of registering multiple targets to a target group.
aws elbv2 register-targets \
--target-group-arn arn:aws:elasticloadbalancing:region:account-id:targetgroup/my-targets/1234567890abcdef \
--targets Id=i-1234567890abcdef0 Id=i-0987654321abcdef0
This command registers one or more EC2 instances as targets in a target group for load balancing.
Look at what happens when registering many targets:
- Primary operation: Processing each target instance registration with the target group.
- How many times: Once per target instance added.
As you add more targets, the number of registration operations grows directly with the number of targets.
| Input Size (n) | Approx. Operations (Target Registrations) |
|---|---|
| 10 | 10 target registrations |
| 100 | 100 target registrations |
| 1000 | 1000 target registrations |
Pattern observation: The work grows in a straight line as you add more targets.
Time Complexity: O(n)
This means the time to register targets grows directly with how many targets you add.
[X] Wrong: "Registering multiple targets happens all at once, so time stays the same no matter how many targets."
[OK] Correct: Although the register-targets API supports registering up to 1000 targets in a single call, the processing time still grows linearly with the number of targets.
Understanding how operations scale with input size helps you design efficient cloud systems and explain your reasoning clearly in interviews.
"What if we batch register targets in groups instead of one by one? How would the time complexity change?"
Practice
Solution
Step 1: Understand target group role
A target group groups servers (targets) to distribute incoming traffic.Step 2: Identify key functions
It also performs health checks to ensure traffic goes only to healthy servers.Final Answer:
To group servers for load balancing and health checks -> Option DQuick Check:
Target groups = server grouping + health checks [OK]
- Confusing target groups with security groups
- Thinking target groups store data
- Mixing target groups with VPC functions
Solution
Step 1: Recall supported protocols for target groups
AWS target groups support HTTP, HTTPS, TCP, TLS, UDP, and TCP_UDP protocols.Step 2: Identify valid protocol in options
HTTP is a valid protocol; FTP, SMTP, and SSH are not supported for target groups.Final Answer:
aws elbv2 create-target-group --protocol HTTP -> Option AQuick Check:
HTTP is valid protocol for target groups [OK]
- Using unsupported protocols like FTP or SSH
- Confusing target group protocol with security group rules
- Misspelling protocol names
Solution
Step 1: Understand health check impact
Load balancers route traffic only to targets marked healthy by health checks.Step 2: Apply to given targets
With two healthy and one unhealthy, traffic goes only to the two healthy targets.Final Answer:
It sends traffic only to the two healthy targets -> Option AQuick Check:
Traffic routes only to healthy targets [OK]
- Assuming traffic goes to all targets regardless of health
- Thinking traffic stops if any target is unhealthy
- Confusing unhealthy targets with backup targets
Solution
Step 1: Check common causes for no healthy targets
Targets not registered or security blocking health checks cause no healthy targets.Step 2: Analyze options
Security group blocking health check traffic prevents health checks from succeeding, causing targets to be unhealthy.Final Answer:
Security group blocks health check traffic -> Option BQuick Check:
Blocked health checks cause no healthy targets [OK]
- Ignoring security group rules
- Assuming region mismatch causes health check failure
- Using unsupported protocols like FTP
/images/* to one group and /api/* to another. Which AWS service feature should you use?Solution
Step 1: Identify routing needs
Routing based on URL path requires path-based routing rules.Step 2: Match AWS service feature
Application Load Balancer supports path-based routing to different target groups.Step 3: Exclude incorrect options
Network Load Balancer does not support path-based routing; Classic Load Balancer lacks this feature; Elastic IPs do not route traffic by path.Final Answer:
Application Load Balancer with path-based routing rules -> Option CQuick Check:
Path-based routing = Application Load Balancer [OK]
- Using Network Load Balancer for path routing
- Confusing Classic Load Balancer features
- Thinking Elastic IPs control routing rules
Ready to prove it?
Pass the test and this pattern moves unknown
