The Cost Structure of using Serverless Functions on Vercel

LAST UPDATED: October 05, 2024

This concise guide will help you understand the reasons behind unexpectedly large bills from Vercel and identify specific code sections that contribute to higher costs. Recently, many developers have expressed concerns about escalating charges from Vercel. Let's examine one of the key factors driving these increased costs.

Serverless Functions

Serverless functions in Next.js are a way to create backend logic without managing a traditional server. They could be API endpoints or server actions.

Here are some common use cases for serverless functions in Next.js:

  1. Form Handling
  2. Authentication
  3. External API Integration
  4. Image Processing
  5. Email Sending
  6. Database Operations
  7. Webhooks
  8. Payment Processing

Cost Structure

When you create a serverless function you will be charged for the following

Function Invocations

The number of invocations is calculated based on the number of times your function gets called, regardless of the response status code. - Vercel Docs

Each time your application triggers your serverless function, it will raise the usage plan by counting the number of invocations that have occurred.

  • Free for the first 100K invocations
  • $20 for the first 1M invocations
  • $0.60 per additional 1M invocations.

Function Duration

You are charged based on the amount of time your Serverless Functions has run - Vercel Docs

Whenever your app calls your serverless function, it increases the usage plan.

  • Free the first 1,00 GB-Hours
  • $20 for the first 1,000 GB-Hours
  • $180 per additional 1,000 GB-Hours/ $0.18 per 1 GB-Hour.

Finally

While Vercel offers an outstanding DX and unparalleled convenience, these benefits come with a price. It's essential to evaluate if there are a room for usage optimization to keep usage at low level with minimum tradeoffs. Here are some Vercel alternatives, that you might want to try out.

I hope this guide provides you with a more comprehensive understanding of the expenses linked to your serverless functions.