SkillSprout
Chapter 4 · Lesson 5
Intermediate
9 min read

Serverless vs Servers

Overview

Serverless means you hand your code to a platform that runs it only when requests arrive and bills per use, so you do not manage machines. Servers (virtual machines or containers you keep running) cost money all day but give you control and predictable performance. The right answer depends on traffic shape. This lesson shows the cost break-even math, the cold start problem, and when to combine both.

Detailed Notes

What Problem Are We Solving?

Every service needs somewhere to run. Two models exist.

  • Servers: you run virtual machines or containers (a container packages your code and its dependencies so it runs the same everywhere). They are always on, you choose their size and count, and you pay for the time they run whether busy or idle.
  • Serverless (also called Function as a Service, for example AWS Lambda): you upload a function. The platform starts it when a request or event arrives, runs it, and bills for the milliseconds used. There are still servers, but you never see or manage them.

The question is who handles the hard part of capacity. With servers, you must forecast traffic and keep enough machines running. With serverless, the platform scales automatically, but you accept its limits and its pricing.

A cold start is the delay when the platform has no ready copy of your function. It must create an environment, load your code and start the runtime before handling the first request. This can add anywhere from about 100 ms to over 1 second depending on language and package size. A request that finds an already-running copy (a warm start) skips that cost.

Cost depends on traffic shape. Use these illustrative prices (assumptions, check real pricing):

text
Serverless function: 512 MB memory, 100 ms per request
  Compute: 0.5 GB x 0.1 s = 0.05 GB-seconds
           0.05 x $0.0000167 = about $0.0000008
  Request fee: $0.20 per million = $0.0000002
  Cost per request = about $0.000001, or $1.00 per million requests

Servers: 2 small VMs (for redundancy) at $0.08 per hour each
  2 x $0.08 x 730 hours = about $117 per month, any traffic level

Break-even traffic:

text
$117 / $1.00 per million = about 117 million requests per month
117M / 2.6M seconds per month = about 45 requests per second, sustained

Low traffic:   1 request/s   = 2.6M per month  -> serverless about $3  (servers $117)
Steady heavy:  100 requests/s = 260M per month -> serverless about $260 (servers $117,
               and the servers could handle several times more)

So spiky or low traffic favours serverless, steady high traffic favours servers.

Serverless vs Servers
Comparison

Serverless

functions on demand

  1. 1

    Event arrives

    HTTP, queue, upload, timer

  2. 2

    Platform finds or starts a copy

    cold start if none is warm

  3. 3

    Function runs and exits

    billed per millisecond

  4. 4

    Idle copies disappear

    zero cost at zero traffic

  • No capacity planning
  • Cheap for spiky or low load
  • Minimal operations
  • Cold starts hurt p99
  • Costly at steady high volume
  • Runtime and connection limits

Best for bursty, event-driven work

Servers

always-on fleet

  1. 1

    Provision a fleet

    VMs or containers

  2. 2

    Load balancer spreads requests

    processes stay warm

  3. 3

    Auto scaling adds machines

    takes minutes

  4. 4

    Pay every hour

    even when idle

  • Steady, low latency
  • Cheaper at sustained load
  • Full control, long connections
  • Pay for idle capacity
  • Patching and capacity planning

Best for steady, latency-sensitive services

Key point. Serverless pays for use. Servers pay for readiness. Traffic shape decides which is cheaper.

Who owns capacity, and when do you pay?

Option 1: Serverless

How it works

You write a function with one entry point, deploy it, and attach a trigger: an HTTP request through an API gateway, a message on a queue, a file upload, a timer. For each event the platform finds or creates a warm instance and runs the function. If 500 events arrive at once, it runs 500 copies in parallel (up to an account limit). When traffic stops, instances disappear and you pay nothing.

Functions must be stateless and short. They have limits on run time (for example 15 minutes), memory and package size, and anything saved in local memory or disk may vanish between calls.

Pros

  • No capacity planning. Scaling from 0 to thousands of copies is automatic.
  • Pay per use. Zero traffic costs almost zero. Great for unpredictable load.
  • Less operations work. No operating system patches, fleet sizing or load balancer tuning.
  • Fast to build. A small team can ship an event-driven backend quickly.

