Skip to content

Storage Fundamentals: Memory, Disk, Block, File and Object

Basic 40 min read Part 5 of 18

The memory and storage hierarchy, HDD vs SSD, block vs file vs object storage, when each fits, durability vs availability, and RAID in brief.

Summary#

Data lives on a ladder of storage: CPU caches and RAM are fast but small and lost on power-off; SSDs and HDDs are slower but keep data permanently. Each step down is roughly 100 to 1,000 times slower and much cheaper per GB. On top of disks, systems expose three storage models: block (raw disk volumes for databases and VMs), file (folders and files shared over a network) and object (whole files stored by key over HTTP, as in Amazon S3). Durability means data is never lost; availability means you can reach it right now. They are different promises. RAID combines several disks for speed or redundancy.

Why It Exists#

Every design choice about databases, caches and file uploads depends on where data physically sits. Reading from RAM takes about 100 nanoseconds; a random read from a spinning disk takes about 10 milliseconds, 100,000 times longer. Picking the wrong storage tier or model makes a system slow, expensive or fragile. This page builds on Numbers to Know.

How It Works#

The memory and storage hierarchy#

TierTypical latencyThroughputPersistent?Relative cost per GB
RAM~100 nsTens of GB/sNoHighest
NVMe SSD~100 µs random read~2-7 GB/sYesMedium
SATA SSD~100-200 µs~500 MB/sYesMedium
HDD~5-10 ms per random seek~100-250 MB/s sequentialYesLow
Object storage (S3)~10-100 ms first byteHigh in aggregateYesLow; archive tiers lower

The pattern: the closer to the CPU, the faster, smaller and more expensive. Caches exist to keep hot data in a higher tier.

The hierarchy in depth#

Each level, closer up.

  • Registers sit inside the CPU core and are read in a fraction of a nanosecond, but there are only a few dozen of them.
  • L1 cache is per core, typically 32 to 64 KB each for data and instructions, with about 1 ns latency (a few CPU cycles).
  • L2 cache is per core, usually a few hundred KB to a couple of MB, at about 3 to 5 ns.
  • L3 cache is shared by all cores on a chip, often tens of MB, at about 10 to 40 ns.
  • Main memory (DRAM) is gigabytes to terabytes per server, at about 80 to 120 ns. It is volatile: the data is held in tiny capacitors that must be refreshed constantly and vanish when power is cut.
  • SSDs keep data without power in flash memory, at roughly 20 to 100 microseconds for a random read on NVMe.
  • Spinning disks take milliseconds.
  • Remote storage adds a network round trip on top: about 0.5 ms within a data centre, and 50 to 150 ms between continents.

A human-scale version. Stretching time so that one nanosecond becomes one second makes the gaps easier to feel. An L1 hit takes a second, about as long as glancing at a note. A RAM read takes around a minute and a half. A random NVMe SSD read takes about a day. A random HDD seek takes about four months. A request to another continent takes four to five years. Most performance problems in systems come from accidentally doing the "four months" thing in a loop that runs thousands of times.

Caches work because of locality. Two patterns make a small, fast tier useful in front of a big, slow one:

  • Temporal locality: data used recently is likely to be used again soon, so keeping it close pays off.
  • Spatial locality: data near what you just used is likely to be used next, so fetching a neighbourhood at once pays off.

Hardware exploits spatial locality by moving data in units, never single bytes: 64-byte cache lines between RAM and CPU caches, and 4 KB pages (or larger) between disk and RAM. Reading one byte costs the whole unit, and reading the rest of that unit is almost free. This is why arrays scan far faster than linked lists, why databases store rows in pages, and why columnar formats are so fast for analytics: a scan touches only the columns it needs, packed tightly together.

Skew makes caching even better. In most real workloads, a small share of the data gets most of the traffic. Popularity often follows a Zipf-like curve, where the most popular item is accessed about twice as often as the second, three times as often as the third, and so on. So a cache holding the hottest 1% of items can often serve well over half of all reads. The hierarchy is not just "fast and small versus slow and large". It is a bet that the small, fast tier will hold what matters most, and the bet usually wins.

Bandwidth is a separate number from latency. Latency is how long the first byte takes, and bandwidth is how many bytes per second flow once data is moving. RAM delivers tens of GB per second per socket, NVMe SSDs a few GB per second each, HDDs a couple of hundred MB per second sequentially, and a 25 Gbit/s network link about 3 GB per second. A design that streams large files cares mostly about bandwidth. A design that does many small lookups cares mostly about latency and operations per second.

Cost per GB falls as you go down. Exact prices change every year, but the ratios are stable enough to plan with. DRAM costs several times more per GB than NVMe flash, which costs several times more than hard disk, and archive tiers in object storage cost less again. The standard design move follows from this: keep the small hot set high in the hierarchy, and push the large cold mass down.

Worked example: why the database needs RAM. A product database of 200 GB serves 20,000 random reads per second. If each read went to an HDD at about 150 random IOPS per disk, you would need over 130 disks just for the reads. On NVMe SSDs at hundreds of thousands of IOPS, one or two drives are enough. If the working set, say the hottest 20 GB, fits in RAM, most reads never touch the disk at all. That is why database servers are sized so that the hot data and indexes fit in memory, and why "the working set no longer fits in RAM" is one of the most common reasons a database suddenly gets slow.

