The sync job that ate its own data
A partial write looks like a successful one if you only check the exit code. Merging beats replacing, and the difference is invisible until it isn't.
Periodic syncs that pull from a third-party API share a failure mode: the upstream returns a subset, you write what you got, and fields the upstream doesn't know about are gone.
The shape of it#
# Replaces the whole document.
asset.specification = build_spec(vendor_payload)
asset.save()
If vendor_payload covers nine of twelve fields, the other three are now null.
Nothing errored. The job logged success. A week later a report is missing
values and nobody connects it to the sync.
Merge, don't replace#
asset.specification = {
**asset.specification, # keep what we already knew
**build_spec(vendor_payload), # overlay what the vendor just told us
}
That is the whole fix, and it is not sufficient on its own. Two more rules:
- Never let a sync write null. Absent means "no opinion", not "clear it". Strip empty values from the payload before merging.
- A shrinking payload is a signal. If the vendor returns materially fewer fields than last run, that is an upstream incident, not new data.
Detecting the damage after the fact#
Once a replace-style job has run, the data is gone and backups are the only source. What you can do cheaply is make the loss visible:
| Signal | Meaning |
|---|---|
| Field populated, then null, no user edit | A sync cleared it |
| Null rate jumps on one sync run | Upstream returned a subset |
| Record updated with fewer keys than before | Replace semantics in play |
The first of those is worth an alert. A field that goes from populated to empty without a human touching it is almost never correct.
