Build a Seller Photo Ingestion and Delivery Service
System DesignModel answerLast updated
Design a pipeline that accepts large seller photos by direct upload, processes and moderates them asynchronously, and serves only approved variants worldwide with safe concurrent edits.
Context
A large online marketplace lets independent sellers manage the photos shown on each product page. Every product (identified by an ASIN) has several photo slots: one MAIN slot and a handful of extra gallery slots. Sellers add, swap, reorder, and remove photos, often several times in a row and sometimes from more than one browser tab.
Design the backend that takes a seller's raw file, turns it into standard buyer-ready renditions, screens it against content policy, and delivers approved renditions to shoppers around the world.
Requirements
Functional
- Sellers upload files of up to 25 MB straight to object storage. Raw bytes must not pass through the main API tier.
- After upload, the system checks format and dimensions, produces standard renditions (for example a 100x100 thumbnail and a 2000x2000 zoom image in WebP/AVIF), and runs automated policy checks for watermarks, prohibited text, and offensive content.
- Sellers can assign, replace, reorder, and delete images in a product's slots. An image that is unapproved or has failed checks must never be reachable by buyers.
- Approved renditions are served with low latency in all buyer regions.
Scale and quality targets
- 50 million uploads or replacements per day (about 600/s average, about 2,500/s peak).
- 5 billion image views per day (about 60,000/s average).
- 95% of images processed, moderated, and visible within 30 seconds of upload completion.
- Processing must be safe to retry and idempotent. Rapid swaps or edits from several seller sessions must not corrupt the listing.
What to cover
- End-to-end architecture, from issuing a signed upload URL through event-driven processing to storage.
- The main APIs (start an upload, update slot order) and a data model that captures image states such as
PENDING_UPLOAD,PROCESSING,APPROVED,REJECTED, andACTIVE. - How you handle duplicate event delivery, worker retries, and concurrent slot edits.
- CDN strategy: purging caches versus using immutable, versioned URLs when an image is replaced.
Hints
Hint 1
Convert the numbers into capacity first: average raw size times uploads per day gives ingest volume, and per-image compute time times peak rate gives how many workers you need. Also note that a high CDN hit rate leaves very little traffic for the origin.
Hint 2
Separate what the seller asked for from what buyers see. Keep a 'desired' slot layout and a 'published' slot layout, and only ever copy approved images into the published one.
Hint 3
Storage events and queues deliver at least once. Make each step a conditional state transition with a lease, and make output keys deterministic so a retry rewrites identical bytes.
Hint 4
Use a version number on the listing's image set with compare-and-set updates, and make the publisher recompute published slots from the latest desired slots, so a late approval of an older image cannot win.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Sizing and assumptions
- Writes: 50M/day is about 600/s average and 2,500/s peak. Assuming about 5 MB per raw file, that is roughly 250 TB/day of raw ingest. Renditions add about 1-2 MB per image (about 75 TB/day). Move raw originals to cold storage after about 30 days.
- Compute: about 4 s of decode, resize, encode, and moderation per image. At peak that is 2,500 x 4, so about 10,000 concurrent worker slots. Autoscale CPU transform workers on queue depth, and run moderation models on a separate GPU/inference fleet.
- Reads: 60k/s average, perhaps 3x at peak. With a 99% CDN hit rate the origin sees about 600-2,000 req/s, so delivery is a CDN problem, not a database problem.
- SLA: a p95 of 30 s rules out batch jobs and demands an event-driven pipeline.
- Core invariant: unapproved bytes are never reachable from a buyer-facing URL.
2. APIs
POST /v1/sellers/{sellerId}/uploads
body: { asin, slot?, contentType, sizeBytes, clientRequestId }
-> { uploadId, imageId, presignedUrl } // PUT, ~15 min expiry
GET /v1/uploads/{uploadId} -> { state, rejectionReasons? }
PUT /v1/listings/{asin}/images
If-Match: <version>
body: { slots: [ {slot:"MAIN", imageId}, {slot:"PT01", imageId}, ... ] }
-> 200 {version} | 412 Precondition Failed
DELETE /v1/listings/{asin}/images/{slot} (also If-Match)
clientRequestIdmakes upload creation idempotent: the same ID returns the sameuploadId.- The signed URL pins the object key (
raw/{sellerId}/{uploadId}), a maximum size of 25 MB, and the content type, so the gateway never sees the bytes. - Slot updates replace the whole layout under a version check. A reorder or swap is therefore one atomic operation rather than several slot-level calls.
3. Data model
Image (key-value store, key imageId, secondary index on contentHash):
sellerId,uploadId, server-computedcontentHash(never trust the client)state:PENDING_UPLOAD -> UPLOADED -> PROCESSING -> APPROVED | REJECTED, laterACTIVE,SUPERSEDED,DELETED; alsoFAILED_PROCESSINGleaseOwner,leaseExpiry,stateVersionvariants(map of rendition name to object key) andmoderation(labels, scores, model version)
ListingImageSet (key asin):
version(optimistic concurrency counter)desiredSlots: what the seller requested, possibly referencing images still processingpublishedSlots: what buyers see, containing only approved images as content-hashed URLs
Separating desired from published is the central decision. The seller's intent is saved instantly, while the buyer view is a projection that only ever includes approved images. If a new MAIN is still processing, buyers keep seeing the previous approved MAIN.
Buckets: raw/ (private, no CDN access), staging/{hash}/ (unapproved renditions, private), public/{hash}/{variant}.{fmt} (the only prefix the CDN origin can read).
4. Flow
- The client calls the upload API, which writes an Image row as
PENDING_UPLOADand returns a signed PUT URL. - The client uploads directly to object storage, using multipart for resumability on poor connections.
- The storage "object created" event enters a queue/log partitioned by
imageId. - Validate: check magic bytes (not the extension), decode in a sandbox to resist decompression bombs and malformed files, check minimum dimensions, and compute SHA-256.
- Dedupe: if the hash is already approved, attach the existing renditions and skip the rest. Sellers re-upload identical files often.
- Transform: write thumbnails, gallery sizes, and zoom images in WebP/AVIF/JPEG to
staging/{hash}/. - Moderate: classifiers for watermarks, OCR for prohibited text, offensive content, and the white-background rule for
MAIN. Borderline scores go to human review, which falls outside the 30 s SLA. - Promote or reject: on approval, copy to
public/{hash}/, setAPPROVED, and emitImageApproved. On rejection, setREJECTEDand notify the seller with reason codes. - Publish: a publisher consumes
ImageApproved, recomputespublishedSlotsfor every listing whosedesiredSlotsreferences the image, and emits a catalog-update event for page caches and search indexing. - Deliver: buyers request
.../{hash}/zoom_2000.avif; the edge negotiates format using theAcceptheader.
Latency budget: queueing under 2 s, validation about 1 s, transforms 3-5 s, moderation 2-5 s, publish under 1 s. That fits within 30 s with headroom for the p95.
5. Idempotency and retries
- Storage events are at-least-once. Every step is a conditional transition, for example: set
PROCESSINGwith a lease of 60 s only if state isUPLOADEDor the current lease has expired. A duplicate event fails the condition and is acknowledged as a no-op. If a worker dies, its lease lapses and another worker takes over. - Output keys depend only on
(hash, variant, encoderVersion). A retried transform overwrites identical bytes, so partial work is harmless. - After N failed attempts a message goes to a dead-letter queue, the image becomes
FAILED_PROCESSING, and the seller is alerted.
6. Concurrency on listings
- Two sessions reordering: both read version 7. The first write with
If-Match: 7succeeds and bumps to 8. The second gets 412, re-reads, and merges or surfaces the conflict. Implement with a conditional write onversion. - Late approval race: the seller sets
MAIN=A, then quickly setsMAIN=B. If A's approval arrives after B was assigned, the publisher must not simply write A. It recomputespublishedSlotsfrom the currentdesiredSlotsand only includes images that are approved. A therefore never overwrites B, and B appears once it is approved. - Publishing itself is also a conditional write on the set version, retried on conflict, so concurrent approvals converge on the same result.
7. CDN and caching
Prefer immutable, content-addressed URLs (/{hash}/{variant}) with long Cache-Control: max-age=31536000, immutable. Replacing an image produces a new hash and so a new URL; the listing's published slots simply point to it. No purge is needed for the image bytes, and old URLs stay valid for pages cached elsewhere.
Only the small mapping from slot to URL (the product page or catalog response) changes, and it can have a short TTL or be refreshed through the catalog-update event. Purge-based invalidation is slower, rate-limited, eventually consistent across edge locations, and risks serving stale or mixed content. Use it only for takedowns (policy violations or legal removal), where you also delete from public/ and issue a purge.
Add an origin shield (regional mid-tier cache) to protect storage from cache-miss storms, and consider pre-warming MAIN thumbnails at publish time.
8. Trade-offs and common mistakes
- Routing uploads through the API tier wastes bandwidth and compute; use signed URLs.
- Trusting client-reported hash, type, or size; re-verify server-side.
- Writing straight to a public prefix before moderation breaks the core invariant.
- Updating slots one by one, which allows half-applied reorders.
- Publishing from the event payload instead of recomputing from current desired state, which causes stale-approval overwrites.
- Relying on CDN purges for correctness instead of versioned URLs.
- Forgetting a dead-letter path, a human-review path, and monitoring of p95 time-to-visible, queue depth, and rejection rates.