Merchant Catalog Service: Full-Dump Feeds and Pinned Admin Edits
System DesignModel answerLast updated
Design a catalog service fed by full retailer snapshot files, serving 11,000 QPS under 400 ms, where admin attribute overrides persist through retailer updates and deletions.
You are designing a product catalog platform. Retailers push their product data as full snapshot files, shoppers browse the resulting catalog, and platform admins can correct product attributes globally.
Ingestion
- Every file contains the retailer's entire catalog, never just the differences.
- There are 50,000 retailers. The mean catalog has 20,000 products, but the median has only 50.
- Strict versioning is not required. While a snapshot is being applied product by product, a shopper may see a mix of old and new products, and that is acceptable.
Browsing
- List all product SKUs of a retailer by
retailer_id. - Fetch one product's details by
product_id. - 50 million users, 11,000 queries per second, and a 400 ms latency target.
Admin overrides
- An admin can override any attribute of any product, and the override applies system-wide.
- A later retailer update must never change an overridden value.
- A retailer may delete a product even if some of its attributes are overridden.
- Deleting an override means users see the retailer's latest value for that attribute again.
Part 1: Core design. Define the entities, choose storage and caching, and describe the write path (file to visible product) and both read APIs. Show how each override rule follows from your model.
Part 2: Diffing. How do you compare a new snapshot with existing data to find added, removed, changed, and unchanged products? Discuss cost for the biggest retailers.
Part 3: A wrong upload, quickly replaced. A retailer uploads snapshot 1, realizes it is wrong, and uploads snapshot 2. The catalog must end up exactly equal to snapshot 2. Consider snapshot 2 arriving before, during, and after processing of snapshot 1.
Part 4: Scale. Another 50,000 retailers join, and every retailer uploads daily. How does the system cope? Separate rows compared from rows written, and discuss fairness between huge and tiny retailers.
Part 5: Observability. What would you monitor, alert on, and verify to be confident the system behaves correctly?
State any assumptions you make, such as whether an override should come back if a deleted product reappears.
Hints
Hint 1
Keep retailer-supplied values and admin overrides in separate tables, and compute the visible product as retailer values overlaid with overrides. Most override rules then fall out without special cases.
Hint 2
Diff each snapshot against the catalog's current stored state, not against the previous file, and give every snapshot a server-assigned increasing sequence number per retailer so that ordering never depends on processing timing.
Hint 3
For scale, estimate rows read versus rows written separately. Most rows in a daily snapshot are unchanged, so content hashes keep writes small even though compared volume is around a billion rows per day.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Assumptions
product_idis globally unique, derived from(retailer_id, sku).- p99 latency is under 400 ms, and SKU listing is cursor-paginated.
- If a deleted product reappears, its overrides apply again, because they are keyed by
product_id. This is a product decision to confirm. - The mean of 20,000 versus a median of 50 means a heavy tail. A few retailers may have millions of products, and most are tiny. Design for the tail without making small retailers wait behind it.
Part 1: Core design
Entities
retailer_product(product_id, retailer_id, sku, attrs, content_hash, last_seen_seq, deleted_at): what the retailer says.override(product_id, attribute, value, admin_id, created_at): what an admin pinned. Primary key is(product_id, attribute).snapshot(retailer_id, seq, object_url, status, counts): one row per upload.catalog_view(product_id, retailer_id, effective_attrs): the read-optimized merged product.
Why the rules hold
- Retailer updates only touch
retailer_product, so they cannot clobber overrides. - The effective value is
override.valueif present, else the retailer value, so deleting an override reverts to the retailer's newest value automatically. - A retailer delete only tombstones
retailer_product. The override rows stay, so there is no conflict, and the product just disappears from the view.
Storage
The load is 11,000 QPS of key lookups and range listings, which is modest. Use a sharded store (a partitioned relational database or a wide-column/KV store) with two access patterns:
- Product lookup: partition by
product_id. - SKU listing: a listing table keyed
(retailer_id, sku)with cursor pagination. Very large retailers are split into sub-buckets to avoid hot partitions.
Put a Redis or CDN cache in front of product detail, with a TTL of a few minutes plus explicit invalidation on write. Reads hit only catalog_view or the cache, never the ingestion tables. Expect cache hits of 90% or more, with p99 in the tens of milliseconds.
Write path
- The retailer uploads the file through a presigned URL to object storage.
- The upload API assigns the next
seqfor that retailer and enqueues a job. - A worker streams the file, diffs it, applies changes, and refreshes
catalog_viewfor each changed product. - An override change updates
overrideand recomputes that single product's view row and cache entry.
Part 2: Diffing snapshots
Compare the new file against the currently stored state of the retailer, not against the previous file. If the previous apply crashed halfway, the stored state is neither the old nor the new file, and diffing file against file would leave the gap permanently.
Method:
- Normalize each record: trim whitespace, canonicalize case where it is semantically irrelevant, fix numeric and currency formats, sort keys, and drop empty versus missing differences. Hash the result into
content_hash. - Stream the file in batches. For each batch, fetch stored hashes by
product_id. Insert the product if it is missing, update it if the hash differs, and otherwise only setlast_seen_seq = N. - After the full pass, any product with
last_seen_seq < Nand not tombstoned is removed. This is a set difference without holding both sets in memory.
Memory is O(batch size). Time is linear in file size. For multi-million-row retailers, shard the file by hash(product_id) ranges and process the ranges in parallel. Validate the file (parsable, row count within a sane range of the previous one) before the delete step. If it fails, reject the upload.
Part 3: Snapshot 1 replaced by snapshot 2
- Ordering: the server assigns a monotonic
seqper retailer at upload time. Never trust file timestamps or worker completion order. - Serialization: the queue is partitioned by
retailer_id, so one snapshot per retailer is applied at a time. - Before processing: the worker sees a newer snapshot exists and marks snapshot 1 as
superseded. It processes only snapshot 2. - During processing: the worker checks for newer
seqbetween batches and aborts cooperatively. As a safety net, every write is conditional (applied_seq <= N), so a stale worker cannot overwrite data from snapshot 2. - After processing: snapshot 2 runs normally against the stored state.
The final state equals snapshot 2 exactly. Products snapshot 1 wrongly removed are reinserted because they are in the file. Products it wrongly added carry last_seen_seq < 2 and are removed in the sweep. Changed attributes are corrected by hash mismatch. Overrides live in a separate table and were never touched, so they remain correct. Use soft deletes (tombstones, purged after a retention period) so that restoring a product is a flag flip, not a recreation.
Part 4: Scale
Estimate. 50,000 retailers at 20,000 products average is about 1 billion rows per day to read and compare. That is about 11,600 rows/s on average, and maybe 100,000 rows/s at peak. If 2 to 5% of rows actually change, writes are 20 to 50 million per day, or about 250 to 600 writes/s. At roughly 1 KB per record, the files total about 1 TB per day, or around 12 MB/s.
The design should therefore minimize writes, not reads: the hash comparison does that.
Scaling
- Uploads go straight to object storage, so API servers never carry file bytes.
- Workers are stateless and autoscale on queue depth.
- Use separate queues or worker pools for size classes (small, medium, huge). A retailer with millions of rows cannot starve the thousands with 50 products.
- Split huge files into hash-range chunks processed in parallel, while still serializing per retailer at the snapshot level.
- Stagger or rate-limit schedules so uploads do not all land at midnight.
- Apply per-retailer write quotas, and throttle on database replication lag to protect the read path.
- Keep ingestion on a separate write path from the read replicas and cache.
Part 5: Observability
Read path
- SLIs: p50/p95/p99 latency per API, error rate, cache hit ratio, replica lag.
- SLO example: 99.9% of requests under 400 ms.
Ingestion
- Upload-to-visible freshness, queue depth and age per size class, and rows read versus written per snapshot.
- Failure and retry counts, plus superseded and aborted snapshot counts.
Correctness checks, not just health
- After each apply, compare row counts to the file and sample a percentage of products to verify
catalog_viewequals the file overlaid with overrides. - Flag suspicious snapshots, such as a sudden drop of more than X% of products, before the delete sweep.
- A periodic reconciliation job rebuilds the view for a sample of products from the source tables and diffs it against serving data.
- Invariant checks: no
overriderow is ever changed by ingestion, and no view row references a deleted retailer product.
Alerting and audit
- Alert on SLO burn rate, freshness breaches, DLQ growth, and reconciliation mismatches.
- Use distributed tracing with the
snapshot_idas a correlation key from upload through apply to cache invalidation. - Keep an append-only audit log of every override create, update, and delete with admin, time, old value, and new value.
Common mistakes
- Storing overrides inside the retailer row, so the next snapshot overwrites them.
- Diffing file against previous file, which breaks after a partial apply.
- Ordering snapshots by completion time or file timestamp.
- Deleting products and overrides together, which loses admin work.
- Letting one giant retailer block the shared queue.