Field note · April 23, 2024

The `else` branch that ate 4% of revenue

A new payment type, a forgiving CASE statement, and six weeks of quietly wrong numbers.

1 min read ·Data quality ·quality sql

The payments team added buy-now-pay-later. New value in the payment_type enum. They shipped it on a Tuesday and did not tell us, because they had no idea we read that column.

Downstream:

sql
case
    when payment_type in ('card', 'wallet') then revenue_usd
    when payment_type = 'cash'              then revenue_usd * 0.98
    else 0
end as net_revenue

Every BNPL order contributed zero. It started at 0.4% of orders and grew. Net revenue drifted below where it should be by an amount that stayed inside normal weekly noise for a month.

Nothing failed. Row counts were right — the rows were all there, containing zeros. Uniqueness passed. Not-null passed. Freshness passed. Someone remarked that growth "felt soft".

Found in week six by a finance analyst reconciling manually for an unrelated reason.

The six controls that each would have caught it independently, and we had none:

  1. An accepted-values test on payment_type.
  2. An else that fails instead of returning zero.
  3. Category-proportion monitoring — the share landing in else went 0% → 4%.
  4. Scheduled reconciliation against billing.
  5. A contract with the payments team.
  6. Taking "feels soft" seriously as a bug report.

We now have all six. The general lesson is the one I keep coming back to: silent failures always live in a default. Audit your else branches, your coalesces, your fillna(0)s. A default never raises an error. It just produces a plausible number.