SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
  • Block Storage
  • Distributed File Systems
  • Object Storage
  • Erasure Coding
  • Storage Tiers (Hot, Warm, Cold)
  • RAID
  • Compression and Deduplication
  • File Storage (NFS)
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Data and Storage/Storage Systems

RAID

Combine several disks to be faster, safer or both: striping, mirroring and parity.

⏱ 13 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

RAID joins several physical disks into one logical disk. Depending on the level, it makes the disk faster, safer, or both.

  • Striping spreads data over many disks, so they work at the same time (faster).
  • Mirroring keeps full copies on more than one disk (safer).
  • Parity stores a small calculated block, so a lost disk can be rebuilt from the others (safer, with less wasted space).
  • RAID protects against a broken disk. It is not a backup.

02Concept: What is it?

A single disk will fail one day. RAID (Redundant Array of Independent Disks) is a way to put several disks together, so that the computer sees one big disk and the disks share the work and the risk.

There are three building blocks. Striping cuts data into small stripes and writes them to the disks in turn, so a big read or write uses all disks together. Mirroring writes the same data to two or more disks. Parity stores an extra block per row of data, computed with XOR. If one block in the row is lost, XOR-ing the others gives it back.

Three building blocks
Striping
💽A1part 1
💽A2part 2
💽A3part 3
Mirroring
💽Acopy 1
💽Acopy 2
Parity
💽A
💽B
🧮A ⊕ Bparity
Every RAID level is a mix of these three ideas.
🧠XOR in one line
XOR is 1 when two bits differ and 0 when they are the same. If P = A ⊕ B ⊕ C, then A = P ⊕ B ⊕ C, and the same works for any one missing block. That is how a RAID 5 or RAID 6 array rebuilds a lost disk.

03Real-Life Example

🍵Copies of an Important Book
A library has one precious book that many students need. If you keep one copy, and it is damaged, it is gone. So you make a plan. Mirroring: keep two identical copies on two shelves. Striping: tear the book into chapters and give each chapter to a different student to read at the same time, so it is read much faster (but if anyone loses a chapter, the book is broken). Parity: keep one extra summary sheet from which any single lost chapter can be worked out.
Library
RAID
Two identical copies on two shelves
RAID 1 mirroring
Chapters shared between readers
RAID 0 striping
An extra summary sheet
Parity block
Working out a lost chapter from the others
Rebuilding a disk with XOR
A fire in the library
A disaster RAID cannot help with
A copy kept in another building
A real backup
One RAID 5 row
💽Disk 1Data 1
💽Disk 2Data 2
💽Disk 3Data 3
🧮Disk 4Parity
Three data blocks and one parity block. Any one of the four can be lost and rebuilt.

04Why Do We Need It?

🛡️Survive a disk failure
Disks break often enough that a server with many disks will see failures. RAID keeps the service running while a disk is replaced.
⚡More speed
Striping lets several disks work on one request at the same time.
📦One big volume
The operating system sees one large disk, which is simpler than managing many.
💸Cheaper than a full copy
Parity protects against a failure while wasting only one or two disks, not half of them.
🔧Replace without downtime
A failed disk can often be swapped while the system runs and then rebuilt in the background.
🧱Simple building block
RAID lives below the file system, so applications do not need to know about it.
One disk is a risk. Several disks, arranged well, turn a broken disk into a small repair job instead of an outage.

05Where Do We Use It?

🗄️Database servers
RAID 10 is a common choice for databases that need speed and safety for small, random writes.
🖥️On-premises servers
Servers in your own data centre often use a RAID controller or software RAID.
📂Network storage (NAS)
Home and office storage boxes usually offer RAID 1, 5 or 6 across several disks.
🎬Video editing machines
RAID 0 is used when speed matters and the data can be recreated or is backed up elsewhere.
🏢Storage arrays
Enterprise arrays combine many disks with RAID-like protection, often now with erasure coding on top.
☁️Cloud block storage
Cloud disks hide this from you: the provider already keeps copies behind the scenes, so you rarely build RAID on top, though some people stripe several volumes for speed.

06Types / Parts / How It Works

The common RAID levels

LevelHow it worksUsable space (N disks)Failures survivedGood for
RAID 0Striping onlyAll N disksNone. One failure loses everything.Speed, when the data can be recreated
RAID 1Mirroring (2 or more copies)One disk's worth (1 of N)N − 1 disksBoot disks, small and important volumes
RAID 5Stripes with 1 parity block per row, spread over all disksN − 1 disks (needs 3 or more)1 diskGeneral storage, read-heavy data
RAID 6Stripes with 2 parity blocks per rowN − 2 disks (needs 4 or more)Any 2 disksLarge arrays where a second failure is a real risk
RAID 10Mirrored pairs, then striped across the pairsHalf of the disks1 per mirror pair (never both disks of one pair)Databases, anything needing speed and safety

