How do you design a bulk/batch API and handle partial failures?
Reviewed by Gurusankar M.
β‘ 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.