Logo
Event-Driven Order Processing System architecture diagram

Event-Driven Order Processing System

azureevent-driven-architecturetypescriptnext.jsazure-functionsservice-businfrastructure-as-codebicep

A production-ready e-commerce order processing system built with Azure Functions, Service Bus, and Next.js. This project demonstrates enterprise-grade cloud-native patterns including event-driven architecture, Infrastructure as Code, and complete observability.

Key Features

  • Event-Driven Architecture: Asynchronous order processing using Azure Service Bus queues
  • Serverless Backend: Four Azure Functions (TypeScript) handling HTTP triggers, queue processing, dead letter handling, and health checks
  • Modern Frontend: Next.js application with React Hook Form, Zod validation, and TanStack Query
  • Infrastructure as Code: Complete Azure infrastructure defined in Bicep with modular design
  • Full Observability: Application Insights integration with custom events, metrics, and KQL queries
  • Automated CI/CD: GitHub Actions workflows for infrastructure and application deployment
  • Error Handling: Automatic retry logic, dead letter queue processing, and circuit breaker pattern
  • Production-Ready: Comprehensive security, validation, testing, and monitoring

Tech Stack

Backend:

  • Azure Functions (Node.js runtime)
  • TypeScript
  • Azure Service Bus
  • Application Insights
  • Zod for validation

Frontend:

  • Next.js with App Router
  • React Hook Form
  • TanStack Query
  • shadcn/ui components
  • Dark mode support

Infrastructure:

  • Bicep (Infrastructure as Code)
  • Azure Resource Manager
  • GitHub Actions for CI/CD

Architecture

The system implements the Queue-Based Load Leveling pattern with Competing Consumers:

  1. Frontend submits orders via HTTP to an Azure Function
  2. HTTP Trigger Function validates the order and publishes it to Service Bus
  3. Service Bus Queue stores messages reliably with automatic retry
  4. Queue Trigger Function processes orders asynchronously
  5. Dead Letter Processor handles failed messages after max retries
  6. Application Insights tracks all events, metrics, and errors

This architecture provides:

  • Decoupling: Frontend and backend are completely independent
  • Reliability: Messages persist if processing fails
  • Scalability: Multiple consumers process messages in parallel
  • Resilience: Automatic retry with exponential backoff
  • Performance: Fast user response times with async processing

Infrastructure as Code

All Azure resources are defined in Bicep modules:

  • Service Bus: Queue with production-ready settings (10 max retries, 5-minute lock duration, 14-day TTL)
  • Function App: Pre-configured with Application Insights, Service Bus connection, and environment settings
  • Application Insights: Monitoring with custom events and KQL queries
  • Storage Account: Required for Azure Functions runtime
  • Static Web App: Hosting for the Next.js frontend

The infrastructure supports multiple environments (dev, staging, prod) through parameterized deployments.

Error Handling & Resilience

  • Automatic Retries: Service Bus retries failed messages up to 10 times with exponential backoff
  • Dead Letter Queue: Messages that fail after max retries move to DLQ for investigation
  • Circuit Breaker: Prevents cascading failures when external services are unavailable
  • Transient Fault Handling: Differentiates between transient (retry) and permanent (DLQ) errors
  • Health Checks: Endpoint for monitoring system health and configuration

Observability

Comprehensive monitoring through Application Insights:

  • Custom Events: OrderSubmitted, OrderProcessed with order details
  • Exceptions: Tracked with context (orderId, error type, delivery count)
  • Metrics: Processing duration, queue depth, error rates
  • KQL Queries: Pre-built queries for submission rate, average processing time, and error analysis
  • Alerts: Configurable alerts for high error rates, slow processing, and queue depth

Deployment

One-command deployment script:

./scripts/deploy-local.sh dev

This deploys:

  1. Complete Azure infrastructure (5-7 minutes)
  2. Backend Azure Functions (2-3 minutes)
  3. Frontend Next.js application (if configured)

Cost estimate: ~$11-21/month for development environment using free tiers.

Security

  • Authentication: Function-level authentication with Azure Functions keys
  • Validation: Zod schemas for type-safe input validation
  • Secrets Management: Azure Key Vault integration for connection strings
  • CORS: Configured to allow specific origins only
  • HTTPS: Enforced on all services
  • Managed Identity: For secure service-to-service authentication

Testing

  • Unit Tests: Test individual functions with mocked dependencies
  • Integration Tests: End-to-end order flow validation
  • Type Safety: TypeScript ensures compile-time type checking
  • Schema Validation: Zod schemas shared between frontend and backend

Read the detailed build process →