🏗️ ทำไม System Design ถึงสำคัญ?
ถ้า Coding Interview คือการทดสอบว่าคุณเขียนโค้ดได้ แล้ว System Design Interview คือการทดสอบว่าคุณสามารถออกแบบระบบที่ใช้งานได้จริงในโลกจริงหรือไม่ สำหรับตำแหน่ง Senior Software Engineer ขึ้นไป คำถาม System Design เป็นสิ่งที่ขาดไม่ได้
📊 System Design ในบริษัท Tech ชั้นนำ
45-60
นาทีต่อรอบสัมภาษณ์
L4+
ระดับที่เริ่มถาม System Design
40%
น้ำหนักคะแนนในการตัดสิน
$200K+
เงินเดือนที่ต้องผ่าน System Design
🎯 โครงสร้างการสัมภาษณ์ System Design
📋 4S Framework: วิธีตอบคำถาม System Design
1️⃣ Scope - กำหนดขอบเขต
ถามกลับเพื่อเข้าใจ Requirements
- Functional Requirements
- Non-Functional Requirements
- Scale (Users, Requests, Data)
เวลา: 2-5 นาที
2️⃣ Sketch - ออกแบบคร่าวๆ
วาด High-Level Design
- API Design
- Database Schema
- Basic Architecture
เวลา: 10-15 นาที
3️⃣ Scale - ขยายระบบ
ออกแบบให้รองรับ Load สูง
- Load Balancing
- Caching
- Database Sharding
เวลา: 15-25 นาที
4️⃣ Solidify - ตอกย้ำ
จัดการ Edge Cases
- Failure Handling
- Security
- Monitoring
เวลา: 10-15 นาที
📚 หัวข้อ System Design ที่ต้องรู้
🌐 1. Design a URL Shortener (like bit.ly)
Requirements
- Functional: สร้าง Short URL, Redirect, Analytics
- Non-Functional: Low latency, High availability
- Scale: 100M URLs/day, 10B read/day
Key Components
Database:
- SQL: PostgreSQL (Consistency)
- NoSQL: Cassandra (Scale)
Caching:
- Redis สำหรับ Hot URLs
- TTL 24 ชั่วโมง
Encoding:
- Base62 (a-z, A-Z, 0-9)
- 6 chars = 62^6 ≈ 57B URLs
Load Balancer:
- Round Robin
- Health checks
📰 2. Design a News Feed (like Facebook, Twitter)
Requirements
- Functional: Post, Follow, Feed, Like, Comment
- Non-Functional: Real-time, Scalable
- Scale: 1B users, 100M posts/day
Feed Generation Approaches
| Approach | Pros | Cons |
|---|---|---|
| Pull (Fan-out on Read) | Real-time, Less storage | Slow for users with many follows |
| Push (Fan-out on Write) | Fast read | High storage, Complex for celebs |
| Hybrid | Best of both | Complex implementation |
💬 3. Design a Chat System (like WhatsApp, Messenger)
Key Challenges
- Real-time: WebSocket for instant delivery
- Order: Sequence numbers for message ordering
- Delivery: At-least-once semantics
- Read Receipts: Separate status tracking
Architecture
Client → Load Balancer → Chat Server → Message Queue → Database
↓
WebSocket Server (for real-time)
🔧 Core Concepts ที่ต้องรู้
⚖️ CAP Theorem
ระบบ Distributed สามารถมีได้แค่ 2 ใน 3:
- C - Consistency: ทุก Node เห็นข้อมูลเหมือนกัน
- A - Availability: ระบบตอบสนองตลอดเวลา
- P - Partition Tolerance: ทำงานได้แม้ Network ล่ม
ตัวอย่าง:
- CP: MongoDB, HBase (Consistency + Partition)
- AP: Cassandra, DynamoDB (Availability + Partition)
- CA: Traditional RDBMS (Consistency + Availability)
📊 Database Scaling
| Technique | Description | When to Use |
|---|---|---|
| Replication | Copy data to multiple servers | Read-heavy workloads |
| Sharding | Split data across multiple servers | Write-heavy, Large dataset |
| Indexing | Create indexes for fast queries | Frequent queries |
| Denormalization | Duplicate data for faster reads | Read >> Write |
| Caching | Store hot data in memory | Frequently accessed data |
💾 Caching Strategies
Cache-Aside (Lazy Loading)
- App ตรวจสอบ Cache ก่อน
- Miss → Query DB → Update Cache
- Pros: Simple, Flexible
- Cons: Initial latency
Write-Through
- Write to Cache + DB simultaneously
- Pros: Data consistency
- Cons: Higher write latency
Write-Behind (Write-Back)
- Write to Cache, Async to DB
- Pros: Fast writes
- Cons: Risk of data loss
Refresh-Ahead
- Refresh cache before expire
- Pros: No stale data
- Cons: Complex, Over-fetching
📖 แหล่งเรียนรู้ System Design
📚 หนังสือที่ต้องอ่าน
| หนังสือ | ผู้เขียน | เนื้อหา |
|---|---|---|
| Designing Data-Intensive Applications | Martin Kleppmann | 🌟 ไบเบิลของ System Design |
| System Design Interview | Alex Xu | สำหรับเตรียมสอบโดยเฉพาะ |
| Building Microservices | Sam Newman | Microservices อย่างละเอียด |
| The System Design Primer | Donne Martin | ฟรีบน GitHub |
🎓 คอร์สออนไลน์
- Educative.io: Grokking the System Design Interview
- ByteByteGo: System Design โดย Alex Xu
- Designing Distributed Systems: ฟรีบน Microsoft Learn
- YouTube: System Design Primer Channel
💡 เคล็ดลับการสอบ System Design
✅ DO's
- ✅ Ask clarifying questions - ถามให้เข้าใจ Requirements
- ✅ Think out loud - พูดคิดออกมาให้ Interviewer เห็นกระบวนการ
- ✅ Start simple, then scale - เริ่มจากง่าย ค่อยๆ ซับซ้อน
- ✅ Discuss trade-offs - อธิบายข้อดีข้อเสียของแต่ละ Approach
- ✅ Draw diagrams - วาดรูปช่วยให้สื่อสารได้ดีขึ้น
- ✅ Consider edge cases - คิดถึงกรณีพิเศษ
❌ DON'Ts
- ❌ ไม่ถาม Requirements แล้วเริ่มออกแบบเลย
- ❌ เงียบคิดคนเดียวนานๆ
- ❌ ยึดติดกับ Technology ที่คุ้นเคยโดยไม่พิจารณา Trade-offs
- ❌ ลืมคิดเรื่อง Scalability และ Reliability
- ❌ ไม่สนใจ Non-functional requirements
🎯 สรุป: กุญแจสู่ความสำเร็จ
📋 Checklist ก่อนไปสอบ
- ☐ อ่าน Designing Data-Intensive Applications จบ
- ☐ ฝกออกแบบระบบอย่างน้อย 10 ระบบ
- ☐ เข้าใจ Trade-offs ของแต่ละ Technology
- ☐ ฝึกอธิบายออกเสียง
- ☐ รู้จัก Numbers สำคัญ (Latency, Throughput)
- ☐ เข้าใจ CAP Theorem และ Consistency Models
🏗️ System Design ไม่ใช่การจำ แต่เป็นการเข้าใจหลักการและ Practice อย่างสม่ำเสมอ 🏗️
บทความนี้เขียนเมื่อ กุมภาพันธ์ 2026 | อ้างอิงจาก Designing Data-Intensive Applications และประสบการณ์สัมภาษณ์จริง