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?"