How to set usage limits on serverless compute like vercel

Saurabh Mhatre
3 min readJun 13, 2024

--

Title image

Setting usage limits on serverless compute platforms like Vercel is important for several reasons:

1. Cost Management: Serverless compute platforms typically charge based on usage. Without usage limits, unexpected spikes in traffic or resource usage can lead to significantly higher costs. Setting limits helps to manage and predict expenses better.

2. Resource Allocation: Usage limits ensure that resources are allocated efficiently. This prevents one project or service from consuming excessive resources, which could impact the performance of other projects or services sharing the same infrastructure.

3. Security: Limiting usage can mitigate the risk of denial-of-service (DoS) attacks or other malicious activities that aim to overwhelm your application. Usage caps can help to throttle and manage such events more effectively.

4. Stability and Performance: By setting limits, you can prevent scenarios where excessive usage leads to performance degradation. This helps maintain a stable and responsive application, ensuring a consistent experience for users.

5. Compliance and Governance: For organizations that need to comply with specific regulatory requirements or internal governance policies, setting usage limits ensures adherence to such standards. It helps in maintaining control over how and where resources are used.

6. Scalability Planning: Usage limits can provide valuable data on how your application scales. By monitoring and analyzing the usage within set limits, you can make informed decisions about scaling strategies and necessary infrastructure investments.

7. Preventing Abuse: In multi-tenant environments or when providing public APIs, setting usage limits prevents users from abusing the system. This protects the overall system integrity and ensures fair usage among all users.

Overall, setting usage limits is a proactive measure to ensure cost efficiency, resource optimization, security, and consistent performance of serverless applications.

Setting up usage limits on serverless platforms like Vercel involves several steps. Here’s a general guide on how to do it:

1. Understand Vercel’s Pricing and Limits
Before setting limits, it’s important to understand Vercel’s pricing model and the default usage limits provided by their plans. Vercel offers several tiers, each with different limits on build minutes, bandwidth, and serverless function execution.

2. Monitor Usage
Regularly monitor your usage to understand your typical consumption patterns. Vercel provides analytics and usage dashboards where you can track metrics such as build minutes, bandwidth, and serverless function invocations.

3. Set Up Alerts
Vercel allows you to set up alerts for when you approach certain usage thresholds. This can be done through the Vercel dashboard:

- Go to your project’s settings.
- Navigate to the "Usage" section.
- Set up email notifications for when you reach certain percentages of your usage limits.

4. Implement Rate Limiting in Your Application
In addition to setting platform-level limits, you can implement rate limiting within your serverless functions to control how frequently they can be invoked. This can be done using middleware or custom logic within your functions.

5. Upgrade or Apply for Custom Limits
If your project requires higher limits than what’s provided by your current plan, consider upgrading to a higher tier. For enterprise-level requirements, Vercel offers custom plans where you can negotiate specific limits tailored to your needs.

6. Use Environment Variables for Configuration
You can use environment variables to configure limits and thresholds in your application. This makes it easier to adjust settings without changing the codebase.

7. Automate Deployments and Scaling
Leverage Vercel’s deployment hooks and integrations to automate scaling operations. This can help manage usage more effectively, especially during high traffic periods.

8. Implement Budget Management Tools
Consider using third-party tools or scripts to manage your budget and track usage across multiple services. These tools can provide additional insights and control over your spending.

Detailed Steps to Set Up Usage Alerts on Vercel:
1. Log In to Vercel: Access your Vercel account by logging in at vercel.com.
2. Navigate to Project Settings: Select the project for which you want to set up usage limits and go to its settings.
3. Usage Tab: Go to the "Usage" tab where you can view your current usage and set up alerts.
4. Set Up Alerts: Configure email alerts to notify you when you reach certain usage thresholds (e.g., 80% of your build minutes or bandwidth).

By following these steps and continuously monitoring your usage, you can effectively manage and control your serverless compute usage on Vercel, ensuring cost efficiency and optimal resource allocation.

--

--