#22EasySearch, Autocomplete & Big Data

Top K Elements: App Store Rankings, Amazon Bestsellers, etc.

ASKED IN INTERVIEWS AT:AmazonBloombergMetaPinterest

EXECUTIVE SUMMARY & PROBLEM STATEMENT

Design a real-time leaderboard service displaying the top 100 best-selling items or trending apps updated continuously across millions of purchases.

SCALE ESTIMATION & TRAFFIC ENVELOPE

DAILY ACTIVE USERS / TPS100,000 purchases/second peak
READ / WRITE TRAFFIC RATIO1:10 read-to-write
5-YEAR STORAGE CAPACITYRedis ZSET with 1M products ~ 100 MB RAM

FUNCTIONAL REQUIREMENTS

  • [1]Increment score when purchase occurs
  • [2]Query top K items by category or platform in real time

NON-FUNCTIONAL REQUIREMENTS

  • •Query response latency < 20ms
  • •Support high write throughput without Redis CPU saturation

CORE ARCHITECTURAL COMPONENTS

Purchase Event Bus
Write Aggregation Buffer
Redis Master-Replica ZSET
Top-K Cache Snapshot Worker

DATA SCHEMA & PERSISTENCE

Redis ZSET `leaderboard:{category}:{date}` score: sales_count, member: product_id

DISTRIBUTED TRADE-OFFS & FAILURE MODES

  • ⟡Batching score increments in application memory for 1 second reduces Redis commands by 90% at the cost of 1s latency.