Move a permit service from free-text inspection duration to an integer minute field while reviewers keep editing cases. The database contains 2.7 million historical records. Six API replicas, two report workers, and a bounded connection ceiling already serve a busy morning queue. A new index must support organization-scoped open-case review. The release has four independent gates: enough connection capacity, safe transaction retries, a resumable and reconciled backfill, and a valid index with an observed query benefit. A failed gate pauses the dependent reader rollout; it does not silently change the response contract for current users.
Project: permit data change under live traffic
Build contract
- Budget every process pool under the database ceiling, reserve emergency slots, and bound acquisition waiting during rollout.
- Retry an entire aborted transaction after rereading current case state; persist one outbox intent and deduplicate delivery by operation identity.
- Backfill duration in bounded case-ID batches. Keep new writes current, replay a failed chunk safely, and reconcile every unresolved row before reader cutover.
- Build the queue index using the chosen engine's supported online procedure. Check validity, representative plans, write latency, and cleanup after cancellation.
Implementation checkpoint
function permitReaderCutover(backfillMismatches, indexValid, queueP95Ms, queueBudgetMs) {
return backfillMismatches === 0 && indexValid && queueP95Ms <= queueBudgetMs;
}
console.log(permitReaderCutover(1, true, 47, 63));
// Output: falseCost and boundaries
The backfill costs O(N) reads and up to O(N) writes for N historical cases; its chunk size controls lock and log pressure, not total work. The new index uses storage and adds write maintenance. Transaction retries consume extra reads and compute under contention. Pool waiting consumes request memory and time even before SQL begins. Separate metrics for connection acquisition, transaction aborts, backfill lag, index build progress, query p95, and write p95. Keep reviewer notes and personal case contents out of broad operational logs. The project is complete only when the old and new fields agree for every record the new reader may return.
Failure drill
Double API replicas during rollout and prove the connection budget still leaves maintenance access. Force opposing lock order on two assignment updates and verify one rolled-back attempt creates no external message. Crash the backfill after a batch commit but before a separate checkpoint and replay it. Edit an already processed case, then reconcile the new minute value. Cancel the concurrent index build and inspect its validity before any queue reader uses it. Finally, show that one mismatched duration keeps the feature gate closed even when the index is valid and queue latency is 47 milliseconds.
Acceptance checks
- No rollout or failover state can demand more connections than the tested ceiling.
- Retryable conflicts restart the whole transaction; committed side effects appear once.
- A crash, concurrent edit, or late import cannot leave an undetected duration mismatch.
- The index is valid and useful for representative tenants before the new queue depends on it.
Common Mistakes
- Scaling application replicas without scaling the connection budget.
- Advancing a backfill checkpoint before its data is durable.
- Releasing a query solely because its index definition exists.
Related lessons
Database Capacity and Online Change Operations; Connection Pool Budgets and Queue Admission; Transaction Retry, Deadlock, and Side-Effect Boundaries; Resumable Data Backfills and Reconciliation; Online Index Builds and Query Plan Release Gates.
