Serverless and Functions as a Service
Run backend code as on-demand functions and managed services, paying per request instead of per server.
Intermediate · about 5 hours · difficulty 3/5
Learn first: Where Backends Run: Hosting Options, Connection Pooling
Serverless means you deploy code or use services without managing servers or capacity: the platform runs your code when events arrive and bills per invocation. Functions as a Service (AWS Lambda, Google Cloud Run functions, Azure Functions, Cloudflare Workers, Vercel functions) is the most visible part; managed databases, queues and storage complete the picture.
How it works
- A function is triggered by an event: an HTTP request through an API gateway, a new file in a bucket, a message on a queue, a cron schedule.
- The platform starts an instance, runs your handler, and may reuse the warm instance for later events or scale out to thousands in parallel.
- You pay for execution time and requests; idle costs nothing.
Strengths
Spiky or low traffic, event-driven glue (resize images on upload, process webhooks), scheduled jobs, and teams that want zero server maintenance.
Constraints to design around
- Cold starts: the first invocation on a new instance is slower. Keep bundles small and initialize clients outside the handler.
- Statelessness: local memory and disk are temporary; state goes in databases or storage.
- Time and size limits on execution and payloads.
- Database connections: many parallel instances can exhaust a database, so use a pooler or an HTTP-based database driver.
- Vendor lock-in and harder local debugging; frameworks like SST or the Serverless Framework help.
- Costs can exceed a plain server at steady high load.
Edge functions
Workers and edge runtimes run code in CDN locations close to users with near-zero cold starts, but with restricted APIs (no arbitrary TCP, limited Node compatibility).
You are ready to move on when you have deployed an HTTP function and a queue-triggered function, measured a cold start, and can state when a container would be cheaper.
Key concepts
- Event triggers
- Cold starts and warm instances
- Stateless handlers
- Database connections from functions
- Edge functions and Workers
- Cost model vs containers
- Infrastructure as code for serverless
Mini project
Build a serverless image pipeline: an upload to object storage triggers a function that creates thumbnails and writes metadata to a database, with an HTTP function to list results.
Check yourself
Why should you create your database client outside the function handler rather than inside it?
Free resources
- What is AWS Lambda? (AWS)
- Cloudflare Workers documentation (Cloudflare)
- Serverless Architectures (Martin Fowler)