System Design Basics
Scaling, caching, queues, CAP, sharding, common interview building blocks.
system-designarchitecture
# System Design Basics ## Scale up vs out - **Vertical** (bigger box): simple, limited, single point of failure. - **Horizontal** (more boxes): requires stateless services + load balancer + shared state. ## Load balancing - L4 (TCP) vs L7 (HTTP, content-aware routing). - Algorithms: round-robin, least connections, consistent hashing (for sticky cache nodes). ## Caching layers - Client (browser, ETag, Cache-Control) - CDN (static + edge cache) - Reverse proxy (Varnish, Nginx) - Application (Redis/Memcached) - DB query cache Patterns: cache-aside, write-through, write-back. ## Database scaling - **Read replicas**: scale reads, eventual consistency. - **Sharding**: by user ID hash, range, or geo. Resharding is hard -> use consistent hashing. - **CQRS**: separate read model from write model. ## Async via queues - Smooth bursty traffic, decouple producers/consumers. - At-least-once delivery is the norm -> consumers must be idempotent. - Kafka (log, replayable, partitioned), RabbitMQ (smart broker), SQS (managed). ## CAP / PACELC In a partition you pick Consistency or Availability. Even without partition you trade Latency vs Consistency. - CP: HBase, ZooKeeper, etcd - AP: Cassandra, DynamoDB (tunable), Couchbase ## Consistency models Strong > Linearizable > Sequential > Causal > Read-your-writes > Eventual. ## Availability math - 99.9% -> 8.76h/year downtime - 99.99% -> 52.6m/year - Each "nine" ~10x harder. ## Building blocks checklist LB | API GW | Auth | App tier | Cache | DB primary+replicas | Queue | Object storage | CDN | Search index | Metrics/logs/traces
API: /api/skills/system-design-basics