Bài tập thực hành & Câu hỏi phỏng vấn
Chuẩn bị cho các câu hỏi system design trong phỏng vấn.
Câu hỏi thường gặp
1. Design a Rate Limiter
Yêu cầu: Giới hạn 100 requests mỗi phút từ một user.
Gợi ý thiết kế:
- Algorithm: Token bucket hoặc sliding window.
- Storage: Redis với atomic operations.
- Distributed: Sync rate limits across servers.
- Granularity: Per-user, per-IP, per-API-endpoint.
2. Design a Distributed Cache
Yêu cầu: Thiết kế hệ thống cache phân tán như Redis cluster.
Gợi ý thiết kế:
- Partitioning: Consistent hashing để distribute keys.
- Replication: Master-slave cho fault tolerance.
- Eviction: LRU, LFU policies.
- Consistency: Cache invalidation strategies.
3. Design a Search Autocomplete
Yêu cầu: Gợi ý từ khóa khi user typing (Google search box).
Gợi ý thiết kế:
- Data structure: Trie với frequency counts.
- Storage: In-memory cho low latency.
- Ranking: Popularity, personalization, trending.
- Scale: Top N suggestions từ billions of queries.
4. Design a Distributed File Storage
Yêu cầu: Tương tự Google Drive, Dropbox.
Gợi ý thiết kế:
- Storage: Object storage (S3) với chunking.
- Sync: Block-level sync, conflict resolution.
- Sharing: ACLs, public links.
- Versioning: Keep multiple versions.
5. Design a Notification System
Yêu cầu: Gửi push notifications đến hàng triệu devices.
Gợi ý thiết kế:
- Channels: Push, email, SMS, in-app.
- Queue: Kafka cho durability.
- Rate limiting: Avoid spamming users.
- Personalization: User preferences, timezone.
6. Design a Web Crawler
Yêu cầu: Crawl billions of web pages.
Gợi ý thiết kế:
- URL frontier: Priority queue cho URLs to crawl.
- Politeness: Respect robots.txt, rate limiting per domain.
- Deduplication: URL normalization, content hashing.
- Scale: Distributed crawling, parallel processing.
7. Design an Analytics Platform
Yêu cầu: Track user events, generate dashboards.
Gợi ý thiết kế:
- Ingestion: Kafka stream processing.
- Storage: Columnar database (ClickHouse, Redshift).
- Aggregation: Real-time + batch processing.
- Query: SQL interface cho analysts.
Gợi ý trả lời
Cấu trúc câu trả lời
-
Clarify requirements (2-3 phút)
- Ask về functional requirements.
- Ask về scale (users, RPS, data size).
- Confirm non-functional requirements (latency, availability).
-
Estimation (2 phút)
- Calculate RPS, storage, bandwidth.
- Identify read-heavy vs write-heavy.
-
High-level design (5 phút)
- Draw block diagram với major components.
- Explain data flow.
-
Detailed design (10 phút)
- Database schema.
- API design.
- Key algorithms.
-
Identify bottlenecks (3 phút)
- Single points of failure.
- Scalability issues.
- Performance optimizations.
-
Trade-offs (3 phút)
- Discuss alternatives.
- Explain why you chose certain approaches.
Tips quan trọng
- Drive the conversation: Đừng chờ interviewer hỏi, chủ động dẫn dắt.
- Think aloud: Giải thích suy nghĩ của bạn.
- Ask for feedback: “Does this make sense?”
- Be flexible: Sẵn sàng thay đổi design khi có yêu cầu mới.
- Practice: Vẽ diagram nhanh, tính toán nhanh.
Tài liệu tham khảo
Sách
- Designing Data-Intensive Applications - Martin Kleppmann
- System Design Interview - Alex Xu
Online Resources
Practice Platforms
- Pramp - Mock interviews
- Interviewing.io - Anonymous mock interviews
Kết luận
System design phỏng vấn không có đáp án đúng/sai duy nhất. Quan trọng là:
- Tư duy có cấu trúc: Follow methodology.
- Communication: Giải thích rõ ràng.
- Trade-off analysis: Hiểu pros/cons của mỗi decision.
- Practical knowledge: Learn from real-world systems.
Chúc bạn thành công! 🎉