Part 10 · System Design · 10.3

8 timed design labs

Mỗi bài kéo dài 45–60 phút. Với mỗi lab, hãy lưu lại assumptions, estimates, diagram, decisions, failure matrix và rubric để có thể review lại cách bạn suy nghĩ, không chỉ nhìn vào kiến trúc cuối cùng.

Cách luyện: bắt đầu bằng requirement và assumptions, ước lượng tải, phác thảo luồng chính, rồi ghi rõ các decision và failure mode. Đến phút 35, áp dụng constraint change của lab và giải thích hệ thống phải tiến hóa như thế nào.

Lab 01 · URL Shortener

Key generationRedirect p99Hot URLsCache / CDNAnalytics eventualExpiryAbuse

Thiết kế URL Shortener và làm rõ cách sinh key, mục tiêu latency p99 cho redirect, xử lý hot URLs, vai trò của cache/CDN, analytics theo eventual consistency, expiry và abuse prevention.

Constraint phút 35: xuất hiện một celebrity link đạt 100k RPS. Hãy cập nhật thiết kế và nêu rõ bottleneck, cache strategy và cách bảo vệ origin.

Lab 02 · Notification Platform

PreferencesTemplatesFan-outProvider quotasRetry / DLQDedupeStatusOpt-out

Thiết kế nền tảng notification có preferences, templates, fan-out, provider quotas, retry/DLQ, dedupe, delivery status và opt-out.

Constraint phút 35: provider outage trong 2 giờ. Sau khi provider phục hồi, backlog phải được drain mà không tạo spam hay gửi trùng.

Lab 03 · Order & Payment

IdempotencyLedgerInventorySaga / outboxUnknown outcomeReconciliationAudit

Thiết kế flow Order & Payment với idempotency, ledger, inventory, Saga/outbox, xử lý unknown outcome, reconciliation và audit.

Constraint phút 35: payment response bị mất sau khi charge đã thành công. Hãy giải thích cách tránh double charge và cách hệ thống xác nhận trạng thái cuối cùng.

Lab 04 · Chat System

Connection gatewayConversation orderingOffline deliveryPresenceMulti-device syncMedia

Thiết kế Chat System gồm connection gateway, ordering trong conversation, offline delivery, presence, multi-device sync và media.

Constraint phút 35: xảy ra regional failure đồng thời xuất hiện message reordering. Hãy chỉ ra invariants nào phải giữ và dữ liệu nào có thể chấp nhận eventual convergence.

Lab 05 · Social Feed

Fan-out-on-writeFan-out-on-readHybridCelebrity problemRankingPrivacyPaginationCache

Thiết kế Social Feed và so sánh fan-out-on-write, fan-out-on-read hoặc hybrid; xử lý celebrity problem, ranking, privacy, pagination và cache.

Constraint phút 35: user thay đổi privacy sau khi fan-out. Hãy mô tả cách ngăn nội dung không còn được phép tiếp tục xuất hiện trong feed đã materialize.

Lab 06 · Large File Upload

Multipart / resumableObject storageChecksumMetadataVirus scanCDNLifecycle

Thiết kế Large File Upload với multipart/resumable upload, object storage, checksum, metadata, virus scan, CDN và lifecycle.

Constraint phút 35: hỗ trợ file 10 GB trên unreliable mobile network. Hãy cập nhật protocol upload, retry/resume và integrity validation.

Lab 07 · Distributed Rate Limiter

Token bucketLeaky bucketKey scopeAtomicityLocal / globalClockFail-open / closedAbuse

Thiết kế Distributed Rate Limiter, cân nhắc token bucket hoặc leaky bucket, key scope, atomicity, local/global enforcement, clock, fail-open/fail-closed và abuse.

Constraint phút 35: hệ thống chạy multi-region với 100 ms latency. Hãy làm rõ consistency boundary và trade-off giữa enforcement chính xác với availability/latency.

Lab 08 · Ticket Booking

Seat inventory invariantHold expiryQueue / waiting roomPaymentFairnessBot defenseOversell prevention

Thiết kế Ticket Booking với seat inventory invariant, hold expiry, queue/waiting room, payment, fairness, bot defense và oversell prevention.

Constraint phút 35: flash sale có 1 triệu users trong 2 phút. Hãy bảo vệ inventory invariant trong khi vẫn kiểm soát queue, fairness và load lên downstream.

Deliverables bắt buộc cho mỗi lab

Mục tiêu của phần thực hành là luyện decision-making dưới time pressure: assumptions phải rõ, trade-off phải nói được, và thay đổi constraint phải dẫn tới thay đổi kiến trúc có lý do.