Edge middleware running in a far away region

I have a project where a edge middleware redirects unauthenticated users.

The middleware runs before the serverless function, but they’re run in a different region from the serverless function, which increases latency.

Is this normal behavior, or is there a solution to this issue?

Here’s a screenshot of the log page:

Here you can see that the edge middleware runs in Singapore, which is different from the serverless function.

My understanding was that edge functions run in the closest region to the user. I’m located in Seoul, so I expected the middleware to run in icn1, which is the closest region.

Thank you in advance.

Hey, @lojcde! Welcome to the Vercel Community :waving_hand:

Yes, from my understanding, this is expected behavior. Edge Middleware and Serverless Functions can run in different regions and operate independently.

In your case, Singapore (sin1) is geographically close to Seoul and was likely chosen based on network conditions to deliver optimal performance at that time. Middleware doesn’t need to run in the same region as your Serverless Function because they serve different purposes: middleware handles request processing and routing, while serverless functions run your application logic.