Data at Scale — Storage Choices, Search, Blobs, CDNs & Multi-Region
A decision guide for picking data stores, replication and sharding in practice (resharding, hot partitions, cross-shard queries), full-text search with inverted indexes, object storage and large uploads, CDNs, data pipelines and CDC, and multi-region active-passive vs active-active designs.
A decision guide for storage
Replication and sharding in practice
Recap of the theory in DBMS: distributed data; here are the practical concerns.
| Problem | Solutions |
|---|---|
| Choosing a shard key | high cardinality, even distribution, matches the dominant query (user_id, tenant_id) |
| Hot partition (celebrity, viral item) | key salting (key#0..9) and scatter-gather reads, dedicated shards for big tenants, caching |
| Cross-shard queries | denormalise, global secondary indexes, scatter-gather with limits, or a separate analytics store |
| Cross-shard transactions | avoid by co-locating related data (same shard key); otherwise sagas or a distributed SQL DB |
| Resharding | many logical shards → few physical; online migration via CDC/dual write + backfill + verify + cutover |
| Global uniqueness | Snowflake IDs, UUIDv7, or a uniqueness table keyed by the unique value |
| Replication lag | read-your-writes routing, monotonic reads (sticky replica), lag-aware load balancing |
Zero-downtime migration recipe
- Dual-write (or CDC stream) to old and new stores.
- Backfill history in batches (idempotent upserts).
- Verify: row counts, checksums, shadow reads comparing results.
- Gradually move reads (feature flag, 1% → 100%).
- Stop writes to old store; keep it for rollback; finally decommission.
Search
Architecture: DB → CDC → Kafka → indexer → Elasticsearch (sharded, replicated) ← search API. Reindex for mapping changes into a new index and atomically swap an alias. Typeahead uses prefix structures (edge n-grams, tries, completion suggesters) — see the typeahead case study.
Object storage and uploads
Object storage facts: 11 nines durability (S3), flat key namespace, strong read-after-write consistency on S3, storage classes (standard → infrequent access → archive), lifecycle rules, versioning, cross-region replication.
CDNs
| Concept | Detail |
|---|---|
| Push vs pull | pull (origin fetched on miss) is the default; push for large pre-known assets |
| Cache keys | URL + selected headers/cookies; avoid variance explosion |
| Invalidation | versioned/fingerprinted URLs (app.3f9a.js) beat purges |
| Origin shield | an extra tier so a miss storm hits the origin once |
| Dynamic acceleration | TLS termination near users + persistent connections to origin |
| Edge compute | Workers/Lambda@Edge for auth, A/B, personalisation |
| Signed URLs/cookies | protect paid or private content |
Data pipelines
Lambda architecture = batch layer (accurate, slow) + speed layer (approximate, fast). Kappa = one streaming pipeline, replay the log to recompute. Modern lakehouses (Iceberg/Delta/Hudi tables on S3) add ACID and time travel to the lake.
Multi-region
| Strategy | RPO | RTO | Complexity |
|---|---|---|---|
| Backup & restore | hours | hours | low |
| Pilot light | minutes | tens of minutes | medium |
| Warm standby (active-passive) | seconds–minutes | minutes | medium |
| Active-active | ~0 | ~0 | high |
Interview questions
Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.