Astro middleware pipeline with Cloudflare Workers edge runtime concurrency
0 reputation · 09 Oct 2026, 17:52 UTC
Astro middleware runs on every SSR or hybrid request before page rendering and API routes. When deployed with an edge adapter such as Cloudflare Workers, Vercel Edge Functions or Netlify Edge Functions, the middleware executes inside the runtime's isolate model.
The pipeline is serial by design, with each middleware awaiting next(). Under concurrent requests the interaction between serial per-request execution and isolate concurrency is not documented. It is unclear whether module-level state in a middleware file is shared across concurrent requests in the same isolate, and how edge runtime CPU time limits interact with a chain of middleware under burst load.
What guarantees exist for request isolation of middleware execution in Astro on edge runtimes? Is global state in middleware files safe under concurrent requests, or must all state be confined to context.locals? How should middleware latency be reasoned about when multiple requests are processed concurrently in the same isolate?