๐ Scaling Writes While Designing Systems
Most engineers donโt know how to scale writes, because writing everything to one single database instance may have worked for your small company but wonโt cut it in a big-tech interview.
Here are the ๐ฐ ๐๐๐ฟ๐ฎ๐๐ฒ๐ด๐ถ๐ฒ๐ one ๐ป๐ฒ๐ฒ๐ฑ ๐๐ผ ๐ธ๐ป๐ผ๐ ๐๐ผ ๐๐ฐ๐ฎ๐น๐ฒ ๐๐ฟ๐ถ๐๐ฒ๐ ๐ถ๐ป ๐ฎ๐ป ๐ถ๐ป๐๐ฒ๐ฟ๐๐ถ๐ฒ๐:
1๏ธโฃ ๐ฉ๐ฒ๐ฟ๐๐ถ๐ฐ๐ฎ๐น ๐ฆ๐ฐ๐ฎ๐น๐ถ๐ป๐ด & ๐๐ฎ๐๐ฎ๐ฏ๐ฎ๐๐ฒ ๐๐ต๐ผ๐ถ๐ฐ๐ฒ๐
Youโre probably underestimating modern hardware. Bigger machines โ 200 cores, 10Gb NICs, SSDs โ can push write limits further than most expect. Consider write-optimized databases like Cassandra, time-series stores, or column databases also improve throughput, though usually at the cost of slower reads.
2๏ธโฃ ๐ฆ๐ต๐ฎ๐ฟ๐ฑ๐ถ๐ป๐ด & ๐ฃ๐ฎ๐ฟ๐๐ถ๐๐ถ๐ผ๐ป๐ถ๐ป๐ด
Spread the load. Hashing on userId or postId spreads writes evenly across shards. Vertical partitioning separates โpost contentโ from โpost metrics,โ so counters update without blocking core content. In interviews, always explain your partition key choice as balanced distribution is key.
3๏ธโฃ ๐ค๐๐ฒ๐๐ฒ๐ & ๐๐ผ๐ฎ๐ฑ ๐ฆ๐ต๐ฒ๐ฑ๐ฑ๐ถ๐ป๐ด
When you can afford it, queues like Kafka or SQS absorb bursts so databases process writes steadily, but they mask issues if overload is constant. Load shedding drops lower-value writes, such as redundant location updates, to preserve critical ones.
4๏ธโฃ ๐๐ฎ๐๐ฐ๐ต๐ถ๐ป๐ด & ๐๐ถ๐ฒ๐ฟ๐ฎ๐ฟ๐ฐ๐ต๐ถ๐ฐ๐ฎ๐น ๐๐ด๐ด๐ฟ๐ฒ๐ด๐ฎ๐๐ถ๐ผ๐ป
Things work better in chunks. Batching collapses many writes into fewer operations, like turning 100 likes into one counter update. Hierarchical aggregation reduces volume further by processing locally before sending upstream. Both approaches ensure no single component is overwhelmed.
๐ก ๐๐ป๐๐ฒ๐ฟ๐๐ถ๐ฒ๐ ๐๐ถ๐ฝ: Donโt just say โshard the DB.โ Show the tradeoffs: โFor posts, Iโd shard by userId to spread writes evenly. For engagement metrics, Iโd batch and aggregate to reduce DB pressure.โ
๐ ๐ฅ๐๐น๐ฒ ๐ผ๐ณ ๐๐ต๐๐บ๐ฏ:
- Exhaust hardware + DB tuning first
- Shard for steady load
- Queue or shed for bursts
- Batch & aggregate for extremes
Creator