Overview
The Event-Driven Order Processing Pipeline is a production-grade order management system that handles the complex, multi-step workflow of processing an order: inventory reservation, payment authorization and capture, fraud checks, fulfillment orchestration, and shipping notification. It uses the Saga pattern with compensating transactions to ensure data consistency across services without requiring distributed transactions.
Built with Node.js, TypeScript, PostgreSQL, Redis, and BullMQ, the pipeline processes orders as a series of discrete, observable steps. Each step either succeeds and advances to the next stage, or fails and triggers compensating actions to roll back previous steps. This makes the system resilient to partial failures -- a common reality in distributed e-commerce architectures.
Architecture
The pipeline is organized around the Saga orchestrator pattern:
- Order Intake -- Orders enter the system through a validated API endpoint. The order is persisted with a
PENDING status and an order saga is initiated. Each order gets a unique correlation ID that tracks it through every step of the pipeline.
- Inventory Reservation -- The first saga step reserves inventory for each line item. Reservations are time-limited (configurable TTL, default 15 minutes) to prevent indefinite holds. If any item is out of stock, the saga fails immediately and no payment is attempted.
- Payment Processing -- With inventory reserved, the payment step authorizes the charge. For card payments, this creates a Stripe PaymentIntent with
capture_method: manual. The actual capture happens only after fulfillment is confirmed, protecting customers from being charged for unshippable orders.
- Fraud & Validation -- A pluggable fraud check step runs rules against the order: velocity checks, address verification, amount thresholds. The system ships with a rule engine that can be extended with custom fraud detection logic or integrated with third-party services.
- Fulfillment Orchestration -- Once payment is authorized and fraud checks pass, the fulfillment step determines the optimal shipping strategy, generates picking lists, and notifies the warehouse system. For multi-warehouse setups, orders can be split across fulfillment centers.
- Compensation & Rollback -- If any step fails after previous steps have succeeded, the saga orchestrator runs compensating transactions in reverse order. Payment authorizations are voided, inventory reservations are released, and the order status is updated with a detailed failure reason.
Key Features
- Saga Orchestration -- Declarative saga definitions with automatic compensation. Define your order steps and their rollback actions, and the orchestrator handles the rest.
- Compensating Transactions -- Every saga step has a corresponding compensation action. If payment fails, inventory is automatically released. If fulfillment fails, payment is voided.
- Inventory Management -- Real-time stock tracking with reservation support. Time-limited holds prevent overselling. Supports multi-warehouse inventory with configurable allocation strategies.
- Payment Lifecycle -- Two-phase payment processing (authorize then capture) protects against charging for unfulfillable orders. Supports partial captures and refunds.
- CQRS Read Models -- Separate read models optimized for common queries: order history, inventory levels, fulfillment status. Updated asynchronously via domain events.
- Event Sourcing -- Every state change is recorded as an immutable event. Full order history is reconstructable from the event log, enabling audit trails and debugging.
- Dead-Letter Queue -- Orders that fail all retry attempts land in a DLQ with complete saga context, enabling manual intervention and replay.
- Observability -- Structured logging with correlation IDs, processing time metrics for each saga step, and alerting hooks for failed sagas.
What's Included
- Full TypeScript source code with strict typing throughout
- Saga orchestrator framework with declarative step definitions
- Inventory service with reservation management
- Stripe payment integration (authorize/capture/void/refund)
- Fraud rule engine with extensible rule interface
- BullMQ job definitions with retry and dead-letter configuration
- CQRS read model projections
- Event store with PostgreSQL-backed persistence
- Database schema and migrations (Prisma)
- Docker Compose for local development (Node.js, PostgreSQL, Redis)
- Comprehensive test suite including saga compensation scenarios
- API documentation with OpenAPI 3.0 spec
Who Is This For?
This pipeline is for engineering teams building e-commerce platforms, marketplaces, or any application with complex order workflows that involve multiple systems (inventory, payments, fulfillment) that must stay consistent. If you have ever dealt with customers being charged for out-of-stock items, or inventory counts drifting out of sync, this system's saga-based approach eliminates those failure modes.
It is especially valuable for teams scaling beyond a monolithic order processing function and moving toward event-driven architecture. The patterns here -- sagas, compensating transactions, CQRS, event sourcing -- are production-proven and will serve as the foundation for a scalable order management system.