Square CloudSquare Cloud

Serverless or an always-on server: which is cheaper

Serverless is usually cheaper with low or rarely spiking traffic; an always-on server tends to cost less under steady load. The break-even point depends on the volume, duration and memory of each request.

Updated 8 min read

Learning objectives

After reading this article you will be able to:

  • Understand how serverless charges (invocations and GB-seconds) and how a fixed server charges
  • Work out the break-even point between the two with your own numbers
  • Spot the costs that show up later: cold starts, bandwidth, database and logs
On this page

Serverless promises you only pay for what you use. An always-on server promises a price that doesn't change at the end of the month. Both are true, which is why "which is cheaper" has no fixed answer: it depends on request volume, how long each request takes and how traffic spreads across the month.

This article builds the break-even math with hypothetical round prices; current rates are on the official pages listed in the sources. For the technical differences between the models, like duration limits and persistent connections, see serverless or container.

How does serverless charge?#

A serverless function usually has three meters:

  1. Invocations: a price per million executions.
  2. Duration: configured memory times execution time, measured in GB-seconds. On AWS Lambda, memory goes from 128 MB to 10,240 MB and CPU scales with it, so giving a function more memory to make it faster also makes every second cost more.
  3. HTTP entry: when the function sits behind an API gateway, the gateway charges per call received and for data sent out, as a separate line.

Duration covers the whole execution, including time spent waiting on the database or an external API. A 512 MB function that runs for 200 ms uses 0.5 × 0.2 = 0.1 GB-second; if it spends 3 seconds waiting on a slow service, it pays for those 3 seconds.

AWS includes a monthly allowance of invocations and GB-seconds on Lambda. For a low-traffic API that keeps compute near zero, and what's left on the bill is the gateway, bandwidth, logs and the database.

How does an always-on server charge?#

A VPS or an always-on container platform charges for reserved capacity: a fixed monthly fee for an amount of RAM and CPU, with or without traffic. You also pay for the hours when nobody calls your API, and in exchange the price doesn't rise with request count.

The useful comparison is the effective cost per request: the monthly fee divided by the requests served. A hypothetical $20-a-month server that handles 1 million requests costs $20 per million; with 50 million, $0.40 per million. The cost per request falls as traffic grows, until capacity runs out; then you pay for the next RAM tier or a second instance.

There are in-between models. Google Cloud Run runs containers with two billing types: request-based, where an instance is billed only while it processes requests, starts or shuts down, and instance-based, where it is billed for its entire lifecycle, even with no incoming requests. Google's documentation recommends the first for sporadic or bursty traffic and the second for steady traffic. It is the same trade-off as this article, inside a single provider.

How do you calculate the break-even point?#

The break-even point is the volume at which both bills match:

requests per month at break-even = server monthly fee ÷ serverless cost per request

The serverless cost per request adds the invocation price, the gateway price and duration times memory times the GB-second price. The script below runs the math for three request profiles with hypothetical prices. Save it as breakeven.mjs and run node breakeven.mjs:

javascript
// breakeven.mjs: break-even point between serverless and a fixed server.
// HYPOTHETICAL prices in US dollars, for the math only. Use your provider's.
const SERVER_MONTHLY = 20; // always-on 1 GB server
const PER_MILLION_INVOCATIONS = 0.3;
const PER_MILLION_GATEWAY = 1.5; // set to 0 if the function takes HTTP without a gateway
const PER_GB_SECOND = 0.00002;
const SECONDS_PER_MONTH = 30 * 24 * 3600;

function costPerMillion(durationMs, memoryMB) {
  const gbSeconds = (durationMs / 1000) * (memoryMB / 1024) * 1_000_000;
  return PER_MILLION_INVOCATIONS + PER_MILLION_GATEWAY + gbSeconds * PER_GB_SECOND;
}

const profiles = [
  { name: "100 ms, 128 MB", durationMs: 100, memoryMB: 128 },
  { name: "100 ms, 512 MB", durationMs: 100, memoryMB: 512 },
  { name: "500 ms, 1024 MB", durationMs: 500, memoryMB: 1024 },
];

for (const p of profiles) {
  const perMillion = costPerMillion(p.durationMs, p.memoryMB);
  const millions = SERVER_MONTHLY / perMillion; // requests per month at break-even
  const perSecond = (millions * 1_000_000) / SECONDS_PER_MONTH;
  console.log(
    `${p.name.padEnd(16)} $${perMillion.toFixed(2)} per million | ` +
      `break-even: ${millions.toFixed(1)} million/month (${perSecond.toFixed(1)} req/s on average)`,
  );
}

The output:

100 ms, 128 MB   $2.05 per million | break-even: 9.8 million/month (3.8 req/s on average)
100 ms, 512 MB   $2.80 per million | break-even: 7.1 million/month (2.8 req/s on average)
500 ms, 1024 MB  $11.80 per million | break-even: 1.7 million/month (0.7 req/s on average)

Three takeaways:

  • Below break-even, serverless is cheaper; above it, the fixed server is. With the middle profile, an API with 1 million requests a month pays $2.80 on serverless against $20 on the server. At 20 million, it pays $56 against the same $20.
  • Duration and memory change everything. 500 ms requests with 1 GB pull break-even down to 1.7 million a month, under one request per second on average. Fixing a slow query cuts the serverless bill directly.
  • For short requests, the gateway outweighs compute. In the first profile, $1.50 of the $2.05 per million is the gateway. Without it (with the function taking HTTP directly), cost drops to $0.55 per million and break-even rises to about 36 million.

