Design Patterns Tutorial 0/70 lessons ~6 min read Lesson 66

    E-Commerce Checkout Architecture

    E-commerce checkout is the canonical capstone — pricing, inventory, payment, fulfilment, notification, audit.

    Course progress0%
    Focus
    21 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    E-commerce checkout is the canonical capstone — pricing, inventory, payment, fulfilment, notification, audit. This lesson walks full architecture naming every pattern at every seam with trade-offs experience teaches.

    The story

    Marketplace checkout lived in one 4,000-line service. Black Friday: payment retries cascaded into inventory locks into notification floods. Rebuild over two quarters used 8 named patterns; next Black Friday peaked 5× load with zero incidents.

    The business problem

    Checkout failures are direct revenue loss amplified at scale:

    • Cascade: payment retry → inventory hold → notification flood.
    • Peak load: Black Friday exposes every weak seam.
    • PCI/GDPR: payment isolation and audit trails required.
    • Multi-provider: Stripe + regional adapters + fallbacks.

    The problem teams faced

    Checkout architecture forces:

    • Distributed workflow across inventory, payment, shipping.
    • Partial failure compensation — can't leave money charged without order.
    • Reliable domain events for notifications and analytics.
    • Resilience on external payment APIs.

    Understanding the topic

    Intent: Compose patterns into production checkout.

    • Strategy — pricing, shipping cost, promotions.
    • Saga — place order across services with compensation.
    • Circuit Breaker — payment provider resilience.
    • Outbox — OrderPlaced events reliably.
    • Adapter — normalize payment provider SDKs.

    Internal architecture

    Checkout service architecture:

    text
    API Gateway → Checkout BFF
    ├─ PricingService (Strategy: standard, promo, member)
    ├─ InventoryService (Repository + optimistic lock)
    ├─ PaymentService (Adapter: Stripe, Adyen) + CircuitBreaker
    └─ SagaOrchestrator.placeOrder()
    1. reserve inventory → compensate: release
    2. charge payment → compensate: refund
    3. confirm order → Outbox: OrderPlaced → notify/analytics

    Visual explanation

    Three diagrams cover checkout flow, saga compensation, Black Friday resilience:

    Checkout pattern map
    Pricing
    Strategy
    Inventory
    Repository
    Payment
    Adapter + Breaker
    Notify
    Outbox + Strategy
    8 patterns — each at a proven force, not decoration.
    Place order saga
    Reserve inventory
    Step 1
    Charge payment
    Step 2
    Payment fails?
    Compensate
    Release inventory
    Rollback
    Saga orchestrator — no distributed 2PC.
    Black Friday resilience
    5× traffic
    Peak
    Breaker on payment
    Fail fast
    Backup provider
    Fallback
    Zero incidents
    Rebuild outcome
    4,000-line monolith → composed patterns — 5× load survived.

    Informative example

    Saga orchestrator — TypeScript sketch:

    ts
    class PlaceOrderSaga {
    async execute(order: Order) {
    const reservation = await this.inventory.reserve(order.items)
    try {
    const charge = await this.payment.charge(order.total) // breaker inside
    await this.orders.confirm(order.id)
    await this.outbox.publish(new OrderPlaced(order.id))
    return charge
    } catch (e) {
    await this.inventory.release(reservation.id) // compensate
    throw e
    }
    }
    }

    Execution workflow

    1Checkout rebuild workflow
    1 / 4

    Map monolith seams

    Pricing, payment, inventory boundaries.

    4,000-line analysis.

    Real-world use

    Amazon checkout evolution; Shopify checkout extensibility; Stripe payment orchestration; marketplace saga patterns at Etsy/eBay scale.

    Production case study

    Black Friday rebuild:

    • Before: 4,000-line service; cascade failures.
    • Rebuild: 8 patterns over 2 quarters.
    • Outcome: 5× peak load, zero incidents next Black Friday.

    Trade-offs

    • Pro: isolated failure domains; testable seams; scale teams.
    • Con: saga operational complexity; eventual consistency UX.

    Decision framework

    • Multi-step distributed checkout → Saga + Outbox mandatory.
    • Multiple payment providers → Adapter + Strategy + Breaker.
    • Monolith under 10k orders/day → don't prematurely distribute.

    Best practices

    • Idempotent saga steps — retry-safe reserve/charge.
    • Outbox for every domain event leaving checkout.
    • Characterize monolith behavior before extracting saga steps.

    Anti-patterns to avoid

    • 2PC across microservices for checkout.
    • Synchronous notification calls in checkout path.
    • Single payment provider with no breaker or fallback.

    Common mistakes

    • Compensation failures — design idempotent release/refund.
    • Inventory oversell under race — optimistic lock or reservation TTL.

    Debugging tips

    • Saga trace ID through all steps — find stuck compensation.

    Optimization strategies

    • Cache pricing rules; async analytics via Outbox consumers.

    Common misconceptions

    • Checkout ≠ one microservice — workflow spans services with saga.
    • Saga ≠ no consistency — eventual with compensations.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1AdvancedQuestionDesign checkout — key patterns?+

    Answer

    Saga for distributed place-order, Strategy pricing, Adapter+Breaker payment, Outbox events, Repository persistence.

    Follow-up

    Payment fails mid-saga?
    2AdvancedQuestionWhy not 2PC for checkout?+

    Answer

    Blocking, doesn't scale across services, single coordinator failure point. Saga with compensations fits microservices.

    Follow-up

    Compensation example?
    3AdvancedQuestionBlack Friday prep?+

    Answer

    Circuit breaker + backup payment, saga idempotency, load test saga path, Outbox consumer scale, inventory reservation TTL.

    Follow-up

    5× story?

    Summary

    You can architect checkout with named patterns at every seam. Tell the Black Friday 5× story — you own E-Commerce Architecture.

    Ready to mark this lesson complete?Track your journey across the entire course.