SkillSprout
Chapter 26 · Lesson 1
Intermediate
3 min read

Data Corruption and Checksum Basics

Overview

A checksum is a small value computed from a block of data. If you compute it again later and get a different value, the data has changed, usually because it was corrupted. Checksums turn silent damage into an error you can see and fix.

Detailed Notes

What is a checksum

A checksum is a short, fixed-size value computed from data so that any change to the data is very likely to change the value. Integrity is the property that data is unchanged and complete; a checksum is the cheapest way to check it.

The problem it solves

Hardware and networks are imperfect, so data gets corrupted by bit rot on disks and SSDs, bit flips in RAM, noisy cables or switches, and software bugs or half-finished writes after a crash. The worst kind is silent data corruption: no error is raised, the system just returns wrong bytes.

Picture a company storing invoices. One bit flips inside an invoice PDF on disk, and the disk reports nothing. The nightly backup and replication copy the damaged file, so every copy is identical and wrong. With a checksum stored next to each invoice and verified on every read, the first read would fail loudly and the system could fetch a good copy from another replica.

How it works

Start with the simplest checksum, parity. Take the bits 1011001. There are four 1s. Add a parity bit that makes the total even: the bit is 0, giving 10110010. If one bit flips in transit, the count becomes odd and we know something is wrong. If two bits flip, the count is even again and we miss it. Real checksums are much stronger versions of this idea.

The process: on write, compute the checksum and store or send it with the data. On read, compute it again over the bytes you got and compare: equal means almost certainly intact, different means corrupt, so reject the data, retry, or repair from another replica. Systems also scrub: periodically read and verify data nobody is reading, to catch rot early.

A checksum only detects. To repair, you need another good copy (replication) or error-correcting codes, which store extra redundancy so the original can be rebuilt. The checksum says which copy is bad, and a replica restores it.

Limits to remember: a collision (two different inputs with the same checksum) is always possible with a small fingerprint (for a 32-bit checksum, roughly 1 in 4 billion for a random change); data already wrong before the checksum was computed passes the check; and plain checksums do not stop a deliberate attacker (next lesson).

A simple example

Think of the total at the bottom of a shopping list. If someone changes one item, adding the prices again will not match the total, so you know something changed.

System design example

A file-sharing service stores uploads in 4 MB blocks, each with a checksum. A nightly scrubber recomputes them all. When one fails, the service reads a healthy replica, rewrites the bad block elsewhere and flags the disk as suspect. Users never see an error.

Summary

  • Corruption happens in disks, memory, networks and software, often silently.
  • A checksum is a small fingerprint recomputed to detect change.
  • Checksums detect; replicas or error-correcting codes repair.
  • Verify on write, on read, and in background scrubbing.

Architecture Diagram

Checksum verification on read
Architecture
Client
Storagedata + checksum
Verifyrecompute and compare
Replicarepair source

Compare stored and recomputed fingerprints; repair from a replica on mismatch.

  1. 1On write, a checksum is computed and stored with the data.
  2. 2On read, it is recomputed over the returned bytes; a match returns the data.
  3. 3A mismatch triggers a read from a replica and repair of the bad copy.

Common Interview Questions

Finished this lesson?

0 of 91 lessons done · 0% of the course