Next.js Discord

Discord Forum

Why is an edge function slower than a serverless function?

Unanswered
Barbary Lion posted this in #help-forum
Open in Discord
Barbary LionOP
In my project, I have a simple API route that accepts a YouTube video ID as a query string parameter. It makes a fetch request to https://www.youtube.com/watch?v=${videoId}, scrapes a few pieces of data from the page, then returns a JSON response.

As a serverless function, it takes about 750-1,000ms, according to the DevTools network tab.

I added export const config = { runtime: 'edge' }; to the file and re-deployed my project to Vercel thinking that I would speed gains. Now, that API endpoint takes 3-4 seconds per request, on average, though.

Can anybody explain why this same, simple API route is slower as an edge function?

2 Replies

Usually, that is because of the location/region of your edge function. Since it's "closer to the user" instead of "closer to YouTube's server", it can be way slower compared to serverless runtime.
You can choose a region close to their data centers, like US East