Also check that the server can handle the break-even volume. For an API that spends most of its time waiting on the database, a few requests per second are far from a small server's limit; to size yours, see how much RAM and CPU your app needs.

Steady or spiky traffic: what changes on the bill?#

The script uses the monthly average, but a fixed server has to handle the peak. Two cases show the difference:

  • Steady traffic. An internal API with 20 million requests spread across the day, about 8 per second all the time. The server costs $20; serverless, with the middle profile, $56. Well-used fixed capacity is the best case for the server.
  • Rare spikes. A sign-up API that sits almost idle and then receives 1 million requests in 10 minutes, the day an event opens: about 1,700 requests per second. With fixed capacity you need several instances running all month, idle most of the time. On serverless, with the middle profile, the spike costs the same $2.80 as any other million.

The rule of thumb is utilization: the more time a server sits idle, the more each request it serves costs. Predictable, continuous traffic favors fixed capacity; traffic that drops to zero and comes back in bursts favors pay-per-use.

What does a cold start cost?#

A cold start is the preparation of a new environment for the function: downloading the code, starting the runtime and running the initialization outside the handler. According to AWS, it lasts from under 100 ms to over 1 second and occurs in under 1% of invocations, more often in functions that are called rarely.

The cost has two parts:

  • Latency. An endpoint called a few times an hour can pay the cold start on nearly every call. For a webhook with a short response deadline, that turns into a timeout.
  • Money. AWS bills the initialization time of Lambda functions as duration. In a function that imports heavy libraries, initialization can take longer than the handler itself.

Avoiding cold starts costs idle capacity: Lambda provisioned concurrency keeps environments ready and is billed for the time it stays enabled, requests or not, and Cloud Run lets you keep minimum instances warm. That is the fixed server model again, which pays for initialization once, on deploy or restart.

What costs show up later?#

  • Bandwidth. On serverless, egress is usually billed per GB, separately from compute; fixed servers often include an allowance. See how this line works in egress fees.
  • Database. In most architectures the database is an always-on instance, so the bill has a fixed floor even with the API on serverless. Price ranges are in how much a cloud database costs.
  • Logs. Every invocation writes log lines even if you log nothing: Lambda records the start, the end and a report for each execution. Services like CloudWatch charge per GB ingested and per GB stored.
  • Billed waiting. A function that calls an AI API and waits 20 seconds for the answer pays for 20 seconds of duration. On a fixed server, that wait only holds a connection, which matters when choosing where to host an AI agent.

The full bill for an API, line by line, is in how much it costs to host an API; the bill for a whole product, with a front end, email and AI, is in how much SaaS infrastructure costs.

How do you decide with your own numbers?#

Traffic pattern Tends to be cheaper
Few requests, scattered or occasional Serverless
Short, rare spikes, near zero the rest of the time Serverless
Continuous traffic above break-even Always-on server
Long requests or requests that wait on external APIs Always-on server
Persistent connections (WebSocket, Gateway bots) Always-on server, as a technical requirement

There is no universal winner. Measure requests per month, average duration and memory, run the math with your provider's current prices and repeat it when traffic changes. A hybrid is common too: the main API on a fixed server and functions for occasional events, or a queue on the server itself for background jobs.

How to do this on Square Cloud#

Square Cloud sits on the always-on server side: each application runs in an isolated container that doesn't sleep, with no cold starts, and the bill is the plan's monthly fee in Brazilian reais. There is no charge per request or for bandwidth (unlimited traffic under a fair use policy), so the gateway and egress lines from the math above don't exist. What sets the price is the plan's RAM, a pool shared across your applications: Hobby costs R$12.49 a month with 1 GB and 1 vCPU, and Standard starts at R$44.99 with 4 GB and includes database hosting.

As with any fixed server, you set the capacity: there is no autoscaling. For a predictable peak, raise the application's RAM in its settings or through the API; to split load, load balancing puts the same custom domain on several applications, from Standard. CPU and RAM metrics, kept for 24 hours on every application, show how much it really uses, the number you need to pick a plan. See runtimes and examples on API hosting.

API hosting

APIs in always-on containers, with no cold starts

API hosting

FAQs

What is a GB-second?

It is the billing unit for serverless compute: configured memory in GB times execution time in seconds. A 512 MB function that runs for 200 ms uses 0.1 GB-second.

Do cold starts increase the serverless bill?

They add latency and, with some providers, cost. AWS bills the initialization time of Lambda functions as duration, but cold starts typically occur in under 1% of invocations.

When does serverless become more expensive than a server?

When traffic is high and steady. The serverless bill grows linearly with requests, while a fixed server costs the same until its capacity runs out.

Can you combine both models?

Yes, and it is common. The main API runs on an always-on server, and functions handle occasional jobs, like processing an upload or receiving a rare webhook.

Next articleHow much does SaaS infrastructure cost?SaaS infrastructure adds up front end, API, database, files, email, domain, observability and AI. See the cost by stage and how each item grows with customers.