When Batch Processing Makes Sense

Ma Mahalakshmi V Updated 16 Sep 2026
7 min read ·Lesson 125 of 224

When Batch Processing Makes Sense

Every workload that calls a language model falls somewhere on a spectrum between two extremes. At one end sits a user typing a question into a chat interface and waiting for an answer within a second or two. At the other end sits a system that needs to process ten thousand support tickets, product descriptions, or research documents sometime before tomorrow morning, with nobody watching the screen while it runs. The first case is a real-time workload. The second is a batch workload. Choosing the wrong processing model for a given job is one of the most expensive architectural mistakes you can make when building on the OpenAI SDK, because it affects cost, reliability, code complexity, and how the rest of your system has to be designed.

Real-Time vs. Batch: The Core Distinction

A real-time (synchronous, interactive) request is one where a human or another time-sensitive system is waiting for the response right now. The defining constraint is latency: the user experience degrades if the response takes too long, so you optimize for speed, usually processing one request at a time or a small number in parallel, and you pay standard API pricing per token.

A batch workload is one where the total time to finish all the work matters far more than the time to finish any single item. Nobody is staring at a spinner waiting for item number 4,732 out of 10,000. This shifts the optimization target from per-request latency to overall throughput and cost efficiency.

The OpenAI SDK gives you two fundamentally different tools for these two situations:

AspectReal-time (client.responses.create)Batch (Batch API, covered in Unit 12)
Optimizes forLow latency per requestHigh throughput, low cost per item
Typical costStandard per-token pricingReduced pricing (roughly half, at the time of writing)
TurnaroundSecondsMinutes to 24 hours
Failure handlingRetry immediately, inlineAggregate error file, reviewed after the run
Concurrency modelA handful of parallel calls at mostThousands of items submitted as one job

Note: Exact Batch API pricing discounts and turnaround windows change over time. Confirm current numbers against the official OpenAI documentation before quoting them to stakeholders or building cost models around them.

Unit 12, Lesson 5 already covered the mechanics of submitting a batch job — building a JSONL file, uploading it, polling for completion, and matching custom_id values back to your original inputs. This lesson does not repeat that. It answers a different, earlier question: how do you decide, before writing any code, whether a given workload should be batch or real-time in the first place?

The Decision Criteria

Four questions reliably separate batch-appropriate workloads from real-time ones.

1. Is there a human waiting synchronously for this specific response?

If a person submitted a form and is looking at a loading spinner, you cannot make them wait an hour. That rules out batch immediately, regardless of volume. Chat assistants, live customer support tools, and autocomplete features are almost always real-time by necessity.

2. Is the volume large enough that per-request overhead matters?

Sending five requests a day gains nothing from batch infrastructure — the engineering cost of building a pipeline, tracking job state, and handling asynchronous results outweighs the savings. Batch processing earns its complexity once you are dealing with hundreds or thousands of items in a single run, where the discounted pricing and the ability to submit everything in one job produce a real difference in cost and operational simplicity.

3. Can the work tolerate delayed results?

If "the summaries will be ready sometime tonight" is an acceptable answer, you have a batch workload. If someone needs the summary of the document they just uploaded before they can continue their task, you don't.

4. Is the work naturally describable as a fixed, enumerable set of independent items?

Batch processing works best when you can enumerate the full list of inputs up front — a table of 50,000 product descriptions to classify, a folder of 10,000 support tickets to tag, an export of a year's worth of transcripts to summarize. It works poorly for open-ended, continuously arriving streams where you would be constantly starting new jobs to catch a handful of new items, because job submission and polling both carry fixed overhead that only pays off at scale.

A Practical Example: Estimating Whether Batch Is Worth It

Suppose you need to classify customer reviews into sentiment categories. Here is a simple way to make the batch-vs-real-time decision data-driven rather than based on gut feeling:

from dataclasses import dataclass


@dataclass
class WorkloadProfile:
    item_count: int
    max_acceptable_delay_hours: float
    is_user_facing_synchronous: bool


def recommend_processing_mode(profile: WorkloadProfile) -> str:
    """Return 'batch' or 'realtime' based on simple, explicit thresholds."""
    if profile.is_user_facing_synchronous:
        return "realtime"

    # Below this volume, batch's fixed overhead (job setup, polling,
    # result reconciliation) isn't worth the discount it buys you.
    MIN_ITEMS_FOR_BATCH = 200

    if profile.item_count < MIN_ITEMS_FOR_BATCH:
        return "realtime"

    if profile.max_acceptable_delay_hours < 1:
        return "realtime"

    return "batch"


# Example usage
nightly_report_job = WorkloadProfile(
    item_count=8000,
    max_acceptable_delay_hours=12,
    is_user_facing_synchronous=False,
)
support_chat_reply = WorkloadProfile(
    item_count=1,
    max_acceptable_delay_hours=0.01,
    is_user_facing_synchronous=True,
)

print(recommend_processing_mode(nightly_report_job))   # "batch"
print(recommend_processing_mode(support_chat_reply))    # "realtime"

