ArchitectAI resilience reviews are here. See what's new
Back to all articles
Low Level Design Sep 08, 2026 14 min read

Low Level Design: Shopping Cart & Coupon Discount Engine with Composite Pattern

Design an enterprise promotion and coupon engine. Handling stacked discounts, buy-one-get-one rules, minimum basket values, and coupon exclusivity with Composite pattern.

LLDDesign PatternsComposite PatternE-CommerceOOP
HFHLDForge Architecture TeamLead Machine Coding Specialist

1. Problem Complexity: Combinatorial Discounts

E-commerce carts support diverse promotional mechanics: Flat dollar discounts ($10 off), Percentage discounts (15% off cart), Category-specific discounts (20% off Shoes), and Buy-X-Get-Y rules.

The challenge lies in discount ordering, exclusivity rules (coupons that cannot be combined), and maximum cap limits.

2. Composite & Decorator Patterns for Discount Application

We model discounts using the Composite Pattern: a `Coupon` interface with an `applyDiscount(cart: Cart): number` method. A `CompositeDiscount` aggregates multiple rules, evaluating applicability in order of priority.

3. Code Implementation

Here is the clean object-oriented discount engine:

typescript
interface CartItem {
  id: string;
  price: number;
  quantity: number;
  category: string;
}

interface DiscountStrategy {
  apply(cartTotal: number, items: CartItem[]): number;
}

class PercentageDiscount implements DiscountStrategy {
  constructor(private percent: number, private maxCap: number) {}
  apply(total: number): number {
    const discount = (total * this.percent) / 100;
    return Math.min(discount, this.maxCap);
  }
}

class FlatDiscount implements DiscountStrategy {
  constructor(private flatAmount: number, private minThreshold: number) {}
  apply(total: number): number {
    return total >= this.minThreshold ? this.flatAmount : 0;
  }
}
Interactive Modeling ArchitectAI

Model this architecture on the HLDForge Canvas

Turn static box diagrams into living, collaborative systems. Drag and drop microservices, Kafka clusters, and cache tiers. Run automated SPOF detection and STRIDE threat modeling in real time.

HF

Written by HLDForge Architecture Team

Lead Machine Coding Specialist

The HLDForge Architecture Team publishes practical engineering guides, real-world case studies, and high-concurrency blueprints to help engineers build scalable and fault-tolerant software.

Free forever plan

Ready to master distributed system design?

HLDForge gives you the tools, templates, and AI reviews to design systems like a Staff Engineer. Get started free.

SOC 2 Type II · ISO 27001 aligned · SSO on every paid plan