HDD vs SSD#

A hard disk drive (HDD) stores data on spinning magnetic platters. A head must move to the right track and wait for the platter to rotate, so each random read costs milliseconds and a disk manages only about 100-200 random reads per second (IOPS, input/output operations per second). Sequential reads are much better because the head stays in place.

A solid-state drive (SSD) stores data in flash memory chips with no moving parts. Random reads take about 100 microseconds, and a good NVMe SSD handles hundreds of thousands of IOPS. SSDs write in pages and erase in larger blocks, so they wear out after many writes; databases and SSD firmware manage this.

HDDSSD
Random IOPS~100-200~10k-1M
Best atLarge sequential reads and writes, cheap bulk storageRandom access, low latency
Cost per GBLowestSeveral times higher
Use forBackups, logs, cold data, big analytics filesDatabases, indexes, OS and app volumes

Today almost all databases run on SSDs. HDDs remain in bulk and archive storage, where cost per TB matters most.

Memory in practice#

RAM is the tier designers think about least and depend on most. A few properties shape real systems:

  • Volatility is absolute. Anything only in RAM is gone after a crash, a restart or a deploy. A cache must be rebuildable from a durable source, and an in-memory database such as Redis needs snapshots or an append-only log, plus replicas, if its contents matter.
  • Error-correcting memory (ECC). Bits in DRAM occasionally flip, from electrical noise or cosmic rays. Server memory uses ECC, which detects and fixes single-bit errors and detects double-bit ones, and large studies of production fleets have found memory errors far more common than many engineers expect. This is one reason servers use ECC and important systems checksum data end to end.
  • NUMA. In servers with several CPU sockets, each socket has its own local memory. Reaching memory attached to the other socket is noticeably slower. Databases and high-performance services pin threads and memory to the same socket, or they lose a surprising share of their speed.
  • Swapping is a cliff. When a process needs more memory than the machine has, the operating system can move pages to disk (swap). Every access to a swapped page then costs a disk read instead of a memory read, so latency jumps by orders of magnitude. Many production databases and caches are run with swap disabled or minimised. They prefer to be killed by the out-of-memory killer, and fail over, rather than limp along at disk speed.
  • Memory is the expensive part of caching. A Redis node with 100 GB of data needs more than 100 GB of RAM, because of per-key overhead, fragmentation and room for snapshots, which fork the process and can temporarily need extra memory. Size with headroom of roughly 25 to 50%.

Persistent memory, which kept data across power loss at near-DRAM speed, was sold for a few years as Intel Optane, but Intel discontinued the product line in 2022. Today the practical choices remain DRAM for speed and flash for persistence, with the gap bridged by careful use of logs and caches.

Inside a hard disk drive#

An HDD is a stack of magnetic platters spinning at a constant speed, usually 5,400, 7,200, 10,000 or 15,000 revolutions per minute. Read and write heads on an actuator arm float nanometres above each surface. Data is laid out in concentric tracks, divided into sectors (4 KB on modern drives).

Why a random read costs milliseconds. Reading a sector takes three steps:

  1. Seek: move the arm to the right track, typically 4 to 9 ms on average.
  2. Rotational latency: wait for the sector to spin under the head. At 7,200 rpm, one rotation takes 60 / 7,200 = 8.3 ms, so the average wait is half that, about 4.2 ms.
  3. Transfer: read the data, which for 4 KB is a tiny fraction of a millisecond.

So a random read costs roughly 8 to 13 ms, which caps a 7,200 rpm drive at about 75 to 150 random IOPS. A sequential read skips the seek and the rotational wait after the first sector, so it streams at 150 to 280 MB per second. That is a gap of roughly a thousand times between random and sequential throughput on the same drive. Nearly every disk-era database design trick, such as B-trees with large nodes, write-ahead logs and log-structured merges, is an attempt to turn random I/O into sequential I/O.

Other details that matter in practice:

  • Outer tracks hold more sectors than inner ones while spinning at the same speed, so sequential throughput is higher at the start of the disk than at the end.
  • SMR (shingled magnetic recording) overlaps tracks like roof shingles to pack in more data. Rewriting data then means rewriting neighbouring tracks too, so random writes can become very slow. SMR drives suit archival, write-once workloads, not databases.
  • Capacities have reached roughly 20 to 30 TB per drive. That is great for cost per TB, but it makes rebuilding a failed drive slow, since even at 200 MB per second, reading 24 TB takes about 33 hours.
  • Drives fail. Large fleets typically see annualised failure rates of around 1 to 2%, and Backblaze publishes yearly statistics from its own fleet. At 10,000 drives, that means a failure every day or two, so redundancy is not optional.

Inside a solid-state drive#

An SSD stores bits as electric charge in NAND flash cells. It has no moving parts, so any location can be read in tens of microseconds, and many reads can run in parallel across the chips and channels inside the drive.

Cell types trade density for endurance and speed. A cell can store one bit (SLC), two (MLC), three (TLC) or four (QLC), by distinguishing more charge levels. More bits per cell means cheaper capacity, but slower writes and fewer program and erase cycles before the cell wears out. Most data-centre drives today use TLC, and QLC is growing for read-heavy, capacity-focused storage.

