Serverless
Serverless computing is a cloud execution model where the cloud provider manages the infrastructure, automatically provisions resources, and scales based on demand. You write code; the platform handles everything else.
Key Characteristics
- No server management: No provisioning, patching, or scaling decisions
- Pay-per-use: Charged only for actual execution time
- Auto-scaling: Scales from zero to thousands of instances automatically
- Event-driven: Functions triggered by events (HTTP, queues, schedules)
Serverless vs Traditional
| Aspect | Serverless | Traditional Server |
|---|---|---|
| Scaling | Automatic | Manual/configured |
| Pricing | Per execution | Per hour/month |
| Cold starts | Yes | No |
| Maintenance | Provider | You |
| Control | Limited | Full |
| State | Stateless | Stateful possible |
AWS Serverless Stack
| Service | Purpose |
|---|---|
| Lambda | Compute (functions) |
| API Gateway | HTTP APIs |
| DynamoDB | Database |
| S3 | File storage |
| SQS / SNS | Messaging |
| EventBridge | Event routing |
| Cognito | Authentication |
| CloudFront | CDN |
Common Patterns
API Backend
CloudFront → API Gateway → Lambda → DynamoDB
Event Processing
S3 Upload → Lambda → Process → Store Result
Scheduled Tasks
EventBridge (cron) → Lambda → Task Execution
Queue Processing
SQS → Lambda → Process Message → External Service
What We Like
- Operational simplicity: Focus on code, not infrastructure
- Cost efficiency: No idle costs, great for variable workloads
- Scalability: Handle traffic spikes without planning
- Speed to deploy: From code to production in minutes
- Reduced risk: Less infrastructure to secure
What We Don't Like
- Cold starts: Initial latency on first invocation
- Vendor lock-in: Architectures tied to specific providers
- Debugging: Distributed systems are harder to trace
- Statelessness: Requires rethinking data patterns
- Execution limits: Timeouts, memory caps, package sizes
Cold Start Mitigation
- Provisioned Concurrency: Keep instances warm (costs money)
- Smaller packages: Faster initialisation
- Choose runtime wisely: Node.js/Python start faster than Java
- Keep functions warm: Scheduled pings (hacky but works)
When to Use Serverless
Good fit:
- Variable or unpredictable traffic
- Event-driven workloads
- APIs with sporadic usage
- Background processing
- Startups and MVPs
Consider alternatives for:
- Consistent high traffic (EC2 may be cheaper)
- Long-running processes
- Stateful applications
- Ultra-low latency requirements
Beyond AWS
| Provider | Service |
|---|---|
| Google Cloud | Cloud Functions, Cloud Run |
| Azure | Azure Functions |
| Cloudflare | Workers |
| Vercel | Edge Functions |