How does an Application Load Balancer route requests to different services?
An ALB listener evaluates rules in priority order. Each rule has conditions, such as path, host header, HTTP header or query string, and an action, usually forward to a target group. A default rule catches everything else.
Explain it simply
An ALB is like the help desk at a hospital: the board says orthopaedics goes to floor 2, paediatrics to floor 3, and everything else to reception. Each visitor is checked against the rules from top to bottom and sent to the first match.
Example
Listener HTTPS :443
Priority 1 host = api.example.com -> forward to tg-api
Priority 2 path = /images/* -> forward to tg-static
Priority 3 path = /admin/* AND source-ip in
office range -> forward to tg-admin
Default (no rule matched) -> forward to tg-web
Other actions
redirect HTTP :80 -> HTTPS :443
fixed-response return 503 maintenance page
authenticate with Amazon Cognito or OIDCEach target group has its own health check and its own targets, which may be EC2 instances, IP addresses, containers or Lambda functions. The ALB sends traffic only to healthy targets.
This lets one load balancer front many microservices, reducing cost compared with one load balancer per service. Rules are evaluated in priority order, so put specific rules first.
What to say in the interview
"An ALB listener checks rules by priority, matching on host, path, headers or query strings, then forwards to a target group with its own health checks, or redirects or returns a fixed response. One ALB can front many microservices this way."
Common mistakes
- Putting a broad rule at a higher priority than specific ones, which shadows them.