Configuring Regions for Vercel Functions
Learn how to configure regions for Vercel Functions.The Vercel platform caches all static content at the edge by default. This means your users will always get static files like HTML, CSS, and JavaScript served from servers that are closest to them. See Regions for a full list of our regions.
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). Serverless Functions are deployed to the iad1 region by default to ensure your Serverless Functions are located close to most external data sources hosted on the East Coast of the USA.
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 theregions
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
preferredRegion
or specify aregions
key within a config object to set one or more regions for you functions to execute in
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.
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:
- Choose the appropriate project from your dashboard on Vercel
- Navigate to the Settings tab
- From the left side, select Functions
- Use the Function Region dropdown to select your project's default region:
To change the default region in your vercel.json
configuration file, add your region code to the "regions"
key:
{
"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.
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:
- Select your project from your team's dashboard
- Navigate to the Settings tab and select Functions
- 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:
{
"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:
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.
Was this helpful?