Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Reliability and Failure
Lesson 16 of 24

Data integrity: checksums, idempotency and double entry

Make sure retries, crashes and bugs cannot silently corrupt, duplicate or lose data.

20 min read

Availability is not enough

A system that stays up while writing wrong data is worse than one that goes down. Corruption replicates faithfully to every replica and into every backup taken after it, so it can be far harder to undo than an outage. Integrity rests on three questions: did the bytes arrive intact, did each operation apply exactly once, and do the numbers still add up? Each needs its own mechanism.

Checksums end to end

Compute a checksum (CRC32C, SHA-256) when data is created, store it with the data, and verify it whenever the data is read, copied or restored. Network and disk-level checks are not enough: TCP's 16-bit checksum misses some errors, and bugs in your own code can corrupt data between layers. Object stores verify checksums on upload; file sync systems hash every chunk, which doubles as deduplication. Background scrubbers re-read stored data periodically to catch bit rot before the last good copy is gone.

Idempotency keys

Timeouts and retries mean the same request can arrive twice. The client generates a unique idempotency key per logical operation and sends it with every attempt. The server stores the key with the result in the same transaction as the effect, and if the key is seen again it returns the stored result instead of acting again. Keys must outlive the client's retry window, typically 24 hours or more. Without this, a retried transfer becomes a double payment.

Double entry and reconciliation

Financial systems record every movement twice: a debit on one account and an equal credit on another, written in one transaction. Balances are derived from the append-only ledger, never edited in place, so the sum of all entries is always zero and any bug that breaks that invariant is detectable.

  • Never update a balance without an entry that explains it
  • Reverse mistakes with new entries; never delete history
  • Run reconciliation jobs that compare your ledger with the bank or provider and alert on any difference

Key takeaways

  • Corruption replicates and gets backed up; integrity needs explicit defences
  • Verify checksums end to end on write, read, copy and restore
  • Idempotency keys stored with the effect make retries safe
  • Append-only double-entry ledgers plus reconciliation make money errors detectable

Sign in to track lessons and earn badges.

Caching under failure: stampedes and thundering herdsConsistency under failure: split brain and fencing

Challenge checkpoint

Course: 0/24 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 6/10Design an Order Fulfillment SagaMake every saga step idempotent and compensatable so retries and crashes never double-charge or lose an order.Medium
All 10 challenges →