Large-Scale LLM Batch Processing Platform for Millions of Prompts

instacart · E-commerce · 2024 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Large-scale LLM batch processing infrastructure

Instacart needed a shared way for internal teams to run millions of LLM prompts for catalog cleanup, item enrichment, fulfillment routing, search relevance, and ML training workflows. Real-time provider APIs caused rate limits, throttling, delays, duplicated team-specific pipelines, fragmented solutions, and high cost. The platform had to batch requests, manage files, track costs, handle provider failure modes, support batch and real-time providers, and let teams process massive prompt jobs without becoming LLM infrastructure experts.

Constraints:

Architecture

Instacart built Maple, a reusable service that accepts CSV or Parquet input plus a prompt and returns an output file merged with AI responses. Maple orchestrates batching, provider-format encoding and decoding, file upload/download, job polling, retry handling, result merging, cost tracking, and progress tracking. It sits between internal applications and external model providers, proxies requests through Instacart's AI Gateway, logs cost and usage through Cost Tracker, stores inputs/outputs on S3, uses Parquet and PyArrow for efficient large-file processing, and relies on Temporal for durable execution. For providers without batch APIs, Maple uses the same interface while adding parallelization, exponential backoff, retry policies, and failure tracking over real-time APIs.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  workflows["Internal AI workflows"] --> maple["Maple service"]
  maple --> rpc["RPC API"]
  maple --> temporal["Temporal workflows"]
  maple --> storage["S3 Parquet storage"]
  storage --> pyarrow["PyArrow processing"]
  maple --> gateway["AI Gateway"]
  gateway --> tracker["Cost Tracker"]
  gateway --> providers["External LLM providers"]
  providers --> failures["Failure handling policies"]
  failures --> temporal
  providers --> gateway
  gateway --> maple
  maple --> storage
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Internal AI workflows Catalog, fulfillment, search, product enrichment, and ML training jobs that need bulk LLM processing. Maple service
Maple service Central orchestration layer for LLM batch processing, real-time provider scaling, retries, file management, and result merging. Internal AI workflows, RPC API, Temporal workflows, S3 Parquet storage, AI Gateway, Cost Tracker, External LLM providers
RPC API Submission and progress-tracking interface for Maple jobs. Maple service, Temporal workflows
Temporal workflows Durable execution engine for guaranteed completion, fault tolerance, and resume after exceptions. Maple service, RPC API, Failure handling policies
S3 Parquet storage Storage for input batch files, provider results, and merged outputs using compressed Parquet files. Maple service, PyArrow processing
PyArrow processing Efficient file processing layer for CSV/Parquet inputs and large data access. Maple service, S3 Parquet storage
AI Gateway Internal abstraction layer for communicating with multiple LLM providers. Maple service, External LLM providers, Cost Tracker
Cost Tracker Usage and spend logging by job and team. AI Gateway, Maple service
External LLM providers Batch or real-time model providers that process prompt batches and return results or task-level failures. AI Gateway, Failure handling policies
Failure handling policies Tailored retry logic for expired, rate-limited, refused, and invalid-image task failures. Temporal workflows, External LLM providers, Maple service

Data flow

Internal applications submit a CSV or Parquet file and prompt to Maple. Maple splits large inputs into smaller Parquet batches on S3, encodes each batch into provider-specific request files, uploads them through the AI Gateway, polls provider jobs, downloads results to S3, matches responses back to inputs, creates per-batch Parquet result files, and merges them into a final output. Cost Tracker records spend by job and team. Temporal preserves long-running job state so failures can resume from the last completed step. Failed task classes such as expired, rate-limited, refused, or invalid-image requests flow into tailored retry policies.

4 supporting quotes
“Maple accepts a CSV or Parquet file and a prompt as input and delivers an output file with the input merged with the AI response.”article, stated
“Large CSV files are split into smaller Parquet batch files, and stored on S3 to avoid costly database usage.”article, stated
“Maple uploads each file, polls for completion, and when complete, downloads results to S3.”article, stated
“It then matches responses to inputs, creating per-batch Parquet result files.”article, stated

Why this architecture

Maple centralizes LLM bulk processing because repeated team-owned scripts were creating duplicated effort and inconsistent operations. Batch processing is cheaper and better suited to million-prompt workloads than real-time APIs, but provider batch interfaces are operationally complex. Temporal is used because long-running jobs need durable resume semantics. S3 and Parquet replace database task storage because large files need cheaper storage, compression, faster load/save, and non-linear access.

