Vercel Functions enable developers to write server-side logic to connect to their database or external APIs. If you are seeing slow response times, this guide will help you identify the root issue for the additional latency.
When a function starts for the first time, it’s a "cold start". Subsequent requests to that function are then considered warm. Cold starts typically occur in under 1% of invocations. The duration of a cold start varies from under 100 ms to over 1 second.
This guide will help you improve the performance of your functions and understand how to determine if the latency increase is from a cold start.
The following suggestions will help you ensure optimal performance of your Vercel Serverless Functions:
- Choose the correct region for your functions: Node.js Functions are deployed to
us-eastby default. All customers can change the default region for their functions in their project settings. Choose a region that’s closest to your data source for optimal performance.
- Use proper caching headers: Function responses can be cached using
Cache-Controlheaders. This will help ensure optimal performance for repeat visitors, and Vercel’s Edge cache even supports
stale-while-revalidateheaders. Note that cache misses will still need to request data from your origin (e.g. database) rather than reading directly from the Edge cache (faster).