Design an E-commerce Cart + Product Page
Problem statement
Design a product page with variant selection, real-time stock, and a persistent cart — covering guest cart in localStorage, cart merge on login, promo codes, and optimistic add-to-cart.
Asked In
Key Challenges
- ·Complex variant selection (Size/Color/Material) with real-time stock mapping
- ·Persistent Guest Cart (localStorage) with seamless merge logic on user login
- ·Optimistic 'Add to Cart' with instant feedback and robust error recovery
- ·Cart consistency across multiple tabs and devices (StorageEvent + Polling/WS)
- ·Race conditions between stock checks and checkout submission
- ·Ensuring SEO indexing (JSON-LD) and Core Web Vitals (LCP, CLS) aren't compromised by heavy client-side state
- ·Maintaining full accessibility (keyboard navigation, ARIA live regions) during optimistic UI state changes
2-Minute Answer — High-Level TL;DR
Read this before your interview
HLD Interview Focus
I would treat the cart as a durable server document with a client cache — not a Context array. Line quantity edits apply optimistically with version/etag checks and rollback on stock conflict. Guest carts merge into the auth cart on login with explicit collision rules. Multi-tab sync listens for storage or push so totals do not diverge. Checkout never optimistic-completes payment: revalidate price and inventory, then redirect to the payment provider. The hard parts are merge, stock races, and money correctness — not the badge count.
My Approach: Building the Solution
How to think about this problem
I'll start from two tabs updating quantity while stock hits zero — then design optimistic lines, reconciliation, and the checkout gate.
Why This Approach?
Most candidates keep a cart array in Context and call it done. That answer collapses on guest→auth merge, two tabs racing quantity changes, and stock hitting zero at checkout. Strong answers model a durable server cart, optimistic line edits with rollback, and a payment gate that revalidates totals.
A cart is a whiteboard on the fridge: everyone in the house (tabs/devices) can erase a line, but the store clerk (server) decides what is actually sellable at the register.
Requirements: What Makes a Great Solution?
Clarify scope before designing anything
Requirements Exploration Questions
Ask your interviewer these questions to refine requirements
How deep are the product variants?
- ·Flat list vs multi-dimensional (Size + Color + Material)
- ·Price differences per variant SKU
- ·Dynamic availability (some variants out of stock)
What is the persistence requirement?
- ·Guest checkout support (localStorage/SessionStorage)
- ·Cross-device sync (Merge guest cart into account on login)
- ·TTL for cart items (Expire after X days)
What are the real-time stock requirements?
- ·Soft stock check on PDP (Product Detail Page)
- ·Hard stock reservation on Checkout
- ·Polling frequency for 'low stock' items
What are the SEO and Delivery requirements?
- ·Search engine indexing needs (Structured Data/JSON-LD)
- ·Global audience handling (CDN, Internationalization/i18n)
- ·Network adaptive loading (e.g., flaky 3G vs 5G)
Functional Requirements
Must Have — MVP
- ✓Variant selection with SKU resolution
- ✓Optimistic Add-to-Cart with success animation
- ✓Persistent cart (survives refreshes)
- ✓Cart merge logic on authentication
- ✓Stock status indicators (In stock / Out of stock)
- ✓Semantic HTML and ARIA attributes for dynamic cart states
Advanced (If Time Permits)
- +Promo code / Coupon validation
- +Cross-tab synchronization (StorageEvent)
- +Wishlist / Save for later toggle
- +Bundle deals and cross-sell suggestions
Non-Functional Requirements
Performance
- ·PDP TTI < 1s (Critical for conversion)
- ·Optimistic Cart updates < 50ms
- ·Core Web Vitals compliance (LCP < 2.5s, strict CLS bounds, low INP)
- ·Image lazy loading, WebP formatting, and adaptive media delivery
Reliability
- ·Idempotent cart additions (prevent double-clicks)
- ·Consistent prices (Client vs Server validation)
- ·Graceful handling of expired SKUs
SEO & Accessibility
- ·JSON-LD structured data injected per variant
- ·WCAG 2.1 AA compliance (Focus trapping in cart drawer, screen reader announcements)
- ·Progressive Hydration to prevent double-data loading
The full solution is part of HelloFrontend Pro
The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.
- Full RADIO-framework walkthrough with architecture diagrams
- Data model, API design, and rendering strategy trade-offs
- Performance, accessibility, and offline sections plus a model answer
Already a member? Log in to open the workspace.