Web & Dev

System Design Patterns

Distributed system patterns — load balancing, caching, queues, replication, sharding.

Scaling

PatternWhat it does
Load balancerDistributes traffic across replicas (round-robin, least-conn, consistent-hash)
Horizontal scalingAdd more machines
Vertical scalingBigger machine
ShardingPartition data by key across shards
ReplicationKeep copies for read scale / failover
Read replicasScale reads; writes go to primary
CDNCache static assets geographically near users
Service meshSidecar proxies for routing, retries, mTLS

Caching

PatternNotes
Cache-asideApp reads cache first, falls back to DB
Write-throughWrite to cache and DB together
Write-behindWrite to cache now, flush async to DB
Read-throughCache transparently fetches on miss
TTL / stale-while-revalidateServe stale briefly while refreshing
Cache invalidationHardest problem — prefer event-driven eviction

Async / messaging

PatternNotes
Message queueBuffer producer/consumer; retry on failure
Pub/subFan-out to multiple subscribers
Event sourcingStore event log; replay to reconstruct state
CQRSSeparate read model from write model
SagaLong-running multi-service transaction with compensations
Outbox patternAtomically write to DB + outbox; relay publishes

Resilience

PatternNotes
Circuit breakerStop calling a failing dependency to let it recover
BulkheadIsolate resources — one failure doesn't drown others
Timeout + retry + backoffNever retry without limits; use exponential backoff with jitter
Rate limitingProtect from overload (token bucket, leaky bucket)
Graceful degradationServe reduced functionality when dependencies fail
Idempotency keysAllow safe retries without double-effects
Was this article helpful?