You are tasked with designing a shopping cart system that supports millions of users simultaneously. Which architectural choice best ensures scalability and low latency?
Think about fast access and handling many users without bottlenecks.
Using a distributed in-memory cache allows fast read/write access to shopping cart data, reducing latency and supporting high concurrency. Periodic persistence ensures data durability.
Which session management approach best balances security and user experience for a shopping cart on a web application?
Consider security risks like session hijacking and user convenience.
Storing session IDs in secure, HttpOnly cookies prevents client-side scripts from accessing them, reducing attack risk. Short expiration with renewal balances security and usability.
In a load-balanced web application with multiple servers, what is the best way to manage shopping cart sessions to ensure consistency and availability?
Consider fault tolerance and server failures in your design.
Using a shared distributed cache allows any server to access session data, improving availability and fault tolerance compared to sticky sessions or database-only storage.
What is the main tradeoff when choosing how frequently to persist shopping cart session data from cache to permanent storage?
Think about balancing system load and data durability.
Persisting session data too often can overload the database, while persisting too rarely risks losing recent user changes if the cache fails.
Your e-commerce platform expects 10 million active users daily. Each shopping cart session averages 5 items, with each item record requiring 200 bytes. Sessions are stored in cache for 24 hours. Estimate the approximate memory needed to store all active shopping cart sessions in the cache.
Calculate total bytes: users × items per cart × bytes per item, then convert to GB.
10 million users × 5 items × 200 bytes = 10,000,000 × 1,000 bytes = 10,000,000,000 bytes ≈ 10 GB. But this is raw data; overhead and indexing typically multiply memory needs by about 10, so ~100 GB is realistic.
