System Design Cheat Sheet -
| Problem | Key pattern | |---------|--------------| | URL shortener | Base62 encoding, write-heavy DB, cache for redirects | | Chat system | WebSocket + message queue, offline storage, presence tracking | | Social feed | Fanout on write (for small audiences) / read (for large) | | Rate limiter | Token bucket / sliding window (in-memory + Redis) | | Distributed ID generator | Snowflake, UUIDv7, DB sequence with segments | | Payment system | Idempotency keys, 2PC / Saga, idempotent consumers | | Leaderboard | Redis sorted sets, sharded with approximate ranking |
| Workload | Recommendation | Rationale | |----------|---------------|-----------| | Strong ACID, complex joins | PostgreSQL, MySQL (RDBMS) | Transactions, referential integrity | | High write throughput, simple lookups | Cassandra, DynamoDB | Partitioned wide-column | | Flexible schema, rapid iteration | MongoDB, Couchbase | Document store | | Search | Elasticsearch | Inverted indexes, full-text | | Real-time analytics | ClickHouse, Druid | Columnar storage | | Graph relationships | Neo4j, ArangoDB | Graph traversal | system design cheat sheet
Start with relational. Scale with read replicas → cache → sharding → NoSQL when needed. | Problem | Key pattern | |---------|--------------| |
Stale data, thundering herd, cache stampede. at-least-once vs exactly-once
Ordering, at-least-once vs exactly-once, dead-letter queues, backpressure.