Thanks! Great questions, and as you might expect…it depends
WAF based geo-fencing is a great option for simple use cases where you just need to redirect users without any additional logic. Depending on what you’re trying to comply with, I’d probably recommend managing these rules with Terraform: Terraform Registry
The alternative is to handle it in edge middleware. This gives you a lot more flexibility because you can execute whatever logic you need (if any). Depending on which version of Next you’re using, you can access geolocation data directly on the request via req.geo
(version <=14) or by using the geolocation()
helper in @vercel/functions
(version 15).
Example for <=14: examples/edge-middleware/geolocation-country-block/middleware.ts at main · vercel/examples · GitHub
Example for 15: @vercel/functions API Reference
Keep in mind that middleware is a billable resource - it is low cost and not something I’ve ever seen cause significant billing problems, but you would likely incur an invocation for every page since you mentioned this is a compliance use case. You can ballpark what your costs would be by assuming most edge requests you receive will also incur a middleware invocation. Check here for pricing: Usage & Pricing for Edge Middleware
One way to mitigate this is by excluding things like static assets and favicon using a matcher - example: Edge Middleware API Reference
Re: CPU time, yes, thank you for flagging this - I should have mentioned it in the video. The CPU does indeed scale up and down when you adjust your memory allocation, even though it’s not explicit in the config object.
This can have a significant effect on CPU-bound workloads as they will have less resources, run more slowly (increasing function duration), and potentially throttle. Finding the right balance of performance and cost-efficiency is more art than science, but our solution for this (still in beta) is the observability tab: Application-aware Observability now in limited beta - Vercel
If you’re using our monitoring product, you should have access to this, so feel free to play around and let me know what questions you have. Docs are a bit sparse at the moment because it’s being worked on so actively, but if you have feedback or anything that you’d like to see included in those views, we’re always open to ideas.
I hope this helps!