This function is intentionally simple — it is not meant to be a sophisticated model, but a concrete, inspectable decision policy. In a real system, MIN_ITEMS_FOR_BATCH should be derived from your own numbers: compare the discounted batch price per token against your standard price, factor in the engineering time to maintain a batch pipeline, and find the volume at which batch actually saves money net of that overhead. The important habit this example demonstrates is turning a vague judgment call ("this feels like it should be a batch job") into an explicit, reviewable policy that a teammate can read and adjust.

Mixed Workloads

Many real systems are not purely one or the other. A common pattern is a hybrid pipeline: the bulk of predictable, high-volume work (nightly re-classification of a product catalog, for instance) runs through the Batch API, while a smaller real-time path handles urgent, user-triggered requests (a merchant needing one product classified immediately after upload). Both paths often share the same prompt templates and parsing logic — only the submission and result-collection mechanism differs. When you design the pipeline in Lesson 2 of this unit, keep this separation in mind: the business logic of building a request and interpreting a response should not need to know whether it will eventually be submitted synchronously or as part of a batch job.

Common Mistakes

  • Building a batch pipeline for a workload that's actually small or urgent. Teams sometimes reach for the Batch API because it looks more "production-grade," then discover they've added a 24-hour worst-case turnaround and a polling loop to a workload that only ever has a few dozen items. Match the tool to the actual volume and latency requirement, not to what looks impressive in an architecture diagram.
  • Ignoring the batch turnaround window in downstream planning. The Batch API does not guarantee completion within any fixed short window. If a report absolutely must be ready by 8 AM, either submit early enough to absorb the worst case or build a fallback that finishes the remaining items via real-time calls if the batch job is still running past a deadline.
  • Treating "large volume" as the only criterion. A workload can be large and still need real-time processing — for example, if it must react to results item-by-item as they arrive (triggering downstream actions per item) rather than being processed as a single reviewable output at the end.

Best Practices

  • Write down your decision criteria before building anything. A short, explicit policy like the recommend_processing_mode function above prevents the choice from being re-litigated informally every time a new workload comes up.
  • Measure actual per-item cost and turnaround before committing. Run a small pilot batch and a small real-time sample of the same workload, and compare real numbers instead of assuming the discount will be worth the added complexity.
  • Design for hybrid from the start when there's any chance you'll need it. Keeping request-building and response-parsing logic independent of the submission mechanism costs little upfront and saves a painful refactor later when a "purely batch" workload grows an urgent real-time requirement.

0 Comments

Reviewed before they appear

No comments yet.

