KatInterview

Event Store for Shopper Behavior Analytics and Fixed Reports

System DesignModel answer
MediumModel answerSystem Designsystem-designanalyticsolap

Last updated

Design a storage and ingestion system for shopper activity events that serves a known set of reports, such as regional unique viewers and top orders, with low latency.

Behavioral Analytics Store for an Online Shop

You are building the analytics backend for a shopping platform. The product emits the following user actions:

  • searching for an item
  • viewing an item page
  • logging in
  • adding an item to the cart
  • viewing the cart
  • completing a purchase
  • viewing an order

The reports that the business wants are known in advance. Two examples:

  1. How many distinct users from Asia viewed item A during the current month?
  2. Which three orders currently have the highest value?

What to deliver

Design the database and the pipeline around it. Your answer should cover:

  • Requirements and scale assumptions: freshness, accuracy, expected event volume, and growth.
  • Event model: the fields every event carries and how type-specific data is handled.
  • Schema: table layout, partitioning and sort keys, and any pre-aggregated structures.
  • Data flow: how events travel from clients to queryable storage, including deduplication and replay.
  • The two sample queries: show how your design answers each one efficiently.
  • Trade-offs and failure modes: late or duplicate events, mutable order state, exact versus approximate counts, and how you would roll the system out.

State your assumptions explicitly. There is no single correct answer, but your choices should be justified by the access patterns.

Hints

Hint 1

Because the reports are known ahead of time, you can denormalize and pre-aggregate for them instead of building a fully general model. Think about which columns each report filters and groups on.

Hint 2

Distinct-user counts cannot simply be added across days. Consider mergeable sketches (HyperLogLog) or bitmaps for the rollup, and decide where exactness matters.

Hint 3

Orders change state (cancelled, refunded), so a click event is not a reliable source of truth for 'current' order value. Consider a separate current-state table fed from the transactional orders database.