| Users | Coupon Requests/Second | Database Reads/Writes | Cache Usage | System Complexity |
|---|---|---|---|---|
| 100 users | ~10 req/s | Low (few DB queries) | Minimal or none | Simple validation logic |
| 10,000 users | ~1,000 req/s | Moderate (more reads, some writes) | Basic caching for coupons | Introduce cache, rate limiting |
| 1,000,000 users | ~100,000 req/s | High (heavy DB load) | Distributed cache (e.g., Redis cluster) | Sharding, load balancing, async processing |
| 100,000,000 users | ~10,000,000 req/s | Very high (DB bottleneck) | Multi-region caches, CDN for static coupon data | Microservices, event-driven, global distribution |
Pricing strategy (discounts, coupons) in LLD - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small to medium scale, the database is the first bottleneck. Coupon validation requires frequent reads and writes (e.g., usage count, expiration). As traffic grows, DB query volume and write contention increase, causing latency and failures.
- Caching: Use in-memory caches (Redis) to store coupon data and validation rules to reduce DB reads.
- Read Replicas: Add DB replicas to distribute read load.
- Sharding: Partition coupon data by user or coupon ID to spread writes and reads across multiple DB instances.
- Async Processing: Use message queues to handle coupon usage updates asynchronously to reduce write contention.
- Rate Limiting: Prevent abuse by limiting coupon validation requests per user/IP.
- Microservices: Separate pricing and coupon logic into dedicated services for independent scaling.
- CDN: Cache static coupon metadata globally to reduce origin load.
Assuming 1M users with 10% using coupons, each making 1 validation request per minute:
- Requests per second: (1,000,000 * 0.1) / 60 ≈ 1,667 req/s
- Database QPS: ~1,667 (mostly reads, some writes)
- Cache size: Coupon data ~100B per coupon * 10,000 active coupons = ~1MB RAM
- Bandwidth: Each request ~1KB, total ~1.6MB/s (13Mbps)
At 100M users, scale these numbers by 100x, requiring distributed caching, sharded DB, and load balancing.
Start by clarifying traffic patterns and coupon usage frequency. Identify the main bottleneck (usually DB). Discuss caching and async updates to reduce load. Explain how sharding and microservices help at large scale. Mention rate limiting to prevent abuse. Always justify your choices with traffic and data estimates.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Introduce caching to reduce DB reads and add read replicas to distribute load. Also consider async processing for writes to reduce contention.
Practice
Solution
Step 1: Understand the role of discounts and coupons
Discounts and coupons are marketing tools used to lower prices temporarily.Step 2: Identify the business goal
Lower prices attract more customers, which can increase sales volume and customer loyalty.Final Answer:
To attract more customers and increase sales volume -> Option DQuick Check:
Discounts and coupons = attract customers [OK]
- Thinking discounts increase prices
- Confusing discounts with product quality
- Assuming coupons slow checkout
Solution
Step 1: Understand percentage representation in code
Percentages are usually represented as decimals for calculations, so 20% is 0.2.Step 2: Check each option
discount = 0.2 uses 0.2 which is correct; others are incorrect as they represent wrong values.Final Answer:
discount = 0.2 -> Option CQuick Check:
20% = 0.2 decimal [OK]
- Using whole number 20 instead of decimal
- Confusing 2 or 200 as percentage
- Not converting percentage to decimal
price = 100 coupon_discount = 15 # fixed amount final_price = price - coupon_discount print(final_price)
What will be the output?
Solution
Step 1: Understand the variables
Price is 100, coupon_discount is 15 fixed amount.Step 2: Calculate final price
final_price = 100 - 15 = 85.Final Answer:
85 -> Option AQuick Check:
100 - 15 = 85 [OK]
- Confusing discount as percentage
- Adding instead of subtracting discount
- Printing coupon_discount instead of final price
price = 200 discount = 20 # intended as 20% final_price = price - discount print(final_price)
Solution
Step 1: Identify discount representation
Discount is 20 but intended as 20%, so it should be 0.2 in decimal.Step 2: Correct calculation method
final_price should be price - (price * discount_decimal), not price - discount integer.Final Answer:
Discount should be converted to decimal before calculation -> Option BQuick Check:
20% = 0.2 decimal needed [OK]
- Subtracting integer discount directly
- Adding discount instead of subtracting
- Ignoring percentage to decimal conversion
Solution
Step 1: Apply the $5 coupon discount first
$50 - $5 = $45.Step 2: Apply the 10% seasonal discount
$45 * 0.9 = $40.5.Step 3: Sequential discounts
Coupon before percentage discount yields $40.5.Final Answer:
$40.5 -> Option AQuick Check:
Coupon then percentage = 40.5 [OK]
- Applying discounts in wrong order
- Adding discounts instead of subtracting
- Ignoring percentage vs fixed discount difference
