Configuring Regions for Vercel Functions

Learn how to configure regions for Vercel Functions.
Table of Contents

In a globally distributed application, the physical distance between your function and its data source can impact latency and response times. Therefore, Vercel allows you to specify the region in which your functions execute, ideally close to your data source (such as your database). This guide will walk you through configuring regions for your Vercel Functions.

If your functions fetch from or write to a data source, you should optimize to reduce latency between where your function executes and where your data source is located.

For Serverless Functions

  • By default, Serverless Functions execute in Washington, D.C., USA (iad1) for all new projects to ensure they are located close to most external data sources, which are hosted on the East Coast of the USA. You can set a new default region through your project's settings on Vercel
  • You can define the region in your vercel.json using the regions setting
  • You can set your region in the Vercel CLI

For Edge Functions:

  • By default Edge Functions execute in the region closest to the incoming request
  • You can set one or more preferred regions using the route segment config preferredRegions or specify a regions key within a config object to set one or more regions for you functions to execute in
This can only be set for Edge Functions

By default, Edge Functions execute in the region that is geographically closest to the incoming request, reducing network request times. However, if your function depends on a data source, you may want it to be close to that source for fast responses.

To configure which region (or multiple regions) you want your function to execute in, pass the ID of your preferred region(s) in the following way:

The preferredRegion option can be used to specify a single region using a string value, or multiple regions using a string array. See the Next.js documentation for more information.

Next.js (/app)
Next.js (/pages)
Other frameworks
app/api/regional-example/route.ts
export const runtime = 'edge'; // 'nodejs' is the default
// execute this function on iad1 or hnd1, based on the connecting client location
export const preferredRegion = ['iad1', 'hnd1'];
export const dynamic = 'force-dynamic'; // no caching
 
export function GET(request: Request) {
  return new Response(
    `I am an Edge Function! (executed on ${process.env.VERCEL_REGION})`,
    {
      status: 200,
    },
  );
}

During regional outage, Vercel has automatic failover to the next closest region to maintain uptime. This is applicable for both global and regionally specified Edge Functions. See the outage resiliency docs for more information.

If you're not using a framework, you must either add "type": "module" to your package.json or change your JavaScript Functions' file extensions from .js to .mjs

The default Function region is Washington, D.C., USA (iad1) for all new projects.

To change the default region in the dashboard:

  1. Choose the appropriate project from your dashboard on Vercel
  2. Navigate to the Settings tab
  3. From the left side, select Functions
  4. Use the Function Region dropdown to select your project's default region:
    The Function Region setting in a Vercel project's dashboard
    The Function Region setting in a Vercel project's dashboard
This can only be set for Serverless Functions

To change the default region in your vercel.json configuration file, add your region code to the "regions" key:

vercel.json
{
  "regions": ["sfo1"]
}

Enterprise users can also use functionFailoverRegions to specify regions that a Serverless Function should failover to if the default region is out of service.

This can only be set for Serverless Functions

Use the vercel --regions command in your project's root directory to set a region. Learn more about setting regions with the vercel --regions command in the CLI docs.

Multiple Serverless Function regions are only allowed for Enterprise accounts. If your Project requires more than one Serverless Function region, contact Sales.

Multiple Edge Functions regions can be set regardless of your plan.

To learn more about the regions that you can set for your Functions, see the region list.

Vercel Functions have multiple availability zone redundancy by default. Multi-region redundancy is available depending on your runtime.

Setting failover regions are available on Enterprise plans

Enterprise teams can enable multi-region redundancy for Vercel Functions using Node.js.

To automatically failover to closest region in the event of an outage:

  1. Select your project from your team's dashboard
  2. Navigate to the Settings tab and select Functions
  3. Enable the Function Failover toggle:

To manually specify the fallback region, you can pass one or more regions to the functionFailoverRegions property in your vercel.json file:

vercel.json
{
  "functionFailoverRegions": ["dub1", "fra1"]
}

The region(s) set in the functionFailoverRegions property must be different from the default region(s) specified in the regions property.

During an automatic failover, Vercel will reroute application traffic to the next closest region, meaning the order of the regions in functionFailoverRegions does not matter. For more information on how failover routing works, see functionFailoverRegions.

You can view your default and failover regions through the deployment summary:

Failover regions for your Serverless Functions shown in the deployment summary.
Failover regions for your Serverless Functions shown in the deployment summary.

Region failover is supported with Secure Compute. See Region Failover to learn more.

In the event of regional downtime, Vercel will automatically reroute traffic to the next closest Edge Network region on all plans. For more information on which regions Vercel routes traffic to, see Outage Resiliency.

Last updated on February 21, 2024