Serverless Architecture
Running code in managed, ephemeral containers billed by invocation rather than provisioned capacity.
Overview
Serverless architecture runs code in managed, ephemeral containers (Functions as a Service, FaaS) billed per invocation and duration rather than provisioned capacity. The provider handles scaling, patching, and availability. Functions are stateless, short-lived, and event-triggered (HTTP, queue message, cron, storage event).
Origin
AWS Lambda (2014) created the FaaS category. Google Cloud Functions (2016) and Azure Functions (2016) followed. The Serverless Framework (2015) provided tooling. The pattern built on Platform as a Service (Heroku, 2007) and the twelve-factor app methodology.
Examples
Lambda function for image processing on upload
import sharp from 'sharp'
import { S3Client, GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3'
const s3 = new S3Client({})
// Triggered by S3 ObjectCreated event
export async function handler(event) {
const { bucket, object } = event.Records[0].s3
const key = decodeURIComponent(object.key)
// Download original
const { Body } = await s3.send(new GetObjectCommand({ Bucket: bucket.name, Key: key }))
const buffer = await Body.transformToByteArray()
// Generate thumbnail
const thumbnail = await sharp(buffer).resize(300, 300, { fit: 'cover' }).toBuffer()
// Upload thumbnail
await s3.send(new PutObjectCommand({
Bucket: bucket.name,
Key: key.replace('originals/', 'thumbnails/'),
Body: thumbnail,
ContentType: 'image/jpeg',
}))
}This function scales to zero (zero cost, zero infrastructure) when no images are uploaded. At 10,000 uploads per minute, the provider scales it to thousands of concurrent executions automatically.
Use Cases
- 01Event-driven processing: image resizing, PDF generation, webhook handlers
- 02Scheduled tasks (cron): nightly reports, data sync, cleanup jobs
- 03Bursty, unpredictable traffic: idle most of the time, then handling large spikes
- 04API backends with simple request-response patterns
When Not to Use
- //Long-running workloads: Lambda has a 15-minute maximum execution time
- //Latency-sensitive applications: cold starts add 100ms-1s to the first invocation after idle
- //Systems requiring persistent connections (WebSockets, database connection pools), function instances are ephemeral
- //When the vendor lock-in and debugging overhead outweigh the operational savings
Technical Notes
- Cold starts: when a function has not been invoked recently, the runtime initialises a new container. Provisioned concurrency (Lambda) keeps containers warm at cost
- Statelessness is mandatory: a function instance may handle one request and then be terminated. All state must be externalised (S3, DynamoDB, RDS, Redis)
- Cost model: serverless is cheaper than provisioned servers for low-to-moderate traffic. At high sustained load, EC2/ECS often costs less
- Observability is harder: distributed traces across many function invocations require AWS X-Ray or a third-party APM. Logs are per-invocation in CloudWatch by default
More in Architecture