SkillSprout
Chapter 31 · Lesson 2
Advanced
4 min read

Block, File and Object Storage, and Erasure Coding

Overview

Not all stored data is accessed the same way, so there are three storage styles: block, file and object. Choosing the right one is mostly about how the data will be read and written.

Plain replication also gets expensive at huge scale. Erasure coding protects data almost as well for much less disk.

Detailed Notes

What is block, file and object storage

  • Block storage gives you a raw virtual disk. One server formats it and uses it, e.g. Amazon EBS or a local SSD. It is the fastest and supports overwriting any part.
  • File storage gives shared folders and files with a path, mounted by many servers over a network protocol (NFS, SMB), e.g. Amazon EFS.
  • Object storage stores objects (bytes plus metadata) addressed by a bucket and key such as "users/42/avatar.png", over an HTTP API (PUT, GET, DELETE), e.g. Amazon S3. The namespace is flat; slashes are only characters in the key. Objects are replaced whole, not edited in part.
BlockFileObject
AccessAttached to one serverShared network folderHTTP by key
LatencyLowestLow to moderateHigher
ScaleTerabytes per volumeLargePractically unlimited
Cost per GBHighestMediumLowest
Best forDatabases, boot disksShared team foldersPhotos, video, backups, logs

The problem it solves

Using the wrong type hurts: a database on object storage is painfully slow (no partial updates), and photos on expensive block disks waste money.

The second problem is cost. Three full copies means 3x storage (200% overhead). For exabytes of rarely used data, that is enormous.

How it works

Object stores use the DFS ideas from the last lesson: an index maps keys to byte locations, the bytes are spread over many disks and data centres, and the system replicates or erasure-codes them. A lifecycle policy can move old objects to cheaper tiers (hot, infrequent, archive), e.g. "after 30 days to infrequent access, after a year to archive".

Erasure coding splits data into k data fragments and computes m parity fragments with maths (Reed-Solomon is the classic). Any k of the k+m fragments rebuild the original, so up to m fragments can be lost.

A tiny version: store pieces A and B plus parity P = A XOR B. Lose A? Rebuild it as B XOR P. Real systems use stronger codes that survive several losses.

SchemePieces storedFailures survivedOverhead
3x replication3 copies2200%
Erasure code 6+39350%
Erasure code 10+414440%

Replication is simple and fast to read and repair (copy one replica). Erasure coding is far cheaper in disk but repairs read many fragments and use more CPU and network. So many systems replicate hot data and erasure-code cold data.

Durability vs availability. Durability is the chance data is never lost (S3 Standard advertises "eleven nines", 99.999999999%). Availability is the chance you can reach it right now. Data can be durable yet briefly unreachable.

A simple example

A website stores "invoices/2024/inv-1001.pdf" in a bucket. The app uploads it with one HTTP call, then gives the customer a time-limited pre-signed URL to download it straight from storage, so the app server never handles the bytes.

System design example

A video platform keeps its database on block storage, engineering documents on a file share, and uploaded videos in object storage. For the first month videos are replicated so streaming is fast. A lifecycle job later moves videos nobody watched for 90 days into an erasure-coded cold tier at about half the storage cost. For 100 GB of data: 3x replication stores 300 GB, a 6+3 code stores 150 GB.

Summary

  • Block = raw disk for databases, file = shared folders, object = keyed items over HTTP for huge, cheap, write-once data.
  • Choose by access pattern: random low-latency writes need block; massive read-mostly data needs object.
  • Erasure coding stores k data and m parity pieces; any k rebuild the data, at about 1.3 to 1.5x instead of 3x.
  • Replicate hot data, erasure-code cold data; repairs are heavier with erasure coding.
  • Durability (never lost) is not availability (reachable now).

Architecture Diagram

Choosing storage and protecting data
Architecture
App server

Storage types

Blockdatabase
Fileshared docs
Objectmedia, backups
Cold tiererasure coded

Match each data type to block, file or object storage, then tier it over time.

  1. 1The application writes database pages to block storage for low latency.
  2. 2Shared documents live on a file system mounted by many servers.
  3. 3Large media and backups go to object storage over HTTP.
  4. 4A lifecycle policy moves old objects to a cheaper, erasure-coded tier.

Common Interview Questions

Chapter quiz

Distributed File Systems · 5 questions

  1. 1.What is a distributed file system?

  2. 2.In HDFS, what does the NameNode store?

  3. 3.Why does a client read blocks directly from data nodes?

  4. 4.With a 6 data + 3 parity erasure code, how many fragments can be lost while data stays recoverable?

  5. 5.Which storage type is best for a database's data files?

0 of 5 answered

Finished this lesson?

0 of 91 lessons done · 0% of the course