Design a batch job orchestrator over a rate-limited LLM API
I was asked this
No reports yet. Sign in to say where you were asked it.
An AI system design interview question asked in Scale AI's system design round, last asked May 2025. It tests batch processing, rate limiting and retries.
Operators create jobs that each list up to 5,000 existing tasks. Every task is a JSON document in MongoDB, and the only way to finish one is a blocking call to an outside LLM provider that is rate limited and accepts at most 10 tasks per request. Design the job service and its workers so operators can watch each task's progress and fetch one final result per job. Training models and writing prompts are out of scope.
Requirements
- Functional: create an immutable job from up to 5,000 task IDs and get back a durable job ID; send pending tasks to the provider in requests of at most 10 within tenant and provider limits; read job and per-task state (queued, running, succeeded, failed, retryable); fetch each task's output and one final job summary.
- Non-functional: no task lost when a worker dies; one authoritative result per task even though a timed-out request may already have run at the provider (execution is at least once); fair sharing of the provider quota across jobs and tenants; progress visible within seconds.
Clarifying questions
- What are the provider's limits: requests per second, tokens per minute, concurrent calls, and are they per API key?
- Can tasks inside one provider request fail independently?
- Does the provider accept an idempotency key, or can a retry be charged twice?
- How long must results be kept, and can a job be cancelled?
- How many jobs run at once, and do tenants get guaranteed shares?
What a strong answer covers
- Data model: job (immutable task list, state, counters), per-task attempt records with lease owner and expiry, and results keyed by job and task so a duplicate write is a no-op.
- Scheduling: a dispatcher claims up to 10 ready tasks with a conditional update (leases), a token bucket per provider key and per tenant, and admission control when the backlog exceeds what the quota can drain.
- Failures: timeouts are ambiguous, so retries reuse the same attempt identity and the first committed result wins; retryable versus terminal errors; backoff with jitter; splitting a failed batch to isolate the bad task; a retry limit and a failed state.
- Progress: counters updated with the task state in the same write, or derived, plus a change stream or polling API for operators.
- Completion: the job turns terminal exactly once when its last task does, then writes the summary.
- Trade-offs named: batch size against latency and blast radius, leases against a message queue, polling against push.
Follow-ups
- The provider cuts your quota in half mid-run.
- A worker pauses for a minute after taking a lease, then wakes up and writes its result.
- Several providers with different prices and limits: how do you route?
- Priority jobs that must jump the queue without starving others.
Where it's asked
- Scale AI · System design · Last asked May 202560 min · Design discussion
What it tests
batch processing · rate limiting · retries · llm apis
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
