Explainstuff.mebeta
All concepts
Architecture Stylesintermediate7 min

Serverless Architecture

Deploy small, single-purpose functions and let the cloud run them on demand — scaling automatically, even to zero, so you pay only for the moments your code is actually executing.

Imagine paying rent on a huge warehouse year-round just so you have somewhere to receive the occasional package. Most of the time the space sits empty, but the bill arrives every month regardless. That's what running your own always-on servers can feel like — you provision capacity for the busiest moment and then pay for it around the clock, even at 3am when nobody is using your app.

Serverless architecture flips that arrangement. Instead of renting the warehouse, you only pay a courier for each package they actually handle. You hand the cloud small pieces of code, and it runs them — and bills you — only when there's real work to do.

The problem

When you run your own servers, you're on the hook for everything underneath your code. You have to provision machines, keep the operating system patched, configure the runtime, and decide how many instances to keep running. Get that sizing wrong and you either fall over under load or burn money on capacity nobody is using.

The deeper waste is idle capacity. To handle a traffic spike you have to keep servers running all the time, which means paying full price during the long stretches when they're doing nothing. And every server you keep alive is one more thing to monitor, secure, and scale by hand.

How it works

With serverless — more precisely Functions-as-a-Service — you write small, single-purpose functions and hand them to the cloud platform. Each function is wired to a trigger: an HTTP request, a message landing on a queue, a scheduled timer, or some other event. When a trigger fires, the platform spins up your function on demand, runs it, and tears it back down.

You never provision or manage the machines. The platform handles all of that and scales automatically — running one copy of your function or a thousand depending on how many triggers arrive, and scaling to zero when nothing is happening so you pay only for actual execution. The animation below shows incoming events and requests triggering small functions that run briefly and reach out to managed services to do their work.

Functions that run on demand
event
Triggers
Function
Function
Function
Managed service
A trigger spins up a function only when needed; it does its work and calls managed services.
Note

"Serverless" doesn't mean there are no servers. There absolutely are — you just never see or manage them. The name describes your experience: from where you sit, there are no servers to provision, patch, or scale. The cloud provider owns all of that for you behind the scenes.

Pairing with managed services

Functions are short-lived and start fresh each time, so they don't hold onto data between runs. To get real work done they lean on managed backing services — a managed database, a queue, an object store — that the cloud also runs for you. The function does a small slice of logic and reads or writes the rest through these services.

This fits the web-queue-worker shape especially well. A function triggered by an HTTP request can validate input and drop a message on a queue, and a second function triggered by that queue can do the slow background work. Each step is a tiny piece of code, and the queue and database between them are fully managed.

The benefits

The headline win is no server management. There's no OS to patch, no fleet to size, no capacity planning — you ship code and the platform runs it. That removes a whole category of operational toil and lets a small team focus on features instead of infrastructure.

You also get fine-grained elastic scaling and pay-per-use pricing. The platform adds and removes function instances in response to demand, all the way down to zero, and you're billed by actual execution rather than by the hour. For workloads that are spiky or intermittent, that combination can be dramatically cheaper than keeping servers warm just in case.

The trade-offs

The most talked-about cost is the cold start. When a function hasn't run recently, the platform has to spin up a fresh environment before your code can execute, which adds latency to that first invocation. There are also firm execution time and resource limits — functions are meant to finish quickly, so long-running or memory-hungry jobs are a poor fit.

Because instances come and go, functions must be stateless: any data that needs to survive between calls has to live in a managed store rather than in the function's memory (see statelessness). And serverless leans hard on a specific provider's triggers, runtimes, and services, so you take on real vendor lock-in — moving to another cloud later is rarely a simple lift.

Watch out

Pay-per-use can flip to expensive at high volume. Per-invocation pricing is a bargain when traffic is bursty or occasional, but for a steady, high-throughput workload that would keep servers busy anyway, the per-call cost can add up to more than simply renting a few always-on machines. Run the numbers for your actual traffic shape, not just the demo.

When to use it

Reach for serverless when your workload is event-driven, spiky, or intermittent — webhooks, scheduled jobs, image processing on upload, lightweight APIs, or glue code that reacts to changes in other services. These are exactly the cases where always-on servers would sit idle most of the time, and where automatic scaling to zero saves the most money.

Be more cautious for steady, high-volume traffic, jobs that need to run for a long time, or systems where predictable low latency is critical and cold starts are unacceptable. And weigh the lock-in: serverless ties you closely to one provider's ecosystem, so if portability matters a lot, factor that into the decision before you commit.

Key takeaways

  • Serverless (Functions-as-a-Service) lets you deploy small, single-purpose functions that the cloud runs on demand in response to triggers — there are still servers, you just don't manage them.
  • The platform handles provisioning, patching, and scaling automatically, including scaling to zero when idle so you pay only for actual execution time.
  • Functions are triggered by events: an HTTP request, a queue message, a timer, or a change in a managed service, and they pair naturally with managed databases and queues.
  • The main trade-offs are cold starts, strict execution time and resource limits, and the need to keep functions stateless by pushing state into managed stores.
  • It shines for spiky, event-driven, or intermittent workloads, but heavy vendor lock-in and per-invocation pricing can make it a poor fit for steady high-volume traffic.

Keep going