Beyond Staging
Back to Notes
5 August 2026PostgreSQL2 min read

Archive the data, not the latency

How treating retention as architecture reduced database pressure and improved an API by 60%.

The database was carrying its own archive

A production database had accumulated historical records that remained important for audit and reference but were rarely needed on the primary request path. Reads became slower and the operational database carried the cost of data whose access pattern had changed.

Could the system preserve the data without forcing every live request to pay for it?

The distinction that unlocked the design

Data has temperature. New records are hot: frequently accessed, frequently updated, and latency-sensitive. Older records become warm or cold: still valuable, but accessed differently.

Keeping every temperature in one operational shape is like storing an archive cabinet in the doorway because somebody may need a file one day.

The migration had to be boring and resumable

The solution was not simply “move old rows.” It required defining eligibility, preserving referential meaning, making the process resumable, and ensuring that historical reads still had a clear path.

An archival workflow identifies records past the active window, transfers them in bounded batches, verifies the result, and only then removes them from the hot path. Idempotency matters because retries must not duplicate or lose data. Observability matters because silent lag gradually recreates the original problem.

The API layer also needs an explicit retrieval policy. Most calls should remain on the fast operational store. Historical access can take a separate path or merge results only when requested. After reducing the active working set and simplifying the common query path, response time improved by roughly 60% while the historical record remained available.

Why another index was not the answer

Indexes initially looked like the obvious answer. They can improve a query, but they do not resolve an unlimited mismatch between retention policy and operational workload. More indexes also increase write cost and maintenance overhead.

Archival was not a one-time cleanup either. Without a lifecycle policy and recurring process, it would become another emergency later.

What I check before tuning queries now

Performance problems are often data-shape problems disguised as query problems.

The durable lesson is to design the data lifecycle alongside the schema: what is hot, how long it stays hot, where it moves, how it can be recovered, and which request paths are allowed to pay for history.