CASE STUDY 02 / CONCURRENCY & CQRSCHECKOUT & IDEMPOTENCY

SAFE EVEN WHEN THE REQUEST REPEATS.

An e-commerce backend designed around checkout, payments, inventory workflows and safe handling of repeated operations, built on ASP.NET Core with Clean Architecture and CQRS.

IDEMPOTENCY EXECUTION FLOWREQUEST → IDEMPOTENCY KEY CHECK
PATH 01 // FIRST RUN
REQUEST INCOMINGKEY SUPPLIED
OPERATION PROCESSED?NO
PROCESS OPERATIONDOMAIN LOGIC
SAVE RESULTRECORDED
PATH 02 // REPEATED PASS
RETRY / DUPLICATE WEBHOOKSAME KEY
OPERATION PROCESSED?YES
DO NOT REPEAT SIDE EFFECTSHORT-CIRCUIT
RETURN SAFE RESULTSTORED RESPONSE
  1. 01 / SECTION

    THE PROBLEM

    Checkout and payment workflows receive retried commands and duplicate webhooks when networks fail or clients retry.

    Without protection, a single customer action can charge twice, decrement stock twice, or create duplicate orders.

  2. 02 / SECTION

    THE APPROACH

    Idempotency keys ensure operations process once; subsequent requests safely return the stored result without re-triggering side effects.

    Commands and queries are separated with CQRS through MediatR, so write paths stay explicit about the state they change.

  3. 03 / SECTION

    STRUCTURE

    Clean Architecture keeps domain rules independent of ASP.NET Core and EF Core, with the domain model owning invariants around carts, orders and inventory.

    JWT-based authentication protects the API surface, and Redis backs caching and fast lookups on hot read paths.

  4. 04 / SECTION

    OUTCOME

    Repeated checkout attempts and duplicate payment webhooks converge on a single correct result.

    The backend stays predictable under retry-heavy, real-world network conditions instead of only on the happy path.

TECHNICAL STACK
  • ASP.NET CORE
  • EF CORE
  • CLEAN ARCHITECTURE
  • DDD
  • CQRS
  • MEDIATR
  • JWT
  • REDIS