Serverless Computing

Here’s a question to sit with for a second. What if you only paid for the exact moments your code was actually running?

  • Like, not the whole day. Not the whole month.
  • Just the few hundred milliseconds your code spent doing real work.
  • And when nobody’s using it? You pay nothing at all.

That’s not a dream. That’s the whole pitch of serverless computing. So let’s slow down and see what it really means, because the name is honestly a little bit of a lie.

🎯 The Idea

Let’s define it first, then we’ll unpack it. Serverless computing means you write the code, and the cloud runs it for you. You don’t set up servers, you don’t keep them running, you don’t worry about scaling them up or down. You just hand over your code, and the cloud takes care of the rest.

Here’s what the cloud quietly handles for you:

  • The servers. It finds a machine to run your code on. You never see it or log into it.
  • The scaling. If one person uses your code or a million people do, the cloud adds or removes capacity on its own.
  • The billing. You pay only when your code actually runs, not for the time it sits idle.

Now here’s the part that trips everyone up, so let’s be honest about it. The name says “serverless”, but there are absolutely still servers. Of course there are, code has to run on something, right? The point is just that you don’t manage them. They’re hidden away, and that’s somebody else’s job now.

Why it's called 'serverless'

It doesn’t mean no servers exist. It means no servers exist for you to think about. From where you’re sitting, there’s no server to set up, patch, or babysit. So the name is really about your experience, not about the actual machines.

⚡ Functions as a Service

The most common flavor of serverless is something called FaaS, which stands for Functions as a Service. Let’s define it simply. FaaS means you write small functions, and each one runs in response to some event.

Let’s break that down:

  • A function here is just a small chunk of code that does one job. Like “resize this image” or “save this form to the database”.
  • An event is something that happens that you want to react to. Like a user uploading a photo, a button getting clicked, or a request hitting your API.
  • So the deal is simple. An event happens, your function wakes up, runs once, does its job, and goes back to sleep.

The famous example here is AWS Lambda. (AWS is Amazon’s cloud, and Lambda is their serverless function service.) You upload a function, you tell it what event should trigger it, and that’s it. Amazon runs it for you whenever that event fires. Other clouds have their own versions too, like Google Cloud Functions and Azure Functions, but they all work the same way.

So what actually happens when an event comes in? Here’s the whole life of a serverless function, start to finish.

Event happens (HTTP request or file upload)

Cloud starts your function

Your function runs and does its job

Cloud sends back the result

No traffic? Scales to zero. You pay nothing

See how it goes back down to zero at the end? That last box is the magic. When nothing’s happening, nothing is running, and nothing is costing you money.

💰 Pay Per Use and Auto-Scaling

This is where serverless really shows off, so let’s spend a minute here. There are two big things going on, and they’re connected.

First, the pay per use part:

  • You don’t pay a flat monthly fee for a server sitting there.
  • You pay for each time your function runs, and for how long it runs (usually measured in tiny slices of time like milliseconds).
  • So a function that runs ten times today costs you the price of ten quick runs. That’s it.

Second, the auto-scaling part. Scaling just means handling more or less traffic. Here’s how serverless does it on its own:

  • If a thousand events come in at once, the cloud runs a thousand copies of your function side by side. You didn’t lift a finger.
  • When the rush dies down, it quietly removes those copies.
  • And when there’s no traffic at all, it scales to zero. That means zero copies running, which means zero cost.

That “scale to zero” idea is the big one. With a traditional server, you’re paying for it 24 hours a day even at 3 in the morning when nobody’s awake. With serverless, an idle app costs you nothing.

A quick way to picture it

Think of a traditional server like renting a taxi for the whole day, even when you’re just sitting at home. Serverless is more like calling a cab only when you actually need a ride, and paying only for that trip. No ride, no bill.

⚖️ Serverless vs Traditional Servers

Let’s put them side by side so the difference is crystal clear. A traditional server is a machine you rent and keep running yourself. Serverless is code the cloud runs for you on demand.

Thing Traditional Servers Serverless
Who manages the server You do (setup, patching, uptime) The cloud does, it’s hidden from you
What you pay for The server running 24/7, even when idle Only when your code actually runs
Scaling You plan and configure it Automatic, zero to many on its own
Idle cost You still pay Scales to zero, you pay nothing
Best for Long-running, steady, heavy workloads Short, event-driven, spiky workloads

Neither one is “better”. They’re just good at different things, and a lot of real systems use both together.

✅ When Serverless Shines

