Cloud, SaaS & IT Spend Cloud Infrastructure Cost Per-invocation GB-second billing model

Serverless vs Container Cost Calculator

Functions bill for the milliseconds you use; containers bill for the hours you reserve. That difference makes serverless dramatically cheaper at low and spiky volumes and dramatically more expensive at steady high ones, and there is a single request volume where the two lines cross. This calculator finds it. Enter invocations, duration and memory on one side, and instance count and hourly rate on the other, and you get both monthly bills, the cost per million invocations, the crossover volume, and the share of the container bill that is idle capacity.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Invocations per monthTotal function calls a month, including retries and scheduled runs.30000000
Average durationMean billed duration per invocation. Use the mean, not the p50, because billing is a sum.120 ms
Memory allocatedConfigured memory per function. It sets both the price per second and the CPU share you get.512 MB
Request feeCharge per million invocations, independent of how long they run.0.2 $/M req
Compute ratePrice per gigabyte-second of execution in your region and architecture.1.66667e-05 $/GB-s
Instances sized for peakHow many always-on instances or tasks you would run to absorb your busiest hour.3
Instance hourly rateAll-in hourly price of one instance or task, including the vCPU and memory it reserves.0.0416 $/h
Average utilisationMean load across the month against the peak the fleet is sized for. It prices the idle capacity, not the bill.45 %

It returns

  • Serverless monthly cost — Request charges plus GB-second compute charges, before any free tier.
  • Container monthly cost
  • Crossover volume — Monthly invocations at which the two paths cost the same.
  • Monthly saving from serverless — Container cost minus serverless cost. Negative means containers are cheaper at your volume.
  • Serverless cost per million invocations
  • Container capacity billed but idle

The formula

N*=k730hf+dmr

In plain text: Serverless = N(f + d·m·r); Containers = k·730·h; N* = k·730·h / (f + d·m·r)

  • NInvocations per month (count)
  • fRequest fee per invocation (fee per million ÷ 1,000,000) ($)
  • dAverage billed duration (seconds)
  • mMemory allocated (GB)
  • rCompute rate ($/GB-second)
  • kInstances or tasks running continuously (count)
  • hHourly rate per instance ($/h)
  • N*Crossover volume — invocations at which both paths cost the same (count)

730 hours is the average month across a year. The free tiers most providers grant are not included; subtract them separately if your account still has them.

Updated Category Cloud Infrastructure Cost Verified against published test cases Reading time 10 min

Two billing shapes, one crossing point

A function is billed as a variable cost with no fixed component: nothing runs, nothing is charged. A container fleet is billed as a fixed cost with no variable component: the instances are up whether or not requests arrive. Plot both against monthly volume and you get a line through the origin and a horizontal line. They cross exactly once, and everything about the serverless-versus-container debate is on one side or the other of that point.

Below the crossover, serverless wins and the margin widens as volume falls. A service handling 200,000 requests a month costs a few dollars on functions and the price of three always-on instances on containers, whatever those instances do with their remaining time. Above the crossover, containers win and the margin widens as volume rises, because you have started paying per request for capacity you could have rented by the hour.

Two details move the crossover a long way. The first is that the container fleet must be sized for peak, not average, so its cost carries whatever idle capacity your traffic shape forces on you — this calculator prices that idle share explicitly. The second is that the serverless charge is proportional to memory as well as time, so a function configured with four times the memory it needs costs four times as much per second and moves the crossover down by the same factor.

The honest framing is that this is a cost comparison, not an architecture recommendation. Cold starts, execution time limits, connection pooling against a relational database, and the operational cost of managing a cluster are all real and none of them appears in the arithmetic below.

GB-seconds, the request fee, and where the crossover comes from

Serverless compute is billed in gigabyte-seconds: memory in gigabytes multiplied by duration in seconds, summed over every invocation. For a month that is N × d × m, where d is seconds and m is gigabytes. Multiply by the GB-second rate and add the per-request fee, and the monthly bill is N(f + d·m·r). The bracket is the cost of one invocation, and it is the single most useful number here — multiply it by a million and you have a figure you can compare across services.

The container side is k × 730 × h: instances, hours in an average month, hourly rate. It contains no reference to traffic at all, which is the entire point.

Setting the two equal gives the crossover directly: N* = k·730·h / (f + d·m·r). Read it as the number of invocations it takes to spend the container bill one invocation at a time. The consequences are worth stating plainly. Halving function duration doubles the crossover. Halving memory doubles it too, provided the function still runs in the same time — which is the catch, because on most platforms memory and CPU are allocated together.

