System Design Cheatsheets

Quick-reference sheets for architecture and system design work. Bookmark this page.


CAP Theorem

         ┌───────────────┐
         │  CAP Theorem  │
         └───────┬───────┘
     Consistency ◄──────► Availability
              (pick1)
System TypeGuarantees
CA (theoretical)Consistent + Available — cannot exist in distributed systems
CPConsistent + Partition-tolerant — blocks on partition
APAvailable + Partition-tolerant — returns stale data

Practical rule: Network partitions WILL happen. Choose CP or AP per use case:

  • CP: Zookeeper, etcd, HBase, MongoDB
  • AP: Cassandra, DynamoDB, CouchDB

Latency Numbers (Must-Know)

OperationLatency
L1 cache reference0.5 ns
L2 cache reference7 ns
Memory access100 ns
Read1 MB from memory250 µs
Read 1 MB from SSD1 ms
Round trip within same DC0.5 ms
Read 1 MB from disk20 ms
Send packet: SF → NYC40 ms

Rule: Latency is6 orders of magnitude from L1 cache to cross-DC round trip. Design accordingly.


HTTP Status Codes

CodeMeaning
200OK
201Created
204No Content
301Moved Permanently
302Found (redirect)
400Bad Request
401Unauthorized
403Forbidden
404Not Found
409Conflict
429Too Many Requests
500Internal Server Error
502Bad Gateway
503Service Unavailable
504Gateway Timeout

SQL vs NoSQL

DimensionSQL (RDBMS)NoSQL
Data modelRelationalKey-value, Document, Column, Graph
SchemaFixed (DML migration)Schema-less (flexible)
TransactionsACIDEventually consistent
ScalingVerticalHorizontal
JoinsYesNo (denormalize)
ExamplesPostgreSQL, MySQLDynamoDB, MongoDB, Cassandra

Load Balancing Algorithms

AlgorithmHowBest For
Round RobinCycle through listHomogeneous backends
Weighted RRAssign weightsDifferent capacity nodes
Least ConnectionsFewest active connectionsVariable request duration
IP HashHash client IP → backendSession affinity (legacy)
RandomRandom selectionSimple, stateless

Caching Patterns

PatternDescriptionUse When
Cache-AsideApp manages read/writeRead-heavy, single app
Write-ThroughWrite to cache + DB simultaneouslyRead-heavy, need consistency
Write-BehindWrite to cache, async DB flushWrite-heavy, can tolerate loss
Refresh-AheadProactively refresh expiring entriesPredictable hot data

Data Replication Models

ModelWritesReadsConsistency
Single-leader→ primary← any replicaEventual (async)
Multi-leader→ any primary← any primaryEventual
Leaderless→ quorum (W+R>N)← quorumTunable (strong/eventual)

Message Queue Patterns

PatternDescriptionExample
Point-to-PointOne consumer per messageSQS, RabbitMQ queue
Pub/SubFan-out to multiple consumersSNS, Kafka (consumer groups)
Dead Letter QueueFailed messages for retry/reviewSQS DLQ, RabbitMQ x-delayed-message

Security Checklist

□ TLS everywhere (in-transit encryption)
□ mTLS for service-to-service
□ Secrets in vault (not env vars in code)
□ RBAC (least privilege)
□ Input validation + sanitization
□ Rate limiting (DoS protection)
□ Audit logging (who did what, when)
□ Encryption at rest (AES-256)

Source