Pages and erase blocks. Flash has an awkward rule: you can write (program) a page, typically 4 to 16 KB, only when it is empty, and you can erase only a whole erase block of hundreds of pages (several MB) at once. So an SSD cannot overwrite data in place. When the operating system rewrites a logical block, the drive writes the new data to a fresh page and marks the old one as stale.

The flash translation layer (FTL) is firmware that hides all of this. It keeps a map from the logical block addresses the OS uses to the physical pages that hold them, writes new data to free pages, and runs garbage collection in the background to reclaim blocks full of stale pages. It also does wear levelling, spreading writes so that no block wears out early.

Write amplification. Garbage collection must copy still-valid pages out of a block before erasing it, so the drive physically writes more than the host asked it to. The ratio is the write amplification factor. A factor of 3 means that writing 1 GB from the application causes 3 GB of flash writes, which uses up endurance three times as fast and steals bandwidth from foreground work. It rises when the drive is nearly full, because there are fewer free blocks to work with. Two things help:

  • TRIM (or discard) lets the OS tell the drive which blocks are no longer used, so garbage collection does not copy dead data.
  • Over-provisioning keeps a share of raw capacity hidden as spare space. Enterprise drives reserve more of it for steadier performance.

Endurance ratings. Drives are rated in total terabytes written (TBW) or drive writes per day (DWPD) over the warranty period. A 3.84 TB drive rated at 1 DWPD for 5 years can absorb about 3.84 × 365 × 5, which is roughly 7 PB of writes. Write-heavy databases and logging systems should budget for this and monitor the drive's wear indicators.

Tail latency. A read that lands behind a garbage-collection erase can take milliseconds instead of microseconds. Average SSD latency looks wonderful, but p99.9 latency under heavy mixed load can be far worse. Databases with strict latency targets watch this, and some spread load across more drives to keep each one less busy.

Interfaces. SATA SSDs use an interface designed for spinning disks and top out at about 550 MB per second with a single command queue. NVMe drives connect over PCIe with up to 64K queues of up to 64K commands each, delivering several GB per second and hundreds of thousands to over a million IOPS per drive. NVMe is the default for database servers today.

Power-loss protection. Enterprise SSDs include capacitors that flush in-flight data to flash if power is cut. That lets them acknowledge a flush (fsync) as soon as data reaches their internal RAM, which makes commits fast and safe. Consumer drives often lack it, so they either make fsync slow or, worse, acknowledge writes that can be lost. For databases, this single feature can matter more than raw speed.

What this means for databases. SSDs make random reads cheap, which weakened the old rule that everything must be sequential. Writes are still best done in large, sequential chunks, because they reduce write amplification. That is one reason log-structured storage engines remain popular on flash. See Storage Engines.

Block, file and object storage#

Block storage exposes a raw volume split into fixed-size blocks. The operating system formats it with a file system, or a database manages it directly. It is low-latency and supports small in-place updates. Examples: a local NVMe disk, Amazon EBS, Google Persistent Disk. A volume is usually attached to one server at a time.

File storage exposes a hierarchy of folders and files over a network protocol (NFS, SMB), so many servers can share the same files. Examples: Amazon EFS, Azure Files, NetApp filers. It suits shared home directories, legacy applications and content that many machines read and write as files.

Object storage stores whole objects (a file plus metadata) in a flat namespace, addressed by a bucket and key, through an HTTP API (PUT, GET, DELETE). You cannot change bytes in the middle of an object; you replace it. In return it scales to practically unlimited size, is very durable and cheap. Examples: Amazon S3, Google Cloud Storage, Azure Blob Storage, MinIO. See Object Storage.

BlockFileObject
AccessAttached volume, OS reads blocksNetwork file system pathsHTTP API by key
UpdateIn place, small writesIn placeReplace whole object
LatencyLowest (µs-ms)Low (ms)Higher (tens of ms)
SharingUsually one serverMany serversAny client, anywhere
ScaleSize of a volume (TBs)LargePractically unlimited
FitsDatabases, VM disksShared files, legacy appsImages, video, backups, data lakes

Block, file and object storage in depth#

The three models are layers of abstraction over the same disks. Each hides more detail and gives up some flexibility in exchange for easier sharing and scale.

Block storage, closer up. A block device is just a numbered array of fixed-size blocks, addressed by logical block address. It knows nothing about files. The file system or database on top decides what each block means. That is why block storage is the most flexible and the fastest: the software above has full control over layout, caching and flushing.

Network block storage, such as Amazon EBS or Google Persistent Disk, puts the disk on the other side of the data-centre network and replicates it within the zone, so a single server or drive failure does not lose the volume. It adds a network hop, typically making latency sub-millisecond to a millisecond or so instead of the tens of microseconds of local NVMe. Performance is usually provisioned: you pay for a volume type with a given IOPS and throughput, for example EBS gp3 volumes start from a baseline of 3,000 IOPS and 125 MB per second, which you can raise. Local NVMe "instance storage" is faster but ephemeral: if the virtual machine stops or its host fails, the data is gone. Databases that use it must replicate to other machines themselves.

Most block volumes attach to one machine at a time. Two machines writing the same blocks without coordination would corrupt the file system, because neither knows what the other cached. Shared block access needs a cluster file system that coordinates locking.

