{"success":true,"name":"design-bulk-write-endpoints-with-explicit-partial-success-se","description":"An endpoint accepts many items to create or update at once","category":"ai-brimind","path":"ai-brimind/design-bulk-write-endpoints-with-explicit-partial-success-se/SKILL.md","file":"SKILL.md","content":"---\nname: design-bulk-write-endpoints-with-explicit-partial-success-se\ndescription: \"An endpoint accepts many items to create or update at once\"\n---\n\n# Design Bulk Write Endpoints With Explicit Partial-Success Semantics\n\n## When to use\nYou are building a bulk operation (import, multi-create, mass update), and what happens when item 37 of 100 fails hasn't been decided.\n\n## Example request\nOne bad row fails the whole import with a generic error → user retries everything blindly; a per-item result report is the missing contract. — Bulk endpoint succeeds partially but returns only 200 → client believes all 100 saved; the response must say exactly which succeeded and which failed, and why. — Retry of a partial success re-creates the items that worked → duplicates; per-item idempotency or upsert semantics make retries safe. — 100k items accepted in one request → timeout mid-way with unknown state; bulk endpoints need batch size caps and possibly async processing.\n\n## Instructions\nAct as a bulk-operation designer who decides the failure semantics before the loop is written. For the endpoint: 1) Choose the mode explicitly and put it in the contract: all-or-nothing (one transaction, any failure rolls back everything) or partial success (independent items, per-item results) — the right answer comes from whether the items depend on each other, and 'whatever the loop does' is not a mode. 2) For partial success, design the result shape: a per-item outcome list (index or client-supplied key, status, error detail) so the client can fix and resubmit only the failures — a bulk response without per-item results forces blind retries. 3) Make resubmission safe: upsert semantics or per-item idempotency keys, because partial-failure retry is the normal flow of bulk operations, not an edge case. 4) Cap the batch size and validate the envelope first (count, total size) — beyond the cap, point to chunking or switch the design to async job processing. 5) Check whether the database/ORM already offers bulk mechanisms (bulk insert, upsert) — item-by-item loops at scale are the N+1 of writes. Only ship once a mixed batch (some valid, some invalid) has been tested and the response tells the exact truth about it, and explain how the semantics let clients recover precisely rather than guessing what saved.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #925\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}