How Application Load Balancer listener rules route /orders and /billing to different target groups, how path patterns, priorities and regex matching behave, how URL rewrite transforms strip prefixes, and the limits you hit as services multiply.

Once a backend grows past one service, the public API usually keeps a single hostname, and on AWS the usual answer is an Application Load Balancer with one listener rule per path prefix: /orders/* to the orders service, /billing/* to billing, everything else to the old monolith.
That works well for a handful of services and gets fiddly as rules, priorities and prefixes multiply, so it helps to know exactly how matching behaves.
A listener evaluates its rules in priority order, lowest number first, and the first rule whose conditions all match decides the action. Every listener also has a default rule that handles anything unmatched, usually a fixed 404 response or the legacy application. The condition types reference lists the details for path conditions: patterns apply only to the path, not the query string, are evaluated after URI normalization, are case-sensitive and can be up to 128 characters.
aws elbv2 create-rule \
--listener-arn "$LISTENER_ARN" \
--priority 10 \
--conditions Field=path-pattern,Values='/orders','/orders/*' \
--actions Type=forward,TargetGroupArn="$ORDERS_TG_ARN"
aws elbv2 create-rule \
--listener-arn "$LISTENER_ARN" \
--priority 20 \
--conditions Field=path-pattern,Values='/billing','/billing/*' \
--actions Type=forward,TargetGroupArn="$BILLING_TG_ARN"
/orders/* does not match /orders without a trailing slash, since * follows the slash, which is why both values are listed. Each target group runs its own health check, so a service with a broken health endpoint drops out of rotation independently of the others.
/api/* at priority 5 swallows /api/orders/* at priority 10, because the lower number wins./orders/123 arrives at the orders service as /orders/123, and the service must serve that path./Orders/123 does not match /orders/*./search?type=orders matches on /search only; use a query-string condition for the rest.Path conditions also accept regular expressions through RegexValues, which helps when versioned or tenant-prefixed paths do not fit wildcards. To change the path before it reaches the target, add a URL rewrite transform to the rule, for example rewriting ^/orders/(.*)$ to /$1 so the service sees /123. A rule can carry one URL rewrite and one host header rewrite, and the rewrite does not change which rule matched.
Rewrites are useful when you place an existing service behind a shared hostname without changing its routes, and they also move part of your API's shape into load balancer configuration, where it is easy to forget during a refactor.
The ALB quotas page sets a default of 100 rules per load balancer, excluding default rules, with 5 condition values and 6 wildcards per rule. The quota is adjustable, but at dozens of services the larger cost is keeping priorities, health checks and target groups in sync with the code, usually in Terraform reviewed separately from the service that changed its paths.
Best fit: a few long-lived services or a monolith being split, where each prefix maps cleanly to one target group.
Encore brings infrastructure from code, and routing is part of it: each endpoint declares its method and path, Encore routes requests to the service that owns the endpoint, and on AWS it provisions the Application Load Balancer in front of your services in your own account, as described in the AWS infrastructure docs. There are no listener rules or priorities to maintain, and the API definition docs note that conflicting paths are rejected when the app is built.
This app has an orders service with its own routes and a fallback route that forwards anything unmatched to the legacy application, which is the path-based migration pattern without a rule per prefix:
Run in your terminal to get started locally.
// orders/orders.go
package orders
import "context"
type Order struct {
ID string `json:"id"`
Status string `json:"status"`
}
//encore:api public method=GET path=/orders/:id
func Get(ctx context.Context, id string) (*Order, error) {
return &Order{ID: id, Status: "shipped"}, nil
}
// legacy/legacy.go
package legacy
import (
"net/http"
"net/http/httputil"
"net/url"
)
//encore:service
type Service struct {
proxy *httputil.ReverseProxy
}
func initService() (*Service, error) {
// Internal address of the monolith that still serves unmigrated routes.
target, err := url.Parse("http://monolith.internal:8080")
if err != nil {
return nil, err
}
return &Service{proxy: httputil.NewSingleHostReverseProxy(target)}, nil
}
// Fallback receives every request that no Encore endpoint matches.
//
//encore:api public raw path=/!fallback
func (s *Service) Fallback(w http.ResponseWriter, req *http.Request) {
s.proxy.ServeHTTP(w, req)
}
Moving a route off the monolith means adding an endpoint in the right service, and the fallback stops receiving that path automatically, with no priority to adjust. Calls between services, such as orders asking billing for an invoice, are typed function calls covered in the API calls docs, so they do not go back out through the load balancer. encore run serves the same routes locally, including the fallback, and the local dashboard lists every endpoint with its path.
That also changes how an AI coding agent works on the API: adding /orders/:id/refund is one annotated function, the route exists locally right away, and a path conflict fails the build instead of shadowing another service in production. Requests through the gateway are traced end to end, as described in the tracing docs.
Best fit: teams adding services behind one API hostname, or migrating a monolith route by route, who want routing to follow the code.
Create one target group per service, then add listener rules with a path-pattern condition such as /orders/* that forward to each target group, with a priority to set evaluation order. Requests that match no rule go to the listener's default action.
No. A path pattern only selects the target group, so /orders/123 reaches the orders service as /orders/123. To change the path, add a url-rewrite transform to the rule, which uses a regex and a replacement string.
Yes. Path patterns are case-sensitive, up to 128 characters, and support * for zero or more characters and ? for exactly one. They match the path only, never the query string.
Each endpoint declares its method and path in code, and Encore routes requests to the service that owns the endpoint, behind the Application Load Balancer it provisions in your account. Conflicting paths are rejected when the app is built, before anything is deployed.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.