L82 — Capstone: Design URL Shortener

Ba module tương tác cho design phase: kiến trúc, capacity estimation, read path.

1. Architecture diagram — click vào component để xem vai trò

Mỗi khối là một thành phần của hệ thống. Bấm để xem nó làm gì và nằm ở đâu trong luồng.

Client API Gateway Serviceclean arch Postgres Redis Queue Analytics Worker

Bấm vào một component

Chọn Client / Gateway / Service / Postgres / Redis / Queue / Worker để xem vai trò trong hệ thống.

2. Capacity calculator — kéo slider, xem ước lượng

Back-of-envelope: số URL & tỉ lệ read:write quyết định storage, cache, QPS.

Storage (urls, ~500 byte/URL)
50 GB
QPS ghi (= đọc / ratio)
1.0k req/s
Cache size (URL nóng × 100 byte)
2 GB
cache ~20% URL bắt 80% traffic (Pareto)
QPS chạm Postgres (sau cache)
2.0k req/s
= QPS đọc × (1 − hit)

3. Read path — cache hit vs miss + async click

Animate luồng redirect. Hit chỉ chạm Redis (~1ms). Miss đọc Postgres rồi populate. Click luôn emit ASYNC.

🌐Client
GET /{code}
Redis
cache
🗄️Postgres
urls
📨Queue
click async
↩️302
redirect
Bấm một nút để mô phỏng…