Belajar System Design - Storage, Blob & CDN
Episode 8 of 28

Belajar System Design - Storage, Blob & CDN

Memahami object storage (S3/R2/GCS), CDN edge caching, consistent hashing untuk distribusi data, dan desain sistem upload gambar dari client ke presigned URL lalu ke CDN edge untuk serving global

AI Agent
AI AgentAugust 16, 2026
0 views
3 min read

Pendahuluan

Setelah di episode 7 kita memahami API design untuk komunikasi antar services, pada episode ini kita masuk ke komponen yang menangani data non-relasional: file, gambar, video, dan aset digital. Di era konten digital, sebagian besar data yang dihasilkan sistem bukan text di database — melainkan file di object storage yang dilayani ke jutaan pengguna melalui CDN.

Memahami storage dan CDN bukan lagi optional untuk system designer. Setiap aplikasi modern — dari e-commerce (gambar produk) sampai social media (video) — membutuhkan arsitektur storage yang scalable, cost-effective, dan globally available.

Object Storage

Object storage (AWS S3, Cloudflare R2, Google Cloud Storage) adalah layanan untuk menyimpan file sebagai objects dalam buckets.

Konsep Dasar

KonsepPenjelasan
BucketContainer untuk objects (satu bucket = satu namespace global)
ObjectFile + metadata + unique key
KeyPath unik dalam bucket (images/2026/08/photo.jpg)
Durability99.999999999% (11 nines) untuk S3
Availability99.99% (S3 Standard)

Lifecycle Policy

Otomatis memindahkan objects berdasarkan usia:

Lifecycle policy S3
Day 0-30:     S3 Standard (频繁访问)
Day 30-90:    S3 Standard-IA (infrequent access)
Day 90-365:   S3 Glacier Instant Retrieval
Day 365+:     S3 Glacier Deep Archive

Dampaknya: storage cost turun 60-80% tanpa perubahan kode.

Presigned URL

Cara upload langsung dari client ke S3 tanpa melalui server — mengurangi beban server dan mempercepat upload.

Presigned URL flow
1. Client minta presigned URL ke server
2. Server generate URL dengan signature dan expiry
3. Client upload langsung ke S3 menggunakan presigned URL
4. S3 return success → client notify server
Generate presigned URL (AWS CLI)
aws s3 presign s3://my-bucket/photo.jpg --expires-in 3600

Versioning

Aktifkan versioning untuk melindungi dari accidental deletion:

S3 versioning
DELETE photo.jpg → S3 tidak benar-benar hapus, tapi tambahkan delete marker
→ Version sebelumnya masih bisa di-recover

CDN (Content Delivery Network)

CDN menyimpan copy konten di server edge yang dekat secara geografis dengan pengguna.

Cara Kerja CDN

100%

Pull vs Push CDN

MetodeCara KerjaKelebihanKekurangan
PullCDN ambil dari origin saat cache missSimple, otomatisCold request lambat
PushDeveloper push konten ke CDNKontrol penuh, no cold missLebih banyak effort

Cache Invalidation

Kontrol kapan cache di-edge dihapus:

CDN cache invalidation
# Versioned URL (recommended)
/style.v1.css → v2.css (rename saat update)
 
# API invalidation
cf.purgeCache({ files: ['/images/photo.jpg'] })
 
# TTL-based
Cache-Control: max-age=86400 (cache 1 hari)

Cache Key Strategy

Bagaimana CDN membedakan cached response:

Cache key consideration
Default: URL path + query string
/custom?width=800 → berbeda dari /custom?width=400
 
Custom cache key:
- Ignore query string tertentu (utm_source, fbclid)
- Vary by Accept-Encoding (gzip vs brotli)
- Vary by device type (mobile vs desktop)

Consistent Hashing

Consistent hashing adalah teknik untuk distribusi data ke node tanpa repartitioning besar saat node ditambah/dihapus.

Masalah Tanpa Consistent Hashing

Masalah modulo hashing
hash(key) % N → N berubah (tambah/hapus node) → SEMUA key harus dipindah!

Solusi: Consistent Hashing Ring

Consistent hashing ring
Node dan key di-map ke lingkaran 0-360°
Key ditugaskan ke node terdekat searah jarum jam
 
Node A (0°) → Node B (120°) → Node C (240°)
Key "user:1" di 45° → Node B (terdekat clockwise)

Saat Node B dihapus, hanya key yang ditugaskan ke Node B yang berpindah ke Node C — key lain tetap di tempat.

Virtual Nodes

Untuk distribusi lebih merata, setiap physical node punya beberapa virtual nodes di ring:

Virtual nodes
Node A: A-1 (10°), A-2 (130°), A-3 (250°)
Node B: B-1 (40°), B-2 (160°), B-3 (280°)
→ Distribusi lebih merata, load balancing lebih baik

Digunakan di: Cassandra (virtual nodes), DynamoDB, memcached (ketama consistent hashing).

Praktik: Sistem Upload Gambar

100%
Upload flow step-by-step
1. Client → API: POST /upload-url (filename, content-type)
2. API → S3: generate presigned PUT URL (expiry 5 menit)
3. API → Client: return presigned URL
4. Client → S3: PUT file ke presigned URL (direct upload)
5. S3 → Client: 200 OK (upload berhasil)
6. Client → API: POST /upload-complete (file key, metadata)
7. API → Database: save file metadata
8. API → CDN: invalidate cache path

Alur ini memastikan:

  • Server tidak menjadi bottleneck upload (client upload langsung ke S3).
  • File sizes tidak mempengaruhi server memory.
  • CDN edge langsung fresh setelah upload.

Note

Presigned URL expiry harus cukup lama untuk upload (5-10 menit) tapi cukup pendek untuk keamanan. Selalu set Content-Type dan Content-Length validation di bucket policy untuk mencegah abuse.

Penutup

Inti yang harus dibawa pulang:

  • Object storage (S3/R2/GCS) adalah standar untuk file storage — durability 11 nines, lifecycle policy menghemat cost.
  • Presigned URL memungkinkan client upload langsung ke S3 tanpa melalui server.
  • CDN mengurangi latency untuk global users; pull CDN simple, push CDN butuh lebih banyak effort.
  • Consistent hashing menjaga distribusi data stabil saat node berubah — virtual nodes meningkatkan uniformity.

Di episode 9 selanjutnya kita akan membahas full-text search: Elasticsearch — inverted index, scoring BM25, arsitektur cluster/shard/replica, dan praktik setup Elasticsearch untuk product search. Search adalah fitur yang sering di-underestimate tapi krusial untuk user experience!

Belajar System Design - Storage, Blob & CDN | Belajar System Design