That coupling produces a genuine optimisation. If doubling memory halves duration, the GB-second cost is unchanged and the invocation completes twice as fast, so latency improves for free. If doubling memory reduces duration by less than half, cost rises. The only way to know is to measure duration at two or three memory settings, and it is one of the few tuning exercises in cloud that reliably pays for itself.

Worked example: 30 million invocations against three always-on instances

Your API handles 30,000,000 invocations a month. Each runs 120 ms on average with 512 MB allocated. The request fee is $0.20 per million and compute is $0.0000166667 per GB-second. The container alternative is three instances at $0.0416 an hour, sized for a peak your average load only reaches 45% of.

  1. GB-seconds. 30,000,000 × 0.12 s × 0.5 GB = 1,800,000 GB-seconds.
  2. Request charge. 30 million ÷ 1 million × $0.20 = $6.00.
  3. Compute charge. 1,800,000 × $0.0000166667 = $30.00.
  4. Serverless total. $6.00 + $30.00 = $36.00 a month.
  5. Cost per invocation. $0.0000002 request + 0.06 GB-s × $0.0000166667 = $0.0000002 + $0.000001 = $0.0000012, or $1.20 per million.
  6. Container total. 3 × 730 h × $0.0416 = $91.10 a month.
  7. Crossover. $91.10 ÷ $0.0000012 = 75.9 million invocations a month.
  8. Idle capacity. At 45% average utilisation, $91.10 × 0.55 = $50.11 of the container bill is capacity nobody is using.

At 30 million invocations serverless costs $36.00 against $91.10, a saving of $55.10 a month. You would need to grow to 75.9 million invocations — two and a half times current volume — before the containers became the cheaper option, and even then only if three instances still absorbed the peak.

How to read the crossover before you commit to an architecture

Compare the crossover against your growth rate, not just your current volume. A crossover two and a half times above today's traffic is about a year of headroom at 8% monthly growth and about three months at 40%. Anything within a year of reach should be treated as reached, because the migration takes longer than the number suggests.

Weigh the idle-capacity figure separately from the comparison. A container fleet at 45% average utilisation is not necessarily wasteful — it is what absorbing a peak looks like. But it does tell you how much of the container path is available to recover through autoscaling before the comparison needs redoing. If the fleet can scale from three instances at peak to one at trough, its effective monthly cost drops and the crossover falls with it.

Do not read a serverless win as a reason to leave memory untuned. Cost is linear in memory at constant duration, so an over-provisioned function is paying a multiple on the largest term in the bill. Measure duration at 256, 512, 1024 and 2048 MB and pick the setting where cost per invocation is lowest — it is often not the lowest memory setting, because CPU scales with memory.

Finally, if you are above the crossover, the container path itself has a second decision inside it. Steady always-on capacity is exactly the profile that commitments are priced for, and a one-year commitment moves the container line down by a third or more, pushing the crossover lower again. Interruption-tolerant work can go further with spot capacity.

Serverless cost per million invocations by memory and duration

Computed as $0.20 per million requests plus GB-seconds × $0.0000166667, where GB-seconds per million invocations is 1,000,000 × duration(s) × memory(GB).
Memory50 ms100 ms500 ms1,000 ms
128 MB$0.3042$0.4083$1.2417$2.2833
512 MB$0.6167$1.0333$4.3667$8.5333
1,024 MB$1.0333$1.8667$8.5333$16.8667
2,048 MB$1.8667$3.5333$16.8667$33.5333

Read along the diagonals: 512 MB at 100 ms and 1,024 MB at 50 ms both cost $1.0333 per million, because doubling memory while halving duration leaves GB-seconds unchanged. That is the trade tuning exploits.

Where this comparison misleads people

  • Comparing a function against an idle container fleet you would not actually run. If containers would autoscale to one instance overnight, size the container side on the average number of running instances, not the peak.
  • Using median duration instead of mean. Billing sums every invocation, so a long tail that barely moves the p50 can dominate the bill. Take the mean from the platform's own duration metric.
  • Forgetting the free tier while it still applies. Most providers grant a monthly allowance of requests and GB-seconds. It matters enormously at small volumes and rounds to nothing above a few million invocations.
  • Ignoring what sits behind the function. A managed gateway, a queue, a NAT gateway for outbound traffic and provisioned concurrency are all separate meters, and on small functions they routinely exceed the function charge itself.
  • Pricing containers without the platform underneath. A managed Kubernetes control plane, load balancers and node overhead are real monthly costs that a single instance rate does not include.
  • Treating cold starts as a cost line. They are a latency problem, and the usual fix — provisioned concurrency — converts serverless back into a fixed hourly charge, which moves the crossover sharply in favour of containers.