File storage, closer up. File storage adds names, directories, permissions and the familiar POSIX operations (open, read, write, seek, rename, lock) on top of blocks, and serves them over a network. NFS is the common protocol on Linux and SMB on Windows. The hard part is consistency between clients that cache. NFS, for example, typically guarantees close-to-open consistency: after one client closes a file, another client that opens it afterwards sees the changes, but two clients writing the same file at once can see surprising results. Metadata operations, such as listing a directory with a million files or renaming a large tree, are often the bottleneck rather than raw bytes.

Distributed file systems spread files across many machines for scale. The Google File System paper (Ghemawat, Gobioff and Leung, 2003) described a design with one master holding metadata, large chunks of 64 MB stored on many chunk servers, and three replicas of each chunk by default. Hadoop's HDFS followed that model, with a NameNode for metadata and large blocks (128 MB by default in modern versions) replicated three times. These systems are tuned for huge sequential reads and appends, not for small random updates. Others, such as CephFS and Lustre, target general-purpose or high-performance computing workloads.

Object storage, closer up. Object storage gives up the directory tree and in-place updates. In return, it can scale almost without limit:

  • Flat namespace. A key such as user42/2026/cat.jpg looks like a path, but the slashes are just characters. "Folders" are an illusion created by listing keys with a common prefix. Renaming a "folder" means copying and deleting every object under it.
  • Whole-object writes. You PUT a new version of the object. There is no "change bytes 100 to 200". Large objects are uploaded in parts (multipart upload) that are assembled at the end, and ranged GET requests can read part of an object.
  • Metadata with every object: content type, size, a checksum (ETag), custom key-value tags, and the storage class.
  • Consistency. Amazon S3 has provided strong read-after-write consistency for all operations since December 2020. Older designs and some other stores were eventually consistent for overwrites and listings, which caught many teams out.
  • Throughput by parallelism. One object request has tens of milliseconds of latency, but the service handles enormous aggregate throughput across many keys. S3 documents per-prefix rates of at least 3,500 writes and 5,500 reads per second, and it scales further by spreading keys across prefixes.

Object storage also offers features the other models lack: versioning (keep every past version of a key), lifecycle policies (move objects to cheaper classes after N days, or delete them), event notifications when objects are created, and pre-signed URLs that grant time-limited access to one object without sharing credentials. Details are in Object Storage.

SAN, NAS and storage networking#

Before the cloud, the three storage models were sold as boxes with their own names, and the terms still show up in enterprise and on-premises designs.

  • DAS (direct-attached storage): disks inside or plugged straight into one server. It is the fastest and simplest, but the storage is tied to that server.
  • SAN (storage area network): a dedicated network that gives servers block access to shared storage arrays. The traditional protocol is Fibre Channel. iSCSI carries the same block commands over ordinary Ethernet and IP, and NVMe over Fabrics (NVMe-oF) extends the fast NVMe protocol across a network, bringing remote block latency much closer to local. A SAN volume looks to the server like a local disk.
  • NAS (network-attached storage): an appliance that serves files over NFS or SMB. It is easy to share across many machines, with the consistency and metadata limits described above.

Cloud block volumes are essentially SANs run by the provider, and cloud file services are managed NAS. Object storage has no traditional equivalent. It grew out of web-scale needs, and it is why the cloud's cheapest, most durable tier speaks HTTP rather than a disk protocol.

Network bandwidth bounds remote storage. A server with a 25 Gbit/s link can move at most about 3 GB per second to or from network storage, whatever the disks behind it can do. Data-heavy designs, such as analytics clusters or video processing, often hit the network before the disks, so they push computation close to the data or read in parallel from many servers.

Worked example: where do uploaded files go?#

Consider a file-sharing product like Dropbox, where users upload files of up to several gigabytes. There are three designs, and the reasoning between them shows the storage models in action.

Option 1: store files in the database. Simple, but a poor fit. Large binary columns bloat the database, slow down backups and replication, evict useful pages from the buffer cache, and cost far more per GB than object storage. Databases are built for many small structured records, not multi-gigabyte blobs.

Option 2: the server receives the file and writes it to blob storage. Metadata (name, owner, size, the object key) goes to the database, and the bytes go to S3 or Google Cloud Storage. This is much better. Storage scales without limit and survives server failures, and you gain lifecycle rules and versioning for free. Two problems remain. First, the file now travels twice, from client to server and from server to blob storage, which wastes bandwidth and ties up application servers for the whole upload. Second, the metadata and the file live in two systems, so a crash can leave a metadata row with no file, or a file with no metadata row.

Option 3: the client uploads directly to blob storage with a pre-signed URL. This is the strongest design.

The application server only signs a URL, which takes milliseconds, so it never touches the bytes. The upload goes straight to the storage service, which is built to absorb that bandwidth. The pre-signed URL limits what the client can do: one bucket, one key, one method, for a few minutes, and optionally a maximum size and content type.

