Memahami serverless (Lambda/Cloud Run/Cloudflare Workers), cold start, edge computing untuk latency reduction global, dan perbandingan cost/latency antara container vs Lambda vs edge worker untuk berbagai skenario traffic

Setelah di episode 17 kita memahami migrasi monolith ke modular monolith dan microservices, pada episode ini kita membahas tren deployment modern: serverless dan edge computing. Dua konsep ini mengubah cara kita berpikir tentang infrastruktur — dari "manage server" ke "just deploy code."
Serverless bukan berarti "tidak ada server" — server tetap ada, tapi kalian tidak perlu mengelolanya. Edge computing membawa compute lebih dekat ke pengguna. Bersama-sama, mereka menawarkan operational simplicity yang powerful — tapi dengan trade-off yang harus dipahami.
| Platform | Bahasa | Cold Start | Free Tier | Use Case |
|---|---|---|---|---|
| AWS Lambda | Python, Node, Go, Java | 100-500ms | 1M requests/bulan | Backend tasks, API |
| Google Cloud Run | Container (any lang) | 500ms-2s | 2M requests/bulan | Container workloads |
| Cloudflare Workers | JavaScript/WASM | 0-50ms | 100K requests/hari | Edge computing |
Cold start adalah delay saat serverless function pertama kali dijalankan (atau setelah idle).
Cold start: 200-500ms (Lambda), 0-50ms (Workers)
→ Function di-deploy dari awal, load dependencies
Warm start: 1-10ms
→ Function sudah berjalan, langsung execute
Optimasi:
- Keep function warm (provisioned concurrency)
- Reduce package size (dependency minimal)
- Avoid VPC (tambah network setup time)Serverless functions bersifat stateless — setiap invocation adalah independent, tidak ada memory yang persist antar invocation.
API Gateway → Lambda (auth) → Lambda (business logic) → DynamoDB
↓
Lambda (notification)
↓
S3 (file storage)Step 1: Validate input (Lambda)
Step 2: Process payment (Lambda) → if fail → Step 2a: refund
Step 3: Update inventory (Lambda)
Step 4: Send notification (Lambda)Step functions mengkoordinasi multiple Lambda calls dengan retry, error handling, dan parallel execution.
Edge computing menjalankan compute di server yang dekat secara geografis dengan pengguna.
- Runtime: V8 isolates (bukan container/VM)
- Cold start: 0-50ms (sangat cepat)
- Location: 300+ edge locations globally
- Use case: API routing, authentication, A/B testing, rate limiting- Runtime: V8 isolates
- Integrated dengan Next.js
- Edge middleware: auth check, redirect, A/B testing
- Edge functions: business logic di edge| Use Case | Edge? | Alasan |
|---|---|---|
| API routing | Ya | Low latency untuk semua region |
| Authentication check | Ya | Cepat, tidak butuh database |
| A/B testing | Ya | Personalization di edge |
| Database query | Tidak | Butuh koneksi ke database (origin) |
| File processing | Tidak | CPU-intensive, butuh resources |
Container (ECS Fargate):
- 0.25 vCPU, 512 MB, always running
- Cost: ~$10-15/bulan
- Latency: 10-50ms (consistent)
Lambda:
- 1M requests x 200ms x 256MB
- Cost: ~$0.40/bulan (bawah free tier 1M)
- Latency: 50-200ms (cold start possible)
Edge Worker (Workers):
- 1M requests x 10ms
- Cost: ~$5/bulan
- Latency: 5-30ms (edge location)Container: auto-scaling 1-10 instances → 2-5 menit scale up
Lambda: otomatis scale ke ribuan concurrent → detik
Edge Worker: otomatis scale → detik| Aspek | Container | Serverless | Edge |
|---|---|---|---|
| Cold start | Tidak ada | 100-500ms | 0-50ms |
| State | Bisa stateful | Stateless | Stateless |
| Cost model | Pay for compute time | Pay per request + duration | Pay per request |
| Debugging | Mudah (logs, SSH) | Sulit (distributed) | Sulit (distributed) |
| Vendor lock-in | Rendah | Menengah | Menengah |
| Latency global | Tergantung region | Tergantung region | Sangat rendah |
Note
Untuk system design interview, tanyakan requirement latency global. Jika user tersebar global dan latency kritis → edge. Jika bursty traffic dan operational simplicity → serverless. Jika stateful atau long-running → container. Tidak ada yang universally lebih baik.
Option A: Container (ECS)
ECS Fargate: 2 task, 1 vCPU, 2GB RAM
Cost: ~$30/bulan (always running)
Latency: 50ms (consistent)
Supports: complex processing, statefulOption B: Lambda
Lambda: process image on-demand
Cost: ~$5/bulan (100K invocations)
Latency: 200ms (cold start) / 10ms (warm)
Limitations: 15 min timeout, 10GB memoryOption C: Edge Worker
Cloudflare Workers: resize image di edge
Cost: ~$8/bulan
Latency: 10ms (edge location)
Limitations: CPU time limit (10-30ms), memory limitInti yang harus dibawa pulang:
Di episode 19 selanjutnya kita akan membahas cost-aware design (FinOps) — infrastructure cost sebagai pertimbangan arsitektur, right-sizing, storage tiering, dan perbandingan cost detail antara berbagai arsitektur. Desain yang bagus bukan yang paling scalable, tapi yang paling cost-effective!