Key terms

GB-second
One gigabyte of allocated memory held for one second of execution. The unit serverless compute is billed in, so cost is proportional to memory and duration together.
Crossover volume
The monthly invocation count at which per-invocation billing and always-on capacity cost the same. Below it functions are cheaper; above it, containers.
Provisioned concurrency
Pre-warmed function instances kept ready to remove cold starts. They are billed by the hour, which gives the serverless path a fixed component and raises its cost at low volume.
Peak sizing
Choosing instance count so the busiest period is served acceptably. It is what forces idle capacity into the container bill, and it is why average utilisation is well below 100% on most fleets.

What the money does not decide

Cost is rarely the binding constraint at either extreme. Below a million invocations a month the absolute difference is a few dollars and you should choose on operational simplicity, which almost always favours functions. Far above the crossover the difference is large enough that architecture follows the money, and long-running or connection-heavy workloads have usually already been pushed off functions by execution limits and pooling problems rather than by price.

The interesting cases sit near the crossover, and there the deciding factors are traffic shape and team capacity. Spiky traffic favours functions even above the nominal crossover, because the container fleet would have to be sized for a peak it rarely reaches. Steady traffic favours containers even below it, because a commitment can be applied to steady capacity and cannot be applied to invocations.

Whichever way it lands, express the result as a unit cost so the decision is auditable later. Divide either monthly bill by the transactions it serves using the cost per transaction calculator, and revisit the comparison whenever volume doubles — the crossover does not move, but your position relative to it does.

Frequently asked questions

At what request volume does serverless stop being cheaper?

At the crossover volume, which is the container bill divided by the cost of a single invocation. There is no universal number because it depends entirely on function duration and memory: a 50 ms, 128 MB function crosses at an order of magnitude more invocations than a one-second, 1 GB function against the same container fleet. Run your own figures; the calculator reports the crossover directly.

Does allocating more memory always cost more?

Not necessarily, because CPU is allocated in proportion to memory on most platforms, so a function with twice the memory often finishes in less than half the time. Cost is memory multiplied by duration, so if duration falls by more than the memory rises in proportion, total cost falls. Measure duration at several memory settings rather than assuming the smallest setting is cheapest.

Should I include the free tier?

Only if your account still has it and you are comparing at low volume, where it dominates. This calculator deliberately excludes it, because free allowances vary by provider and account age and they round to nothing above a few million invocations a month. If you want it, subtract the free requests and GB-seconds from your inputs before running the numbers.

What about the API gateway, queue and NAT charges in front of the function?

They are separate meters and this calculator does not include them. On small, short functions they frequently cost more than the function itself — a managed API gateway charged per million requests can exceed the request fee several times over, and a NAT gateway charges both hourly and per gigabyte processed. Price the whole request path, not just the compute.

How does provisioned concurrency change the comparison?

It gives the serverless path a fixed hourly component, which is the very thing that made containers expensive at low volume. Once you are paying to keep function instances warm around the clock, the serverless line no longer passes through the origin and the crossover moves sharply towards containers. Model provisioned concurrency as an always-on fleet and compare it that way.

Why does my container fleet cost more than the instance rate suggests?

Because the instance is not the whole platform. A managed Kubernetes control plane, load balancers, node-level system overhead, logging agents and the spare capacity needed for rolling deployments all add to the bill. When comparing, use the all-in cost of the fleet divided by the number of instances rather than the list price of one instance.

Is average utilisation part of the cost calculation?

No — it prices the idle share of the container bill but does not change either total. The container cost is instances multiplied by hours multiplied by rate whatever the load. Utilisation matters because it tells you how much of that bill autoscaling could recover, which is the first thing to try before concluding that containers are too expensive.

Does the crossover change if I use spot or committed capacity?

Yes, and substantially. Both lower the effective hourly rate on the container side, which lowers the container line and therefore the crossover volume. A one-year commitment at a third off moves the crossover down by a third. Enter the discounted effective hourly rate rather than the list rate to see it.

References