A guard that refuses to make payroll data worse
Labour data refreshes replaced each day's rows wholesale. When a source occasionally omitted statutory-holiday rows, the refresh would silently delete correct data. A small guard changed the failure from silent to loud.
- The problem
- Refresh logic that trusts every response equally, so one incomplete response can overwrite days of correct records.
- The outcome
- Incomplete responses are rejected and logged; correct data is never replaced by less; the detection query runs every day.
The problem
A delete-then-insert refresh is simple and usually right. It is also exactly wrong when the source sometimes answers with less than it knows. In labour data the rows that went missing were statutory-holiday pay, which is both legally sensitive and easy to overlook until payday.
The pattern
- Before a refresh replaces a day, compare the incoming row types against what that day already has. If a category that existed before is absent now, and the day is not a correction window, refuse the refresh for that day and log it.
- Make the refresh atomic: the delete and the insert succeed or fail together, inside one transaction, so a failed insert can never leave a hole.
- Run a detection query daily that lists any holiday date missing its expected row types, so the guard itself is watched.
- Keep a backfill path that re-pulls specific days on request and goes through the same guard.
What it changes
The pipeline’s worst case becomes “yesterday’s data stays until we look”, instead of “a correct day was quietly replaced by a wrong one”. That is the difference between an alert and an apology.
What carries over
The compare-before-replace rule and the atomic write. They apply to any refresh that trusts a source it does not control.