cheat sheet
Quick-scan numbers, prompt-to-pattern mappings, and every topic's one-line rule of thumb. Press ⌘K anytime to jump straight to a deep dive.
01 · numbers to know cold
Latency Ladder
- L1 / RAM
- 1 ns · 100 ns
- Redis (in-VPC)
- ~0.5 ms
- SSD random read
- ~0.1 ms
- Cross-AZ / DB query
- 1–10 ms
- Cross-region RTT
- 50–150 ms
Single-Box Caps
- App server
- 1K–10K RPS
- Postgres
- ~10K QPS · 64 TB
- Redis
- ~100K ops/s · RAM
- Kafka broker
- ~1M msg/s · GB/s
- S3 / Object
- ∞ storage · high BW
Fast Math Shortcuts
- 1 day
- ≈ 10⁵ sec (86,400)
- Daily → avg RPS
- chop 5 zeros
- Peak RPS
- 2–3× avg (10× flash)
- Bloom 1% FP
- ~10 bits / key
- Quorum
- W + R > N (2F+1)
02 · when the prompt says x → reach for y
building blocks
Estimation is not about 3 decimal places — it exists to answer one architectural question: does this fit on one box, or do I need caching, replicas, or sharding?
State your constraints first (QPS, sort order, 64 vs 128-bit, offline clients, public predictability) — the right pillar falls out automatically.
Pick Token Bucket when controlled bursts are desirable, Sliding Window Counter when strict rolling caps matter, and always run read-check-write atomically inside a Redis Lua script.
Consistent hashing solves topology churn (1/N remapping), virtual nodes solve key balance, and bounded-load or key salting solves viral hot keys.
Put a Bloom filter in RAM in front of an expensive lookup (disk SSTable, remote DB, or cache miss) whenever most queries ask for keys that do not exist.
storage
Read-heavy transactional OLTP defaults to B-Trees; write-heavy append/telemetry workloads default to LSM-Trees.
A cache is a latency and load-shedding layer, not a source of truth — always design for what happens the millisecond a hot key misses.
Strong consistency is never free: every extra replica you wait for on writes (W) or reads (R) buys freshness at the cost of tail latency and fault tolerance.
Choose a shard key with high cardinality and uniform access — then plan explicitly for the one celebrity key that breaks uniformity.
coordination
Almost every concurrency bug is TOCTOU (Time-of-Check to Time-of-Use): two actors act on state that changes in the gap between observing it and mutating it. Close the gap, or make the action safe when repeated.
Ask first: what breaks if two clients hold the lock at the same time? If the answer is money or data integrity, you need storage-enforced fencing tokens (or DB transactions), not just a Redis TTL.
Exactly-once network delivery does not exist. Build 'effectively-once' by pairing at-least-once retries with idempotent receivers and a transactional outbox.
Never run a 2-node consensus cluster, and do not use Raft for high-throughput bulk data — use it for the small, critical control plane (leases, shard maps, leader metadata).
messaging & traffic
Ask two questions first: do multiple independent services need the same event, and do you ever need to replay history? If yes, pick a partitioned log; otherwise a work queue is simpler.
Healthy distributed systems fail fast and route around gray failures. Never trust blind round-robin or unbounded retries when a downstream node slows down.
case studies
Never trust an async Bloom filter alone for uniqueness — use DynamoDB's conditional put (attribute_not_exists) as the true guard.
Shard Redis counters by rule_id:entity_id (never rule_id alone) so a single high-traffic global rule never melts one shard.
Never dual-write Postgres and RabbitMQ — commit the job row in Postgres first and stream it via CDC/outbox, then enforce optimistic locking on status transitions.
Never refresh an alert's dedup TTL on every firing tick — you will silence a 6-hour outage forever. Use explicit state transitions (FIRING → RESOLVED) plus fixed-TTL cooldowns.
Key the WebSocket routing table by user_id (holding a map of active devices), never by group_id:user_id — otherwise every reconnect rewrites dozens of group keys and breaks multi-device.
Never trust a Redis SETNX lock alone for financial seat ownership — enforce final uniqueness with a conditional DB write and wire an automated Refund path for late payments.
Scope the lock key strictly to the contested resource (driver:{id}:lock) with ride_id as the VALUE — never put ride_id in the key, or two rides can lock the same driver simultaneously.
Pure push stalls on 50M-follower celebrities; pure pull is too slow when you follow 1,000 normal accounts. Hybrid fan-out gives O(1) reads without celebrity write amplification.
Never generate unique per-user presigned URLs for every 4-second video chunk — unique query strings destroy CDN cache hit rates. Use static CDN URLs (or CDN Signed Cookies for paid/private streams).
Never traverse a distributed Trie over the network per keystroke, and never rebuild the Trie from Redis — Redis only holds top-5 per prefix, so keep the full long-tail snapshot in S3.
In financial systems, never DELETE or overwrite ledger rows, never rely on webhooks alone without a reconciliation poller, and never trust an eventually consistent OLAP store as your source of truth.
Never put Vault, Postgres, or ClickHouse synchronously on the LLM hot path — cache keys and policies in RAM, rate-limit by tokens rather than RPS, and emit billing events only after the stream closes.
Treat every agent sandbox as hostile and disposable — never share the host kernel, never write raw secrets to VM disk, and let an external orchestrator (Temporal) own retry state.
Never execute production mutations directly from a Slack webhook or hold worker threads open waiting for humans — park in Temporal on a Signal + TTL timer, lock approval in Postgres, and compensate via Saga on failure.