Batch Processing with LLMs: Practical Lessons in Concurrency, Cost, and Scheduling

    How should you tune concurrency, measure real throughput, and control costs when batch-processing with large language models? This article walks through validating output quality before optimizing speed, measuring effective throughput instead of raw request counts, separating API quotas from time-of-day capacity and local resources, calculating the true cost per valid result, and building a scheduling system that can throttle, recover, and gracefully wrap up batch runs.

    Validate Results First, Then Optimize Speed

    When task rules are clear, input structure is relatively stable, and each result can be checked automatically, several models may all meet your business requirements. In that situation, comparing single-response latency helps little. The more meaningful question is: given the same quality bar, which execution plan delivers the entire batch on time? And to get those valid results, how much quota does it consume, how many retries does it require, and how much manual review is needed?

    Start by separating deterministic computation from steps that require model judgment. Format conversion, numeric calculations, field mapping, and filtering based on well-defined rules should go to testable code. Models are better suited to extracting information from unstructured content, semantic classification, and summarization that fixed rules cannot cover. This reduces call volume and keeps precisely verifiable computations out of probabilistic models.

    Before formal load testing, prepare a sample set covering typical, boundary, and abnormal inputs, and define acceptance criteria up front. For structured extraction, for example, don’t just check whether the output parses—verify that required fields are present, that field values can be traced back to the source text, and that missing information isn’t silently fabricated. Automatically reject results that can be programmatically validated; keep human spot-checks for those that can’t. Only plans passing the same acceptance criteria are worth comparing on speed and cost.

    Measure Concurrency Gains with Effective Throughput

    Concurrency is the number of requests in flight at a given moment; throughput is the number of tasks completed per unit of time. They are not the same thing. After increasing concurrency, if per-request latency grows, rate limiting increases, or more results need retries, raw request counts may go up while the delivery rate of valid results doesn’t improve at all.

    A useful definition of effective throughput is the number of deduplicated tasks per unit of time that pass validation and are successfully persisted. If a task timed out, was retried, and ultimately produced one valid result, it counts once. To explain throughput changes, track these metrics separately:

    • Total completion time: from when the first task enters the queue to when the last valid result lands in storage, including queuing, retries, and waiting on slow tail tasks.
    • Latency distribution: record the 95th percentile in addition to the median. Even when the mean barely changes, rising tail latency can delay the whole batch.
    • Rate-limit rate, retry rate, and result pass rate: these respectively reflect the server’s acceptance capacity, extra workload, and output quality—don’t collapse them into one vague failure rate.
    • Resource usage: watch memory peaks, CPU load, local queue length, and write backlog to determine whether the bottleneck is remote requests or local processing.

    Load tests should ramp up in steps: start at low concurrency, increase one level at a time, and observe the stable range under similar input lengths, expected output sizes, and task mixes. If effective throughput has plateaued while rate limiting, tail latency, or resource usage keeps climbing, back off to the previous level. In production, leave headroom so that a burst of long documents or sudden resource usage by other processes doesn’t turn marginal stability into a persistent backlog.

    Treat API Quotas, Time-of-Day Capacity, and Local Capacity Separately

    The server-side limit on in-flight requests is just one constraint. It is not the concurrency you can sustain long-term, and you can’t directly derive delivery times from it. Real runs are also bounded by requests per unit time, tokens processed per unit time, network connections, result parsing, and storage write speed. Even when the API still accepts new requests, your local result queue may already be unable to keep up.

    Judging time-of-day capacity also requires real measurement. In different time windows, run the same sample set with the same validation criteria under similar load, and record stable throughput at each concurrency level. If one window consistently yields higher throughput, schedule large batches with loose deadlines there. If differences between windows are unstable, don’t bake an occasional peak into your delivery plan. Check price and capacity separately: no time-based price differences doesn’t mean consistent throughput, and a cheaper window doesn’t guarantee it can absorb more tasks.

    Local hardware capacity depends on how your program manages data, not just on memory size. Loading all inputs at once, keeping full responses in memory indefinitely, and retaining duplicate context for every task all inflate per-task memory. Safer practices: read inputs in chunks, cap queue size, write out results promptly, and reuse connections. Under sustained high CPU load or rising device temperatures, measure throughput after extended runs rather than using the first few minutes as your capacity baseline. If you change environments, re-run load tests—don’t extrapolate concurrency linearly from hardware specs.

    Calculate the Real Cost per Valid Result

    If billing is token-based and the bill separates cache-hit input, cache-miss input, and output tokens, multiply each category by its unit price and sum them. Cache hit rate is only one variable: when responses are long, inputs have low repetition, or failed validation triggers repeated generation, output and cache-miss input can still account for a large share of spend. Examining your bill’s composition before optimizing beats chasing cache hit rate alone.

    For pay-as-you-go tasks, measure unit delivery cost as “actual cost attributable to this batch ÷ deduplicated valid task count.” The numerator should include calls that were billed but produced no usable result, plus the cost of subsequent re-runs. If manual review and waiting time also affect delivery, list them separately so a low API bill doesn’t mask high rework costs. When compressing input, prioritize removing duplicated, useless material; when shortening output, keep the fields and evidence your acceptance checks require. If saved tokens buy you more rework, unit cost can actually rise.

    In subscription scenarios, distinguish new cash outlay from the opportunity cost of quota. Using already-paid, idle quota that is about to reset may add no current cash cost—but if that quota is reserved for more urgent tasks, spending it on the current batch may force later tasks onto pay-as-you-go billing. When scheduling, check remaining quota, reset times, projected usage of priority tasks, and the marginal cost of exceeding limits together. Whether a pay-as-you-go call is worthwhile should also depend on whether it helps you meet a deadline—not just on unit price or advertised concurrency.

    Build Scheduling That Can Throttle, Recover, and Wrap Up

    A reliable batch pipeline can be organized around four stages: task enqueuing, controlled invocation, validation and persistence, and failure triage. Give every task a stable identifier and record input version, attempt count, and processing state; on writes, deduplicate by task ID and processing version so retries don’t create duplicate results. After an interruption, recover from persisted state and process only unfinished tasks. For timed-out requests with unknown outcomes, check existing state first; only if you can’t confirm whether the remote call completed should you decide whether to resend, within your retry budget.

    Handle retries by error type. For transient network faults or temporary rate limiting, use backoff with random jitter so failed requests don’t all fire simultaneously; if the server returns an explicit wait time, follow it. For invalid input, insufficient permissions, or tasks failing validation repeatedly, stop retrying blindly and move them to an exception queue. Set both a batch-level budget and a per-task attempt cap: when the budget is hit, pause admitting new tasks and save progress, so runaway loops stop consuming quota.

    For scheduling, roughly estimate remaining time as “remaining tasks ÷ measured effective throughput,” then add buffer for long tasks, review, and re-runs. If different task types have noticeably different durations, estimate per category rather than treating all tasks as equal. High-priority tasks should get dedicated queues and reserved capacity so large batches can’t block them. When planning to switch execution channels, first re-verify output format and pass rates with representative samples—never assume identical inputs will produce directly interchangeable results across channels.

    Ultimately, the measure of a batch processing solution isn’t how high you push concurrency, but whether it delivers stably and predictably. Use representative samples to set the quality bar, use measured throughput to set concurrency and run windows, and account for cost per valid result. With this approach, even when task structure, quota, or billing rules change, you can re-run the same decision process instead of relying on the peak numbers of a single batch run.