The metadata status field solves the two-systems problem. A row starts as uploading. The storage service's event notification (S3 Event Notifications, for example) moves it to uploaded, so the database never claims a file exists before it does. A cleanup job deletes rows stuck in uploading for too long, along with any partial objects, and object lifecycle rules can automatically abort incomplete multipart uploads after a few days. For very large files, the client uploads in chunks with multipart upload, which lets it retry a failed 10 MB part instead of restarting a 5 GB file, and resume after a dropped connection. Downloads use the same idea in reverse: a pre-signed GET URL, usually served through a CDN.

This pattern of keeping bytes away from application servers, granting access with signed URLs and tracking state in the metadata database appears in nearly every system that handles large files. See Pattern: Handling Large Blobs.

When each fits#

  • Database data files: block storage on SSD (local NVMe or network volumes).
  • User uploads, images, video, static assets: object storage, usually behind a CDN.
  • Backups, logs and analytics data: object storage, moving to cheaper tiers as it ages.
  • Several servers sharing a working directory (render farms, legacy apps): file storage.
  • Hot lookups needing microseconds: RAM, in a cache such as Redis.

Choosing storage in depth#

A short sequence of questions settles most storage choices.

Data usually splits across several stores. In a photo-sharing app, the user and photo metadata lives in a relational database on SSD. The photos themselves go to object storage, behind a CDN. Thumbnails and the hottest feed entries sit in Redis. Logs and analytics events land in object storage as compressed columnar files. Each choice follows from the access pattern: small, structured and updated goes to a database; large and immutable goes to object storage; hot and rebuildable goes to RAM.

Temperature tiers. Data cools over time. A photo is viewed heavily in its first week and rarely after a year. Object stores offer storage classes for this:

  • a standard class for frequently accessed data;
  • an infrequent-access class with cheaper storage but a per-GB retrieval fee;
  • archive classes where retrieval can take minutes to hours, at a fraction of the price.

Lifecycle rules move objects between classes automatically based on age. The trap is retrieval cost and minimum storage durations. Putting data that is still read often into an archive tier can cost more than leaving it in standard storage.

A worked cost and size estimate. A service stores 50 million new photos a month at an average of 2 MB each, which is 100 TB per month. After three years, that is about 3.6 PB of originals. If 90% of those photos are older than 90 days and are almost never viewed, moving them to an infrequent-access or archive class cuts the storage bill substantially, often by half or more depending on the tiers. Meanwhile, the metadata (about 1 KB per photo, so 1.8 billion rows and roughly 2 TB including indexes) fits comfortably in a sharded or large relational database on SSD. The ratio, petabytes of blobs to terabytes of metadata, is typical, and it is exactly why the bytes and the metadata go to different systems.

Signs you picked wrong:

  • Database backups take hours because of blob columns.
  • Object storage is used as a key-value store with thousands of tiny updates per second.
  • A shared file system becomes the bottleneck because thousands of clients list the same directory.
  • Local ephemeral disks hold the only copy of important data.

Durability vs availability#

Durability is the chance your data still exists and is correct after some period. Availability is the chance you can read or write it at a given moment. A system can be durable but unavailable: during a regional outage the data is safe but unreachable. Amazon S3 Standard, for example, is designed for 99.999999999% ("eleven nines") durability and 99.99% availability.

Durability comes from keeping multiple copies (replication) or erasure coding (splitting data into pieces plus parity so lost pieces can be rebuilt), across disks, machines and data centres. A single disk is never durable enough on its own: drives fail at a rate of a few percent per year.

Durability versus availability in depth#

Two different questions. Durability asks, "Will my data still exist, uncorrupted, a year from now?" Availability asks, "Can I read or write it right now?" They fail in different ways and are fixed by different means:

  • A regional power outage makes data unavailable but not lost. When power returns, it is all there.
  • A silent disk corruption that spreads to every replica makes data lost while the system stays perfectly available, happily serving wrong bytes.

Reading the nines. Eleven nines of annual durability (99.999999999%) means an expected loss rate of 10^-11 per object per year. If you store 10 million objects, you can expect to lose one object about once every 10,000 years on average. Four nines of availability (99.99%) allows about 52 minutes of unavailability a year. The two numbers are wildly different in size because losing data is far worse than a brief outage, and the systems are engineered accordingly.

Where durability comes from: redundancy. Single drives fail, so durable systems keep data in several places and repair losses quickly.

  • Replication keeps full copies, typically three, on different drives, machines and often different availability zones. It is simple and fast to read. Any copy can serve a request, and repair is just copying. The cost is three times the raw storage.
  • Erasure coding splits data into k data fragments and computes m parity fragments, so any k of the k + m fragments can rebuild the original. A common scheme uses Reed-Solomon codes. For example, 6 data plus 3 parity survives the loss of any 3 fragments while storing only 1.5 times the raw data, half the overhead of triple replication with similar or better fault tolerance. The cost is CPU work to encode and decode, and slower repair, because rebuilding one fragment means reading k others. Object stores use erasure coding heavily for bulk data, while hot, small or latency-sensitive data often stays replicated.

The repair race. Durability depends on how quickly lost redundancy is restored, not just on how many copies exist. With three replicas, data is lost only if all three fail before repairs finish. If drives fail independently at 2% a year and a lost replica is re-created within an hour, the chance of losing the other two in that hour is tiny. If repair takes a week, the risk is much higher. So production systems invest in fast, parallel repair: when a drive dies, its data is rebuilt from many other drives at once, so no single disk's bandwidth limits the recovery.

