Durability

Learn about implementation of the durability guarantee in ACID transactions.

Introduction

Durability guarantees ensures that once the transaction commits, the database ensures that the changes are permanent and available even in the event of a database crash. The definition of durability varies from one database to another and depends on how much data durability is required.

Durability strategies

There are multiple strategies to persist the data durably on disk.

Persistence to disk

The main memory is volatile and loses its contents during a power outage. Therefore, main memory is not used to store data permanently. Instead, applications persist the data on durable devices like disks to store it permanently. Disks are durable during power outages and keep the data intact.

Disks have a lifespan dictated by Mean Time to Failure (MTTF). For example, an HDD has a lifespan of 3–5 years, and an SSD has a lifespan of roughly ten years.

Note: Components of a disk can fail within this lifespan or can last beyond this, but the important point to remember is that disks come with a lifespan and durability is not indefinite.

To avoid data loss due to single disk failures, most hardware employ RAID, as discussed in the next section.

RAID

RAID stands for Redundant Array of Independent Disks or Redundant Array of Inexpensive Disks, which adds a layer of redundancy to the data by storing copies of the data on multiple disks. This setup of redundancy prevents data loss on single disk failures as we can reread from other redundant copies of the disk.

  1. Mirroring: Disk mirroring involves replicating disk volumes onto separate physical drives in real time to provide additional durability in case of a single disk failure. When a particular disk fails, we can serve reads and writes from the mirrored copies.

  2. Striping: Striping is breaking down a data sequence into segments and storing individual segments onto different physical disks. Striping is beneficial when the data is too large to fit onto a single disk drive. Also, spreading the data over physical devices increases the throughput of reads and writes.

  3. Parity: Parity includes a check bit added to the data that act as an error detection code. They are used only in error detection and not error correction.

The system provides different RAID levels that include different configurations, which provide a different combination of guarantees around mirroring, striping, and parity.

RAID 0

RAID 0 level supports data striping and distributing data across multiple disks but does not implement parity and redundancy. The failure of one disk drive results in data loss. RAID 0 level is beneficial where throughput is most important despite data loss.

Get hands-on with 1200+ tech skills courses.