Skip to main content

Preview — Pro guide

You are seeing a portion of this guide. Sign in and upgrade to unlock the full article, quizzes, and interview answers.

Online Shopping Cart & Checkout — LLD (Lines, Idempotency, Order Boundaries)

Object-oriented design for a production-style cart: immutable product snapshots, merge-on-login, promotion strategies, and checkout with idempotency keys aligned to payment APIs. Explains when cart inventory is advisory vs when it must call reservation services, and how Order differs from Cart as an aggregate.

50 min read 3 sections 1 interview questions
Online Cart LLDIdempotency KeyStripeCheckoutAggregate RootLine ItemProductSnapshotPromotion StrategyMerge CartObject-Oriented DesignOrder vs CartSEDIE Framework
IMPORTANT

What Interviewers Are Actually Testing

They want to see whether you can draw aggregate boundaries: Cart is a mutable working document; Order is an immutable, paid or payable contract. Weak candidates stuff everything into a User and leak HTTP session into domain objects. Strong candidates show ProductSnapshot on the line (price at add time) so a catalog reprice does not retroactively nuke the cart, and a CheckoutService that accepts an idempotency key so double POST from flaky mobile cannot place two Order rows — the same pattern payment APIs (Stripe) document for mutating calls. A staff signal: cart availability is usually best-effort until checkout, where a reservation or ORDER BY stock FOR UPDATE step finally commits against stock.

Clarifying Questions (SEDIE — S)

01

Cart ownership — session vs logged-in user?

Model CustomerId (nullable) + session_id. Merge anonymous cart into user on login. Interface CartRepository keyed by (customer, session) per your auth story.

02

Price source — live catalog, or price when added?

Snapshot on add or on checkout line-lock. E-commerce default: snapshot per line to avoid customer shock and audit disputes, with optional 'price changed' notice.

03

Inventory — reserve on add, or at checkout only?

Advisory until submit is typical for most SKUs. High-conflict (limited sneaker) may call InventoryService on add with short TTL — say both and let interviewer choose.

04

Promotions and tax?

PromotionEngine (Strategy) returns adjustments; TaxCalculator interface by jurisdiction — do not hardcode 8% in Cart.

05

Guest checkout and partial shipments?

Below the line: split Order into Shipment aggregates; LLD can stop at a single Order with line items for v1.

06

Multi-currency?

Money in minor units + Currency on cart; FX conversion is a separate service, not a float field.

IMPORTANT

Premium content locked

This guide is premium content. Upgrade to Pro to unlock the full guide, quizzes, and interview Q&A.