Read-Heavy vs Write-Heavy Systems
How the read-to-write ratio decides your architecture: caches, replicas and CDNs for reads; queues, batching, LSM-tree storage and sharding for writes.
Every system reads data and writes data, but rarely in equal amounts. The ratio between the two is one of the most useful facts you can know about a system, because the techniques that make reads fast are different from the techniques that make writes fast.
A cache, for example, speeds up reads. Adding a cache to a logging system that receives hundreds of thousands of writes per second and is rarely read solves nothing. These notes explain how to classify a workload and which tools belong to each side.
What the terms mean
A system is read-heavy when read operations far outnumber writes. A social post is written once and read by thousands of people. A product page is updated a few times a day and viewed millions of times. Ratios of 100 to 1 or even 1000 to 1 are common.
A system is write-heavy when it ingests data much more often than it serves it. A fitness band records a measurement every second, but the user looks at a summary once a day. Application logs, metrics, click streams, chat messages and vehicle location updates are all write-heavy.
The ratio is found during requirement gathering by asking how often each main operation happens, and it is confirmed during estimation by calculating reads per second and writes per second separately.
Tools for read-heavy systems
The goal on the read side is to avoid doing the same expensive work repeatedly and to serve data from somewhere closer and cheaper than the primary database.
- Cache: keep frequently requested data in memory (for example Redis or Memcached). A cache hit avoids the database entirely.
- Read replicas: copies of the database that serve only read queries. Writes go to the primary; reads are spread across replicas.
- CDN: images, videos and static files are served from edge servers near the user instead of from your origin.
- Denormalisation and precomputation: store data in the shape the read needs (for example a precomputed feed), so that reading is a simple lookup instead of a join.
- Indexes: speed up queries, at the cost of slower writes because every index must be updated.
Tools for write-heavy systems
The goal on the write side is to accept data quickly and durably, smooth out bursts, and spread the load over many machines.
- Message queue: producers append to a queue such as Kafka and return immediately; consumers write to storage at a steady pace. The queue acts as a buffer during spikes.
- Batching: one write of a thousand rows is far cheaper than a thousand writes of one row, because the per-request overhead (network round trip, transaction, disk flush) is paid once.
- Write-optimised storage: databases built on LSM trees, such as Cassandra, turn random writes into sequential appends.
- Sharding: split the data over many machines so that write throughput grows with the number of shards.
- Fewer indexes and asynchronous secondary work: do the minimum in the write path and derive everything else later.
Why LSM trees suit writes and B-trees suit reads
Most relational databases store data in B-trees. A B-tree keeps rows sorted on disk in pages. Reads are efficient because a lookup walks a few levels of the tree. A write, however, must find the right page and modify it in place, which means random disk I/O and occasional page splits.
An LSM tree (log-structured merge tree) takes the opposite approach. A write is appended to a log for durability and inserted into an in-memory sorted table. When that table fills, it is flushed to disk as an immutable sorted file. Background compaction merges those files. Writes are therefore sequential and very fast. Reads may need to check several files, so they are somewhat slower, and Bloom filters are used to skip files that cannot contain the key.
The practical rule: B-tree engines favour read-heavy and transactional workloads, LSM-tree engines favour write-heavy workloads.
Why a cache does not help a write-heavy system
A cache is useful when the same data is read many times between changes. In a write-heavy system the data changes constantly, so each cached value is invalidated almost as soon as it is stored. The hit rate is low, and you have added a component that must be kept consistent with the database. The benefit is small and the complexity is real.
The correct first move for a write-heavy system is a buffer in front of the storage, not a cache in front of the reads.
Most real systems are both
Workload classification applies to each component, not to the product as a whole. A chat application has a write-heavy message path, but profile photos are read-heavy. An e-commerce site has a read-heavy catalogue and a write-heavy order and inventory path during a sale. A video platform is read-heavy for playback and write-heavy for view-count events.
A strong design therefore treats each data type separately and may use a different storage system for each one.
Component Reads vs writes Main techniques --------------------------------------------------------------------------- Product catalogue read-heavy cache, read replicas, CDN Product images read-heavy object storage + CDN Orders balanced, critical SQL with transactions Click / view events write-heavy queue, batching, LSM store Search suggestions read-heavy precomputed index, cache Driver locations write-heavy in-memory store, TTL, sharding
Interview summary
- Ask for the read-to-write ratio during requirements, and confirm it in estimation.
- Read-heavy: cache, read replicas, CDN, precomputed views.
- Write-heavy: queue as a buffer, batching, write-optimised storage, sharding.
- Choose the database by access pattern: B-tree engines for reads and transactions, LSM engines for heavy writes.
- Classify each component separately; most systems contain both kinds.
Summary
The read-to-write ratio tells you where the load is, and the load decides the architecture. Read-heavy data is served from caches, replicas and CDNs. Write-heavy data is buffered in queues, batched, stored in write-optimised engines and sharded. Apply the classification per component, because one product usually contains both workloads.
Puneet Tiwari
Full Stack Developer
