SYSTEM DESIGN QUICK REFERENCE
beingsde.in — Built for Staff+ Engineering Interviews
1. Database Selection Matrix
| Data Type | Database | Why |
|---|---|---|
| Transactions / Ledger | PostgreSQL | ACID, WAL, JOINs |
| User Profiles | MongoDB | Flexible JSON schema |
| Logs / Metrics | Cassandra | High write throughput, LSM |
| Real-time Analytics | Apache Druid | Columnar, sub-second aggs |
| Search / Catalog | Elasticsearch | Inverted index, fuzzy search |
| Sessions / Cache | Redis | In-memory, sub-ms reads |
2. CAP Theorem
- C — Consistency: Every read returns the most recent write or an error.
- A — Availability: Every request receives a (possibly stale) response.
- P — Partition Tolerance: System continues operating despite network splits.
- → Distributed systems must choose CA, CP, or AP during a network partition.
CP Systems
PostgreSQL, Spanner, HBase
AP Systems
DynamoDB, Cassandra, CouchDB
CA Systems
Single-node RDBMS (no partition)
3. Scaling Decision Rules
- ✓ Vertical first — Add CPU/RAM until hardware limits or cost spikes.
- ✓ Horizontal — When write volume exceeds single-node capacity.
- ✓ Read replicas — When reads >> writes (e.g., 90/10 ratio).
- ✓ Caching — For repeated, slow queries with <1% write rate.
- ✓ Sharding — When storage or write throughput hits single-DB ceiling.
- ✓ CDN — For static assets; eliminates origin server load entirely.
4. Sharding vs Partitioning vs Indexing
| Strategy | Scope | Goal |
|---|---|---|
| Indexing | Single table | Faster reads |
| Partitioning | Single DB instance | Manage table layout |
| Sharding | Multiple DB nodes | Scale write throughput |
5. Auth Mechanisms
| Method | State | Revocable | Use Case |
|---|---|---|---|
| Sessions (Redis) | Stateful | ✓ Yes | Web apps, high security |
| JWT | Stateless | ✗ Hard | APIs, microservices |
| OAuth 2.0 | Delegated | ✓ Yes | SSO, 3rd-party access |
💡 Pattern: API Gateway validates JWT/session, then passes X-User-ID headers downstream.
6. Consistent Hashing
- • Hash ring spans 0 → 2³² − 1. Servers and keys map onto the ring.
- • Key routes clockwise to nearest server on the ring.
- • Adding/removing a node only moves 1/N keys (vs. 100% in modulo hashing).
- • Virtual nodes (100–200 per server) prevent hotspots and ensure even distribution.
- Used in: Cassandra, Dynamo, Memcached, Discord gateway.
7. Rate Limiting Algorithms
| Algorithm | Burst? | Memory |
|---|---|---|
| Token Bucket | ✓ Yes | Low |
| Sliding Window Log | ✗ No | High (stores timestamps) |
| Sliding Window Counter | ~ Partial | Low (approximation) |
💡 Use Lua scripts in Redis for atomic rate-limit evaluation across distributed gateways.
8. WebSocket Scaling
- • Increase Linux file descriptor limit (
nofile) to ~1M. - • Use Layer 4 load balancing (HAProxy) with sticky sessions.
- • Use Redis Pub/Sub backplane for cross-server message routing.
- • Pattern: Client → L4 LB → WS Server ↔ Redis Pub/Sub → WS Server → Client
9. Kafka Key Rules
- • Same partition key → same partition → strict ordering within partition only.
- • Max consumers in a group = number of partitions.
- • At-least-once delivery requires idempotent consumers.
- • Consumer group lag = key metric for scaling consumer count.
10. Snowflake ID Layout (64-bit)
1b Sign|41b Timestamp (ms)|5b Datacenter|5b Worker|12b Sequence
- • Time-sortable, no central coordinator needed.
- • Up to 4,096 unique IDs per millisecond per machine.
beingsde.in — System Design Cheat Sheet — Use alongside full topic guides at beingsde.in/topics