SDE & MLE Prep

Scaling Writes

When: high ingest (metrics, clicks, location updates, logs, likes).

  • Shard / partition by a key with high cardinality and even load; avoid monotonically increasing keys on range-partitioned stores (all writes hit the last shard) — hash them or prefix with a bucket.
  • Batch & buffer: accumulate in memory or a queue and write in bulk; Kafka absorbs bursts and decouples producers from the database.
  • Write-optimized storage: LSM-tree stores (Cassandra, RocksDB, ScyllaDB) turn random writes into sequential ones; time-series DBs compress heavily.
  • Pre-aggregate: don't store every like as a row you count later — increment counters (sharded counters for hot ones: likes:post42:{0..15}, sum on read) or aggregate in a stream processor.
  • Drop what you don't need: ephemeral data (driver location every 4 s) can live only in memory with the latest value; sample high-volume analytics.
  • Backpressure: when consumers fall behind, queues grow — monitor lag, autoscale consumers, shed low-priority work.