Catalog Backend for a Multi-Retailer Grocery Delivery App
System DesignModel answerLast updated
Design the service that ingests retailer product, price and stock data and serves store-scoped browse, search and item pages, while keeping checkout prices consistent.
You are building the catalog layer for an online grocery delivery marketplace. Shoppers pick a nearby store, browse its aisles, search for items and fill a cart. A personal shopper then collects the order inside the physical store. Item listings, search results, product pages and the prices used in the cart and at checkout all come from the catalog.
The marketplace has these characteristics:
- Many independent retailers, each operating many store locations.
- One physical product (for example a specific brand and size of milk) is sold by many retailers, but price, availability and promotions differ by store.
- Retailers deliver data as bulk files and incremental updates, on their own schedules, with inconsistent quality.
Your task: design the system that ingests retailer data and serves it to customers.
Constraints and notes
- No scale, freshness or latency numbers are given. Propose reasonable ones and keep the design consistent with them.
- Search ranking quality, recommendations, payments and shopper routing are out of scope, except for what they require from the catalog.
- Actual in-store stock is never known exactly. The catalog only knows what retailers report.
Points worth clarifying or assuming explicitly
- Is browsing limited to one selected store, or do we also need cross-store views such as comparing one product across retailers?
- How fresh must price and availability be, and if the price changes between add-to-cart and checkout, which price applies?
- Do retailers provide standard identifiers (such as barcodes) for every item, or must we match items to shared products ourselves?
- Are there weight-priced items (produce) or variants (sizes, flavors)?
- Roughly how many retailers, stores and items per store?
A strong answer covers requirements and scale, the data model, ingestion and data quality, the read path, consistency at checkout, and scaling, failure handling and observability.
Hints
Hint 1
Separate what is true of a product everywhere (name, brand, size, images) from what is true only at one store (price, stock, aisle, promotion). Decide the key for each.
Hint 2
Treat ingestion as a pipeline with stages: raw landing, parse, validate, normalize, match to a shared product, then diff against current state and publish only the changes.
Hint 3
Serve reads from a store-scoped, denormalized view and search index, and make checkout re-validate against the authoritative offer rather than trusting cached browse data.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements and assumptions
Functional
- Browse by store and aisle or category, search within a store, view item pages.
- Provide price, availability, unit price and promotion data to cart and checkout.
- Ingest retailer catalogs, prices and inventory (bulk files plus incremental updates).
Non-functional (assumed numbers)
- Scale: 500 retailers, 50k stores, about 30k items per store, so roughly 1.5B store-item offers. Distinct shared products: about 5-10M.
- Reads vastly outnumber writes (on the order of 1000:1). Peak is about 50k read QPS on browse and search, with p99 under 200 ms.
- Freshness: price and availability visible within about 15 minutes of a retailer update, with full-feed reconciliation daily.
- Checkout must be correct, not merely fast: the price charged must be well defined and explainable.
- Availability target of 99.95% for the read path. Ingestion may degrade without taking reads down.
2. Data model
Split shared product data from per-store offers.
- Product (global):
product_id, brand, name, size/unit, category, images, attributes, barcodes (GTIN/UPC). Roughly 5-10M rows, rarely changing, heavily cacheable. - Retailer item (per retailer): the retailer's own SKU, raw title, raw attributes, and a link to
product_id(nullable until matched). This preserves the source data and lets us re-match later. - Offer (per store x item):
store_id,product_id(or retailer item id), price, sale price and its validity window, unit price, sold-by-weight flag, availability status, aisle,source_version,updated_at. This is the huge, fast-changing table (about 1.5B rows). - Store: location, hours, retailer, delivery zones.
Variants (sizes, flavors) are separate products grouped by a product_family_id. Weight-priced items store price per unit of weight plus an estimated weight per piece. The final price is settled when the shopper weighs the item, so the UI shows "estimated".
Storage: products in a relational store with aggressive caching. Offers in a partitioned key-value or wide-column store keyed by (store_id, product_id), so a store's data is co-located and sharded by store_id.
Availability is a status with confidence, not a count: in_stock, low, out, unknown. Because stock is never exact, we also track shopper-reported "not found" events and downgrade availability on them.
3. Ingestion pipeline
- Landing: files and webhooks go to object storage and a queue, unmodified. Keep raw data for replay and audit.
- Parse and validate per-retailer adapters convert to a canonical schema. Reject malformed rows to a dead-letter queue with reasons.
- Normalize: units (oz vs g), currency, casing, category mapping to our taxonomy.
- Match to shared product: first by barcode (exact). Fallback is fuzzy matching on brand + normalized name + size, with ML or heuristic scoring. Low-confidence matches go to a review queue, and the item stays retailer-only until resolved. Never auto-merge on weak evidence, because a wrong merge shows the wrong product to many customers.
- Diff: compare against the current offer and emit only changes. Incremental feeds are small, but bulk feeds are mostly unchanged, so diffing avoids millions of needless writes.
- Publish: write to the offer store and emit change events (via a log such as Kafka) that update caches and the search index.
Protection against bad feeds
- Sanity checks: price of zero or negative, a price jump of more than e.g. 10x, a sudden drop in row count of more than 30-50% versus the last feed.
- Failing checks quarantine the batch and alert, and the last known good data keeps serving.
- Ordering and idempotency: each update has a
source_versionor timestamp, and older updates never overwrite newer ones. Processing is keyed by(store_id, item)so retries are safe. - Staleness: if a store has had no update beyond a threshold, mark its availability
unknownand optionally hide the store or show a warning.
4. Read path
- Browse and item pages: the client calls a catalog API with
store_id. The service reads the offer from a cache (Redis or similar, keyed by store and product), and joins to product data from a local or CDN-cached product cache. Aisle listings are precomputed per store as ordered lists of product ids and refreshed on change events. - Search: a search engine (Elasticsearch/OpenSearch). Two designs: one index of products with store-level filters, or per-store documents. A good compromise is to index the shared product for text relevance and filter on a per-store availability set (bitmap or posting list) so a query returns only products the chosen store carries. Index updates come from the change stream with a delay of seconds to minutes. Shard by retailer or region to keep a store's data local.
- Caching: product data has long TTLs, since it changes rarely. Offer data has short TTLs plus event-driven invalidation. Hot stores and popular items are a small fraction of keys, so hit rates are high. Use request coalescing to avoid stampedes after invalidation.
- Cross-store comparison (if needed) reads from the product-to-offers index (
product_idto stores), kept as a separate, eventually consistent view.
5. Consistency at checkout
Browse data is allowed to be slightly stale. Checkout is not.
- Adding to cart stores the product id, store id and the displayed price as a snapshot for display only.
- At checkout, re-read the authoritative offer (bypass the cache). If the price changed, show the change and require confirmation (or apply a rule such as "customer gets the lower of the two" if the business wants that). State the rule explicitly.
- Promotions are evaluated with their validity window at order time.
- Final charges can still differ because of weights and substitutions, so authorize with a buffer (e.g. +10-15%) and settle after picking.
- Availability at checkout is advisory. The shopper app handles out-of-stock with substitution preferences chosen by the customer.
6. Scaling, failures, observability
- Scaling: shard offers by
store_id. Ingestion workers scale horizontally per retailer, with per-retailer rate limits so one huge feed does not starve others. Search indexing uses batched bulk updates. - Failures: the read path is independent of ingestion. If a feed fails or the pipeline is down, serve last known data and show degraded freshness. Replay from raw storage and the change log to rebuild caches and indexes. Multi-region read replicas for serving.
- Observability: per-retailer freshness (age of last successful update), reject rate, match rate, diff size, index lag, cache hit rate, and the checkout price-mismatch rate. Alert on freshness SLO breaches and anomaly checks.
7. Trade-offs and common mistakes
- Single table of "products with a price": duplicates shared data 100x and makes matching and updates painful. Separate products from offers.
- Trusting feeds: no validation leads to $0 items or mass-hidden catalogs. Always add guards and quarantine.
- Aggressive auto-matching: wrong merges are worse than unmatched items.
- Strong consistency everywhere: unnecessary and costly. Use eventual consistency for browse and strict re-validation only at checkout.
- Exact inventory counts: not available. Model confidence and use feedback signals.
- Full reindex on every bulk feed: diff first and write only changes.
- Ignoring weight-priced items: pricing and charging differ from fixed-price items and must be modeled explicitly.