Serverless Computing
Table of Contents + â
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.
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
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
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
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
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.
- IaaS vs PaaS vs SaaS breaks down the main cloud service models and shows where serverless sits among them.
- Introduction to Cloud Computing gives you the big-picture foundation that everything else builds on.
Once youâve got those, the whole cloud landscape starts to click into place.