How do you design a bulk/batch API and handle partial failures?
⚡ Short Answer
Accept an array of items, cap the batch size, and decide the failure model: all-or-nothing (transactional) or best-effort with per-item results. For best-effort, return a per-item status array (or 207 Multi-Status) so clients know exactly which items succeeded/failed and can retry just the failures.
☕Coffee Chat Question
Concept Made Simple
“How do you design a bulk/batch API and handle partial failures?”
🧠Mind Map Answer
Remember It Faster
⌨️Hands-on Keyboard
Learn by Doing
POST /orders/batch
{ "items": [ {...}, {...}, {...} ] }
-->
{ "results": [
{ "index":0, "status":201, "id":"o1" },
{ "index":1, "status":422, "error":"INVALID_SKU" },
{ "index":2, "status":201, "id":"o3" }
]}🔥What If?
Think Beyond the Expected
A client retries a failed batch — how do you avoid duplicating the items that already succeeded?
Make each item idempotent (client supplies a per-item key, or you dedupe on a natural key). On retry, already-processed items return their prior result instead of re-creating. Per-item idempotency is what makes batch retries safe under partial failure.
😂Real World
Bulk import/sync APIs (and email/SMS/order batch endpoints) return per-item results so clients retry only the failures; capping batch size protects the server from giant payloads.
🎯Interviewer's Expectation
Keywords they're listening for:
⚠️Common Mistakes
- ✗Single status code hiding partial failures
- ✗Uncapped batch sizes
- ✗Non-idempotent items breaking retries
✅Best Practices
- ✓Return per-item status; document the failure model
- ✓Cap and validate batch size
- ✓Make items idempotent for safe retries
🔁Follow-up Questions
- 1When is transactional (all-or-nothing) the right model?
- 2How does 207 Multi-Status work?
- 3How do you keep batch processing within timeouts?
🧩Related Technologies
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Status Codes (REST APIs) Interview question: "How do you design a bulk/batch API and handle partial failures?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
⭐ Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission — at no extra cost to you. It helps keep Full Stack Interview Guru free.