Edge Middleware: Moving Request-Time Logic to the Network Perimeter

Vercel has announced general availability for Edge Middleware in Next.js 12.2, alongside a public beta that extends the capability to all frameworks. The company reports 80% month-over-month growth since Middleware's beta launch last October, with more than 30 billion requests routed through the edge layer to date. Customers including Vox Media, Hackernoon, Datastax, HashiCorp, SumUp, and Sanity are using the feature to take control of routing in their applications.

Edge Middleware runs before the Edge Network Cache serves a response, giving developers a code-based alternative to lengthy configuration files for expressing rewrites, redirects, and header rules. Because the middleware executes at the edge rather than at the origin, tasks that previously forced a round trip to the core data center or required bulky client-side code can resolve quickly from a nearby point of presence.

Note: This release is historical. For new projects, Vercel recommends Vercel Functions with the Node.js runtime and Fluid compute, reserving Routing Middleware for request-time routing before a response completes.

Use Cases Driving Adoption

During the beta period, more than 100,000 developers used Routing Middleware on Vercel, including nearly half of the company's Enterprise customers. The following patterns are among the most common.

Experimentation and Feature Flags

SumUp and Sanity use Edge Middleware to run A/B tests and serve personalized variants of otherwise static content. The middleware connects to flagging and experimentation services such as LaunchDarkly, ConfigCat, Koala, Optimizely, and Split. Based on the incoming request, the visitor is bucketed server-side and rewritten to the appropriate variant URL.

This approach eliminates heavy client-side personalization libraries and the layout shift caused by post-render validation. A Middleware A/B test example is available in the Vercel examples repository.

"With Edge Middleware, we can show the control or experiment version of a page immediately instead of using third-party scripts. This results in better performance and removes the likelihood of flickering/layout shifts."

— Jillian Anderson, Slate Software Engineer at SumUp

Geolocation and Localization

The Routing Middleware API ships with a geolocation object that is pre-populated with the visitor's country, region, and city derived from their IP address. Developers can use that data to localize content or enforce regulatory restrictions without integrating a separate geolocation service. HashiCorp is exploring the feature for its globally distributed customer base.

Vercel includes geolocation for all customers at no additional cost. A Middleware localization example demonstrates the pattern.

"The API for Middleware is pretty intuitive, it allows developers to build features without worrying too much about framework-specific details since it conforms to the same standard that browsers use for requests and responses."

— Dylan Staley, Software Engineer at HashiCorp

Edge Authentication

Authentication is another workload the middleware layer handles well. When a visitor requests protected content, Edge Middleware validates the request before the response is served—including CDN-cached pages. Unauthorized visitors are redirected to an explanatory page rather than waiting for a client-side check or an origin-server round trip.

A Middleware authentication example demonstrates basic password protection at the edge.

Framework-Agnostic Edge Support

Alongside the Next.js GA, Vercel extended Edge Middleware and Edge Functions to the CLI, so developers can add a middleware.js or middleware.ts file to any project, run vercel dev, and use the same edge primitives regardless of framework. Framework authors are also receiving tooling to build native edge support; Svelte, Nuxt, and Astro have begun implementing Routing Middleware and Edge Functions for their users.

Getting Started

Current guidance distinguishes between request-time routing and backend logic: developers should use Routing Middleware to authenticate, personalize, or localize responses before a request completes, while Vercel Functions handle server-side logic with the Node.js runtime by default. Function regions can be selected to sit close to a data source when latency matters.