On this pageHow each one runs your code
Serverless functions and a VPS sell the same thing in different packaging: CPU time that answers your requests. A function platform starts your code when a request arrives and bills for each invocation and its duration. A server keeps your process running all day for a flat price, busy or idle. Neither is the modern choice and the other the legacy one. The shape of your traffic decides which is cheaper and which is less work.
How each one runs your code
Functions
You upload a handler. The platform loads it into a short-lived sandbox when an event arrives (an HTTP request, a queue message, a file upload), runs more copies when events arrive faster, and scales to zero when nothing happens. The bill counts requests plus compute time, usually measured in GB-seconds: memory size multiplied by run time. An API gateway, outbound transfer and the platform's own database or queue services are often billed on top.
The platform also sets limits. Each invocation has a maximum run time measured in minutes, request and response sizes are capped, local disk is temporary, and the account has a ceiling on concurrent copies.
An always-on server
Your process (Node.js, Python, Go, PHP-FPM, anything) stays loaded. It keeps database connections open, caches data in memory, runs cron jobs and background workers, and holds WebSocket connections for as long as clients stay. You pay the plan price per hour or month, and you scale by resizing or adding servers.
Where the differences bite
| Concern | Functions | VPS |
|---|---|---|
| Idle time | Free or nearly free | Full plan price |
| Sudden bursts | Absorbed automatically, up to the concurrency limit | Absorbed up to the server's capacity, then requests queue |
| First request after idle | Waits for a cold start | No wait |
| Long jobs | Capped by the platform's time limit | Run as long as needed |
| WebSockets and streaming | Need a separate managed service | A normal process |
| Database connections | Each concurrent copy opens its own | One fixed pool per process |
| Memory between requests | Not guaranteed | Kept |
| Patching the OS and runtime | Done by the platform | Done by you |
| Moving elsewhere | Event formats and services are platform-specific | Any Linux host |
Cold starts
When no warm copy exists, the first request waits while the platform creates a sandbox, starts the runtime and runs your imports. Large bundles and heavy runtimes make that wait longer. Platforms sell pre-warmed capacity to avoid it, but then you pay for idle copies again, which erodes the main saving. For background jobs, cold starts rarely matter. For a checkout page, they might.
Database connections
A burst of 300 concurrent invocations can mean 300 new database connections. PostgreSQL ships with max_connections set to 100, so the burst that the functions absorbed easily can knock over the database behind them. Function backends need a connection pooler such as PgBouncer or a database proxy service. A server process keeps a small pool of 10 or 20 connections and reuses them for every request.
Cost follows the shape of your traffic
The function bill grows with every request and every millisecond. The server bill stays flat until the server is full. That gives a simple break-even:
- Cost per request on functions = price per request + (duration in seconds × memory in GB × price per GB-second) + gateway price per request.
- Break-even requests per month = monthly server price ÷ cost per request.
Below the break-even, functions are cheaper. Above it, the flat server wins, provided it can carry the load. Plug in your platform's published rates and your own measurements:
# Fill in your platform's published rates and your measured traffic
price_per_request = 0.0 # from the platform's pricing page
price_per_gb_second = 0.0
gateway_per_request = 0.0 # 0 if you call functions without a gateway
memory_gb = 0.5 # memory configured for the function
avg_duration_s = 0.120 # measured, see below
server_monthly = 0.0 # the plan you would run instead
per_request = price_per_request + avg_duration_s * memory_gb * price_per_gb_second + gateway_per_request
if per_request == 0:
raise SystemExit("Fill in the platform rates first.")
print(f"cost per million requests: {per_request * 1_000_000:.2f}")
print(f"break-even: {server_monthly / per_request:,.0f} requests per month")
Two traffic shapes sit at the extremes. A webhook receiver that wakes a few hundred times a day and idles the rest is a textbook function: a server would sit idle almost all month. An API that serves a steady flow around the clock keeps a small server busy, and functions would bill that same compute one request at a time. Most backends sit between the two, which is why measuring beats guessing.
Measure your own traffic first
If the backend already runs behind nginx, the access log answers both questions: how many requests, and how they spread over the day.
# Requests per hour, in log order, for the last 48 hours of traffic
awk '{print substr($4, 2, 14)}' /var/log/nginx/access.log | uniq -c | tail -n 48
A peak hour many times the average points to functions. A flat profile points to a server. For durations, log nginx's $request_time:
log_format timed '$remote_addr [$time_local] "$request" $status $request_time';
access_log /var/log/nginx/timed.log timed;
awk '{sum += $NF; n++} END {printf "requests: %d, average: %.3f s\n", n, sum / n}' /var/log/nginx/timed.log
Feed the average into the break-even script. Measure on a normal week, not a launch week.
Use both where each fits
A hybrid is often the right answer, and a sound design rather than a compromise:
- Server core, function edges. The API and database run on a VPS; bursty side jobs such as image thumbnails, third-party webhooks and nightly reports run as functions.
- Function front, server muscle. Lightweight functions accept requests and drop work onto a queue; a server drains the queue at its own pace, with no time limit.
Keep the code portable either way. Write handlers as plain HTTP apps that also run in a container, keep data in standard engines such as PostgreSQL, and use S3-compatible object storage. Then moving a piece in either direction is a deploy, not a rewrite.
For the server side, CloudSat can bill any plan by the hour (a full month of the smallest Cloud VPS is $1.98), so a side-by-side load test of a server against your function setup costs little. When one server stops being enough, scale up or out before reaching for a different model.
FAQ
Is serverless cheaper than a VPS?
At low or very spiky traffic, usually yes, because idle time costs nothing. At steady load, a flat server is usually cheaper per request, and the gap widens as traffic grows. The break-even formula above tells you where your backend sits. Cloud pricing models compared covers the other meters.
Are cold starts a problem for APIs?
For user-facing endpoints with strict response targets, they can be. Smaller bundles, lighter runtimes and paid warm capacity reduce them. For queue consumers, webhooks and scheduled jobs, a cold start of a moment is rarely noticed.
Can I run serverless on my own VPS?
Yes. Open-source function frameworks exist, most built on containers or Kubernetes. You then operate the platform yourself, which removes the main reason to use functions. On a single server, a process manager or Docker Compose gives the same result with less machinery.
Can a VPS scale like functions do?
Not instantly. A VPS scales by resizing or by adding servers behind a load balancer, which takes minutes rather than milliseconds. For predictable growth that is fine; for sudden spikes, keep headroom or put a queue in front of the slow parts.
Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.




