No Servers? No, Just Other People's Servers.
Serverless: You write code (Function). Cloud Provider manages infrastructure (OS, patching, scaling).
Key Traits:
- Event-Driven: Code sleeps until triggered (HTTP, S3 upload, Queue message).
- Stateless: Functions are ephemeral. No local disk persistence.
- Scale to Zero: If no traffic, you pay $0.
Architecture Patterns
1. Web API (API Gateway + Lambda)
Replaces EC2 + Nginx.
graph LR
User -->|HTTP Request| APIGw[API Gateway]
APIGw -->|Invoke| Lambda[Lambda Function]
Lambda -->|Read/Write| Dynamo[(DynamoDB NoSQL)]
2. Async Processing (S3 + Lambda)
Image resizing pipeline.
- User uploads
photo.jpgto S3 Bucketraw-images. - S3 sends event
ObjectCreatedto Lambda. - Lambda resizes image and saves to
processed-images.
3. Fan-Out (SNS + multiple Lambdas)
- User registers.
- Publish "UserCreated" to SNS Topic.
- Lambda A (Email Service): Sends Welcome Email.
- Lambda B (Analytics): Updates Dashboard.
The Cold Start Problem āļø
The biggest drawback.
- Request arrives: AWS finds no running container.
- Download Code: Pulls your zip file (50MB) from S3.
- Start Container: Spins up Firecracker MicroVM.
- Init Runtime: Starts Python/Node/Java process.
- Execute Handler: Runs your code.
Total Latency: 200ms (Node.js) to 10s (Java Spring Boot).
Mitigation:
- Keep Warming: Ping function every 5 mins.
- Provisioned Concurrency: Pay to keep instances warm.
- Micro-Frameworks: Don't use heavy frameworks (Spring/Django). Use lightweight ones (Flask/Express/Go).
Limitations
| Feature | Serverless (Lambda) | Containers (Fargate/K8s) | Virtual Machines (EC2) |
|---|---|---|---|
| Max Runtime | 15 minutes (Hard limit) | Unlimited | Unlimited |
| Disk Space | 512MB - 10GB (Ephemeral) | Persistent Volumes | Infinite (EBS) |
| Connection Limits | Massive concurrency kills DBs (Connection Pooling needed) | Controlled scaling | Controlled scaling |
| Cost | Expensive at high sustained load | Cheaper at scale | Cheapest (Reserved Instances) |
Code Example: AWS Lambda (Python)
import json
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Users')
def lambda_handler(event, context):
"""
Triggered by API Gateway.
event: { "body": "{\"name\": \"Alice\"}" }
"""
print(f"Received event: {event}")
try:
# Parse Input
body = json.loads(event.get('body', '{}'))
name = body.get('name')
if not name:
return {"statusCode": 400, "body": "Missing name"}
# Business Logic
user_id = save_user(name)
return {
"statusCode": 200,
"body": json.dumps({"message": "Success", "id": user_id})
}
except Exception as e:
print(f"Error: {e}")
return {"statusCode": 500, "body": "Internal Error"}
def save_user(name):
item = {"pk": name, "status": "active"}
table.put_item(Item=item)
return name
Interview Tips š”
- "When NOT to use Serverless?" ā Long-running tasks (>15m), WebSocket servers (need stateful connections), Heavy GPU tasks (Training), High-frequency trading (latency variance).
- "Idempotency" ā Lambda guarantees "At Least Once" delivery. Your function might run twice for the same event. Make it idempotent! (Check DB before writing).
- "Vendor Lock-in" ā Moving Lambda logic to Google Cloud Functions requires rewriting infrastructure code (Terraform helps, but logic is tied to SDKs).
Related Concepts
- Microservices
- Distributed Tracing (X-Ray)
- Message Queues (SQS)
About ScaleWiki
ScaleWiki is an interactive educational platform dedicated to demystifying distributed systems, software architecture, and system design. Our mission is to provide high-quality, technically accurate resources for software engineers preparing for interviews or solving complex scaling challenges in production.
Read more about our Editorial Guidelines & Authorship.
Educational Disclaimer: The architectural patterns and system designs discussed in this article are based on common industry practices, technical whitepapers, and public engineering blogs. Actual implementations in enterprise environments may vary significantly based on specific product requirements, legacy constraints, and evolving technologies.
Related Articles
Caching Strategies
A breakdown of where to place your cache and how to keep it in sync with your database.
Database Sharding
How to split a massive database across multiple servers. Horizontal scaling strategies, challenges (Joins, ACID), and real-world algorithms used by Instagram, Vitess, and CockroachDB.
System Design: Dropbox (Google Drive)
Designing a file synchronization service like Dropbox or Google Drive. Key concepts: Block-level Deduplication, Delta Sync, and Strong Consistency.