[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live) [Discussions](/c/community/4) # Usage Optimization, Spend Management, and Security Best Practices for Vercel Pro 307 views · 9 likes · 3 posts Phil Zona (@pbzona) · 2024-08-20 · ♥ 6 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! https://youtu.be/rZ2LH6gEbgo Joeyouss (@joeyouss) · 2024-11-04 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! Phil Zona (@pbzona) · 2024-11-04 · ♥ 3 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: https://registry.terraform.io/providers/vercel/vercel/latest/docs/resources/firewall_config 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: https://github.com/vercel/examples/blob/main/edge-middleware/geolocation-country-block/middleware.ts Example for 15: https://vercel.com/docs/functions/vercel-functions-package#geolocation 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: https://vercel.com/docs/functions/edge-middleware/usage-and-pricing#billing-information One way to mitigate this is by excluding things like static assets and favicon using a matcher - example: https://vercel.com/docs/functions/edge-middleware/middleware-api#match-based-on-a-negative-lookahead 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: https://vercel.com/changelog/application-aware-observability-in-limited-beta 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!