Rebuilding with parity (XOR)

Worked example with 3 data blocks
A10110010
B01101100
C11001001
→↓XOR
P00010111
↓Disk with B fails
A10110010
Blost
C11001001
P00010111
↓A ⊕ C ⊕ P
B = 01101100rebuilt
Data Parity Lost Rebuilt
The lost block is the XOR of everything that survived.

Hardware or software RAID

KindWho does the workGood and bad
Hardware RAIDA dedicated controller cardTakes work off the CPU and may have a battery-backed cache. But the controller is itself a part that can fail, and the array may only be readable on a similar controller.
Software RAIDThe operating systemFlexible and cheap, with no special card. It uses some CPU, and you rely on the operating system for the setup.
VisualizerPick a RAID level, then fail some disksChange the level and the number of disks. Click disks to fail them. For RAID 10, fail both disks of one pair. For RAID 5, fail one of the first four disks and watch the lost block rebuilt with XOR.
RAID level

Stripes plus one parity block per row (the XOR of the data blocks). Any one lost disk can be rebuilt from the others.

Click a disk to switch it between working and failed.
Usable space
80%
4 of 5 disks
Failures survived
1
any disks
Now failed
0
disks
Data readable?
Yes
healthy
Healthy: 5 disks, 80% of the raw space is usable. Click a disk to fail it and see what happens.
One RAID 5 row, rebuilt with XOR (disks 1 to 4)
Data 1 (disk 1)10110010
Data 2 (disk 2)01101100
Data 3 (disk 3)11001001
Parity (disk 4)00010111
Parity = Data 1 XOR Data 2 XOR Data 3 = 00010111. XOR of all four blocks in a row is always 00000000.
Fail exactly one of disks 1 to 4 to see the lost block rebuilt from the other three.

Capacity and survival rules follow the standard definitions of each level. Real controllers differ in details (stripe size, hot spares, rebuild order). RAID protects against disk failure only: it does not protect against deleted files, bugs, a failed controller or a fire, so you still need backups.

07How to Use It / Steps / Implementation

Choosing and running a RAID setup

  1. 1
    Decide what matters
    Speed, safety or cheap space? RAID 0 is for speed only. RAID 1 and 10 favour speed and safety. RAID 5 and 6 favour space and safety.
  2. 2
    Count the cost of failure
    With big disks, a rebuild can take many hours. During it, a second failure can destroy a RAID 5 array. Prefer RAID 6 or RAID 10 for large disks.
  3. 3
    Plan usable space
    RAID 5 gives N − 1 disks of space, RAID 6 gives N − 2, RAID 10 gives half. Do the arithmetic before you buy disks.
  4. 4
    Keep a spare
    A hot spare disk starts rebuilding by itself when a disk fails, shortening the risky time.
  5. 5
    Monitor disk health
    Watch SMART data and RAID alerts. A degraded array that nobody notices is just a bigger risk.
  6. 6
    Test the rebuild
    Practise replacing a disk before you need to. A rebuild you have never done is a plan you have not tested.
  7. 7
    Still take backups
    RAID will not help against deleted files, bugs, ransomware, a failed controller or a fire. Keep backups in another place.
⚠️RAID is not a backup
RAID copies mistakes instantly. If you delete a file or a program corrupts it, every disk in the array agrees that the file is gone. Only a separate, older copy can bring it back.
💡Checksums find silent damage
A disk can return wrong data without saying so. File systems and storage systems that keep checksums can notice that and repair it from another copy or from parity.

08Key Terms to Know

TermMeaning in easy words
RAIDRedundant Array of Independent Disks: several disks used together as one
StripingSplitting data into pieces and writing them to the disks in turn, for speed
MirroringWriting the same data to two or more disks, so one copy survives
ParityAn extra calculated block that lets one lost block be rebuilt
XORA bit operation that is 1 when two bits differ. The maths behind parity
StripeOne row of blocks spread across all disks of the array
Degraded arrayAn array that has lost a disk but still works, more slowly and with less safety
RebuildRecreating the data of a failed disk onto a new disk
Hot spareAn idle disk that takes over automatically when another disk fails
Write penaltyThe extra reads and writes that parity needs for each small write
Hardware RAIDRAID done by a controller card instead of the operating system

