1 ) DAU = 10M
Concurrent Users = 20% off DAU = 02 M
Read QPS = 2 M /24*3600=20
Write QPS = 2
1) List the Product
GET /api/v1/search
return list of the product available for sale
2)Purchase the product
POST /api/v1/purchase
parameters { product_id,user_id,count,price}
return success/failure messages
1) User table
User_id: UUID(primary key)
name :String
address: String
email_id = String
2)Product table
product_id :UUID (primary_key)
product_name: String
quantity: int
inventory_id:int (foreign key)
3) Inventory table
inventory_id:UUID(primary key)
product_id: int(foreign key)
available_Quantity
Sold_quantity:String
4)order table
order_id:uuid(primary_key)
product_id:int(foreign key)
user_id(foreign_key)
status:String
1) User search request will be authenticated via API gateway and redirect to search Services.
2) Search service fetches the product from search index and we use elastic search for that and then check the availability of the product by calling availability service.
3)Availability services fetches the product availability and quantity from distributed cache.
4) Distributed cache is populated based on CDC ,if there any change in inventory CDC will be triggered and do the invalidation of cache.
5)User can use order serivce to purchase the item and we can use Kafka for asynchronous purchase experience
1) As one of the major constraints is how the system is available and scalable in case of concurrent peak load for that purpose we are going to use the search index to fetch the product quickly and based on load we can horizontally scale the search service ,Secondly we need to peak the product availability and quantity we need to call availability service fetched the real time data from distributed cache and we can use Redis for that .We can also have two level cache one is in-memory cache to peek the recent product search and second from Redis .The Redis cache invalidation will be based on CDC pattern and we want to have almost real time consistent data to avoid the excess product sale.
2)To handle the concurrent users and access of inventory and place order in fair manner we can plan to have epoc time stamp when user select any product during flash sale and then use Redis sorted set to sort the order based on epoc timestamp and then allow the order to process in that order for fairness
1 .