Correlated failures are the real enemy. The math above assumes failures are independent, and real failures often are not. Drives from the same manufacturing batch can fail together. A bad firmware update can hit every server at once. A rack loses power, or a whole data centre floods. Durable designs spread copies across failure domains (disk, server, rack, power feed, availability zone, region) and roll out changes gradually, so one mistake cannot reach every copy.

Corruption, not just loss. Disks occasionally return wrong data without reporting an error, known as bit rot or silent corruption. Durable systems store checksums with every block or object and verify them on read. They also run background scrubbing, which reads everything periodically and repairs bad copies from good ones before a second copy also goes bad. File systems such as ZFS checksum every block for the same reason.

Replication is not a backup. Replication faithfully copies mistakes. If an engineer runs DELETE FROM orders or a bug overwrites records, every replica applies it within milliseconds. Protection against human and software error needs backups or versioning that keep past states. A common rule of thumb is "3-2-1": three copies of the data, on two different kinds of media, with one copy off-site, today often in another region or cloud account with separate credentials, so that one compromised account cannot delete everything. Backups also need restore tests, because a backup that has never been restored is a hope, not a plan.

RPO and RTO. Two numbers turn durability and availability into business requirements:

  • RPO (recovery point objective): how much recent data you can afford to lose. An RPO of 5 minutes needs continuous replication or frequent log shipping, while an RPO of 24 hours allows nightly backups.
  • RTO (recovery time objective): how long recovery may take. Restoring 10 TB from object storage at 1 GB per second takes nearly 3 hours, which matters if the RTO is 1 hour.

See Availability and Reliability for how these feed into a design.

RAID briefly#

RAID (redundant array of independent disks) combines disks in one server:

LevelHowGainCost
RAID 0Stripe data across disksSpeedNo redundancy: one disk failure loses everything
RAID 1Mirror each diskSurvives one disk failure; fast readsHalf the capacity
RAID 5 / 6Stripes plus 1 or 2 parity blocksSurvives 1 or 2 failures, good capacitySlower writes; long, risky rebuilds
RAID 10Mirrored pairs, stripedSpeed plus redundancyHalf the capacity

RAID protects against a disk failure, not against a server, rack or data-centre failure, accidental deletion or corruption. Distributed systems replicate across machines and keep backups instead.

RAID in depth#

Parity with XOR. RAID 5 stores, for each stripe, the XOR of the data blocks on the other disks. XOR has a convenient property: if A XOR B XOR C = P, then any one value can be recovered from the other three. If the disk holding B dies, B = A XOR C XOR P. That is the whole trick behind single-parity protection, and RAID 6 adds a second, independent parity calculation to survive two failures.

The write penalty. Updating one block in RAID 5 means reading the old data and the old parity, then writing the new data and the new parity, which is four I/O operations instead of one. RAID 6 needs six. That is why parity RAID is a poor fit for write-heavy databases, and why RAID 10 (mirrors striped together) is the traditional choice for them. It costs half the capacity, but each write is just two writes.

Rebuild risk on big drives. When a disk fails, the array must read every remaining disk end to end to rebuild the lost one. With 20 TB drives, that can take a day or more, during which the array is slower and, in RAID 5, has no redundancy left. A second failure, or an unreadable sector on a surviving disk, during the rebuild can lose the array. The bigger drives get, the stronger the argument for RAID 6 or RAID 10 over RAID 5.

The write hole. If power fails after the data block is written but before the parity block is, the stripe's parity no longer matches. A later rebuild would then reconstruct garbage. Hardware RAID controllers avoid this with battery- or flash-backed write caches. Software approaches such as ZFS's RAID-Z avoid it with copy-on-write, never overwriting a stripe in place.

Hardware or software. Hardware RAID cards offload the work and add a protected cache. Software RAID (Linux mdadm, ZFS, Windows Storage Spaces) is flexible, visible to the OS and does not lock you into one controller model. In cloud and large distributed systems, RAID inside a server matters less, because redundancy is handled across machines. Many distributed databases simply run on plain disks (JBOD, "just a bunch of disks") or RAID 0 for speed, and rely on replicas on other servers for safety.

When to Use It#

  • Choosing where each kind of data lives in a design (database, cache, blob store, archive).
  • Estimating latency: count disk seeks and network hops.
  • Sizing storage cost: hot data on SSD, bulk data in object storage.

When NOT to Use It#

  • Do not store large files (images, video) in a relational database's tables; put them in object storage and keep the key in the database.
  • Do not use object storage as a low-latency database for small, frequently updated records.
  • Do not count on RAID or a single volume as your backup.
  • Do not use a shared network file system as a coordination mechanism between services, for example by polling a directory for new files or using file locks across machines. Network file locking and caching semantics are subtle, and failures are hard to diagnose. Use a queue, a database or object storage events instead.
  • Do not pick an archive storage class for data that a user might request interactively; retrieval delays of minutes to hours turn into a broken feature.

How to Implement It#

  1. Classify data: hot (RAM or SSD), warm (SSD), cold (object storage, archive tiers).
  2. Put databases on SSD block storage with replication across machines.
  3. Put blobs in object storage and serve them through a CDN.
  4. Add lifecycle rules to move old objects to cheaper storage classes.
  5. Back up to a different place (another region or account) and test restores.
