Sub topic 2
Workloads that Fit Offline Processing
This chapter assumes you can write basic Python with file I/O and JSON, have called an LLM chat API before, and know what tokens and rate limits are. You don't need to know the batch file format yet. Later chapters cover it.
The question here is which jobs belong in a batch and which don't. A batch API accepts a large set of requests, processes them within a completion window (for example 24 hours), and returns the results as files. Nobody is waiting on any single answer, so the workload has to tolerate that.
The Three Questions
Ask these about a candidate workload, in order.
- Does a person or a downstream system wait on each result? If a user is watching a chat window, use synchronous calls. If the results feed a report, a dataset, or a database table, batch is a candidate.
- Are the requests independent? Each batch request runs on its own. Request 50 cannot read the answer to request 49. Chains of dependent calls, such as an agent loop that picks its next step from the last result, don't fit. You can still batch each stage of a pipeline separately.
- Is the full input known up front? A batch needs a finite file of requests at submission time. A steady stream of events fits only if you can collect them into groups and accept the delay.
If the answer to the first question is "no" and the other two are "yes," the workload is a good fit.
Common Fits
| Workload | Why it fits |
|---|---|
| Classifying a backlog of tickets, reviews, or emails | One prompt template applied to thousands of independent items |
| Summarizing an archive of documents | Each document stands alone and nobody needs it immediately |
| Extracting structured fields from text | The output is loaded into a table later |
| Running an evaluation set against a model | Hundreds or thousands of fixed test prompts, compared afterward |
| Generating synthetic data or embeddings for a corpus | Large volume, no deadline per item |
| Re-processing old data after a prompt or model change | A one-off bulk job |
Common Misfits
| Workload | Why it doesn't fit |
|---|---|
| Interactive chat or autocomplete | A person waits for each reply |
| Fraud checks during a payment | The decision is needed in seconds |
| Multi-step agents | Each step depends on the previous result |
| Tiny jobs of a few requests that are needed now | Waiting for the window gains almost nothing |
A Quick Decision Helper
The function below encodes the three questions. It's deliberately simple. Its purpose is to make your reasoning explicit when you review a new job.
def fits_batch(someone_waiting: bool, independent: bool, input_known: bool) -> str:
if someone_waiting:
return "Use synchronous calls: results are needed immediately."
if not independent:
return "Use synchronous calls, or batch each independent stage separately."
if not input_known:
return "Collect requests into groups first, then batch each group."
return "Good fit for a batch API."
print(fits_batch(someone_waiting=False, independent=True, input_known=True))
print(fits_batch(someone_waiting=True, independent=True, input_known=True))
print(fits_batch(someone_waiting=False, independent=False, input_known=True))Where Workloads Are Mixed
Many real systems have both kinds of work. A support product might answer customers live with synchronous calls, then classify the whole day's tickets overnight in a batch. Treat these as two separate paths that share prompts and code but not scheduling.
Common Mistakes
- Batching because it's cheaper, without checking the deadline. Lower cost is a benefit of batching, but only for work that can wait. The next chapter covers the trade-off in detail.
- Hiding a dependency. If a prompt needs the output of another request, the batch will not supply it. Split the work into two batches, run in sequence.
- Using batch for a three-request job. Setup and polling code costs more effort than it saves.
Exercise
A team wants to (a) label 200,000 archived support tickets by topic, (b) show a suggested reply while an agent types, and (c) run a 1,500-prompt evaluation set after each model change. Which of these fit a batch API, and why?
Show answer
(a) and (c) fit. Both are large sets of independent requests with known inputs, and nobody waits on any single result. (b) does not fit, because a person is waiting on each reply and needs it within seconds.