09Pros, Cons and Trade-offs

✅ Pros
  • Survives disk failures without downtime
  • Striping raises throughput
  • Looks like one simple disk to applications
  • Parity is cheaper than full mirroring
  • Mature, well understood and widely supported
⚠️ Cons
  • Not a backup: copies mistakes and cannot survive a disaster
  • Rebuilds on big disks take a long time and are risky
  • RAID 5 and 6 slow down small writes (parity update)
  • Hardware controllers are another part that can fail
  • Only protects against whole-disk failure unless checksums are used

Trade-offs

ChoiceWe gainWe lose
RAID 0Full capacity and best speedAll safety. One disk dies, everything is lost
RAID 1Simple and safe, fast readsHalf the space (or less with more copies)
RAID 5Good space use with protection from one failureSlow small writes and a risky rebuild on large disks
RAID 6Survives two failuresSlower writes and two disks of space for parity
RAID 10Speed and safety, quick rebuild (copy one disk)Half the space, and two failures in one pair are fatal
More disksMore space and speedA higher chance that at least one disk fails

10Common Problems and Mistakes

Common mistakes

  1. Treating RAID as a backup. Deletes, bugs and ransomware are copied to every disk.
  2. RAID 5 on very large disks. A long rebuild leaves a wide window for a second failure.
  3. Buying all disks from one batch. Disks from the same batch and age tend to fail around the same time.
  4. Ignoring a degraded array. Nobody notices the first failure, and the second one destroys the data.
  5. Using RAID 0 for important data. The failure chance grows with every disk you add.
  6. Forgetting the controller. If a hardware controller dies, you may need the same model to read the array.
  7. Never testing a rebuild. The first time should not be during an emergency.

Things to watch

⏳Rebuild time
Many hours or days on large disks. Performance drops and the other disks work hard.
🧟Silent corruption
A disk may return wrong data without an error. Use checksums and regular scrubbing.
✍️Write hole
A crash in the middle of a parity update can leave parity wrong. Battery-backed caches or a journal protect against this.
🔌Shared cause
A power problem, a bad batch or a failing controller can hit several disks together.

11Real-World Examples

🐘Database hosts
Many on-premises database servers use RAID 10 for data and logs.
🏠Home NAS
Popular home storage boxes offer RAID 1, 5, 6 or 10 in a simple menu.
🏭Enterprise arrays
Big storage arrays group many disks into RAID sets, and often add spare disks and monitoring.
🧰Software RAID in operating systems
Linux and other systems include software RAID, and some file systems have built-in mirrors and parity.
☁️Cloud providers
Behind a cloud disk, the provider already stores copies or erasure-coded pieces, so you rarely need RAID for safety.
🎞️Scratch disks
Editing and rendering machines use RAID 0 for fast temporary files that can be recreated.
📝Note
Exact features, limits and rebuild behaviour depend on the controller, the file system and the disks. Check the documentation of your system before planning an array.
Mini case: a database server with 6 disks
🚀RAID 06 disks of space, no safety
🧮RAID 55 disks of space, 1 failure
🧮RAID 64 disks of space, 2 failures
🪞RAID 103 disks of space, 1 per pair
RAID 0 usable space
RAID 5 usable space
RAID 6 usable space
RAID 10 usable space
Illustrative: the same six disks give very different results depending on the level.

12Related Topics to Read Next

Erasure Coding→

The large-scale cousin of parity: protect data across many machines with less extra space.

Block Storage→

The raw disks that RAID combines, and what cloud block volumes give you.

Replication→

Mirroring across machines instead of across disks.

Checksums→

How silent disk corruption is noticed.

Fault Tolerance and Redundancy→

The general idea behind every RAID level.

Backups, RPO, RTO and Disaster Recovery→

What RAID cannot do, and what protects you from the rest.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: several disks used as one, for speed, safety or both.
  • ✔Blocks: striping (speed), mirroring (copies), parity (XOR, rebuildable).
  • ✔RAID 0: all space, no safety. RAID 1: mirror.
  • ✔RAID 5: N − 1 space, survives 1. RAID 6: N − 2 space, survives 2.
  • ✔RAID 10: half the space, survives 1 per mirror pair, fast.
  • ✔Rebuild: long on big disks, and a second failure during it can be fatal.
  • ✔Not a backup: deletes and corruption are copied to every disk.
  • ✔One line: “RAID turns a dead disk into a repair job, not an outage. It does not turn into a backup.”
← Previous
Storage Tiers (Hot, Warm, Cold)
Next →
Compression and Deduplication