Sequential Versus Random I/O
Sequential I/O streams contiguous blocks at device bandwidth; random I/O seeks between locations and pays per-access latency — an order-of-magnitude gap on disks, narrower but real on SSDs.
Definition
Access pattern determines storage throughput. Sequential access reads contiguous addresses, amortizing mechanical seek and rotational latency — or on SSDs, benefiting from larger read units and prefetching. Random access jumps between addresses, paying per-operation latency and command overhead. The performance ratio historically reached 100x on HDDs and remains several-fold on NVMe for small random operations versus sequential streaming.
Context and scope
Drives database index versus table scan decisions, LSM-tree versus B-tree write amplification, log-structured storage, and defragmentation rationale.
Common misconceptions
- SSDs make access pattern irrelevant — SSDs remove seeks, but small random operations still pay per-command overhead and queue depth; sequential remains faster
- Databases prefer index lookups always — for large range fractions, a sequential table scan beats thousands of random index seeks
- Random writes are unavoidable in databases — LSM trees and clustered layouts convert random writes into sequential ones, at read cost
Anti-patterns
- Building UUID-keyed indexes that scatter all inserts randomly across the tablespace
- Reading files with tiny unbuffered reads at random offsets and blaming the disk for latency
- Tuning filesystem readahead for random workloads and prefetching data that is never used
Related concepts
Authoritative source
What it is
Storage delivers bytes either by streaming through adjacent blocks or by jumping between them. The mechanics — seek time on HDDs, command and flash-page overhead on SSDs — price the two patterns very differently.
How it works
HDDs pay milliseconds per seek, making locality everything. SSDs have no heads, but each operation carries submission overhead, and flash erase-block semantics reward clustered writes and larger transfer units. Queue depth partially hides per-op latency on SSDs: many parallel random operations approach sequential bandwidth.
When to design around it
Key ordering for write-heavy tables, index choice versus scan for analytical queries, file layout for logs versus records, and readahead tuning for sequential consumers. Convert random to sequential with buffering, batching, and log-structured writes when throughput dominates.
Pitfalls
High queue depth narrows the gap but stresses device CPU and latency tails. Fragmentation creeps: files that were sequential become scattered, halving throughput without any code change. Measuring with synthetic single-threaded benchmarks misrepresents the parallel reality production sees.