E-commerce Catalog Update System with Asynchronous Image Processing
System DesignModel answerLast updated
Design a scalable system for merchants to update product catalogs individually or in bulk, with image validation and CDN delivery.
Problem Statement
You're building a platform where online retailers manage their product inventories. Sellers need to modify product information through two channels: immediate edits to individual items and batch file uploads containing thousands of records. When sellers provide image links, the system must fetch, validate, transform, and distribute these assets.
What You Need to Design
Core Capabilities:
- Individual modifications: Allow targeted changes to specific product fields (pricing, inventory levels, descriptions).
- Batch operations: Process uploaded files (CSV or JSON format). When some records fail while others succeed, generate detailed failure reports showing exactly what went wrong.
- Asset handling: Download images from provided URLs, verify their validity, create multiple size variants, and store them for fast global access.
- Progress visibility: Let sellers query the current state of their batch operations.
Quality Attributes:
- Handle traffic surges: The system experiences 10x load increases during holiday shopping periods.
- Data accuracy: Product information displayed in search results and recommendation feeds must stay synchronized.
- Fault tolerance: Network issues when downloading images should trigger automatic retries rather than permanent failures.
Your Deliverable
Produce a technical design covering:
- Service interfaces: What endpoints do sellers call? What request/response formats?
- Storage schema: How do you organize product records and track batch job progress?
- Execution flow: Walk through the journey from receiving an upload to reflecting changes in the live catalog.
- Conflict resolution: What happens when two updates target the same product simultaneously?
Consider discussing trade-offs between consistency and availability, how you'd monitor system health, and what capacity planning looks like.
Hints
Hint 1
Think about separating fast metadata updates from slower image processing—can they proceed independently?
Hint 2
For large file uploads, consider whether your API servers should handle the data directly or delegate to specialized storage.
Hint 3
When multiple updates race to modify the same product, per-field versioning can preserve more work than whole-record versioning.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Solution: E-commerce Catalog Update Architecture
1. Scope and Scale Estimation
Begin by establishing concrete numbers that drive design decisions:
- Data volume: Approximately 500K active sellers with 1B total products. Each product's metadata averages 2 KB, yielding ~2 TB total that can be horizontally sharded.
- Traffic patterns: Baseline throughput of 10K product modifications per second. Holiday peaks reach 100K/s.
- Batch characteristics: Files range from 1K to 1M rows, with file sizes up to 500 MB.
- Image workload: Average of 3 images per product. Only 10–20% of updates involve new images. At peak, this translates to 20–30K image downloads per second, each producing ~4 size variants.
- Latency requirements: Price and inventory changes should appear in search within seconds to minutes. Images can lag slightly longer.
Key clarifications:
- Should products become visible before images finish processing? (Assume yes, showing previous image or placeholder)
- Do batch files completely replace catalogs or apply incremental changes? (Assume incremental patches keyed by seller ID and SKU)
2. API Design
PATCH /v1/sellers/{seller_id}/products/{sku}
Headers: Idempotency-Key, ETag (optional for optimistic locking)
Body: { "price": 19.99, "quantity": 150 }
Response: 200 { sku, version, image_processing_status }
| 409 Conflict | 202 Accepted (images pending)
POST /v1/sellers/{seller_id}/batch-jobs
Body: { "file_format": "csv|json", "operation": "patch", "webhook_url": "..." }
Response: 201 { job_id, upload_link (pre-signed, 1h expiry) }
POST /v1/sellers/{seller_id}/batch-jobs/{job_id}/finalize
GET /v1/sellers/{seller_id}/batch-jobs/{job_id}
Response: { status, total_rows, successful, failed, in_progress, error_report_url }
GET /v1/sellers/{seller_id}/batch-jobs/{job_id}/failures?page_token=...
Design rationale:
- Direct-to-storage uploads: Large files bypass application servers entirely via pre-signed URLs, preventing memory exhaustion and timeout issues.
- Two-phase batch submission: Sellers first request an upload slot, then explicitly finalize after upload completes. This enables checksum validation before processing begins.
- Idempotency tokens: Single updates accept client-provided tokens (24h TTL in Redis) to make retries safe.
3. Data Schema
Products table (sharded by seller_id for locality):
seller_id, sku (composite primary key)
metadata (JSON: title, description, price, quantity, etc.)
field_metadata (JSON: per-field {version, timestamp})
record_version (monotonic counter, incremented each write)
images (array: {original_url, hash, cdn_paths, status})
BatchJob table:
job_id, seller_id, status, file_location, sequence_number,
total_rows, successful_count, failed_count, created_timestamp
JobSegment table (for checkpointing):
job_id, segment_id, row_range, status, retry_count
RowResult table (append-only audit log):
job_id, row_index, sku, outcome, error_type, error_detail
ChangeLog table (transactional outbox pattern):
event_id, seller_id, sku, record_version, change_payload
Job lifecycle: PENDING → UPLOADED → VALIDATING → PROCESSING → COMPLETE | PARTIAL_SUCCESS | FAILED
4. System Architecture
API Gateway Layer:
- Handles authentication, per-seller rate limiting
- Idempotency token lookup (Redis with 24h expiration)
Single Update Path:
- Catalog service validates the patch against schema
- Executes atomic database transaction: product update + changelog insert
- Enqueues image URLs (if changed) to
image-processing-queue - Returns 200 or 202 immediately
Batch Upload Path:
- Finalization handler: Assigns monotonic sequence number, validates file integrity, emits
job-readyevent - File parser service: Streams from object storage, validates each row against schema, writes malformed rows directly to
RowResult, chunks valid rows into segments of ~1K rows - Distribution: Publishes segments to Kafka/SQS, partitioned by
hash(seller_id, sku)ensuring ordered delivery per product - Update workers: Consume messages, apply conditional writes identical to single-update path, record outcomes in
RowResult - Aggregation service: Monitors segment completion, finalizes job status, generates error report CSV, triggers webhook
Image Processing Pipeline (parallel, decoupled):
- Downloader workers: Fetch from source URLs with timeout (10s), validate MIME type, file size (<10 MB), basic dimensions
- Content addressing: Compute SHA-256 hash for deduplication—identical images reuse existing variants
- Transformation workers: Generate size variants (thumbnail, standard, high-res, zoom), optimize encoding
- Storage: Write to object storage with content-addressed keys, configure CDN
- Callback: Update product record with
cdn_paths, using conditional write to prevent stale overwrites
Change Propagation:
- CDC process (Debezium or similar) tails the
ChangeLogtable - Publishes
product-modifiedevents to message bus - Search indexers and recommendation engines consume events, applying only when event's
record_versionexceeds their cached version
5. Concurrency Control Strategy
Per-field versioning with deterministic ordering:
Each write operation carries a sequence number:
- Batch jobs use
job_sequence_number + row_index - Individual updates obtain fresh sequences from a per-seller counter
Write logic:
- Read current product state
- For each incoming field, compare
incoming_sequencevsfield_metadata[field].version - Merge only fields where incoming version is higher
- Execute compare-and-swap on
record_version - Retry on conflict (exponential backoff, max 3 attempts)
This approach allows concurrent updates to different fields to both succeed. For example, Job A updating price and Job B updating inventory can both win their respective fields rather than last-write-wins destroying one change.
Kafka partitioning by SKU already serializes most writes. The CAS provides safety for direct API updates and during consumer rebalancing.
6. Reliability Patterns
Image fetch retries:
- Classify errors: transient (timeout, 5xx) vs permanent (404, invalid format)
- Transient errors: exponential backoff up to 5 attempts over ~30 minutes
- Permanent errors: record failure, notify seller, keep product live with existing/placeholder image
- Circuit breaker per source domain to handle misbehaving origin servers
Idempotency mechanisms:
- Each row operation keyed by
(job_id, row_index) - Workers may redeliver after crash; re-application is safe because field-version checks make duplicate writes no-ops
- Counter updates derived from
RowResultrecords rather than blind increments
Partial failure handling:
- File parsing errors (malformed CSV): fail individual rows, continue processing
- Database write failures: retry with backoff, eventually DLQ for manual review
- Job never marked complete until all segments reach terminal state
7. Monitoring and Operational Concerns
Metrics:
- Per-seller upload rate and success rate
- Image processing latency percentiles (p50, p95, p99)
- Database write conflict rate
- Change propagation lag (write to search index)
Capacity planning:
- Horizontal scaling: add more update workers and image processors based on queue depth
- Database sharding: redistribute when individual shards exceed 1 TB or 10K QPS
- CDN costs: estimate egress from image variant count × traffic patterns
Common mistakes to avoid:
- Processing images synchronously blocks metadata updates
- Whole-record versioning causes lost updates when concurrent edits touch different fields
- Unbounded batch files can exhaust memory; always stream and chunk
- Missing idempotency tokens leads to duplicate products on retry
- Tight coupling between update and search indexing prevents independent scaling