Prompt
I'm building an API that needs header-based routing and quick auth decisions near the user. What stack fits best?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
For header-based routing plus very fast auth decisions close to the user, the best fit is usually:
Best fit: Cloudflare Workers + Cloudflare Load Balancer / Workers + Durable Objects (if needed)
Why this fits:
- Runs at the edge: auth and routing decisions happen near users globally.
- Great for header-based routing: inspect request headers and route accordingly.
- Very low latency: especially good for “allow/deny” or lightweight token checks.
- Simple deployment model: one edge script can do routing + auth + forwarding.
Typical pattern:
- Request hits Cloudflare edge.
- Worker inspects headers (e.g.
Authorization,X-Tenant,X-Region,X-Plan). - Worker:
- routes to the right origin/service, and/or
- returns 401/403 immediately, and/or
- calls a fast edge-friendly auth check.
- Forward only valid requests to your backend.
If you need stronger centralized auth logic
Use:
- Cloudflare Workers for edge routing
- A central auth service only for cache-miss / refresh / policy sync
- JWTs or signed session tokens so most checks are local and fast
Good alternative stack if you’re not on Cloudflare
Fastly Compute + edge auth
- Also excellent for header-based routing and edge execution.
- Strong performance, very good for advanced proxying.
- Often more complex than Cloudflare for general app teams.
AWS
If you want to stay in AWS:
- CloudFront + Lambda@Edge for header-based routing
- or API Gateway + Lambda if you care more about integration than edge proximity
- But for “quick auth decisions near the user,” it’s usually not as clean or low-latency as Cloudflare/Fastly.
Recommended architecture
If you want the simplest strong setup:
- Edge: Cloudflare Worker
- Auth: JWT validation at edge, with short-lived keys cached at edge
- Routing: header-based rules in the Worker
- Origins: regional microservices behind load balancers
- Policy refresh: central control plane, pushed periodically
Rule of thumb
Choose:
- Cloudflare Workers if you want the easiest, most practical edge stack.
- Fastly Compute if you need very advanced edge proxy behavior and are comfortable with more infrastructure complexity.
- AWS Lambda@Edge only if your org is already deep in AWS and can accept more constraints.
If you want, I can propose a concrete stack based on your cloud preference, auth method (JWT/OAuth/mTLS), and whether routing is purely header-based or also path/geo/tenant-based.