Book a free call

How Much Does Serverless Cost?

Serverless cost depends on how often your functions run, how long they run and how much memory they use. Here is how the pricing works and what a service costs.

Hertiv engineering teamReviewed by a senior engineer
6 min read
How Much Does Serverless Cost?
On this page

Short answer

Serverless typically costs a few dollars a month for a small service and scales with use, because you pay per request and per unit of compute time rather than for servers sitting idle. The main charges are requests, duration measured in GB-seconds, and extras such as data transfer and storage. A small API often costs less than a dollar a month after the free tier.

What does serverless cost?

Serverless cost is the sum of what you pay for each function invocation, the compute time it uses, and the services around it, such as databases, storage and data transfer. There is no charge for idle time, which is the main difference from renting a server.

The pricing model is simple on paper: a charge per request and a charge per GB-second of compute. A GB-second is one gigabyte of memory held for one second, so a function with 512 MB of memory that runs for 200 milliseconds uses 0.1 GB-seconds per call.

Using the rates published for AWS Lambda, requests cost $0.20 per million, duration costs $0.0000166667 per GB-second on x86 and about $0.0000133334 on Arm, and the free tier covers 1 million requests and 400,000 GB-seconds a month. Rates vary by provider and region, so check the vendor site before you budget.

That sounds cheap, and for many workloads it is. The bill only grows when functions run very often, run for a long time, or hold a lot of memory. A function that runs constantly is effectively a server, and it is priced like one, often at a higher rate.

How are you charged for serverless?

You are charged for serverless in four main ways: requests, duration, data transfer and the services your functions call. The first two are the core of the bill, and the last two are where surprise charges usually appear.

Charge How it is billed What drives it
Requests Per invocation Traffic volume and retries
Duration Per GB-second Memory size and run time
Data transfer Per gigabyte out Response sizes and downloads
Storage and state Per gigabyte per month Files, databases and queues
Extras Per use Provisioned concurrency, logging, API calls

Duration is usually the largest charge, because it multiplies memory by time by calls. Doubling the memory doubles the duration charge, though it can also make the function faster, so the right memory setting is a trade-off rather than a race to the smallest size. See what serverless is for how the model works before you estimate costs.

What drives the bill up or down?

The serverless bill is driven by traffic, run time, memory and the services around the functions. Small changes in any of these can move the total a lot, because the charges multiply together.

  • Traffic volume. More calls mean more request and duration charges, so a traffic spike shows up directly in the bill.
  • Run time. A function that takes two seconds costs ten times as much as one that takes 200 milliseconds at the same memory.
  • Memory size. Duration is billed per GB-second, so memory and time multiply together.
  • Retries. A failing function that retries three times is billed three times, which is why error handling matters for cost.
  • Services around it. Databases, queues, storage and API gateways often cost more than the functions themselves.
  • Cold starts. Functions that start rarely pay a startup cost in time, which adds to duration on the first call.

The cheapest lever is usually run time: a faster function costs less and performs better. The most overlooked lever is retries, because a small error rate can double the bill without anyone noticing. For the trade-offs against a fixed server, see serverless vs microservices.

Example (hypothetical): a small API on Lambda

Example (hypothetical): a small API runs on AWS Lambda with 512 MB of memory and an average run time of 200 milliseconds. It handles 5 million requests a month. Using the published Lambda rates, here is the monthly bill.

Requests: 5 million minus the 1 million free tier leaves 4 million billable requests at $0.20 per million, which is $0.80. Duration: each call uses 0.5 GB for 0.2 seconds, which is 0.1 GB-seconds, so 5 million calls use 500,000 GB-seconds. The free tier covers 400,000, leaving 100,000 billable GB-seconds at $0.0000166667 each, which is about $1.67.

The total is $0.80 + $1.67 = $2.47 a month, before data transfer and the database. That is the point of serverless for a small service: the bill is a few dollars, and it grows only when traffic grows. The same API on a small always-on server would cost far more each month, even when nobody calls it.

When does serverless cost more than servers?

