Message queue (7/10): Kafka/SQS & tách service ~500K user
Event-driven system design: Kafka hoặc SQS, redirect service, analytics consumer, idempotency, DLQ — không block redirect khi ghi click.
· 1 min read
Khóa học System Design cơ bản — thiết kế hệ thống scale 1 → 1 triệu user · Phần 7/10▼
Mục tiêu phần 7
~500.000 user: ghi click và analytics không được block redirect — message queue, tách Redirect / Link API / Analytics.
Tách theo workload
| Service | Nhiệm vụ |
|---|---|
| Link API | CRUD, auth |
| Redirect | Chỉ cache + redirect + publish event |
| Analytics | Consume click.events |
Redirect → publish {event_id, slug, ts, ua}
→ Queue → N consumers → OLAP
Delivery semantics
At-least-once + idempotent consumer (insert event_id unique).
DLQ
Message fail 5 lần → DLQ → alert on-call.
Backpressure
Queue depth > threshold → scale consumer; nếu OLAP chậm, không block redirect.
Bài tập
1M event/ngày — retention queue bao lâu nếu consumer down 2h?
Câu hỏi thường gặp
Phần 7 tập trung vào quy mô nào?
Event-driven system design: Kafka hoặc SQS, redirect service, analytics consumer, idempotency, DLQ — không block redirect khi ghi click.
Bài đọc tiếp theo
Thiết kế hệ thống cơ bản (1/10): Học System Design — metric, QPS, CAP
System design là gì? Khóa miễn phí 10 phần: functional/non-functional, QPS, p99, availability, CAP — ước lượng traffic ShortLink scale 1→1M user. Bản đồ: /blog/hoc-system-design-co-ban-tu-dau
Đọc tiếp →Capstone URL shortener (10/10): System Design 1M MAU + rubric
Đề phỏng vấn URL shortener: 20k RPS redirect, 200 write/s, p99 & availability — rubric 100 điểm và đáp án tham khảo.
Đọc tiếp →Monolith System Design (2/10): Scale 1 user — kiến trúc MVP ShortLink
Thiết kế hệ thống giai đoạn MVP: monolith, Nginx, PostgreSQL một server — API URL shortener, schema SQL, sequence redirect, failure mode trước khi scale.
Đọc tiếp →Startup của bạn cần tech partner?
Trao đổi miễn phí về MVP, timeline và mô hình chia lợi nhuận phù hợp.