Durability: not losing data
Surviving what it was meant to survive
Section titled “Surviving what it was meant to survive”Durability is whether data survives the failures it was designed to survive. When the system tells you it has stored something, a durable system means it: the data will still be there after a crash, a power cut, a failed disk, and, depending on the design, a lost machine or a lost data centre.
It is not the same as availability, and mixing them up is a common mistake.
- Availability: whether you can reach the data now.
- Durability: whether the data still exists.
A database that is unreachable for twenty minutes because of a network problem has lost availability and kept every byte of its data. A database that is reachable all day and loses last week’s orders has lost durability while looking perfectly available. Amazon’s S3 documentation gives them separate figures: it is designed for 99.999999999% durability and 99.99% availability over a year.
Mental model. Durability is a promise about the past: what I have already told you I stored, I will still have. Availability is a promise about the present: I will answer now.
When is a write durable?
Section titled “When is a write durable?”A write is durable once it is on storage that survives the failures you care about, in enough independent places. Everything before that is a promise the system cannot yet keep. A write passes through stages, and the system decides at which one it tells the client “done”:
client ─▶ ① memory ─▶ ② log on disk ─▶ ③ second machine| The failure | Confirmed after ① (memory) | Confirmed after ② (log on disk) | Confirmed after ③ (second machine) |
|---|---|---|---|
| The server loses power | Lost | Survives: the log is replayed | Survives |
| The disk is destroyed | Lost | Lost: it was the only copy | Survives |
| The whole machine is destroyed | Lost | Lost | Survives |
| Both machines burn in one fire | Lost | Lost | Lost: they were not independent |
The rule: a system may only confirm a write when it can survive the failures it promises to survive. A database that waits for the log to reach disk before confirming survives a crash. One that waits for a second machine as well survives the loss of a machine, and a second machine in the same room does not survive the room.
The price is time. Waiting for a disk adds milliseconds, and waiting for another machine adds a network round trip. Many systems offer a choice: PostgreSQL has an asynchronous commit mode, which reports success before the log has been flushed to disk. After a crash it recovers to a consistent state, but the most recent confirmed transactions can be missing. The documentation puts the length of that window at up to three times its wal_writer_delay setting, and it risks losing recent transactions rather than corrupting the database. That is a legitimate trade for some data (a page-view counter) and a wrong one for others (a payment).
The documentation also warns that “flushed” depends on the hardware telling the truth. Disk and controller write caches can hold data in volatile memory, and some drives do not honour a request to flush it, so a power loss can lose data that the operating system believes is safely on disk. Durability depends on the whole stack, not on the software alone.
What each protection covers
Section titled “What each protection covers”No single protection covers every failure. Match each one to the failure it was made for.
| Failure | Log on disk | Replica in another zone | Replica in another region | Backup kept at another site | Versioning |
|---|---|---|---|---|---|
| The process crashes | Yes | Yes | Yes | — | — |
| The server loses power | Yes | Yes | Yes | — | — |
| A disk fails | No | Yes | Yes | Yes | — |
| A machine is destroyed | No | Yes | Yes | Yes | — |
| A data centre is destroyed | No | Yes | Yes | Yes | — |
| A region is lost | No | No | Yes | Yes | — |
| Someone deletes data by mistake | No | No: the deletion is copied | No: the deletion is copied | Yes, back to its date | Yes |
| A bug writes wrong values | No | No: the wrong values are copied | No: the wrong values are copied | Yes, back to its date | Yes |
Two rows deserve attention. First, a replica copies mistakes: a deleted table is deleted on every replica a moment later. Only something that keeps the past, a backup or a versioned store, protects against a mistake. Amazon’s documentation says as much, recommending versioning to recover from unintended user actions and application failures. Second, a backup protects against what it is kept apart from. A backup in the same building as the database does not survive the building.
Backups have their own measures. The recovery point objective (RPO) is how much recent data you can afford to lose, which is the age of the newest backup at worst. The recovery time objective (RTO) is how long it takes to be back. A nightly backup gives an RPO of up to 24 hours.
Eleven nines
Section titled “Eleven nines”Storage services often quote durability as a number of nines. Amazon S3’s documentation says S3 Standard is designed for 99.999999999% durability, eleven nines, over a year.
What does it mean? The chance of losing a given object in a year is 1 − 0.99999999999 = 10⁻¹¹. If you store 10,000,000 (10⁷) objects, the expected number of objects lost in a year is 10⁷ × 10⁻¹¹ = 10⁻⁴, which is one object every 10,000 years.
That is a very small number, and four things stand behind it.
- It is a design target, from how many copies exist and how fast lost ones are repaired. It is not a measurement, and it is not a guarantee.
- It counts hardware loss. S3 stores objects redundantly across at least three availability zones, and repairs lost redundancy, which is what the figure describes.
- It does not cover you. An object you delete or overwrite by mistake is gone as completely as an object lost to a disk. That is what versioning and backups are for.
- It assumes that copies fail independently. Real systems are exposed to correlated failures: one bug in the software that every copy runs, or one stolen credential.
What happens if the data centre burns down?
Section titled “What happens if the data centre burns down?”A company takes a full backup every night. The backup is stored on a disk in the same room as the database. Fifteen hours after the last backup finished, the building is destroyed by a fire.
The database is gone and the backup is gone with it. Nothing survives, because the backup was protected against the failures that happen to a disk and not against the failure that happened. The same company, with the backup copied to another site each night, would have recovered the data as of the last backup. It would have lost 15 hours of writes, since the backup was 15 hours old when the fire came: the RPO, here, was up to 24 hours, and this fire fell at 15 hours.
To lose less, the writes would have to be sent to the second site as they happen, and then the cost is in the write path: a network round trip before each confirmation. Each step toward durability moves cost into the path of every write. Durability is bought, and what it costs is time on every write and money for every copy.
Check what you have learnt
Section titled “Check what you have learnt”Check your understanding: durability
This quiz needs JavaScript to check your answers.
- Durability is whether data survives the failures it was meant to survive. Availability is whether you can reach it now. They are different properties.
- A write is durable only once it is on storage that survives the failures you care about, in enough independent places. A confirmation sent earlier is a promise the system cannot yet keep.
- Each protection covers certain failures: a log covers a crash, a replica covers a lost machine, a backup kept elsewhere covers a lost site, and only something that keeps the past, a backup or versioning, covers a mistake.
- A replica copies mistakes. A backup protects against what it is kept apart from.
- Eleven nines is a design target for hardware loss: 10,000,000 objects would lose about one every 10,000 years. It does not cover deletion by mistake, and it is not a guarantee.
- Durability costs time on every write and money for every copy.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.