Silent Data Corruption from an Off-By-One Migration

A database migration that ran successfully corrupted currency amounts for 6% of transactions due to a truncation error: amounts were converted with int() instead of being rounded.

Overview

A currency migration finished with no errors, and 11 days later reconciliation found $847,000 of revenue recorded short.

What happened

The payment platform stored money as integer cents. A migration converted a legacy float column, which held dollars with two decimal places, into that integer format. It passed every test environment and staging with a sample of production data.

The story has four beats.

  • The migration passed its tests and a staging run with a production sample.
  • The production run converted 14M rows in 22 minutes with zero errors.
  • Eleven days later, the monthly reconciliation found bad amounts.
  • The team recovered by replaying the event store.

Key concepts

  • Floating point precision error
  • Integer arithmetic for currency
  • Migration dry run with comparison
  • Event sourcing

Interview questions

  • How do you safely run a data-transforming migration on a large production table?

Sign up free to read the full topic

More War Stories topics

Start free on Cariara · Coding problems · System design studio