Prompt
How do I offload simple request handling from my main app server to the edge?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
A good pattern is to move only the fast, stateless, repetitive parts of request handling to the edge, and keep anything heavy or stateful on your origin server.
Good candidates for the edge
Offload things like:
- Redirects and rewrites
http -> httpswww -> non-www- old paths to new paths
- Auth pre-checks
- verifying session presence
- rejecting obviously invalid requests early
- Header normalization
- adding
cache-control - setting security headers
- geo/device-based routing headers
- adding
- Simple A/B routing
- sending users to variant A or B
- Bot filtering / rate limiting
- lightweight checks before hitting origin
- Static response generation
- small JSON responses
- maintenance pages
- Cache lookup
- serve from edge cache if possible
What should stay on the main server
Keep these on origin:
- database access
- complex business logic
- user-specific personalized rendering
- anything that needs durable state
- long-running jobs
- heavyweight auth/session validation
Common implementation options
1) Edge functions / serverless at the CDN
Use an edge runtime from a CDN or platform:
- Cloudflare Workers
- Fastly Compute
- Vercel Edge Functions
- Netlify Edge Functions
- AWS Lambda@Edge
This is usually the cleanest way to do it.
Example use case:
- request arrives
- edge checks path and headers
- if it’s a redirect or cached response, return immediately
- otherwise forward to origin
2) Reverse proxy rules
If you run your own edge proxy:
- Nginx
- HAProxy
- Envoy
- Apache
You can handle:
- rewrites
- redirects
- compression
- caching
- header injection
This is simpler than code for very basic logic.
3) CDN rules/configuration
Some logic can be done without code:
- page rules
- transform rules
- redirect rules
- cache policies
- WAF rules
Use config when the rule is deterministic.
A practical architecture
A common setup looks like this:
- Client sends request to CDN/edge
- Edge checks:
- redirect rules
- cache hit
- auth token presence
- bot/rate-limit rules
- If handled at edge, return response immediately
- If not, forward to origin app server
- Origin handles full application logic
Example edge logic
Pseudo-code:
export default async function handler(request) {
const url = new URL(request.url)
if (url.pathname === '/old-page') {
return Response.redirect('/new-page', 301)
}
if (!request.headers.get('cookie')?.includes('session=')) {
return new Response('Unauthorized', { status: 401 })
}
return fetch(request)
}
Tips
- Keep edge logic small and fast
- Avoid database calls from the edge unless necessary
- Prefer idempotent operations
- Cache aggressively where safe
- Measure latency and origin offload before/after
- Use edge for decision-making, origin for application state
Rule of thumb
If the request can be answered in:
- a few header checks
- a path match
- a cached response
- a simple redirect
…it’s probably a good edge candidate.
If you want, I can show you how to do this specifically with Cloudflare Workers, Vercel Edge Functions, Nginx, or AWS Lambda@Edge.