Usage Optimization, Spend Management, and Security Best Practices for Vercel Pro

Thank you to everyone who joined the “Usage Optimization, Spend Management, and Security Best Practices” session! During the session, you:

  • Learned how to optimize your team’s infrastructure spend
  • Discovered Vercel’s out-of-the-box features to keep your site secure

We encourage you to use this space for any follow-up questions, discussions and connect with others you met on the call.

What insights or strategies are you excited to implement from today’s session? Feel free to share your thoughts or ask any lingering questions!

5 Likes

Hey @pbzona , great video! I couldn’t join it live but just viewed. However, I do have a couple of questions:

  • For applications that require regional compliance, is WAF-based geo-fencing recommended, or are there other methods for redirecting specific regions?
  • Since billing is based on provisioned memory and execution time, does CPU adjustment impact costs?

Thank you in advance!

Thanks! Great questions, and as you might expect…it depends :slight_smile:

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!

3 Likes