Skip to content

Functions are a mechanism for you to provide functionality on your sites, such as authentication and personalized content, and enable you to run server-side code on-demand without any additional infrastructure configuration.

Vercel enables you to do this in three ways:

Each method above can provide this differently, with each coming with its own trade-offs, such as where the request will physically run when it runs, what is cached, and the cost.

All options can be created and deployed within your code without additional configuration.

Overview of the Vercel infrastructure

Vercel Serverless Functions enable running code on-demand without needing to manage your own infrastructure, provision servers, or upgrade hardware.

By default, Serverless Functions are deployed to the IAD1 region to ensure they are located close to most external data sources hosted on the East Coast of the USA. Depending on where your users may be based and where your data source is, you may want to change the Serverless Function region. Reading data from sources that are physically close to your Serverless Functions allows for less latency rates.

Some common use cases for Serverless Functions are handling user authentication, form submission, database queries, custom slack commands, and more.

Function responses can be cached, by using the Cache-Control headers.

Serverless Functions can use any of the official runtimes, allowing them to be writting in any of the supported languages: Node.js, Go, Python, Ruby.

Serverless FunctionsLearn how to deploy Serverless Functions with Vercel.

Vercel Edge Functions allow you to deliver content to your site's visitors with speed and personalization. They are deployed globally by default on Vercel's Edge Network and enable you to move server-side logic to the Edge, close to your visitor's origin.

Edge Functions use the Vercel Edge Runtime, which is built on the same high-performance V8 JavaScript and WebAssembly engine that is used by the Chrome browser. By taking advantage of this small runtime, Edge Functions can have faster cold boots and higher scalability than Serverless Functions.

Some common use cases are handling user authentication, form submission, custom slack commands, and more.

Like Serverless Functions, Edge Functions also run after the cache, and can therefore both return responses and cache them on the Edge Network, making future invocations even faster.

Because Edge Functions are built on top of the Edge Runtime, native Node.js APIs are not supported.

While in beta, we recommend only fetching data from data sources that have read replicas or global distribution. If you anticipate fetching large amounts of data, using a Serverless Function that is deployed to a region close to your data source may be a better alternative.

Edge FunctionsLearn what Edge Functions are and how to use them with Vercel.

Vercel Edge Middleware is code that executes before a request is processed on a site. Based on the request, you can modify the response. Because it runs before the cache, using Middleware is an effective way of providing personalization to statically generated content. Depending on the incoming request, you can execute custom logic, rewrite, redirect, add headers and more, before returning a response. Edge Middleware is deployed to every region in Vercel's Edge Network, meaning they run physically close to your visitors for improved performance.

Some common use cases for Edge Middleware are authentication, A/B testing, bot protection, and geolocation. See the examples repository to start using many of the common use cases.

Edge Middleware runs before the cache and means that, unlike other functions, the response cannot be cached.

Because Edge Middleware is built on top of the Edge Runtime, native Node.js APIs are not supported.

Edge MiddlewareLearn what Edge Functions are and how to use them with Vercel.