call(back)

Design a Shopping Cart (Front End)

Design the shopping cart of a large e-commerce web app from the front end's point of view: anonymous and signed-in carts, several tabs open at once, poor or absent connectivity, and prices or stock that change while the cart is open.

Cover the data model (items, quantities, variants, promotions), client state management and caching, the sync strategy with the backend (optimistic updates, conflict resolution, idempotency), performance for large carts and few API calls, observability and failure handling. You may propose the APIs and backend pieces you need, but the focus is the client architecture and the end-to-end behaviour.

Hints

Hint 1

Keep one normalized cart in a store keyed by line id (variant plus options), persisted locally, and treat the server's cart as the source of truth that the client reconciles with, not a copy to overwrite.

Hint 2

Every mutation is a small command with a client-generated idempotency key; apply it optimistically, queue it, send it, and reconcile from the server's response (which carries the cart version and current prices).

Hint 3

Tabs share one cart through the storage event or a BroadcastChannel, with a single tab electing itself to talk to the server so two tabs do not race the same queue.

Asked at

Similar Problems6