So when should you actually reach for serverless? It’s great when the work is short and comes in bursts. Here are the spots where it really fits:

  • Event-driven tasks. Something happens, you react to it. A file gets uploaded, so you make a thumbnail. A user signs up, so you send a welcome email.
  • Spiky or unpredictable traffic. Maybe your app is dead quiet most of the day, then suddenly gets slammed. Serverless scales up for the rush and back down after, and you only pay for the busy moments.
  • Small APIs. A handful of endpoints that don’t run constantly. (An API is just a way for programs to talk to each other.) No need to keep a whole server warm for them.
  • Glue code. Little bits of code that connect two systems together. Like “when a new row lands in the database, ping this other service”.
  • Background jobs. Work that runs on its own, away from the user. Like cleaning up old data every night, or processing a queue of tasks.

The pattern across all of these? The work is short, it happens now and then, and it doesn’t need a server sitting around waiting.

⚠️ The Catches

Serverless isn’t free magic, though. There are real trade-offs, and a good engineer knows them. Let’s go through the big ones.

  • Cold starts. Here’s the definition. A cold start is the small delay you get when a function has been idle and the cloud has to spin it up fresh before it can run. The very first request after a quiet period feels a bit slow because of this. Once it’s warm, the next requests are quick.
  • Time limits. Serverless functions are meant to be short. Most platforms cut them off after a few minutes. So a job that needs to run for an hour straight just won’t fit.
  • Hard for long-running or stateful work. “Stateful” means the code needs to remember things between runs. But serverless functions forget everything once they finish, so anything that needs to hold on to data or run for a long time is a poor fit.
  • Vendor lock-in. When you build heavily on one cloud’s serverless tools, your code gets tied to that cloud’s way of doing things. Moving to a different provider later can be a real headache. That tie-in is what people mean by vendor lock-in.

Cold starts matter when speed matters

For a background job that runs at midnight, a cold start of a second or two is nothing. But for a user clicking a button and waiting, that same delay feels slow. So always ask: is this on the path where a human is waiting? If yes, cold starts are worth thinking about.

⚠️ Common Mistakes and Misconceptions

A few ideas about serverless get repeated so often that people just believe them. Let’s clear them up.

  • “There are no servers.” Nope. There are servers, plenty of them. They’re just hidden from you and managed by the cloud. “Serverless” describes your experience, not reality.
  • “Serverless is always cheaper.” Not true. For an app that runs constantly with steady, heavy traffic, a regular server can actually cost less. Serverless wins on idle and spiky workloads, not on every workload.
  • “Use it for everything.” Also a trap. Serverless is a tool, not a religion. Long-running jobs, heavy steady traffic, and stateful apps often belong on regular servers. Pick the right tool for the job.

🛠️ Design Challenge

Try this one on your own to test yourself.

Imagine Alex is building a photo-sharing app. Whenever a user uploads a photo, the app needs to create a small thumbnail version of it. Think through these:

  • Why is this a good fit for serverless? (Hint: it’s event-driven, and uploads come in bursts.)
  • What event would trigger the function?
  • Now imagine the app also needs to run a live video stream that stays connected for an hour. Would serverless fit that part? Why or why not?

Working through this is exactly the kind of “right tool for the job” thinking interviewers love to see.

🧩 What You’ve Learned

You can now explain serverless to anyone, even an interviewer. Here’s what you’ve picked up.

  • ✅ Serverless means you write the code and the cloud runs it, with no servers for you to manage.
  • ✅ There are still servers, you just don’t see or manage them.
  • ✅ FaaS (like AWS Lambda) runs small functions in response to events.
  • ✅ You pay only when your code runs, and it auto-scales from zero to many on its own.
  • ✅ It shines for event-driven tasks, spiky traffic, small APIs, glue code, and background jobs.
  • ✅ Watch out for cold starts, time limits, trouble with long-running or stateful work, and vendor lock-in.

Check Your Knowledge

Test what you learned. Pick an answer for each question, then click Check.

  1. 1

    What does serverless computing mean?

    Why: Serverless means you write the code and the cloud runs it, managing the servers, scaling, and billing for you.

  2. 2

    What is FaaS?

    Why: FaaS, or Functions as a Service, is the most common form of serverless, where small functions run when events happen, like with AWS Lambda.

  3. 3

    What is a cold start?

    Why: A cold start is the small delay when a function that has been idle must be started fresh before handling a request.

  4. 4

    When is serverless usually a poor fit?

    Why: Serverless struggles with long-running, steady heavy, or stateful work, where a traditional server is often better and cheaper.

🚀 What’s Next?

Serverless is one piece of the bigger cloud picture. To see where it fits, these two are the natural next stops.

Once you’ve got those, the whole cloud landscape starts to click into place.

Share & Connect