System Design Framework: Universal Approach
π― The 4-Step Framework
Use this framework for any system design question:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SYSTEM DESIGN FRAMEWORK β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β STEP 1: REQUIREMENTS (5 min) β
β βββ Functional requirements (what it does) β
β βββ Non-functional requirements (how it performs) β
β βββ Constraints & assumptions β
β βββ Capacity estimation β
β β
β STEP 2: HIGH-LEVEL DESIGN (10 min) β
β βββ Core components β
β βββ Data flow β
β βββ API design β
β βββ Database schema (high-level) β
β β
β STEP 3: DEEP DIVE (20 min) β
β βββ Detailed component design β
β βββ Database schema (detailed) β
β βββ Scaling strategy β
β βββ Bottleneck identification & resolution β
β βββ Monitoring & reliability β
β β
β STEP 4: TRADE-OFFS & WRAP-UP (10 min) β
β βββ Pros/cons of key decisions β
β βββ Alternative approaches β
β βββ Future improvements β
β βββ Summary β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Step 1: Requirements (5 minutes)
Functional Requirements
Ask: βWhat does the system need to do?β
Example (URL Shortener):
β
Users can create short URLs from long URLs
β
Users are redirected when visiting short URLs
β
Users can customize short URL aliases
β
Links expire after a configurable time
β
Users can view analytics (click counts)
β Out of scope:
- User authentication (assume handled elsewhere)
- Payment processing
- Mobile app design
Tip: Start with 3-5 core features. Ask the interviewer which ones to focus on.
Non-Functional Requirements
Ask: βHow should the system perform?β
Availability: 99.99% uptime (52 min downtime/year)
Latency: < 100ms for redirects
Throughput: 100M URLs created/day
Consistency: Eventual consistency OK for analytics
Durability: URLs should not be lost
Scalability: Handle 10x traffic spikes
Capacity Estimation
Traffic:
- 100M URLs created/day = ~1,160 URLs/sec
- 10:1 read:write ratio = ~11,600 reads/sec
- Peak: 2x average = ~2,320 writes/sec, ~23,200 reads/sec
Storage:
- Each URL record: ~500 bytes (long URL + short code + metadata)
- 100M/day Γ 365 days Γ 5 years = 182.5B records
- 182.5B Γ 500 bytes = ~91 TB
Bandwidth:
- Write: 1,160 Γ 500 bytes = ~580 KB/s
- Read: 11,600 Γ 500 bytes = ~5.8 MB/s
Step 2: High-Level Design (10 minutes)
Draw the Architecture
ββββββββββββ ββββββββββββββββ βββββββββββββββββ
β Client βββββββ Load Balancerβββββββ API Servers β
ββββββββββββ ββββββββββββββββ βββββββββ¬ββββββββ
β
βββββββββββββββββββββββββββΌβββββββββββββββββ
β β β
βββββββΌβββββββ ββββββββΌββββββββ ββββββΌββββββ
β Cache β β Database β β Queue β
β (Redis) β β (PostgreSQL) β β (Kafka) β
ββββββββββββββ ββββββββββββββββ ββββββββββββ
API Design
POST /api/v1/urls
Request: { "long_url": "https://...", "custom_alias": "my-link", "expires_at": "..." }
Response: { "short_url": "https://short.ly/abc123", "created_at": "..." }
GET /{short_code}
Response: 301 Redirect to long URL
GET /api/v1/urls/{short_code}/analytics
Response: { "total_clicks": 1234, "clicks_by_date": {...}, "referrers": {...} }
DELETE /api/v1/urls/{short_code}
Response: { "status": "deleted" }
Database Schema (High-Level)
-- Core table
urls (
id BIGINT PRIMARY KEY,
short_code VARCHAR(10) UNIQUE NOT NULL,
long_url TEXT NOT NULL,
user_id BIGINT,
created_at TIMESTAMP,
expires_at TIMESTAMP,
click_count BIGINT DEFAULT 0
)
-- Analytics table (append-only)
click_events (
id BIGINT PRIMARY KEY,
short_code VARCHAR(10),
clicked_at TIMESTAMP,
ip_address VARCHAR(45),
user_agent TEXT,
referrer TEXT
)
Step 3: Deep Dive (20 minutes)
Pick 2-3 Components to Deep Dive
Always ask: βWhich component would you like me to dive deeper into?β
Common deep-dive topics:
- Data Storage β Sharding, replication, indexing
- Caching β Strategy, invalidation, consistency
- Scaling β Horizontal scaling, load balancing
- Reliability β Failover, redundancy, monitoring
Deep Dive: Caching Strategy
Cache-Aside Pattern (most common):
ββββββββββββ ββββββββββββ ββββββββββββ
β Client βββββββββββ App βββββββββββ Database β
ββββββββββββ β Server β ββββββββββββ
ββββββ¬ββββββ
β
ββββββΌββββββ
β Cache β
β (Redis) β
ββββββββββββ
Read Path:
1. Check cache β Hit? Return cached data
2. Cache miss β Query database
3. Store result in cache β Return data
Write Path:
1. Write to database
2. Invalidate cache (delete key)
3. Next read will fetch fresh data from DB
Cache Eviction:
- LRU (Least Recently Used) β default for most cases
- TTL (Time To Live) β for time-sensitive data
Deep Dive: Database Sharding
Sharding by Short Code (Hash-based):
βββββββββββββββββββββββββββββββββββββββββββ
β Hash Function β
β shard_id = hash(short_code) % N β
βββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βββββββββββΌββββββββββ¬ββββββββββ
β β β β
βββββΌβββ βββββΌβββ βββββΌβββ βββββΌβββ
βShard0β βShard1β βShard2β βShard3β
β a-f β β g-l β β m-r β β s-z β
ββββββββ ββββββββ ββββββββ ββββββββ
Pros: Even distribution, simple routing
Cons: Range queries hard, resharding complex
Deep Dive: Scaling
Horizontal Scaling:
βββ Stateless API servers behind load balancer
βββ Database read replicas for read-heavy workloads
βββ Cache cluster (Redis Cluster)
βββ Message queue for async processing
Load Balancing:
βββ L4 (TCP) β Fast, simple
βββ L7 (HTTP) β Content-aware routing
βββ Algorithms: Round Robin, Least Connections, IP Hash
βββ Health checks every 5-10 seconds
Step 4: Trade-offs & Wrap-up (10 minutes)
Discuss Key Trade-offs
"I chose [Decision A] over [Decision B] because:
Decision: SQL vs NoSQL
βββ SQL chosen for: ACID compliance, complex queries
βββ Trade-off: Harder to scale horizontally
βββ Mitigation: Read replicas, connection pooling
Decision: Cache-aside vs Write-through
βββ Cache-aside chosen for: Simpler, better for read-heavy
βββ Trade-off: Possible stale data
βββ Mitigation: Short TTL, cache invalidation on write
Decision: Synchronous vs Async processing
βββ Async chosen for: Click analytics
βββ Trade-off: Eventual consistency
βββ Acceptable: Analytics don't need real-time accuracy"
Mention Future Improvements
"If I had more time, I would consider:
1. Geographic distribution with multi-region deployment
2. Rate limiting to prevent abuse
3. Analytics with real-time streaming (Kafka + Flink)
4. A/B testing framework for URL aliases
5. Machine learning for spam detection"
π System Design Checklist
Use this checklist to ensure you cover everything:
Requirements:
β‘ Functional requirements defined
β‘ Non-functional requirements quantified
β‘ Capacity estimated (traffic, storage, bandwidth)
β‘ Out of scope items listed
High-Level Design:
β‘ Core components identified
β‘ Data flow diagram drawn
β‘ API endpoints designed
β‘ Database schema outlined
Deep Dive:
β‘ Database design (schema, indexing, sharding)
β‘ Caching strategy (what to cache, TTL, invalidation)
β‘ Scaling approach (horizontal, vertical, auto-scaling)
β‘ Reliability (replication, failover, monitoring)
β‘ Security (authentication, encryption, rate limiting)
Trade-offs:
β‘ Key decisions justified
β‘ Alternatives discussed
β‘ Bottlenecks identified and addressed
β‘ Future improvements mentioned
π― Common Mistakes to Avoid
- Jumping to solution without understanding requirements
- Over-engineering β Donβt design for Google scale if itβs a startup
- Ignoring non-functional requirements β Availability and latency matter
- Not drawing diagrams β Visual communication is essential
- Staying too abstract β Dive into specifics when asked
- Not discussing trade-offs β Every decision has pros and cons
- Forgetting operational concerns β Monitoring, alerting, deployment
π Cross-References
- URL Shortener β Example of applying this framework
- Architecture Concepts β Quick reference for all concepts
- Architecture Questions β Interview questions on architecture
- Coding Framework β Similar structured approach for coding