The Real Cost of a Slow Batch Load: What Cutting 4 Minutes to 45 Seconds Actually Taught Me

The Real Cost of a Slow Batch Load: What Cutting 4 Minutes to 45 Seconds Actually Taught Me

For most of 2025, the data engineering conversation I kept running into was about capability: can your pipeline handle the volume, can it handle the velocity, can it handle the next order of magnitude. Walking into 2026, the conversation I actually see everywhere now is different. It's about cost. Compute is not free, and "it eventually finishes" stopped being an acceptable answer for a job that runs on a schedule and burns money every time it does.

I hit that shift directly while building the Cloud ETL Ingestion Pipeline. The first working version loaded 1.6 million rows in just under 4 minutes. It worked. It also would have been embarrassing to leave alone.

Where the 4 minutes actually went

The instinct when a load is slow is to blame the data volume. That's rarely where the time goes. Profiling the pipeline showed three separate costs stacking on top of each other:

  • Reading the whole file into memory first. The original loader read the full source file before processing a single row, so peak memory scaled directly with file size, and nothing downstream could start until the read finished.
  • One connection, one row at a time. Every insert opened a round trip to PostgreSQL individually. At 1.6 million rows, that's 1.6 million network round trips before you've done anything else.
  • No encoding assumption. The loader tried a default encoding first and fell back on failure, which meant re-reading files that didn't match on the first pass.

The three fixes, in the order I made them

BEFORE                                  AFTER
Full-file read into memory              Chunked reading, fixed-size buffers
        |                                      |
        v                                      v
Peak memory scales with file size       Peak memory under 300MB regardless of file size

Row-by-row INSERT                       5,000-row batch execution
        |                                      |
        v                                      v
1.6M network round trips                ~320 round trips

Encoding: try, fail, retry              Automatic encoding detection up front
        |                                      |
        v                                      v
Wasted first-pass reads                 One read, correct encoding, first try

None of these three changes are exotic. Chunked reading, batched writes, and upfront encoding detection are close to first-year data engineering material. That's the point. The 4-minute version wasn't slow because the problem was hard. It was slow because nobody had gone back and asked why it was slow.

What it actually bought

After the three changes: full load time dropped from 4 minutes to 45 seconds, throughput landed at roughly 70,000 rows per second, and peak memory stayed under 300MB regardless of source file size, because chunked reading decoupled memory use from file size entirely. Extract, Transform, and Load also got split into independent Docker microservices with exponential-backoff retry, so a transient cloud failure in one stage no longer means restarting the whole job from zero.

The honest trade-off

Batching writes means you're no longer inserting rows the instant they're ready, you're holding them until a batch fills or a timeout fires. For a pipeline where "eventually consistent within a few seconds" is fine, that's a non-issue. For something like PesaGuard's reconciliation engine, where a transaction needs to be checked close to the moment it happens, batched writes are the wrong tool, which is exactly why that system stays event-driven instead. Performance tuning isn't a single set of best practices you apply everywhere. It's picking the right cost to pay for the latency your specific pipeline actually needs.

Share this article

Back to Blog See Projects