Scaling writes
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Scaling writes: the 60-second story

    Scaling writes

    Assume 500,000 delivery partners ping every 4 seconds. Can one database keep up?

    That’s 125,000 writes a second at about 100 bytes, only 12.5 MB/s. Bandwidth is easy; the write count is the problem.

    Signals that you’re scaling writes

    1. “Ingest N events a second” from a fleet
    2. Append-mostly data, rarely read row by row
    3. Bursts tied to a moment: a midnight sale
    4. Counters on popular things: likes and views

    Climb the ladder. Stop at the first rung that fits.

    Cheaper writes, batches, a log for bursts, a key that spreads, LSM storage, hot-key tricks, writing less. Each costs latency, durability or read cost.

    125,000 writes a second. Add read replicas?

    Bad: More replicas

    Every replica replays every write. They add no write capacity.

    Good: Batch, log, partition

    Cheaper writes, bigger transactions, a log for bursts, then shards.

    10×

    throughput from 100-row batches

    Every transaction pays a fixed cost. Assume 50 µs a commit plus 5 µs a row, and one node goes from 18,000 rows a second to about 182,000.

    A burst becomes backlog, not an outage

    A city reconnects, 275,000 pings a second for 20 s. Kafka holds a 2.3-million backlog, and writers drain it with up to 14 s of lag.

    You shard pings by time bucket. Eight shards, and seven sit idle.

    The trick

    Hash a high-cardinality key like partner ID. Each shard gets an even share, and each partner’s pings stay in order.

    One hot row is a queue of lock waits

    8,000 partners in one zone send 2,000 pings a second, but one locked row manages about 200 updates. Sum in memory and flush each second instead.

    Say it like this

    Make each write cheap, batch, put a log in front for bursts, partition by a key that spreads, then defuse hot keys and write less. Name what each rung can lose.