In a simple e-commerce system, what is the main responsibility of the Order class?
Think about what happens after a user completes their purchase.
The Order class represents a finalized purchase. It stores the products bought, their quantities, and payment or shipping status. The Cart manages products before purchase.
Which class should be responsible for calculating the total price of all products including quantities and discounts?
Consider where the products and quantities are managed before checkout.
The Cart class holds products and quantities before purchase, so it is best placed to calculate the total price including discounts. Product only knows single item price, Order is finalized, and PricingService is optional.
When many users add products to their carts at the same time, which design approach best ensures performance and data consistency?
Think about fast access and avoiding bottlenecks for many users.
Using in-memory cache per user reduces database load and improves speed. Periodic sync ensures data persistence. Single table locking or global locks cause bottlenecks. Querying DB on every action is slow.
What is a key tradeoff when the Cart stores full product details versus only product IDs with quantities?
Consider data duplication and access speed.
Storing full product details in Cart duplicates data but avoids extra lookups, improving speed. Storing only IDs saves space but requires fetching product info separately.
Your e-commerce system expects 10,000 orders per minute at peak. Each order has on average 5 products. Estimate the minimum number of database writes per second needed to store orders and order items.
Calculate total writes considering one write per order and one per product item.
10,000 orders/min ≈ 167 orders/sec. Each order: 1 write (order) + 5 writes (items) ≈ 1,000 writes/sec base. With overhead (logs, updates, etc.), approximately 3,000 writes/sec. Closest is C.