Behind The Scenes of Vercel's Infrastructure - Achieving Optimal Scalability and Performance - Vercel
Behind The Scenes of Vercel's Infrastructure - Achieving Optimal Scalability and Performance - Vercel
← Back to Blog
Engineering
Friday, January 27th 2023
Posted by
Lydia Hallie
Staff Developer Advocate
Vercel's platform provides speed, reliability, and the convenience of not having to worry about setting up and maintaining your own
infrastructure. But what exactly goes on behind the scenes when we deploy our projects to Vercel, and what happens when you make
a request to a site on the platform?
This post will go behind the scenes, explaining how Vercel builds and deploys serverless applications for maximum scalability,
performance, and fast iterations.
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 1/18
Building and deploying any framework
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
1 Interested in talking to
Deployments start with code written in one of the over 35 frameworks supported by Vercel, or by using the Build Output API. 2 a Vercel product expert?
Deployments can be created through the Vercel CLI or by pushing code to your git repository. The Vercel Git integration automatically 3
A deployment process triggered from the CLI starts with two API requests:
1. Uploading project files
A POST request is made containing the project’s files to be uploaded to a scalable, secure, and highly durable data storage service¹.
2. Creating the deployment
Once the files have been uploaded successfully to the storage service, another POST request is made to start the build and
deployment process.
Before the deployment can be created, Vercel first authenticates the user and inspects the request to confirm its authenticity and the
user's permission to create the deployment to protect against unauthorized access and loss of integrity. It also validates the Vercel
configuration in the vercel.json file.
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 2/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 3/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
The build step transforms the project into a Vercel deployment by executing a "builder" on the source code. The builder can be an
internal one provided by Vercel, or a custom builder that requires installation from an npm registry. Vercel's build system is configured
to automatically detect over 35 frontend frameworks or to recognize a prebuilt project that adheres to the Build Output API's spec.
This API allows you to create a build output that is compatible with Vercel's deployment platform and enables you to utilize all of the
platform's features.
While the build container is processing the files, it pings an API endpoint that keeps track of the deployment’s status. The CLI and
dashboard use this endpoint to display the correct status to the user.
The build container creates a build output that runs on one of Vercel's supported runtimes, and provisions resources such as:
– Serverless Functions for handling API routes and server-side rendered pages
– Edge Functions for Middleware and other functions using the edge runtime
– Optimized Images
– Static output
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 4/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
Deployment triggers a build in the build container which provisions resources and updates the deployment's status
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 5/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
Deployment triggers a build in the build container which provisions resources and updates the deployment's status
Once the necessary resources have been provisioned, a Deployment database document is created and the deployment metadata is
uploaded to static storage¹. This metadata is later used during the request phase to route the user to the correct location and invoke
the appropriate resource based on the incoming request path.
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 6/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
The newly created deployment is now ready to be served via the Vercel CDN. What happens when a user requests a website hosted
on Vercel is part of the request phase. 1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 7/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 8/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 9/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 10/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
failover and DDoS protection, and provides performance-enhancing features that are designed 3 to improve resiliency and reduce the
impact of attacks. 4 Schedule a call
Vercel's IP address connects the user to the nearest edge location, which acts as a gateway to the network infrastructure⁵.
This is where the request enters Vercel's Kubernetes cluster. The request is first inspected and filtered for malicious users, then routed
to a virtual machine⁶ serving as a reverse proxy. This gateway is responsible for rewriting and proxying requests.
First, it determines which version of a deployment should be served to a user based on data such as the hostname of the incoming
request, and fetches the deployment’s metadata. Depending on whether the request path matches a route specified in the
deployment’s metadata, the request either resolves with a status code 404 , or continues to produce a response.
Before continuing to the response phase, the request might get modified if Vercel Edge Middleware is enabled, in which case the
request is first forwarded to a platform responsible for executing edge functions.
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 11/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 12/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
– For Edge Functions - such as a server-rendered page or API Route using the edge runtime - the gateway formats the request
to invoke an Edge Function execution at the edge. 1 Interested in talking to
– For pages using Incremental Static Regeneration, the gateway first checks whether this3 page has been rendered before,
2 a Vercel product expert?
which would make its static output available in static storage¹. If that’s not the case, the4 gateway
Schedule invokes
a call a Serverless Function
execution⁷ to dynamically (re)generate the content. Invoking this function also happens in the case of stale content, which
happens when the static resource was cached previously but its time-to-live (TTL) has passed. In that case, the stale content
gets served to the user while the function gets invoked in the background to regenerate the content.
– For optimized images, the request gets forwarded to a dedicated service to optimize the image on-the-fly and cached at the
edge for subsequent requests, reducing the file size and using modern formats supported by the requesting client's browser.
The optimized image will be served until it expires, at which point a stale version of the image will be served while the image is
re-optimized in the background. The image's expiration time is determined by either a configuration setting or the upstream
image's Cache-Control header.
The responses of all the above-mentioned steps get cached based on the caching headers to speed up future lookups. The response
phase indicates the end of the request lifecycle on Vercel.
Conclusion
Setting up and maintaining your own infrastructure can be tedious, and requires selecting and configuring the appropriate server
hardware and operating system, setting up and configuring network infrastructure, configuring and maintaining the necessary
software stack, and more.
Ensuring that your infrastructure is secure and scalable requires continuous monitoring, maintenance, and updating. This includes
implementing security protocols and solutions to protect against threats and vulnerabilities, as well as ensuring that your infrastructure
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 14/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
can handle a spike in traffic efficiently. All these tasks are time-consuming, complex, and require a dedicated team of experienced
engineers to handle at scale. 1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 15/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
Try out Vercel today and experience the ease, security, and performance benefits for yourself.
1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
Develop.Preview.Ship.
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 17/18
21/08/2023, 01:52 Behind the scenes of Vercel's infrastructure: Achieving optimal scalability and performance – Vercel
Vercel is the platform for frontend developers, providing the speed and reliability
innovators need to create at the moment of inspiration. 1 Interested in talking to
2 a Vercel product expert?
3
4 Schedule a call
Start Deploying
Tour the Product
https://vercel.com/blog/behind-the-scenes-of-vercels-infrastructure 18/18