Serverless costs more than servers when functions run constantly at high volume, because the per-call pricing adds up to more than a fixed machine would cost. The crossover depends on traffic, run time and memory, but the pattern is consistent.

Workload Serverless Fixed server
Spiky, occasional traffic Cheaper: you pay only when called Expensive: idle time is wasted
Steady, low traffic Cheaper: a few dollars a month Expensive: the server runs all month
Steady, high traffic Costly: per-call charges add up Cheaper: fixed cost, high use
Long-running jobs Costly: duration charges grow Cheaper: the machine is already paid for
Unpredictable traffic Better: scales without planning Risky: needs capacity planning

A good rule is to estimate the monthly cost at your real traffic before choosing. If the functions would run for most of the month at high volume, compare the serverless estimate with a fixed server price, and remember to include the database and data transfer in both. For the basics of the model, see what serverless computing is.

What are the common mistakes?

The most common serverless cost mistakes are ignoring the services around the functions, letting retries multiply the bill, and choosing memory without testing.

  • Forgetting the database. The functions are cheap, but the database, storage and API gateway often cost more.
  • Unbounded retries. A failing function that retries forever is billed for every attempt.
  • Too much memory. Memory you do not need doubles the duration charge for no benefit.
  • Too little memory. Too little memory makes the function slow, which also raises the duration charge.
  • No cost alerts. A traffic spike or a bug can run up a large bill before anyone notices.
  • Chatty functions. Functions that call other services on every invocation add charges each time.

How do you keep the serverless bill down?

You keep the serverless bill down by making functions faster, right-sizing memory, limiting retries and watching the bill every week.

  1. Right-size memory. Test each function at several memory settings and pick the one with the lowest cost per call.
  2. Shorten run time. Cache repeated work, reuse connections and avoid slow calls inside the function.
  3. Limit retries. Set a small retry count and a dead-letter queue so failures do not multiply the bill.
  4. Batch where possible. Process several items per call instead of one call per item.
  5. Set billing alerts. Alert at 50% and 80% of the expected monthly spend so surprises are caught early.
  6. Review the services. Check the database, storage and gateway costs each month, since they often exceed the function charges.

Review the bill monthly and compare it with the traffic, so a rising bill always has a visible cause. A cloud services review can help if the bill keeps growing without a clear reason, or if the architecture has drifted from the original design.

Key takeaways

  • Serverless charges per request and per GB-second, not for idle time
  • Duration is usually the largest charge, so faster functions cost less
  • A small API can cost a few dollars a month after the free tier
  • Constant high-volume workloads can cost more than a fixed server
  • Retries and surrounding services are the usual causes of surprise bills

Frequently asked questions

Is serverless really cheaper than a server?

It depends on the workload. For spiky or low traffic, serverless is usually cheaper because you pay only when functions run. For steady high-volume traffic or long-running jobs, a fixed server is often cheaper. Estimate both at your real traffic before choosing.

What is a GB-second in serverless pricing?

A GB-second is one gigabyte of memory held for one second. A function with 512 MB of memory running for 200 milliseconds uses 0.1 GB-seconds per call. Providers charge per GB-second, so memory size and run time multiply together to set the duration cost.

Does serverless have a free tier?

Most providers offer one. AWS Lambda, for example, includes 1 million requests and 400,000 GB-seconds a month at no charge. That covers many small services entirely, so check the vendor site for the current free-tier terms before you budget.

Why is my serverless bill higher than expected?

The usual causes are retries multiplying the bill, a database or storage service costing more than the functions, or a traffic spike. Check the billing breakdown by service first, then look at error rates and retry counts for the functions themselves.

How do I estimate serverless cost before building?

Estimate the monthly requests, the average run time and the memory size, then apply the provider's per-request and per-GB-second rates. Add the database, storage and data transfer costs, and set a billing alert so the first real month does not surprise you.

Can serverless costs spike suddenly?

Yes. A traffic spike, a bug that retries endlessly, or a runaway function can raise the bill quickly, because there is no fixed cap by default. Billing alerts and retry limits are the two controls that prevent a spike from becoming a large bill.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: software products in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning a serverless service and want the cost right? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Cloud Services service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call