Cons

  • Cold starts. The first request after idle, or during a sudden scale-up, is slow. This hurts p99 latency (the slowest 1% of requests).
  • Expensive at steady high volume. The per-request price beats servers only when servers would sit idle.
  • Limits. Maximum run time, payload size, concurrency caps, and limited control of the runtime environment.
  • Connection problems. Hundreds of parallel copies each opening a database connection can overwhelm a relational database. A connection pool proxy is usually needed.
  • Vendor coupling and harder local testing.

When to use it

Choose serverless when traffic is spiky, unpredictable or low; work is event-driven and short; the team is small; or latency spikes of a few hundred milliseconds are acceptable.

Realistic scenario. A photo app creates thumbnails whenever a user uploads an image. Uploads arrive in bursts: nothing at 3 a.m., 2,000 per second after a viral event. A function triggered by the storage upload event generates thumbnails. Nobody is waiting on the request, so cold starts do not matter, and the team never provisions for the peak.

Option 2: Servers (VMs or containers)

How it works

You run a fixed or auto-scaled fleet that keeps your process alive. The process stays in memory, so caches, connection pools and loaded models are reused across requests. You pick the size, count and runtime, and an auto scaling group or container orchestrator adds capacity when load rises.

Pros

  • Predictable latency. Always warm, no cold starts, steady p99.
  • Cheaper at steady high load. If you keep servers 50% to 70% busy, cost per request is far below per-invocation pricing.
  • Full control. Any language, long-running processes, WebSocket connections, GPUs, big in-memory caches, custom networking.
  • Efficient connections. Pooled database connections are shared by many requests.

Cons

  • You pay for idle time. A server at 5% load costs the same as one at 80%.
  • Capacity planning. Too few and traffic gets dropped, too many and you waste money. Scale-up takes minutes.
  • Operations burden. Patching, deployments, monitoring and security of the fleet.
  • Slower to start small. More setup before the first request is served.

When to use it

Choose servers when traffic is steady and high, latency must be consistently low, connections are long-lived (WebSocket, streaming), or the workload needs resources serverless cannot offer (long jobs, GPUs, large memory).

Realistic scenario. A payments API runs at 400 requests per second all day, with a 50 ms p99 latency target. On serverless that is about 1 billion requests a month, which would cost over $1,000 and risk cold-start spikes. Eight containers at 50% load cost a fraction of that, stay warm, and share database connection pools.

The hybrid: servers for the core, serverless for the edges

The common architecture uses both. The steady, latency-sensitive path (API, WebSocket gateway) runs on servers or containers. Spiky, asynchronous work (image processing, sending emails, scheduled reports, reacting to events) runs on functions triggered from a queue. A third pattern is to run on servers for baseline load and burst to serverless when a spike exceeds capacity.

Cold Start vs Warm Invocation
Request flow
ClientAPI gatewayPlatformFunction copy1request 1 (idle app)2invoke function3create + load codecold start: +300 to 1,000 ms4response 1 (slow)5request 2 (seconds later)6reuse warm copyno start cost: +5 ms7response 2 (fast)
Key point. Cold starts matter when a person is waiting and p99 is tight. For background work they are invisible.

The first call after idle pays for creating the environment. The next one does not.

Interview Discussion

Decide with three questions.

  1. What is the traffic shape? Idle most of the day with spikes, or steady? Do the break-even math: here about 45 sustained RPS.
  2. Is a user waiting, and how strict is p99? If yes and p99 must be under 100 ms, cold starts are a risk. Mitigate with provisioned concurrency (the platform keeps some copies warm, for a fee) or choose servers.
  3. What does the function talk to? A relational database needs a connection pooler. A queue, object store or key-value store works naturally.

Interview tip. "Serverless scales infinitely" is a trap. Concurrency limits, database connection limits and downstream services all cap you. Name the real bottleneck.

Interview discussion. "Image processing is bursty and nobody waits on it, so I'd use functions triggered by uploads. The main API is steady at 400 RPS with a tight latency target, so I'd run it on containers behind a load balancer and avoid cold starts."

Trade-off thinking. Serverless trades per-request cost, cold starts and limits for zero idle cost and no capacity planning. Servers trade idle cost and operations work for lower steady cost, control and consistent latency. The cross-over is a number you can calculate, so calculate it.

Final Takeaway

Choose serverless when traffic is spiky or low, work is event-driven and short, and a small team should avoid operating machines. Choose servers when traffic is steady and high, latency must be consistent, connections are long-lived or you need special resources. Combine them: servers for the always-on core, functions for bursty background work. Bring the break-even calculation to the interview.

Common Interview Questions

Finished this lesson?

0 of 44 lessons done · 0% of the course