KatInterview

Design a Contextual Pricing Service for a High-Volume Retail Platform

System DesignModel answer
HardModel answerSystem Designapi-designcachingbatch-processing

Last updated

Design a pricing API that handles batch lookups, personalized context, explicit freshness guarantees, and partial failure at one million item evaluations per second.

Scenario

You are a senior engineer at a large e-commerce platform that sells digital and physical goods across 30 regional markets worldwide. The platform's frontend surfaces prices in three distinct places: product detail pages, search result grids, and a checkout funnel. A third-party partner network also queries your pricing data in bulk.

A single search grid can render up to 100 items simultaneously, and pricing for each item depends on who is asking: their loyalty tier, where they are shipping to, what promotional code they've applied, and whether a time-limited sale is currently running. Your job is to design the core Pricing Service that powers all of these surfaces.

Requirements

Functional

  • Single and batch retrieval: The API must support fetching a price for one item or up to 250 items in a single request.
  • Pricing context: Each request carries contextual inputs — customer loyalty level, destination country, active promo codes, and preferred currency — which affect the final computed price.
  • Freshness metadata: Every price in the response must include when it was calculated, how long it is valid, and whether it was computed fresh or retrieved from a cache.
  • Per-item fault isolation: If one item in a batch fails to resolve (for example, due to a downstream tax service timeout or an unrecognized item ID), that item returns an error while all other items in the batch succeed normally.

Non-Functional

  • Throughput: 100,000 requests per second at peak, with an average of 10 items per request — roughly 1 million item evaluations per second.
  • Latency: Single-item p99 under 25 ms; 100-item batch p99 under 75 ms.
  • Scale: 50 million active items across 30 regional markets.
  • Availability: 99.99% uptime for pricing evaluations.

What You Are Expected to Cover

1. API protocol and schema

Compare GET with query parameters versus a read-only POST for batch requests. Consider URL length limits, proxy caching behavior, and whether idempotency is affected. Define the JSON request and response schema, including how per-item errors are represented alongside successes.

2. Batch orchestration and fan-out

Walk through how the service handles a batch internally: deduplicating repeated item IDs within a single request, decomposing the batch for downstream calls, enforcing bounded concurrency, and propagating request deadlines so that slow downstream services don't blow your p99 budget.

3. Contextual caching strategy

Pricing depends on user-specific inputs, which can destroy cache hit ratios if handled naively. Describe a caching topology — potentially multi-tier — that preserves high hit rates despite personalization. Cover how you key the cache, how you handle cache stampedes, and how stale-while-revalidate applies here.

4. Overload handling and graceful degradation

Explain how the service protects itself and its downstream dependencies under load. Cover backpressure mechanisms, circuit breakers, and differentiated staleness policies: for example, a search page may tolerate a slightly stale price, while the checkout flow must not.

Hints

Hint 1

A single price is really a composition of layers with very different volatility: base price (slow-changing, high-cardinality), promotion rules (fast-changing, low-cardinality), tax tables (stable, tiny), and FX rates (ticking, tiny). Each layer has a different optimal caching strategy. Decomposing the price this way is the key insight that makes both latency and hit-rate targets achievable.

Hint 2

For batch fan-out, the number of downstream network calls should be proportional to the number of distinct cache shards or DB partitions hit — not proportional to the number of items in the batch. Group L2 misses by shard and issue one multi-get per shard, not one call per item. A bounded worker pool and a global per-node concurrency semaphore prevent a large batch from monopolizing all downstream…

Hint 3

Cache keys for personalized prices must include a rule-version token, not the full promo token list. When a flash sale starts, bumping the rule version implicitly invalidates all segment-level cache entries without requiring explicit key enumeration. User-specific promo tokens are applied as a pure in-memory overlay after the segment price is retrieved — they never appear in the cache key.