Design Recently Viewed Listings for a User

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2022-02-16

Problem Statement

Designing the Recently Viewed Listings feature for a large-scale e-commerce platform (e.g., Amazon, Flipkart). When a user browses product listings, the system should capture these interactions and display a personalized, chronologically ordered list of recently viewed items.


The feature must be efficient, scalable, and provide a smooth user experience across web and mobile apps.


✅ Functional Requirements

1.<span></span>Track when a user views a product listing.
2.<span></span>Store a fixed number (e.g., last 50) of recently viewed items per user.
3.<span></span>Display the recently viewed listings in reverse chronological order.
4.<span></span>Deduplicate listings → if a user views the same item multiple times, it should appear only once (latest timestamp retained).
5.<span></span>Support multi-device sync (recent views on mobile should appear on web).


⚙️ Non-Functional Requirements

1.<span></span>Low latency → Show recent listings instantly.
2.<span></span>Scalability → Support millions of users and billions of product views daily.
3.<span></span>Durability → Data must not be lost (even if the user logs out and comes back later).
4.<span></span>Consistency → Views across devices should reflect in near real-time.


🔐 Constraints

1.<span></span>Limit on storage per user (e.g., last 50 or 100 items).
2.<span></span>Need to handle high write throughput (as every view is an event).
3.<span></span>Reads are frequent (shown on homepage, product page, etc.).


🎯 Discussion Areas

1.<span></span>Data Flow
2.<span></span>How product view events are captured (tracking service, Kafka, event stream).
3.<span></span>Real-time vs batch updates to the user’s recently viewed list.
4.<span></span>Data Modeling
5.<span></span>Store per-user recent items in Redis / DynamoDB / Cassandra.
6.<span></span>Maintain ordering by timestamp.
7.<span></span>TTL (time-to-live) policies for old items.
8.<span></span>System Components
9.<span></span>Tracking service (event ingestion).
10.<span></span>Storage layer for recent views.
11.<span></span>API layer to fetch & update recently viewed items.
12.<span></span>Caching for fast reads.
13.<span></span>Scalability & Reliability
14.<span></span>Sharding user data by user ID.
15.<span></span>Handling hot users (very high activity).
16.<span></span>Ensuring deduplication under concurrent requests.
17.<span></span>Trade-offs
18.<span></span>Redis (fast but expensive memory) vs. persistent DB (slower but durable).
19.<span></span>Push updates vs. pull reads for syncing across devices.
20.<span></span>Exact ordering guarantees vs. eventual consistency.


👉 The candidate is expected to design the overall system architecture, storage strategy, and retrieval mechanism for a user’s recently viewed listings, while discussing trade-offs in performance, scalability, and cost.

Solution

Comments