SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
  • What is an API?
  • API Styles
  • Idempotency
  • Data Formats
  • REST, GraphQL, gRPC
  • Pagination, Filtering and Sorting
  • API Versioning
  • Error Handling and Status Codes
  • OpenAPI / Swagger
  • Bulk APIs and File Upload
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/APIs and Communication/API Design

Bulk APIs and File Upload

Handle many items in one call, and send big files without tying up your servers.

โฑ 14 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A bulk API lets a caller do many things in one request (create 500 products, for example). File upload is the special case of sending big blobs of data. Both save round trips, but both need care, because one request now carries a lot of work or a lot of bytes.

  • For bulk calls, return one result per item, so a single bad row does not hide the good ones.
  • For big work, answer quickly with a job id and let the caller check the status later.
  • For big files, send them in chunks so they can resume, or send them straight to storage with a presigned URL, so your app servers are not in the way.

02Concept: What is it?

Bulk APIs

Suppose a client has 10,000 contacts to import. One request per contact means 10,000 round trips, 10,000 logins checked and 10,000 chances for a network error. A bulk (batch) endpoint takes a list in a single request, like POST /contacts:batch, and handles them together.

The hard part is partial success. If 3 of the 500 items are invalid, you must decide: reject the whole batch (all or nothing), or accept the good ones and report the bad ones. Most public APIs choose partial success with a status for each item.

A batch request and a per-item answer (illustrative)
POST /products/batch
{ "items": [
  { "clientId": "a1", "name": "Pen",   "price": 2 },
  { "clientId": "a2", "name": "",      "price": 3 },
  { "clientId": "a3", "name": "Book",  "price": 12 }
] }

200 OK
{ "results": [
  { "clientId": "a1", "status": 201, "id": "p-901" },
  { "clientId": "a2", "status": 400, "error": "name is required" },
  { "clientId": "a3", "status": 201, "id": "p-902" }
] }

File upload

A file is just bytes, but a big file is slow and can fail half way. The simple way is one multipart/form-data request: good for small files. For large files you need two upgrades: chunked, resumable uploads and direct-to-storage uploads.

A presigned URL keeps big files off your servers
๐Ÿ“ฑClient1. ask to upload
โ†’โ†“small request
๐Ÿ–ฅ๏ธYour API2. checks, then signs
โ†signed URL
๐Ÿ“ฑClient3. sends the file
โ†’โ†“big bytes
๐Ÿ—„๏ธObject storage4. tells you it is done
The app does a tiny job (signing), and the storage service does the heavy job (receiving the bytes).
๐Ÿง Two rules
One result per item for bulk calls, and keep big bytes away from your app servers for file uploads.

03Real-Life Example

๐ŸตThe Moving Day
You are moving house. Carrying boxes one at a time from the flat to the van is slow, because you walk back and forth a hundred times. So you load a trolley with 20 boxes. But if one box is cracked, you do not throw away the whole trolley: you set the cracked box aside and tell the owner. For the piano, you do not carry it through the shop. You hire a mover who takes it straight from the flat to the new house, and just ring the shop to say it is on the way. If the van breaks down half way, you restart from the last landing, not from the bottom of the stairs.
Moving day
Bulk APIs and uploads
A trolley of 20 boxes
A batch request with many items
Setting the cracked box aside
Partial success with a status per item
A label on each box
A client id on each item, to match results
A moving company for the piano
A presigned URL, straight to storage
Restarting from the last landing
Resuming a chunked upload
Ringing to say the piano is on the way
A completion callback or a status check
The shop's limit of 20 boxes per trolley
A maximum batch size and file size
The life of a big batch job
๐Ÿ“ฆSubmit10,000 items
โ†’โ†“202 + job id
โš™๏ธWorker runsin the background
โ†’โ†“
๐Ÿ”ŽPoll status45% done...
โ†’โ†“
โœ…Resultsone line per item

04Why Do We Need It?

โšกFewer round trips
One call for 500 items is far quicker than 500 calls, each with its own network wait and login check.
๐Ÿ’ธCheaper to run
Less per-request overhead on both sides, and many databases insert a batch faster than single rows.
๐ŸงพClear partial failure
Per-item results tell clients exactly which rows to fix and which already worked.
๐Ÿ›ก๏ธProtect the servers
Size limits and background jobs stop one huge request from tying up a server.
๐Ÿ”Cheap retries
A resumable upload only sends again what was lost, not the whole file.
๐Ÿ“ˆScales with big files
With direct-to-storage uploads, adding users does not need more app servers just to carry bytes.
Do many things per call, report each one on its own, and never make your app servers carry heavy bytes if they do not have to.

05Where Do We Use It?

