Scalable Contest Winners Page
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-04-13
Problem Statement
Design and implement a highly scalable and performant web page that displays the list of daily contest winners. The page should fetch data from backend services, support frequent updates, and handle large traffic during peak hours (e.g., right after contest results are announced).
Requirements
Functional
1.<span></span>Display a list of contest winners for the current day.
2.<span></span>Support filtering/search (by contest name, user, rank).
3.<span></span>Auto-update results when new winners are declared.
4.<span></span>Provide APIs to fetch winners (daily and historical).
Non-Functional
1.<span></span>Scalability – Handle traffic spikes (millions of users simultaneously).
2.<span></span>Performance – Page load < 200ms for cached data.
3.<span></span>Consistency – Users should see the latest results with minimal lag.
4.<span></span>Availability – System must remain available during peak traffic.
5.<span></span>Caching – Use smart caching (CDN, Redis, API-level caching) to reduce DB load.
Design Considerations
1.<span></span>Frontend (Page Components)
2.<span></span>Winners List Component
3.<span></span>Filters/Search Component
4.<span></span>Auto-refresh / Live Updates via WebSockets or Polling
5.<span></span>Pagination / Infinite Scroll for historical results
6.<span></span>Backend Services
7.<span></span>Contest Service – declares winners
8.<span></span>Winners API Service – exposes REST/GraphQL APIs to fetch winners
9.<span></span>Notification/Streaming Service – pushes updates to clients
10.<span></span>Data Layer
11.<span></span>Winners stored in DB (partitioned by contest/date).
12.<span></span>Cache layer (Redis/Memcached) for recent results.
13.<span></span>Historical data offloaded to cold storage (S3/BigQuery).
14.<span></span>API Structure
15.<span></span>GET /winners/today – fetch today’s winners
16.<span></span>GET /winners/{date} – fetch winners for a specific date
17.<span></span>GET /winners?c123 – filter by contest
18.<span></span>WS /winners/live – subscribe for live updates
19.<span></span>Scalability Techniques
20.<span></span>CDN for static content (page shell, JS, CSS).
21.<span></span>API Gateway + Load Balancer.
22.<span></span>Read-heavy optimization → cache results in Redis and serve from CDN edge.
23.<span></span>Event-driven pipeline (Kafka) for updating winners in near real time.
Trade-offs to Discuss
1.<span></span>Push vs Polling for Live Updates – Push reduces latency but adds infra complexity.
2.<span></span>DB Choice – SQL (for structured joins) vs NoSQL (for scale & partitioning).
3.<span></span>Caching Strategy – Cache invalidation frequency (e.g., TTL vs event-based).
4.<span></span>Scalability vs Freshness – Serving from cache may slightly delay fresh data.