4 supporting quotes
“multiple teams across the company were independently writing similar code to handle their AI workflows”article, stated
“Without shared tooling, each team would be forced to implement this workflow from scratch.”article, stated
“Temporal’s fault tolerance safeguards data integrity and guarantees job completion.”article, stated
“We moved task data storage from the database to S3 using Parquet files, which improved load/save speed and reduced cost.”article, stated

Models used: LLM provider batch APIs · LLM provider real-time APIs · AI Gateway · Temporal · PyArrow · Parquet · orjson

Scale

Alternatives considered (roads not taken)

Use real-time LLM APIs for million-prompt workloads

Rejected because: Real-time APIs were rate-limited, required throttling, introduced delays, and were not designed for that scale.

“real-time LLM provider APIs just aren’t designed for that scale.”article, stated
“Real-time LLM calls were frequently rate-limited, forcing us to throttle requests to stay within token limits.”article, stated

Let each team build its own LLM batch workflow

Rejected because: That produced duplicated effort, fragmented solutions, and repeated implementation of provider batch mechanics.

“multiple teams across the company were independently writing similar code to handle their AI workflows”article, stated
“leading to duplicated effort and fragmented solutions.”article, stated

Store task data in the database

Rejected because: Database storage became inefficient at scale, so Maple moved task data to S3 Parquet files.

“We moved task data storage from the database to S3 using Parquet files”article, stated
“which improved load/save speed and reduced cost.”article, stated

Only support providers with batch APIs

Rejected because: Instacart needed the same simple interface for providers that only expose real-time APIs.

“Not all LLM providers offer a batch interface, some only support real-time APIs.”article, stated
“we extended Maple to abstract the complexity of handling large-scale real-time prompts”article, stated

Patterns

batch-offline-processing (processing)

Maple turns large CSV/Parquet prompt sets into provider batch files, processes millions of prompts asynchronously, and merges results back into output files.

“makes large-scale LLM batch processing fast, cost-effective”article, stated
“Splits large input files into smaller batches.”article, stated

durable-execution (reliability)

Temporal lets long-running LLM batch jobs resume exactly where they left off after exceptions or provider failures.

“Temporal’s fault tolerance safeguards data integrity and guarantees job completion.”article, stated
“jobs can resume exactly where they left off without losing any work.”article, stated

cost-aware-routing (cost)

Maple routes through batch APIs when available, tracks spend per job and team, and saves up to 50% relative to real-time calls.

“Tracks detailed cost usage for each team.”article, stated
“saving up to 50% on LLM costs compared to standard real-time calls”article, stated

fallback-degradation (failure-handling)

Maple uses tailored retry policies for expired, rate-limited, refused, and invalid-image failures, including provider-specific real-time fallback handling.

“LLM providers return various types of task-level failures, each requiring tailored handling logic”article, stated
“automatic parallelization, exponential backoff on rate-limited requests, intelligent retry policies, and failure tracking”article, stated

observability-tracing (operations)

Maple exposes job progress, AI Gateway cost logging, per-job/team spend, and failure tracking so bulk prompt jobs remain traceable.

“The AI Gateway is also responsible for integrating with the Cost Tracker, logging detailed usage and spend per job and team.”article, stated
“prompt jobs are fully traceable, cost-monitored, and fault-tolerant.”article, stated

tool-use-orchestration (platform)

Maple orchestrates provider batch APIs, real-time APIs, AI Gateway, Cost Tracker, S3, Parquet, PyArrow, Temporal, retries, and result merging behind one interface.

“serving as the orchestration layer between internal teams and external model providers.”article, stated
“the underlying platform will handle the complexities of interacting with real-time APIs at scale.”article, stated

Tradeoffs

LLM processing mode

Chose Batch-first processing through Maple over Direct real-time API calls for bulk workloads.

Rationale: Batch APIs fit million-prompt workloads better and can reduce LLM costs by up to 50%, while real-time calls hit rate limits and throttling.

“real-time LLM provider APIs just aren’t designed for that scale.”article, stated
“saving up to 50% on LLM costs compared to standard real-time calls”article, stated

Storage layer

Chose S3-backed Parquet files over Database-backed task storage.

Rationale: S3 and Parquet reduce database operations, improve load/save speed, compress files, and support fast access for huge datasets.

“Inputs and outputs are stored in S3, avoiding costly database operations.”article, stated
“compression reduces file sizes up to 25x compared to CSV.”article, stated

Failure handling policy

Chose Failure-class-specific retries over One generic retry policy for every provider error.