OpenAI SDK
Introduction to the OpenAI SDK Setting Up Python Creating an API Key Your First Call — client.responses.create() and response.output_text Understanding Billing, Credits, and What a Request Costs Why Responses Replaced Chat Completions Anatomy of a Request: model, input, and instructions Anatomy of a Response: The Typed output Array, Not Just Text Roles: User, Assistant, and Developer/System Choosing a Model, and Reading the Models Page Instead of Memorizing Names Instructions vs. Input Writing Prompts That Get Consistent Results Few-Shot Examples Reasoning Models and the reasoning Parameter Debugging a Prompt That Misbehaves Why Streaming Matters for User Experience stream=True and Iterating Over Events Handling the Event Types You Actually Care About Background Mode for Long-Running Jobs Project — Add Live Streaming to Your Chatbot The Problem With Parsing Free Text JSON Schema and Strict Mode Pydantic Models With the SDK's Parse Helpers Handling Refusals and Validation Failures Project — A Resume-to-JSON Extractor Working With input_image input_file, PDFs, and the Files API Image Generation Speech-to-Text and Text-to-Speech Project: A PDF Question-Answering Script What Function Calling Is Defining a Tool Schema The Full Loop Multiple Tools Errors, Timeouts, and Untrusted Arguments Project: A Weather Assistant Web Search File Search and Vector Stores Code Interpreter Remote MCP Servers and Connectors Project: A Research Assistant What an Embedding Is, Without the Maths Generating and Storing Embeddings Similarity Search From Scratch Hosted Vector Stores vs. Rolling Your Own A Small RAG App Over a Folder of Notes Agents vs. a Single API Call — When You Need One pip install openai Giving Agents Tools Handoffs and Multi-Agent Triage Guardrails and Approvals Tracing and Observing What Your Agent Did A Multi-Agent Support Desk Error Codes and What Each One Means Retries, Timeouts, and Backoff Rate Limits and Spend Limits Prompt Caching and Cost Optimisation The Batch API for Bulk Work Async Clients and Concurrency Moderation and Safety Best Practices Designing the App Backend With FastAPI Streaming to a Simple Frontend Deploying and a Cost/Safety Checklist Why Web Search Is Useful for Current Information Using the Web Search Tool with the Responses API Configuring Search Behavior for Application Use Cases Understanding Citations and Source Attribution Where to Go Next Building a Research Assistant with Web Search Combining Web Search with Structured Outputs Handling Conflicting or Low-Quality Web Sources Reducing Unsupported Claims with Grounded Generation Testing Freshness-Sensitive AI Answers Production Considerations for Web-Grounded Applications Understanding File Search and Retrieval-Augmented Generation Creating and Organizing Vector Stores Uploading Documents for Retrieval Connecting Vector Stores to Responses API Requests Designing Document Metadata and Filtering Strategies Building a PDF Question-Answering Application Improving Retrieval Quality With Better Document Preparation Handling Missing Evidence and Retrieval Failures Combining File Search With Web Search Building a Production Knowledge-Base Assistant What the Code Interpreter Tool Is Designed For Running Python-Based Analysis Through the OpenAI SDK Uploading Datasets for Analysis Analyzing CSV and Spreadsheet Data Generating Charts and Data Summaries Handling Generated Files and Downloadable Artifacts Building a Data-Analysis Assistant Combining Code Execution with Structured Outputs Validating Generated Calculations and Results Security and Sandbox Considerations for Code Execution Understanding Multimodal Input with the OpenAI SDK Sending Images to a Model Image Analysis from URLs and Uploaded Files Extracting Text and Information from Screenshots Building an Image-Question-Answering Application Combining Image Input with Structured Output Analyzing Multiple Images in One Request Handling Image Quality and Input Limitations Designing Multimodal Prompts for Reliable Results Building a Practical Vision-Powered Python Application Understanding Speech-to-Text and Text-to-Speech Workflows Transcribing Audio with the OpenAI SDK Working with Uploaded Audio Files Handling Timestamps and Transcription Metadata Building a Meeting Transcription Workflow Generating Spoken Responses from Text Handling Long Audio and Processing Failures Combining Audio with Text and Tool Calling Building an End-to-End Python Voice Application What Embeddings Are and When to Use Them Generating Embeddings With the OpenAI API Preparing Text for Embedding Comparing Vectors With Cosine Similarity Building a Simple Semantic Search Engine in Python Storing Embeddings in a Database Metadata Filtering for Semantic Search Chunking Strategies for Better Retrieval Evaluating Semantic Search Quality Building a Document Similarity Application When Batch Processing Makes Sense Designing Large-Volume AI Processing Pipelines Using Asynchronous Python with the OpenAI SDK Running Concurrent Requests Safely Controlling Concurrency and Avoiding Rate Limits Tracking Batch Job Progress Handling Partial Failures in Bulk Workloads Retrying Failed Items Without Duplicating Successful Work Designing Resumable AI Processing Jobs Building a Production Batch-Processing Pipeline Batch Processing Makes Sense Large-Scale AI Processing Pipelines Async Python with OpenAI SDK Safe Concurrent Requests Concurrency & Rate Limits Batch Progress Tracking Partial Failure Handling Safe Retry Handling Resumable AI Jobs Production Batch Pipeline System–User Data Separation Reusable App Instructions Prompt Templates & Variables Extraction & Classification Prompts Summarization & Transformation Prompts Explicit Output Requirements Prompt Version Management Prompt Testing & Evaluation Reusable Python Prompt Library API Key Security Secure API Key Storage Secure Secret Management Prompt Injection Prevention Trusted vs. Untrusted Content Tool Argument Validation Sensitive Data Handling Secure Logging AI Action Authorization Production AI Security Checklist Why AI Applications Need Evaluation Beyond Unit Tests Unit Testing OpenAI SDK Integration Code Mocking API Responses in Python Tests Testing Structured Outputs Against Schemas Testing Tool-Calling Workflows Building a Small Evaluation Dataset Measuring Accuracy, Consistency, and Failure Rates Regression Testing Prompts and Model Changes Human Evaluation Versus Automated Evaluation Creating a Repeatable Evaluation Pipeline AI Request Monitoring Token Cost Management Usage Metrics Design Reducing Model Calls Prompt & Context Optimization Model Selection & Optimization AI Caching Strategies Interactive Latency Optimization Usage Dashboards & Budget Alerts Performance & Cost Checklist Every API Call Starts Fresh Fixing API Statelessness Server-Side Conversation Memory Limits of Response Chaining What We're Building Conversation Memory Challenges Preparing an OpenAI SDK Application for Deployment Environment-Specific Configuration for Development and Production Deploying a Python AI Service with Docker Container Health Checks and Startup Configuration Managing Secrets in Cloud Deployments Background Workers for Long-Running AI Tasks Queues and Asynchronous Job Architectures Scaling AI Workloads Horizontally Monitoring Production Incidents and Failures Production Deployment Checklist for OpenAI SDK Applications Reusable OpenAI Service Classes AI Client Dependency Injection Typed AI Responses Python Configuration Management AI Request Decorators Centralized AI Error Handling Clean SDK Abstractions Reusable OpenAI Utilities Internal AI Python Libraries SDK Integration Maintenance Production AI Chatbot Document Q&A System Web Research Assistant Customer Support Agent AI Data Analysis Assistant Image Analysis App Meeting Transcription & Summary Semantic Document Search Multi-Tool AI Agent Production OpenAI SDK App Why "It Looked Fine When I Tested It" Isn't Enough Timing Note Status Note Pre-Decision Status Note Current Availability Note
Ask about this post
AI Ask about this post

Ask questions about When Batch Processing Makes Sense and get answers drawn from it.

Signed-in readers only.