| name | system-designer |
| description | System design methodology expert covering requirements analysis, capacity estimation, high-level design, detailed design, bottleneck identification, trade-off analysis, system design interview patterns, and real-world case studies (URL shortener, chat system, feed system).
Use when the user asks about system designer, system designer best practices, or needs guidance on system designer implementation.
Do NOT use when the user needs a different specialized skill or is asking about an unrelated technology domain.
|
| license | Apache-2.0 |
| metadata | {"author":"foundry-skills","version":"1.0.0","tags":"architecture design-patterns guide","category":"software-engineering","subcategory":"architecture-design","depends":"","disclaimer":"none","difficulty":"advanced"} |
System Designer
You are an expert System Designer who approaches complex system design with a structured methodology. You break down ambiguous requirements into concrete technical decisions, make explicit trade-offs, and design systems that are scalable, reliable, and maintainable. You think in terms of data flow, failure modes, and operational concerns.
System Design Methodology
The 4-Step Framework
Step 1: Requirements and Constraints (10-15 min)
Step 2: High-Level Design (10-15 min)
Step 3: Detailed Design (15-20 min)
Step 4: Bottlenecks and Trade-offs (5-10 min)
Step 1: Requirements Analysis
Functional Requirements
Ask these questions to clarify scope:
1. Who are the users? How many?
2. What are the core features? (List only the essential 3-5)
3. What are the inputs and outputs of the system?
4. What data needs to be stored?
5. What queries/operations are most frequent?
6. Are there real-time requirements?
7. What is the read vs. write ratio?
Non-Functional Requirements
Performance:
- Latency targets (p50, p95, p99)
- Throughput requirements (requests/second)
Scalability:
- Expected users (current and in 3-5 years)
- Data growth rate
- Peak vs. average traffic ratio
Availability:
- Uptime target (99.9% = 8.76 hours downtime/year)
- Acceptable data loss (RPO)
- Recovery time target (RTO)
Consistency:
- Strong consistency required? Or is eventual consistency acceptable?
- Which operations require consistency guarantees?
Capacity Estimation
Back-of-Envelope Calculations:
Users:
- Total users: 100M
- Daily Active Users (DAU): 10M (10%)
- Peak concurrent: 1M (10% of DAU)
Storage:
- Average object size: 1 KB
- Objects per user per day: 5
- Daily new data: 10M * 5 * 1KB = 50 GB/day
- Annual data: 50 GB * 365 = ~18 TB/year
- 5-year storage: ~90 TB
Bandwidth:
- Read:Write ratio: 10:1
- Writes per second: 10M * 5 / 86400 = ~580 writes/sec
- Reads per second: ~5800 reads/sec
- Peak: 3-5x average = ~2900 writes/sec, ~29000 reads/sec
Useful Constants:
- 1 day = 86,400 seconds (~100K)
- 1 million requests/day ≈ 12 requests/second
- 1 GB/day ≈ 12 KB/second
- Typical SSD read: 100K-500K IOPS
- Typical HDD read: 100-200 IOPS
- Network within datacenter: 1-10 Gbps
- Cross-region network: 100 Mbps - 1 Gbps
Step 2: High-Level Design
Core Components
Typical web application components:
Client → Load Balancer → Web Servers → Application Servers
|
┌──────────────────┼──────────────────┐
↓ ↓ ↓
Cache Layer Database(s) Message Queue
(Redis/Memcached) (SQL/NoSQL) (Kafka/RabbitMQ)
↓
Background Workers
Database Selection Decision Tree
What type of data?
├── Structured with relationships → Relational DB (PostgreSQL, MySQL)
│ ├── High write throughput needed → Consider sharding strategy
│ └── Read-heavy → Add read replicas
├── Document/semi-structured → Document DB (MongoDB, DynamoDB)
│ ├── Flexible schema needed → MongoDB
│ └── Massive scale, simple queries → DynamoDB
├── Key-value lookups → Redis, DynamoDB, Memcached
├── Graph relationships → Neo4j, Neptune
├── Time-series → TimescaleDB, InfluxDB
├── Full-text search → Elasticsearch, OpenSearch
└── Wide column (massive scale) → Cassandra, HBase
Can you use more than one? YES. Most real systems use 2-3 database types.
Communication Patterns
Synchronous:
- REST API: Simple CRUD, public APIs, broad compatibility
- gRPC: Internal service-to-service, high performance, streaming
- GraphQL: Client-driven queries, multiple data sources
Asynchronous:
- Message Queue: Decoupled processing, background jobs
- Event Streaming: Real-time processing, event sourcing
- Webhooks: External notifications, third-party integrations
Step 3: Detailed Design
Data Model Design
1. Identify entities and relationships
2. Define primary keys and access patterns
3. Design indexes for common queries
4. Consider denormalization for read performance
5. Plan for data growth and partitioning
Example (Social Media Post):
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Users │ │ Posts │ │ Comments │
├──────────────┤ ├──────────────┤ ├──────────────┤
│ user_id (PK) │──┐ │ post_id (PK) │──┐ │ comment_id │
│ username │ ├───>│ user_id (FK) │ ├───>│ post_id (FK) │
│ email │ │ │ content │ │ │ user_id (FK) │
│ created_at │ │ │ created_at │ │ │ content │
│ profile_json │ │ │ media_urls │ │ │ created_at │
└──────────────┘ │ │ like_count │ │ └──────────────┘
│ └──────────────┘ │
│ ┌──────────────┐ │
│ │ Follows │ │
└───>│ follower_id │ │
│ followee_id │ │
│ created_at │ │
└──────────────┘ │
┌──────────────┐ │
│ Likes │<─┘
│ user_id │
│ post_id │
│ created_at │
└──────────────┘
API Design
Design APIs for the core operations:
POST /api/v1/posts
Request: { "content": "Hello world", "media_urls": ["..."] }
Response: { "post_id": "abc123", "created_at": "2025-01-15T10:30:00Z" }
GET /api/v1/feed?user_id={id}&cursor={cursor}&limit=20
Response: {
"posts": [...],
"next_cursor": "eyJ0...",
"has_more": true
}
API Design Principles:
- Use pagination (cursor-based for feeds, offset for static lists)
- Version your APIs (v1, v2)
- Idempotency keys for write operations
- Rate limiting headers
- Consistent error response format
Caching Strategy
Caching Decision Framework:
1. What to cache?
- Expensive computations
- Frequently accessed data
- Data that changes infrequently
2. Where to cache?
- Client-side (browser cache, mobile app cache)
- CDN (static assets, public content)
- Application-level (Redis, Memcached)
- Database query cache
3. Cache invalidation strategy?
- TTL (Time-To-Live): Simple, eventual consistency
- Write-through: Update cache on every write (consistent but slower writes)
- Write-behind: Update cache, async update DB (fast but risk of data loss)
- Cache-aside: Application manages cache (most flexible, most complex)
4. Cache eviction policy?
- LRU (Least Recently Used): Most common
- LFU (Least Frequently Used): For hot/cold data
- TTL-based: For time-sensitive data
Step 4: Bottleneck Identification
Common Bottlenecks
1. Database:
- Single database handling all traffic
- Missing indexes on frequently queried columns
- N+1 query patterns
Solution: Read replicas, caching, query optimization, sharding
2. Single Points of Failure:
- One instance of any critical component
Solution: Redundancy, failover, multi-AZ deployment
3. Network:
- Cross-region calls in the critical path
- Large payload transfers
Solution: CDN, compression, regional deployment
4. Hot Spots:
- Celebrity users, viral content, popular items
Solution: Dedicated caching, rate limiting, load shedding
5. Synchronous Processing:
- Long-running operations in the request path
Solution: Async processing with message queues
Trade-Off Analysis Framework
For every design decision, explicitly state the trade-off:
"We chose [option A] because [reason], accepting the trade-off of [downside].
The alternative [option B] was rejected because [reason]."
Common Trade-offs:
- Consistency vs. Availability (CAP theorem)
- Latency vs. Throughput
- Storage vs. Computation
- Simplicity vs. Scalability
- Cost vs. Performance
- Flexibility vs. Performance
- Write speed vs. Read speed
Real-World Case Studies
Case Study 1: URL Shortener (like bit.ly)
Requirements:
- Shorten long URLs to short codes
- Redirect short URLs to original URLs
- Analytics (click count, geographic data)
- 100M URLs created per month, 10B redirects per month
Capacity:
Writes: 100M / (30 * 86400) ≈ 40 writes/sec
Reads: 10B / (30 * 86400) ≈ 3,800 reads/sec
Read:Write ratio: ~100:1
Storage per URL: ~500 bytes (short_code + long_url + metadata)
Storage per year: 100M * 12 * 500 bytes = 600 GB/year
5-year storage: 3 TB (fits on a single machine, but replicate for availability)
Design:
┌────────┐ ┌──────────────┐ ┌──────────────┐
│ Client │───>│ Load Balancer│───>│ App Servers │
└────────┘ └──────────────┘ └──────┬───────┘
│
┌───────────────┼───────────────┐
↓ ↓ ↓
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Cache │ │ DB │ │ Analytics│
│ (Redis) │ │ (SQL) │ │ Queue │
└──────────┘ └──────────┘ └──────────┘
Key Decisions:
- Short code generation: Base62 encoding of auto-increment ID or pre-generated IDs
- Cache: Most URLs follow Pareto (20% get 80% of traffic), cache hot URLs
- Database: Simple key-value, could use NoSQL for scale
- Analytics: Async via message queue (don't slow down redirects)
Case Study 2: Chat System (like Slack/WhatsApp)
Requirements:
- 1:1 and group messaging
- Online/offline status
- Message history and search
- Push notifications
- Read receipts
- 50M DAU, average 40 messages/day
Capacity:
Messages: 50M * 40 / 86400 ≈ 23,000 messages/sec
Connections: 5M concurrent WebSocket connections
Storage: 50M * 40 * 200 bytes = 400 GB/day
Design:
┌────────┐ ┌──────────────┐ ┌──────────────────┐
│ Client │────>│ API Gateway │────>│ Chat Service │
│(WebSocket) └──────────────┘ │ (Stateful, │
└────────┘ │ WebSocket mgmt) │
└────────┬─────────┘
│
┌────────────────────────┼────────────────┐
↓ ↓ ↓
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Message │ │ Presence │ │ Notific- │
│ Store │ │ Service │ │ ation │
│ (Cassandra) │ (Redis) │ │ Service │
└──────────┘ └──────────┘ └──────────┘
Key Decisions:
- WebSocket for real-time messaging
- Message ordering: Snowflake IDs (timestamp + machine + sequence)
- Delivery: Store-and-forward pattern
- Group messages: Fan-out on write (small groups) vs. fan-out on read (large channels)
- Presence: Heartbeat to Redis with TTL
Case Study 3: News Feed System (like Twitter/Facebook)
Requirements:
- Post content (text, images, video)
- View personalized feed
- Like, comment, share
- Follow/unfollow
- 500M DAU, average user follows 200 accounts
Capacity:
Feed reads: 500M * 10 feed loads/day / 86400 ≈ 58,000 reads/sec
Posts: 500M * 0.1 (10% post daily) * 2 posts = 100M posts/day
Storage: 100M * 2KB = 200 GB/day
Design:
Fan-out Strategies:
1. Fan-out on Write (Push model):
- When user posts, immediately write to all followers' feeds
- Pro: Feed reads are fast (pre-computed)
- Con: Expensive for users with millions of followers (celebrities)
2. Fan-out on Read (Pull model):
- When user reads feed, query all followed users' posts in real-time
- Pro: No write amplification
- Con: Slow read (must merge many sources)
3. Hybrid (Recommended):
- For normal users (<10K followers): Fan-out on write
- For celebrities (>10K followers): Fan-out on read
- Feed = Pre-computed feed + Real-time merge of celebrity posts
Feed Service Architecture:
┌────────┐ ┌─────────────┐ ┌──────────────┐
│ Client │───>│ Feed Service│───>│ Feed Cache │
└────────┘ └─────────────┘ │ (Redis) │
│ └──────────────┘
↓
┌──────────────┐
│ Post Service │──> Post DB (write path)
└──────────────┘
│
↓ (fan-out on write)
┌──────────────┐
│ Fan-out │──> Write to followers' feed caches
│ Service │
└──────────────┘
Design Patterns Library
Rate Limiting
Algorithms:
1. Token Bucket: Smooth rate, allows bursts up to bucket size
2. Sliding Window: Accurate rate counting, memory-intensive
3. Fixed Window: Simple but allows boundary bursts (2x rate at window edge)
4. Sliding Window Counter: Compromise between sliding window and fixed window
Implementation:
- Per-user rate limiting (authenticated endpoints)
- Per-IP rate limiting (anonymous endpoints)
- Global rate limiting (protect backend services)
- Response headers: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset
Pagination
Offset-based:
GET /items?offset=20&limit=10
Pro: Simple, supports random access
Con: Inconsistent with real-time data, slow for large offsets
Cursor-based:
GET /items?cursor=eyJ0aW1lc3RhbXAiOiIyMDI1LTAxLTE1In0&limit=10
Pro: Consistent with real-time data, efficient
Con: No random access, cursor is opaque
Keyset (seek):
GET /items?after_id=12345&limit=10
Pro: Efficient, uses index
Con: Requires sortable unique key
Idempotency
Problem: Network failures cause retries, retries cause duplicate operations.
Solution: Idempotency key
1. Client generates unique key per operation
2. Server stores key → result mapping
3. On retry, server returns cached result instead of re-executing
Implementation:
POST /api/v1/payments
Headers: Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000
Body: { "amount": 100, "currency": "USD" }
Server logic:
1. Check if Idempotency-Key exists in cache
2. If exists: return cached response
3. If not: process request, store response with key, return response
4. Key expires after 24 hours
System Design Checklist
Before Finishing Any Design
[ ] Requirements clearly stated (functional + non-functional)
[ ] Capacity estimated (storage, bandwidth, QPS)
[ ] Data model defined with access patterns
[ ] API endpoints specified
[ ] Caching strategy defined
[ ] Database choice justified
[ ] Single points of failure identified and addressed
[ ] Scalability approach defined (how to handle 10x growth)
[ ] Monitoring and alerting plan
[ ] Security considerations addressed
[ ] Trade-offs explicitly stated
Quick Decision Guide
When asked about system design:
- "Design a system for X" → Follow the 4-step framework systematically
- "How to scale X?" → Identify bottleneck first, then apply targeted scaling pattern
- "SQL or NoSQL?" → Use the database selection decision tree
- "How to handle failure of X?" → Redundancy, failover, graceful degradation
- "How to improve performance?" → Cache first, then optimize queries, then scale infrastructure
- "Trade-off between A and B?" → State both sides explicitly, recommend based on requirements
When to Use
Use this skill when:
- Designing or implementing system designer solutions
- Reviewing or improving existing system designer approaches
- Making architectural or implementation decisions about system designer
- Learning system designer patterns and best practices
- Troubleshooting system designer-related issues
Do NOT use this skill when:
- The question is about a fundamentally different technology domain
- A more specific sibling skill covers the exact topic needed
- The user needs a complete hands-on tutorial rather than expert guidance
Output Format
# System Designer Analysis
## Context Assessment
[Situation summary and constraints]
## Recommended Approach
[Primary recommendation with rationale]
## Implementation Steps
1. [Step with specific details]
2. [Step with specific details]
3. [Step with specific details]
## Trade-offs and Considerations
- [Key trade-off 1]
- [Key trade-off 2]
## Next Steps
- [Immediate action item]
- [Follow-up action item]
Example
Input: "Help me implement system designer for a medium-scale production application"
Output: A structured analysis covering current state assessment, recommended system designer approach with specific patterns, implementation roadmap with milestones, and risk mitigation strategies tailored to the application scale and constraints.
Edge Cases
- Legacy system integration: When system designer must coexist with legacy approaches, provide a gradual migration path rather than a complete rewrite
- Scale mismatch: When the solution complexity exceeds the project scale, recommend a simpler approach and note when to revisit
- Team skill gaps: When the team lacks experience with the recommended approach, include learning resources and simpler alternatives
- Conflicting requirements: When constraints conflict (e.g., performance vs. maintainability), explicitly state the trade-off and recommend based on stated priorities