๐Ÿ“‡Imports
Importing contacts, products or transactions from a spreadsheet or another system.
๐Ÿ”„Syncing
A mobile app sends the 40 changes it made while offline in one call.
๐ŸŽž๏ธMedia
Photos and videos are uploaded straight to object storage, then processed in the background.
๐Ÿ“„Documents
Invoices, contracts and ID scans, often with a virus scan before they are used.
๐Ÿ“ŠExports and reports
Large exports run as a background job and give a download link when ready.
๐ŸงฐAdmin tools
Bulk update or bulk delete of many records at once.

06Types / Parts / How It Works

Three ways to answer a bulk request

StyleHow it worksGood forWatch out
All or nothingRun everything in one transaction. One bad item fails the whole batch.Items that depend on each other (a payment and its lines)One typo blocks everything. Batches must stay small.
Partial successProcess each item on its own and return a status per item.Independent items: imports, syncsThe client has to read the per-item results and retry only the failures.
Async jobReply 202 Accepted with a job id. Workers process in the background. The client polls or gets a callback.Very large batches, slow workMore moving parts: job storage, status endpoint, expiry.
๐Ÿ“Note
With partial success, many APIs return 200 with item statuses in the body. Some use 207 Multi-Status. Pick one, and write it in your contract.

Four ways to take a file

MethodHow it worksGood forLimits
Multipart formOne request with the file and fields (multipart/form-data)Small files, simple formsWhole file in one request. A failure means starting again.
Raw bodySend the bytes as the body of a PUT or POSTSimple API clientsSame: no resume, and the server carries the bytes.
Chunked / resumableSplit into parts, send each, and ask which parts arrivedBig files, bad networksMore requests, and the server must track parts.
Presigned URL to storageYour API signs a short-lived URL, and the client sends the file straight to object storageLarge files at scaleChecks happen after the file arrives (scan, type, size).
Chunked upload
One request
Sent before the drop80%
Sent again after the drop100%
Chunks
Sent before the drop80%
Sent again after the dropabout 20%
First attempt Whole file again Only the missing part
Each chunk is confirmed. After a drop, the client asks which chunks the server has and sends only the missing ones.
VisualizerRestart or resume? Through your server or straight to storage?First, drop the connection at different points and compare one big request with chunks. Then switch to the second view and raise the number of simultaneous uploads until the app servers saturate.
What do you want to see?
How is the file sent?
Chunk size
20 equal parts of the file of up to 50 MB. Green = sent once and kept. Amber = sent twice, the first copy was wasted.
Data sent
1.8 GB
file is 1 GB
Wasted
800 MB
sent, then thrown away
Time
3 min 0 s
at 10 MB/s (illustrative)
Requests
2
including the failed one
The connection dropped at 800 MB. With one big request the server cannot keep a partial file, so the whole 1 GB is sent again. 800 MB was wasted. With chunks it would be 0 MB.

Illustrative numbers, not benchmarks: each connection sends 10 MB/s and the app servers together pass 250 MB/s. Real links, storage limits and retry rules differ. The model ignores the final call that tells the server the upload is complete.

07How to Use It / Steps / Implementation

Designing a bulk endpoint

  1. 1
    Set a maximum size
    Limit the number of items and the bytes per request (for example, 100 items). Write the limit in the docs and reject larger ones with a clear error.
  2. 2
    Give every item a client id
    The client sends its own id for each item, and you echo it back, so results can be matched even if the order changes.
  3. 3
    Return a status per item
    Each result has its own status and either the new id or an error. The overall call succeeds if the batch was understood.
  4. 4
    Make items idempotent
    Retries will happen. An idempotency key (per request or per item) stops the same item being created twice.
  5. 5
    Go async for big work
    Reply 202 with a job id and a status URL. Expire old jobs and keep results for a while.

Designing an upload

  1. 1
    Ask your API for permission first
    The client says what it wants to upload (name, type, size). The API checks the user, the size limit and the type, then creates a record.
  2. 2
    Hand out a presigned URL
    Return a short-lived URL that allows one upload to one place. For big files, return one per chunk or use the storage service's multipart upload.
  3. 3
    Let the client send the bytes to storage
    Your servers are not in the data path. Retries and resume use the storage service's features.
  4. 4
    Confirm when done
    The client calls a complete endpoint, or storage sends an event. Only then mark the file as available.
  5. 5
    Check after it arrives
    Verify the real size and type (not just the file name), scan for viruses, and keep the file private until it passes.
โš ๏ธNever trust the file name or the type header
A client can call a program photo.jpg. Check the real content, store files under names that you generate, and never serve uploads from a place where they could run as code.

08Key Terms to Know

TermMeaning in easy words
Bulk / batch endpointAn endpoint that takes many items in one request
Partial successSome items worked and some failed, and the response says which
207 Multi-StatusAn HTTP status that carries a separate status for many operations in one response
202 AcceptedThe work was accepted, but it is not finished yet
Job id / status endpointA handle that the client uses to check on a background job
Idempotency keyA unique value that makes a retried request safe to repeat
multipart/form-dataA request format that can carry files and fields together
Chunked / resumable uploadA file sent in pieces, so a failure costs only the missing pieces
Presigned URLA temporary link that allows one specific upload (or download) without a login
Direct-to-storage uploadThe client sends the file straight to object storage, not through your app
Virus scan / content checkLooking inside an upload to see if it is safe and really what it claims to be

