The Cost Structure of using Serverless Functions on Vercel

LAST UPDATED: September 07, 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.

TLDR;

  1. Function Invocations: Charged per function call, excluding cache hits.
    1. Free for the first 100K invocations
    2. $20 for the first 1M invocations
    3. $0.60 per additional 1M invocations.
  2. Function Duration: Charged based on execution time in GB-Hours.
    1. Free for the first 100 GB-Hours
    2. pro plan: $20 for 1,000 GB-Hours
    3. $180 per additional 1,000 GB-Hours/ $0.18 per 1 GB-Hour.
  3. Edge Network (CDN) Usage:
    • Fast Data Transfer: refers to the data transferred between Vercel's CDN and the end user's device
    • Fast Origin Transfer: refers to the data transferred between Vercel's CDN and the "origin" - which in this case refers to Vercel's compute resources like Serverless Functions, Middleware, or the Data Cache
    • Edge Requests
    • Edge Request Additional CPU Duration

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

1. 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.

2. 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.

3. Edge Network (CDN) Usage

Vercel doesn't charge you only for function calls and function duration, but also for the response size and the request count.

Serverless Function execution will increase edge network usage as well. Caching your Serverless Function reduces the GB-hours of your Serverless Function, but does not reduce the network usage that comes with executing your Serverless Function. Vercel Docs

3.1 Transferred data size

The size of the requests as well as the response of the serverless functions

will increase the following metrics:

  • Fast Data Transfer (FDT): refers to the data transferred between Vercel's CDN and the end user's device
    • Free for 100 GB
    • $20 for 1TB
    • $150 per 1TB/ $0.15 per 1 GB
  • Fast Origin Transfer (FOT): refers to the data transferred between Vercel's CDN and the "origin" - which in this case refers to Vercel's compute resources like Serverless Functions, Middleware, or the Data Cache
    • Free for 10 GB
    • $20 for 100 GB
    • $6 per 100 GB/ $0.06 per 1 GB

3.2 Requests

Also, Vercel charges for the count of requests your app makes after 1M requests.

  • Edge Requests are all requests made to your site, including static assets and functions.
    • Free for the first 1M requests
    • $20 for the 10M requests
    • $20 per additional 10M requests/ $2 per 1M requests
  • Edge Request Additional CPU Duration
    • Free till unspecified time
    • $20 for the first hour
    • $0.30 per additional hour

Finally

While Vercel offers an outstanding DX and unparalleled convenience, these benefits come with a price. It's essential to evaluate whether your project's revenue can comfortably cover total costs. If not, consider alternatives such as self-hosting (Coolify), other hosting providers such as Netlity, Cloudflare Pages, Render, and Fly.io

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

Need help lowering your costs and optimizing your usage plan on Vercel? Feel free to reach out to me via email or DM me on X.