Rationale: Expired and rate-limited tasks can retry indefinitely, while refused tasks often repeat and are capped at two retries.

“Expired: Occasionally, the LLM provider fails to return results within 24 hours”article, stated
“Refused: The LLM provider can just refuse to execute your request”article, stated

Provider abstraction

Chose Same Maple interface for batch and real-time providers over Require teams to adopt different workflows per provider.

Rationale: Teams can keep CSV input/output workflows while Maple handles real-time parallelization, backoff, retries, and future migration to batch interfaces.

“while maintaining our simple CSV input/output interface.”article, stated
“the underlying platform will handle the complexities of interacting with real-time APIs at scale.”article, stated

Gotchas (what bit them)

Provider batch APIs are cheaper but operationally involved.

Root cause: Batch workflows require encoding, upload, monitoring, download, parsing, and retrying failed prompts.

Resolution: Centralize those mechanics in Maple instead of making each team implement them.

“batch workflows have a more involved process: encoding requests in a specific format, uploading them, monitoring job status, downloading result files”article, stated
“Without shared tooling, each team would be forced to implement this workflow from scratch.”article, stated

Large prompt files can turn database task storage into a bottleneck.

Root cause: High-volume jobs hit storage, memory, and processing limits as internal clients sent larger inputs.

Resolution: Move task data to S3 Parquet files, stream processing, and faster JSON handling with orjson.

“we hit storage, memory, and processing limitations.”article, stated
“We moved task data storage from the database to S3 using Parquet files”article, stated

Failures are inevitable in tens-of-millions prompt processing.

Root cause: Network issues, provider failures, bugs, expiration, rate limits, refusals, and invalid images can occur mid-run.

Resolution: Use Temporal for resume semantics and separate retry policies by failure class.

“Running batch jobs at this scale means errors are inevitable — network issues, provider failures, or bugs can happen mid-run.”article, stated
“LLM providers return various types of task-level failures, each requiring tailored handling logic”article, stated

Invalid images create a retry-cost tradeoff.

Root cause: Checking every image in a large batch adds significant overhead, but bad URLs can cause request failures.

Resolution: Retry invalid-image tasks optionally, and only check image existence on the second attempt.

“Invalid images: Sometimes the requests have an image URL that is invalid.”article, stated
“We don’t do this the first time around because checking each image in a large batch can add significant overhead.”article, stated

Provider interface differences can leak complexity to product teams.

Root cause: Some providers expose batch APIs and others only expose real-time APIs.

Resolution: Hide provider differences behind the same Maple CSV input/output interface and switch providers transparently when batch support appears.

“Not all LLM providers offer a batch interface, some only support real-time APIs.”article, stated
“Later on, if a provider starts offering a batch interface, we can switch it over seamlessly without our users needing to do anything.”article, stated

Evaluation

Instacart evaluates Maple through operational throughput and completion metrics, cost tracking, progress tracking, provider-failure handling, and real-world batch statistics collected from hundreds of large batches.

Metrics: prompt processing speed · batch completion time · job size versus completion time · cost usage per job and team · up to 50% LLM cost savings · ~580-batch sample · 40-50K tasks per batch · 2.6 average tasks per second · most batches complete under 12 hours · 10M+ prompt job support

4 supporting quotes
“We have compiled stats from a sample set of ~580 batches with 40–50K tasks per batch”article, stated
“LLM batches average 2.6 tasks per second. Note that processing time can vary based on the prompt, especially when including images with the prompt”article, stated
“most batches complete in under 12 hours, with occasional batches that take almost a full day”article, stated
“* Cost tracking: Tracks detailed cost usage for each team. By managing these steps, Maple eliminates the need for teams to write custom batch processing code”article, stated

Outcomes

The source reports millions of items/customers/deliveries, million-prompt workflows, 50,000-prompt or 200MB batch limits, at least 20 batches for a million-prompt job, 25x Parquet compression compared with CSV, ~580 observed batches of 40-50K tasks, 2.6 tasks/sec average throughput, most batches under 12 hours, 10M+ prompt jobs, up to 50% LLM cost savings, and annual process costs reduced from hundreds of thousands to thousands.

4 supporting quotes
“Teams can now explore new ideas, automate repetitive work, and ship faster — without becoming LLM infrastructure experts.”article, stated
“Maple has become part of the backbone of our AI infrastructure at Instacart”article, stated
“Many processes have been reduced from hundreds of thousands of dollars per year to just thousands of dollars per year.”article, stated
“These optimizations allowed Maple to scale efficiently to 10M+ prompt jobs.”article, stated