Skip to content

Repository files navigation

PixelMart-Order Processor

.NET PostgreSQL RabbitMQ Docker

This ASP.NET Core system delivers a scalable, event-driven e-commerce order processor. It showcases key production patterns: a decoupled microservices architecture, reliable asynchronous message processing with RabbitMQ, and robust distributed transaction management utilizing PostgreSQL.

🏗️ Architecture

┌─────────────┐         ┌──────────────┐         ┌──────────────────┐
│  Client/UI  │ ──────> │  OrderAPI    │ ──────> │   RabbitMQ       │
│             │ <────── │ (Publisher)  │         │  Message Broker  │
└─────────────┘         └──────────────┘         └──────────────────┘
                                                           │
                              ┌────────────────────────────┼────────────────────┐
                              │                            │                    │
                              ▼                            ▼                    ▼
                    ┌──────────────────┐      ┌──────────────────┐   ┌──────────────────┐
                    │ Payment Worker   │      │ Inventory Worker │   │  Email Worker    │
                    │  (Consumer)      │      │   (Consumer)     │   │  (Consumer)      │
                    └──────────────────┘      └──────────────────┘   └──────────────────┘
                              │                            │                    │
                              └────────────────────────────┼────────────────────┘
                                                           ▼
                                                 ┌──────────────────┐
                                                 │   PostgreSQL     │
                                                 │    Database      │
                                                 └──────────────────┘

✨ Features

Core Capabilities

  • Asynchronous Order Processing - Non-blocking order placement with immediate API response
  • Event-Driven Architecture - Loose coupling between services using message queues
  • Distributed Transaction Management - Multi-step order workflow with status tracking
  • Fault Tolerance - Message acknowledgment, retry logic, and dead letter queue support
  • Data Persistence - Full ACID compliance with PostgreSQL
  • Audit Trail - Complete order history with timestamps and status transitions

Technical Features

  • 🔐 Secure Configuration Management - User Secrets for development, environment variables for production
  • 📊 Real-time Status Tracking - Monitor order progress across multiple processing stages
  • 🔄 Automatic Retries - Failed messages are automatically requeued for processing
  • 📝 Comprehensive Logging - Structured logging with correlation IDs
  • 🔍 Distributed Tracing - OpenTelemetry traces exported to Jaeger across the API and workers
  • 🎯 Input Validation - FluentValidation for robust request validation
  • 🐳 Docker Support - Full containerization with Docker Compose
  • 📚 API Documentation - Interactive Swagger/OpenAPI documentation

Installation

  1. Clone the repository
   git clone https://github.com/yourusername/PixelMartOrderProcessor.git
   cd PixelMartOrderProcessor
  1. Start infrastructure services
   docker-compose up -d

This starts PostgreSQL, RabbitMQ, and Jaeger containers.

  1. Configure User Secrets (for each project)
   # OrderApi
   cd OrderApi
   dotnet user-secrets init
   dotnet user-secrets set "DB_PASSWORD" "your_postgres_password"
   
   # PaymentWorker
   cd ../PaymentWorker
   dotnet user-secrets init
   dotnet user-secrets set "DB_PASSWORD" "your_postgres_password"
   
   # InventoryWorker
   cd ../InventoryWorker
   dotnet user-secrets init
   dotnet user-secrets set "DB_PASSWORD" "your_postgres_password"
   
   # EmailWorker
   cd ../EmailWorker
   dotnet user-secrets init
   dotnet user-secrets set "DB_PASSWORD" "your_postgres_password"
  1. Apply database migrations
   cd OrderApi
   dotnet ef database update
  1. Run the application

    Open 4 separate terminal windows:

   # Terminal 1 - API
   cd OrderApi (PixelMartOrderProcessor)
   dotnet run
   
   # Terminal 2 - Payment Worker
   cd PaymentWorker
   dotnet run
   
   # Terminal 3 - Inventory Worker
   cd InventoryWorker
   dotnet run
   
   # Terminal 4 - Email Worker
   cd EmailWorker
   dotnet run
  1. Access the application

    • API: https://localhost:5001
    • Swagger UI: https://localhost:5001/swagger
    • RabbitMQ Management: http://localhost:15672 (guest/guest)
    • Jaeger UI: http://localhost:16686
  2. Place a new order

    Send a POST request to create an order. The Idempotency-Key header is required (use a unique value per order; repeat the same key to safely retry without creating duplicates).

curl -X POST https://localhost:7197/api/orders \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "customerEmail": "customer@example.com",
    "totalAmount": 149.97,
    "items": [
      {
        "productId": "SKU-001",
        "productName": "Wireless Mouse",
        "quantity": 1,
        "price": 29.99
      },
      {
        "productId": "SKU-002",
        "productName": "Mechanical Keyboard",
        "quantity": 2,
        "price": 59.99
      }
    ]
  }'

On Windows PowerShell, generate a unique idempotency key with [guid]::NewGuid().ToString() instead of uuidgen.

🩺 Health Checks

The API provides built-in health monitoring for reliable observability. All critical components (PostgreSQL DB, RabbitMQ, and the three background workers) are actively monitored.

  • GET /health — Overall system health (API + DB + RabbitMQ + Workers)
  • GET /health/ready — Readiness probe
  • GET /health/live — Liveness probe
  • GET /health-ui — Interactive health dashboard

🔍 OpenTelemetry & Distributed Tracing (Jaeger)

The API and workers use OpenTelemetry for traces and metrics—instrumenting ASP.NET Core, HTTP clients, EF Core, RabbitMQ message propagation, and custom activities. Spans are exported to Jaeger via OTLP (http://localhost:4317, configurable in appsettings.Development.json). Jaeger starts automatically with docker-compose up -d, or on its own:

docker-compose -f docker-compose.jaeger.yml up -d

Open Jaeger UI at http://localhost:16686, place an order, then search for traces from OrderApi to follow the request through payment, inventory, and email workers.

Sample Jaeger trace showing an order flowing through OrderApi and workers

🤝 Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

About

A distributed, event-driven order processing sample solution built with ASP.NET Core and RabbitMQ. It implements asynchronous microservices to offload long-running operations from the API layer, ensuring scalable background processing and responsive user interactions.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages