Reference
System Design Cheatsheet
A quick reference for system design interviews and architecture decisions. Covers estimation, components, patterns, and trade-offs.
- Estimation — Back-of-the-envelope math
- Components — When to use what
- Patterns — Common design patterns
- Trade-offs — CAP, PACELC, and beyond
Keep this cheatsheet handy for interviews and architecture discussions.
Quick Estimation
QPS Calculation
Here,
- =Seconds in a day
Storage Calculation
Here,
- =Days to retain data
Bandwidth Calculation
Here,
- =Average request/response size
Common Numbers
| Metric | Value |
|---|---|
| Seconds in a day | 86,400 |
| Seconds in a month | 2.6M |
| Seconds in a year | 31.5M |
| 1 million QPS | ~86B requests/day |
| Latency: memory | < 100ns |
| Latency: SSD | ~100us |
| Latency: HDD | ~10ms |
| Latency: Network (same DC) | ~500us |
| Latency: Network (cross-region) | ~50ms |
Database Selection
| Database | Use Case | Example |
|---|---|---|
| MySQL/PostgreSQL | ACID transactions, relational data | Orders, Users |
| MongoDB | Flexible schema, document storage | Content, Profiles |
| Cassandra | Write-heavy, time-series data | Metrics, Logs |
| Redis | Caching, sessions, leaderboards | Cache, Sessions |
| Elasticsearch | Full-text search, logging | Search, Logs |
| Neo4j | Graph relationships | Social graph |
| DynamoDB | Key-value, serverless | Session data |
Caching Patterns
| Pattern | Description | Trade-off |
|---|---|---|
| Cache-Aside | App manages cache | Flexible, extra hop |
| Write-Through | Write to cache + DB | Strong consistency, slow writes |
| Write-Behind | Write to cache, async to DB | Fast writes, data loss risk |
| Read-Through | Cache fetches from DB | Transparent, cache miss penalty |
Load Balancing Algorithms
| Algorithm | Description | Best For |
|---|---|---|
| Round Robin | Sequential distribution | Equal capacity servers |
| Weighted Round Robin | Proportional to weight | Mixed capacity |
| Least Connections | Fewest active connections | Long-lived connections |
| IP Hash | Hash of client IP | Sticky sessions |
| Consistent Hash | Hash ring | Distributed cache |
CAP Theorem
CP Systems: Consistent + Partition-tolerant (e.g., HBase, MongoDB with majority reads). AP Systems: Available + Partition-tolerant (e.g., Cassandra, DynamoDB). Most systems choose AP and optimize for consistency within the AP model.
PACELC Theorem
DfPACELC
Extension of CAP: In case of Partition, choose Availability or Consistency. Else (normal operation), choose Latency or Consistency. This captures the latency-consistency trade-off even when the network is healthy.
Message Queue Comparison
| Queue | Throughput | Ordering | Persistence |
|---|---|---|---|
| Kafka | Very high | Partition-level | Disk |
| RabbitMQ | High | Queue-level | Disk/Memory |
| SQS | High | Best-effort | Disk |
| Pulsar | Very high | Partition-level | Disk |
Common Patterns
| Pattern | Problem | Solution |
|---|---|---|
| Circuit Breaker | Cascade failures | Short-circuit on failure |
| Retry | Transient failures | Exponential backoff + jitter |
| Saga | Distributed transactions | Compensating transactions |
| Outbox | Dual write problem | Transactional event publishing |
| Sidecar | Cross-cutting concerns | Co-located helper container |
| Strangler Fig | Monolith migration | Incremental replacement |
| Back Pressure | Overload | Flow control signaling |
Interview Tips
- Clarify requirements before designing
- Start high-level, then deep-dive
- Make trade-offs explicit
- Use back-of-the-envelope for estimation
- Discuss failure modes and recovery
Practice Exercises
- Estimation: Estimate the QPS, storage, and bandwidth for a URL shortener with 100M URLs/month.
- Database: When would you choose Cassandra over PostgreSQL? Give specific use cases.
- Caching: Design a caching strategy for a social media feed with 1B daily reads.
- Patterns: Which patterns would you use for an e-commerce checkout flow?
Key Takeaways:
- Back-of-the-envelope estimation grounds design in reality
- Database selection depends on access patterns, not just data shape
- Caching patterns trade consistency for performance
- CAP/PACELC guide fundamental architecture decisions
- Patterns solve recurring problems: circuit breakers, sagas, outbox
What to Learn Next
-> System Design Interview Tips Ace your system design interview.
-> System Design Roadmap Learning path for system design.
-> CAP Theorem Consistency vs availability.
-> Load Balancing Distribution algorithms.
-> Caching Strategies Distributed caching.
-> Databases SQL vs NoSQL.