0
0
LLDsystem_design~10 mins

Product, Cart, Order classes in LLD - Scalability & System Analysis

Choose your learning style9 modes available
Scalability Analysis - Product, Cart, Order classes
Growth Table: Product, Cart, Order Classes
ScaleUsersProductsCarts ActiveOrders PlacedSystem Changes
Small1001,0005020Single server, simple DB, no caching
Medium10,00010,0005,0002,000DB read replicas, caching for products, load balancer
Large1,000,000100,000100,00050,000Sharded DB, distributed cache, multiple app servers, async order processing
Very Large100,000,0001,000,00010,000,0005,000,000Microservices, event-driven order system, CDN for product data, global DB shards
First Bottleneck

At small scale, the database is the first bottleneck. It handles product lookups, cart updates, and order writes. As users grow, the DB CPU and I/O get overwhelmed by many read and write requests.

Scaling Solutions
  • Read Replicas: Use read-only copies of the database to handle product and cart read queries, reducing load on the main DB.
  • Caching: Cache product details and cart sessions in memory (e.g., Redis) to reduce DB hits.
  • Horizontal Scaling: Add more application servers behind a load balancer to handle increased user requests.
  • Sharding: Split the database by user ID or order ID to distribute writes and reads across multiple DB instances.
  • Async Processing: Use message queues to process orders asynchronously, reducing latency and DB write spikes.
  • CDN: Serve static product images and data from a CDN to reduce bandwidth and server load.
Back-of-Envelope Cost Analysis
  • At 1M users, assuming 5% active carts = 50,000 carts active concurrently.
  • Each cart update generates ~2 DB writes per minute -> 100,000 writes/min = ~1,666 writes/sec.
  • Orders placed at 50,000/day -> ~0.6 orders/sec, but spikes during sales.
  • Product catalog reads at 1M users -> ~10,000 QPS for product info.
  • Bandwidth for product images served via CDN reduces load on origin servers.
Interview Tip

Start by explaining the main components: Product, Cart, Order. Discuss how each scales with users and data. Identify the database as the first bottleneck. Then propose solutions in order: caching, read replicas, horizontal scaling, sharding, async processing. Use numbers to justify your choices.

Self Check Question

Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?

Answer: Add read replicas and implement caching for product and cart data to reduce load on the main database before considering sharding or more complex solutions.

Key Result
The database is the first bottleneck as users grow; adding caching and read replicas is the first step to scale Product, Cart, and Order classes efficiently.