Serverless Architecture Trade-offs
Cold starts, vendor lock-in, and the pay-per-execution cost model — when FaaS is the right call, and when it quietly isn't.
Serverless Architecture Trade-offs
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A cold start is the latency penalty paid the first time (or the first time in a while) a function runs on a given instance, because the platform has to provision a runtime, load your code, and initialize it before your handler ever executes.
- Serverless genuinely removes capacity planning — you pay per invocation and per unit of compute-time, not for an idle server sitting at 2% utilization waiting for traffic — but that same pay-per-execution model can make a function with real, sustained load several times more expensive than the same workload on reserved compute.
- Vendor lock-in in serverless comes less from the function runtime itself and more from everything wired around it — provider-specific event triggers, IAM roles, and managed-service integrations — which is what actually makes a migration expensive, not the code inside the handler.
- Serverless functions are built to be stateless and short-lived; anything that needs a long-held connection, large in-memory state, or a multi-minute execution window is fighting the platform's basic assumptions rather than using them.
- The right call for serverless is bursty, event-driven, intermittent work — a webhook handler, an image-resize-on-upload job, a scheduled cleanup task — not a steady-state service that's busy around the clock, where the overhead this lesson describes stops paying for itself.
Serverless is a deployment model, not an absence of servers
“Serverless” is a slightly dishonest name — there is still a server, you simply never provision it, patch it, or decide how many of them to run. You write a function, hand it to a platform (AWS Lambda, Azure Functions, Google Cloud Functions), and the platform decides when and where to run it, scaling from zero instances to however many concurrent invocations arrive and back down again when traffic stops. For an architect, the interesting part isn’t the marketing name — it’s that this model makes a specific, concrete set of trade-offs, and choosing it well means knowing exactly which problems it solves and which ones it creates.
The cold start, in mechanism
When a request arrives and no instance of your function is already running and warm, the platform has to build one: pull your deployment package, start a language runtime, load your dependencies, and run any top-level initialization code (opening a database connection pool, loading a configuration file) before your actual handler logic executes for the first time. That whole sequence is the cold start, and it can add anywhere from tens of milliseconds (a small Go or Python function with few dependencies) to several seconds (a large Java or .NET function pulling in a heavy framework). Once that instance is warm, the platform typically keeps it alive for a few minutes in case another request arrives, reusing it and skipping the whole sequence — which is why cold starts show up as an occasional spike rather than a constant tax, concentrated on functions with low, bursty traffic rather than busy ones. The two standard mitigations both cost something: provisioned concurrency keeps a fixed number of instances permanently warm, which eliminates cold starts for those instances but means paying for idle capacity exactly like a traditional server — undoing a chunk of serverless’s core pitch. Scheduled pings (“keep it warm” cron jobs that invoke the function every few minutes) are a cheaper hack that reduces cold-start frequency without eliminating it and that adds a small, perpetual background cost and a little bit of needless invocation noise to your metrics.
The cost model inverts past a certain volume
Serverless pricing charges per invocation plus per unit of compute-time (memory allocated × duration), with no charge at all while nothing is running. For spiky or low-volume workloads, this is a genuinely better deal than a server that sits mostly idle: a webhook that fires twenty times a day costs essentially nothing, where a dedicated server for it would cost a flat monthly fee regardless. But the economics flip as volume and duration climb: a reserved virtual machine or container has a fixed cost no matter how busy it is, while serverless cost keeps climbing linearly with invocations. Past some workload-specific crossover point — a function running close to continuously, processing high and steady traffic — the accumulated per-invocation charges exceed what the same compute would cost reserved outright. The architectural lesson isn’t “serverless is expensive” or “serverless is cheap”; it’s that the pricing model rewards bursty, intermittent work and penalizes sustained, high-utilization work, so the shape of your traffic, not its total volume alone, should drive the choice.
Lock-in lives in the wiring, not the handler
A function’s actual business logic — parse this payload, write that row, call that API — is often reasonably portable between providers, especially in a mainstream language with few platform-specific SDK calls. What’s genuinely hard to move is everything around the function: the specific event source that triggers it (an S3 bucket notification, an Azure Event Grid subscription, a particular queue’s exact message format), the IAM role and permission model it runs under, and any managed services it calls directly by their provider-specific API (a specific flavor of managed database, a provider’s own queue or pub/sub service). Migrating a serverless architecture to a different cloud usually means re-building all of that integration surface from scratch, which is a real cost — but the honest framing, per the trade-off this lesson’s video makes, is to ask about switching cost, not to treat lock-in as an absolute to avoid at any price: building an abstraction layer to stay portable across providers you’ll likely never actually migrate to often costs more in complexity than the lock-in it’s insuring against.
Statelessness is the deal you’re making
Serverless functions are designed to be ephemeral and stateless: an instance can be frozen, reused, or destroyed between invocations with no guarantee which will happen, so anything that depends on in-memory state surviving between calls, a long-held database connection staying open, or an execution running past the platform’s timeout (commonly 5–15 minutes) is working against the model rather than with it. This is precisely why serverless is the right call for event-driven, bursty glue code — a function that resizes an image the moment it’s uploaded, a webhook handler that fires a few hundred times a day, a scheduled nightly cleanup job — and the wrong call for a steady-state, long-running, stateful service, where a container or a traditional server, with none of the cold-start or statelessness constraints, is simply a better architectural fit.
Check yourself
What specifically causes a cold start, and why doesn't it happen on every invocation?
A cold start happens when the platform has no already-initialized instance of your function warm and waiting, so it has to provision a new execution environment, load your code and dependencies, and run any startup logic before your handler can run; once that instance stays warm, subsequent invocations reuse it and skip all of that.
Why can a function handling sustained, high-volume traffic end up more expensive than the same workload on a reserved server?
Pay-per-execution pricing charges for every invocation and every unit of compute time with no economy of scale, while a reserved server or container has a flat cost regardless of how busy it is — once request volume is high and steady enough, the fixed cost of reserved capacity undercuts the accumulated per-invocation cost of serverless.
Why is vendor lock-in described as coming from "what's wired around" a function more than the function's own code?
The handler code itself (the business logic) is often fairly portable, but the event source it's triggered from, the IAM role and permissions model it runs under, and the managed services it calls directly are usually provider-specific APIs with no equivalent elsewhere, so migrating means re-wiring all of that, not just moving a function body.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.