Global Serverless URL Shortener: Sub-15ms Redirection
Architecting a high-throughput, low-latency URL redirection engine with API Gateway HTTP APIs, Lambda, and DynamoDB single-table design.
1. Business Problem & Context
A digital marketing enterprise needed a branded URL shortener service handling over 30 million link clicks monthly. Traditional relational database architectures struggled with read concurrency and incurred high baseline server hosting fees even during off-peak hours.
2. Requirements & Constraints
- Sub-20ms Redirects: Return
HTTP 301 Moved Permanentlyimmediately. - Near-Zero Maintenance: Completely serverless infrastructure with auto-scaling.
- Cost Optimization: Budget under $50/month for 30 million monthly link visits.
3. Architecture Overview & Data Flow
Interactive Architecture Diagram (Use controls to zoom & pan)
4. AWS Services Used & Rationales
AWS Services Architecture Rationale
Concrete reasons why these specific services were chosen over alternatives
| Service | Category | Architectural Rationale ("Why this service?") |
|---|---|---|
| API Gateway HTTP APIs | Serverless | Chosen over REST APIs for 60% lower latency overhead and $1.00/million pricing. |
| AWS Lambda (Graviton2 ARM64) | Compute | Delivers 20% better price-performance compared to x86_64 architectures. |
| Amazon DynamoDB (On-Demand) | Database | Provides consistent 2-4ms key-value lookups with zero capacity provisioning required. |
5. Key Design Trade-offs
Architecture Decision & Trade-Off Matrix
Evaluating alternative approaches under real-world constraints
API Gateway REST APIs
- + Built-in API keys
- + Request validation models
- − $3.50/million requests
- − Higher latency (30-50ms)
API Gateway HTTP APIs + DynamoDB (Chosen)
✓ Chosen Design- + $1.00/million requests
- + Sub-15ms response times
- + Zero cold start latency on small bundles
- − Fewer legacy transformation features
6. Implementation Highlights
Code Recipe Sub-5ms Lambda 301 Redirect Handler
import { DynamoDBClient, GetItemCommand } from "@aws-sdk/client-dynamodb";
const ddb = new DynamoDBClient({ region: process.env.AWS_REGION });
export const handler = async (event) => {
const code = event.pathParameters.code;
const result = await ddb.send(new GetItemCommand({
TableName: process.env.TABLE_NAME,
Key: { PK: { S: `SHORT#${code}` } }
}));
if (!result.Item) {
return { statusCode: 404, body: "Short link not found" };
}
return {
statusCode: 301,
headers: { Location: result.Item.targetUrl.S, "Cache-Control": "public, max-age=86400" }
};
}; 7. Results & Key Metrics
- Median Latency: 11ms globally.
- Monthly Hosting Cost: $42.60 for 30,000,000 requests.
8. Key Architectural Takeaways
Cost Tip: For microservices that only route or proxy requests, always default to API Gateway HTTP APIs rather than REST APIs to save 70% on networking costs.