Replication
Reach for replication as the cheapest read-scaling lever, pick the right topology (single-leader, multi-leader, leaderless) for the consistency and geography required, and fix lag-induced bugs with session guarantees.
Read Scaling with Replicas
Single-leader replication scales reads linearly but never writes; pick async/sync/semi-sync by durability vs latency, watch lag, and shard only when writes outgrow one leader.
Replication Topologies & Consistency
Single-leader avoids conflicts, multi-leader buys local writes at the cost of write-write conflicts, leaderless uses R+W>N quorums; resolve conflicts losslessly and reason with PACELC.
Replication Lag & Session Guarantees
Map each lag-induced bug to its session guarantee and fix it with sticky routing or version tokens, instead of over-promising linearizability.
Partitioning & Sharding
Split a dataset or write rate past one machine: pick a partition strategy that survives skew, rebalance with consistent hashing, choose shard keys that dodge the celebrity problem, and design correct cross-shard operations.
Partitioning Strategies: Range vs Hash vs Directory
Range wins range scans but hotspots on sequential keys, hash spreads evenly but loses ranges, directory adds a flexible routing hop; map every dominant query to its partitions.
Consistent Hashing, Virtual Nodes & Rebalancing
Hash mod N remaps nearly everything on resize; a ring with virtual nodes moves only ~1/N of keys, smooths load, and spreads rebalancing across many neighbors.
Shard-Key Selection, Hotspots & the Celebrity Problem
A good shard key is high-cardinality, evenly accessed, and query-aligned; a celebrity is one key on one node, so split the key, dedicate shards, or change the read pattern.
Cross-Shard Operations & Distributed Transactions
Avoid 2PC on the hot path (locks, blocks on coordinator failure); use sagas of local transactions with compensations, idempotency keys, and the outbox pattern.
Caching at Scale
Put a cache in front of a database and defend every part: the right write policy and invalidation story, stampede and hot-key protection, and a shared cache tier that survives node failures at a million ops/sec.
Caching Patterns & Write Policies
Default to cache-aside reads plus invalidate-on-write, pick the write policy by its durability/latency trade, and always state the TTL and consistency window.
Cache Stampede, Thundering Herd & Hot Keys
Layer the defenses: singleflight coalescing with a distributed lock, jittered TTLs and probabilistic early refresh, plus L1 caches and key replication for genuinely hot keys.
Distributed Cache Architecture
Shard by hash slots, replicate each shard with failover, tier L1-near plus L2-remote, treat the cache as disposable, and never bring a cold cache online under load.
CDN, Search & Geo
Push bytes to the edge behind a multi-tier CDN, stand up a search tier on an inverted index kept in sync via CDC, extend it with vector and hybrid retrieval, and index millions of points on a sphere without hot-spotting.
CDN & Edge Caching at Scale
An L1/L2/origin-shield hierarchy coalesces misses to ~1 fetch per object; version URLs instead of purging, normalize cache keys, and never cache authenticated bodies.
Full-Text Search & the Inverted Index
A dedicated search tier: inverted index plus analysis pipeline, BM25 with boosting, cached filters, shards and replicas, CDC-fed eventual consistency, search_after pagination.
Vector, Semantic & Hybrid Search
Embeddings plus ANN give semantic recall, BM25 catches exact tokens; fuse by rank with RRF, rerank the top-k with a cross-encoder, and plan re-embedding migrations.
Geospatial Indexing: Geohash, Quadtree, S2 & H3
Encode points into cell keys (geohash/S2/H3) so 2D proximity becomes an indexable range query, ring-query neighbors, tune cell size to radius, and defuse hot cells.
Derived Data & Sync
Trade write cost for cheap reads with denormalization, precomputation, and hybrid feed fan-out, and keep every derived store from drifting by replacing dual writes with the transactional outbox and log-based CDC.
Denormalization, Precomputation & Materialized Views
Precompute rollups and sketches so reads are O(1) lookups, and feed timelines with hybrid fan-out: push for normal users, pull-and-merge for celebrities.
Keeping Derived Stores in Sync (CDC & Outbox)
Never dual-write to a DB and a derived store: use the transactional outbox or log-based CDC through Kafka, with at-least-once delivery and idempotent, versioned consumers.