09Pros, Cons and Trade-offs

โœ… Pros
  • Fewer round trips and less overhead
  • Per-item results make fixes easy
  • Async jobs keep requests short
  • Resumable uploads survive bad networks
  • Direct uploads keep app servers free
โš ๏ธ Cons
  • More complex API and more states to document
  • Partial success is harder for clients than a single yes or no
  • Async jobs need storage, status and clean-up
  • Chunk tracking adds server work
  • Checks come after the file arrives

Trade-offs

ChoiceWe gainWe lose
Bigger batchesFewer callsLonger requests, more to retry, higher timeout risk
Smaller batchesFast, simple, easy to retryMore calls
All or nothingA clean result and no half-done stateOne bad item blocks the rest
Partial successGood items go throughClients must handle mixed results
Smaller chunksLess wasted on a failureMore requests and more bookkeeping
Direct to storageScale and speed, simple serversA second system to secure and a delay before checks

10Common Problems and Mistakes

Common mistakes

  1. No size limit. One caller sends a million items, and a server runs out of memory.
  2. Hiding the failures. Returning 200 with no per-item results leaves clients guessing which rows failed.
  3. Retrying without idempotency. A timeout and a retry create the same 200 items twice.
  4. Long synchronous work. A batch that takes two minutes will hit a timeout in a proxy, and the client has no idea what happened.
  5. Passing every file through the app. Large uploads fill the app servers' bandwidth and slow down normal requests.
  6. Trusting the file type. Checking only the extension or the Content-Type header lets bad files in.
  7. Presigned URLs that live too long. A leaked link that lasts for days is an open door. Keep them short and narrow.

Things to watch

๐ŸงฉOrphan uploads
Clients start uploads and never finish. Clean up unfinished parts and unreferenced files on a schedule.
๐Ÿ”’Public by mistake
Keep uploaded files private by default, and share them with short-lived links.
๐ŸงฎOrder of results
Do not rely on order alone. Match results to items with the client id.
๐ŸงชPartial rollback
If a later step fails, say clearly what was already saved and how to undo it.

11Real-World Examples

โ˜๏ธCloud object storage
Services such as Amazon S3, Google Cloud Storage and Azure Blob Storage support presigned or signed URLs and multipart uploads.
๐Ÿ“งEmail and marketing tools
Bulk contact imports often run as background jobs with a report of which rows failed.
๐Ÿ›’Commerce platforms
Merchants import thousands of products through bulk endpoints or file imports.
๐Ÿ“ฑPhoto apps
A phone uploads a photo straight to storage, and a worker makes thumbnails afterwards.
๐ŸงพFinance and payroll
Batch files carry many payments, each with its own result code.
๐Ÿ“ฅResumable upload protocols
Open protocols such as tus define a standard way to resume interrupted uploads.
๐Ÿ“Note
Limits (item counts, file sizes, part sizes, URL lifetimes) differ between products. Read the documentation of the service you use before you set your own numbers.
Mini case: photo upload
๐Ÿ“ฑPhone12 MB photo
โ†’โ†“1. may I?
๐Ÿ–ฅ๏ธAPIsigns a URL
โ†’โ†“2. upload
๐Ÿ—„๏ธStoragestores it
โ†’โ†“3. event
โš™๏ธWorkerscan + thumbnail
Client App Storage Background work
The app server handles three tiny requests. The photo itself never touches it.

12Related Topics to Read Next

Idempotencyโ†’

Makes retried batch items and retried uploads safe.

Object Storageโ†’

Where big uploaded files usually end up.

Message Queuesโ†’

Carry the background work behind a batch job or an upload.

Rate Limitingโ†’

Protects the API from huge or very frequent batches.

Error Handling and Status Codesโ†’

207, 202 and per-item errors all need to be designed with care.

Pagination, Filtering and Sortingโ†’

The opposite problem: returning big lists a page at a time.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”Bulk: many items per request, with a size limit, a client id per item and a status per item.
  • โœ”Failures: partial success for independent items, all-or-nothing for dependent ones.
  • โœ”Big jobs: reply 202 + job id, work in the background, poll or call back.
  • โœ”Retries: idempotency keys, so repeated items do not duplicate.
  • โœ”Files: small = multipart. Large = chunked and resumable.
  • โœ”At scale: presigned URL straight to object storage, so app servers carry no bytes.
  • โœ”Check: real type and size, virus scan, private by default, short-lived URLs.
  • โœ”One line: โ€œDo many things per call, report each one, and keep heavy bytes off the app servers.โ€
โ† Previous
OpenAPI / Swagger
Next โ†’
Rate Limiting