TechnologyFits when
Local NVMeLowest latency; data replicated by the application or database
Amazon EBS, GCP Persistent DiskDurable network block volumes for databases and VMs
Amazon EFS, Azure Files, NFSShared file systems
Amazon S3, GCS, Azure Blob, MinIOObjects, media, backups, data lakes

Trade-offs#

ChoiceGainCostPick when
RAMFastestVolatile, expensiveCaches, hot indexes
SSDFast random accessHigher cost per GBDatabases
HDDCheapest diskSlow random accessBulk, sequential, cold data
Object storageUnlimited, durable, cheapHigher latency, whole-object writesFiles and backups
Replication (3 copies)Simple, fast reads and repair3x raw storageHot, small or latency-sensitive data
Erasure coding (for example 6+3)Same or better fault tolerance at 1.5xCPU cost, slower repair, higher tail latencyLarge, cold data at scale
Local NVMe instance storeLowest latency, high IOPSLost with the hostReplicated databases, caches, scratch space
Network block volumeSurvives host failure, resizableExtra network latency, provisioned IOPS costSingle-node databases, VM disks

Common Pitfalls#

  • Treating durability and availability as the same number.
  • Running a database on a single local disk without replication.
  • Many tiny random reads against HDDs or object storage.
  • Relying on replication alone, so an accidental delete or corrupting bug reaches every copy with no backup to restore.
  • Running write-heavy databases on parity RAID or SMR drives and hitting the write penalty.
  • Putting frequently read data into archive tiers, then paying retrieval fees and waiting hours.
  • Uploading large files through application servers instead of directly to object storage with pre-signed URLs.

Real-World Examples#

Amazon S3 is designed for eleven nines of durability by storing data redundantly across multiple devices and facilities in a region.

Large analytics platforms commonly use object storage as a "data lake", keeping raw and processed data as files that many engines can read.

  • Google's GFS paper (2003) described large 64 MB chunks replicated three times across chunk servers, a design that HDFS later followed.
  • Backblaze publishes annual hard-drive failure statistics from its fleet, a widely used source for real-world drive failure rates.

In the Interview#

In the interview: storage in a few sentences#

Storage choices come up in almost every design, usually in the high-level design step. You rarely need to explain SSD internals. What interviewers look for is the right store for each kind of data, with a reason:

  1. Separate metadata from blobs. "The file metadata goes in Postgres; the bytes go to S3, uploaded directly from the client with a pre-signed URL."
  2. Know the rough numbers. Memory about 100 ns, SSD about 100 µs, HDD about 10 ms, and a same-region round trip about 0.5 ms. Use them to justify a cache, or to explain why a design that does ten sequential disk reads per request is slow.
  3. Separate durability from availability. "S3 gives us durability through replication and erasure coding. For availability during a regional outage, we replicate the bucket to a second region."
  4. Mention backups and versioning when data loss would be serious, because replicas copy deletions too.

Typical follow-ups and short answers:

  • "How would you handle a 10 GB upload?" Multipart upload directly to object storage with pre-signed URLs per part, resumable, with the metadata status updated by a storage event.
  • "The database is slow after the dataset doubled." Check whether the working set still fits in RAM. If not, add memory, add read replicas, or shard. See Database Performance.
  • "Why not keep everything on local NVMe for speed?" Local disks are lost with the host, so you need replication across machines, which distributed databases provide, or durable network volumes for single-node databases.
Deep Dive: Why sequential access and page sizes matterShow

Disks and SSDs read in fixed units (4 KB pages are common), and operating systems cache recently read pages in RAM (the page cache). Reading one byte costs a whole page. Databases therefore group related data on the same pages and prefer sequential writes. Log-structured designs turn random writes into sequential appends, which is why write-heavy databases often use them. See Storage Engines.

fsync forces data from the OS cache onto the device. Without it, an "acknowledged" write can be lost on power failure. Databases call fsync on their log at commit, which is why commit latency depends on the disk.

The write path: page cache, fsync and what durable really meansShow

When an application calls write(), the data usually does not go to disk. It goes into the operating system's page cache in RAM, and the call returns at memory speed. The kernel writes dirty pages to the device later, typically within seconds. That makes ordinary writes fast, and it also means a power failure can silently lose data the application believes it wrote.

fsync is the durability boundary. fsync() (or fdatasync()) asks the kernel to push a file's dirty pages, and the device's own volatile cache, onto stable media before returning. Databases call it on their write-ahead log at every commit, or at every group of commits. Its latency sets a floor on commit latency:

  • tens of microseconds on an enterprise NVMe SSD with power-loss protection, because the drive can acknowledge from its protected cache;
  • a millisecond or more on drives that must reach the flash itself;
  • several milliseconds on a spinning disk, which must wait for the platter to rotate.

Group commit amortises the cost. Many transactions waiting to commit share a single fsync, so throughput stays high even when each fsync is slow. This is why a database can commit tens of thousands of small transactions per second on hardware that manages only a few thousand fsyncs per second.

