Archival sounds like a solved problem: move old rows somewhere else, delete them from the working table, done. It's solved right up until the first time a job fails halfway through, or someone asks "wait, can we get that record back?" six months later.
Start with the questions archival has to survive
- What happens if the job is killed mid-run?
- Can someone restore a single archived record without restoring everything around it?
- How do you prove, months later, that a specific row was archived correctly and not silently dropped?
If the design can't answer these cleanly, it's not an archival system — it's a delete script with extra steps.
Idempotency is the whole game
Every archival job in the system I built can be re-run safely. It doesn't ask "has this ever run before" — it asks "is this specific record already archived," record by record, before acting on it. That single design choice removed an entire category of 2am incidents, because a job crashing halfway through just means running it again.
function archiveRecord(record) {
if (archiveStore.exists(record.id)) return SKIPPED;
archiveStore.write(record);
sourceStore.markArchived(record.id);
return ARCHIVED;
}Soft-delete first, hard-delete later
Records are never immediately purged from the source table. They're flagged, archived, verified, and only removed from the live table after a separate, deliberately delayed cleanup job. That gap — usually a week — has saved more than one "we didn't actually mean to archive that" situation.
Make the audit trail the product, not an afterthought
Every archival run writes a structured log: what ran, what was skipped and why, what failed, timestamps for each. When someone asks "was invoice #4471 archived, and when," that's a query against the log, not a guess.
An archival system nobody can audit isn't actually an archival system — it's just a second place data can quietly disappear.
Where I'd push further next time
If I were rebuilding this from scratch today, I'd add automated periodic checksum verification between the source and archive stores, instead of relying on the audit log to catch drift after the fact. It's on the list.