Lies and edge cases. Durability depends on every layer telling the truth. Some consumer drives and virtualised storage layers have acknowledged flushes before the data was safe. File systems have had subtle bugs around error handling after a failed fsync. A notable case was PostgreSQL's discovery around 2018 that retrying fsync after an error on Linux could falsely report success, which led it to treat fsync failures as fatal and recover from the log. The lesson is not to distrust everything, but to use hardware and configurations that are known to honour flushes, and to test crash recovery for real.

Bypassing the cache. Some databases open files with O_DIRECT to skip the page cache and manage their own buffer pool. That avoids caching the same page twice, once in the database's memory and once in the kernel's, and gives the database precise control over what stays in memory. Others, such as PostgreSQL, deliberately lean on the page cache, which is one reason PostgreSQL tuning guides suggest a database buffer of only a fraction of RAM, leaving the rest to the operating system.

Replication as durability. Distributed databases often treat "written to the memory of a majority of replicas" as durable enough, sometimes fsyncing less often, on the reasoning that several machines losing power at the same instant is less likely than one disk failing. Whether that is acceptable depends on the failure domains. Three replicas in one rack on one power feed are not independent. Three replicas in three availability zones are much closer to it.

Erasure coding and storage efficiency at scaleShow

Why big stores move from replication to erasure coding. At petabyte scale, the difference between storing data 3 times and 1.5 times is the difference between buying 3 PB of disks and 1.5 PB for every petabyte of user data. Reed-Solomon codes, invented by Irving Reed and Gustave Solomon in 1960 and long used in CDs, QR codes and deep-space communication, made that saving practical for storage systems.

How the trade-off shifts with k and m. With k data fragments and m parity fragments:

  • storage overhead is (k + m) / k, so 10 + 4 costs 1.4 times the raw data and survives any 4 losses;
  • reading normally needs only the k data fragments, or any k fragments if some are missing;
  • rebuilding one lost fragment needs k reads across the network, so wide codes save space but make repairs expensive.

That repair cost drove research into codes that repair with less traffic. Microsoft's Azure Storage paper "Erasure Coding in Windows Azure Storage" (Huang and others, 2012) described Local Reconstruction Codes, which add local parity groups so most single failures are repaired from a few fragments instead of all k.

Placement matters as much as math. Fragments are spread across failure domains. A 6 + 3 code placed so that no zone holds more than 3 fragments survives the loss of a whole zone. Placing all 9 in one rack survives only disk failures. Object stores also apply erasure coding asynchronously in many designs. New data is first written with fast replication, then converted to an erasure-coded form once it cools, combining low write latency with low long-term storage cost.

Hot data stays replicated. Erasure-coded reads of small objects must contact several servers and can suffer from the slowest one, so tail latency rises. Systems therefore often keep small or hot objects replicated and erasure-code large or cold ones. This is the same hierarchy idea again: spend more resources per byte where speed matters, and fewer where size matters.

Data layout: rows, columns and compressionShow

How bytes are arranged on storage often matters more than the device they sit on.

Row-oriented layout stores each record's fields together. Reading or updating one whole record touches one place, which suits transactional workloads: fetch an order, update its status. Most relational databases store rows this way, in fixed-size pages (8 KB in PostgreSQL, 16 KB in InnoDB).

Column-oriented layout stores each column's values together. A query that sums revenue over a billion orders reads only the revenue column, not the other 30 fields, and similar values packed together compress extremely well: dates, repeated country codes, small integers. Columnar formats such as Apache Parquet and ORC on object storage, and analytical databases such as ClickHouse, Amazon Redshift and Google BigQuery, use this layout. A scan can read ten times less data, or more, than a row layout for the same query. The cost is that writing or updating one record touches every column file, so columnar stores favour large batch writes.

Compression trades CPU for I/O. Fast codecs such as LZ4 and Snappy compress at hundreds of MB to GB per second per core, and Zstandard offers better ratios at tunable speed. When storage or network bandwidth is the bottleneck, which is common, compressing data makes reads faster, because fewer bytes cross the slow link and decompression on the CPU is cheap. Columnar formats add encodings such as dictionary encoding (store each distinct value once and refer to it by a small number), run-length encoding (store "France, repeated 10,000 times") and delta encoding for sorted numbers and timestamps.

Large sequential files suit object storage. Analytics data is usually written as large files of tens to hundreds of MB, partitioned by date or another key in the object path, for example events/date=2026-12-01/part-0001.parquet. Query engines then skip whole partitions that a query does not need, and read the rest in parallel. Millions of tiny files defeat this: each file costs a request and some metadata work, so pipelines compact small files into larger ones periodically.

Key Takeaways#

  • Storage is a hierarchy: RAM (~100 ns), SSD (~100 µs), HDD (~10 ms), object storage (tens of ms).
  • SSDs dominate databases; HDDs remain for cheap, sequential, cold data.
  • Block storage fits databases, file storage fits shared files, object storage fits media, backups and data lakes.
  • Durability (not losing data) and availability (reaching it now) are separate promises.
  • RAID protects against disk failure only; replicate across machines and keep backups.
  • Random I/O on HDDs is about a thousand times slower than sequential; SSDs fix reads, but large sequential writes still reduce wear and write amplification.
  • Upload big files straight to object storage with pre-signed URLs, and track their state in the metadata database.
  • Durability comes from redundancy across failure domains, checksums, scrubbing, fast repair and backups; replication alone does not protect against mistakes.