Order State Machine

DiagramsIntermediate
Back to Gallery

E-commerce order processing state diagram with transitions and error handling

#mermaid#state-machine#workflow#e-commerce#diagrams
Created by md2x teamNovember 2, 2025

Get Started with This Example

Download MarkdownDownload StyleDownload PDF

Markdown Source

input.md
# E-Commerce Order Processing

**State Machine Diagram**

## Order Lifecycle

The following state machine shows how orders progress through our e-commerce system from creation to completion.

```mermaid
stateDiagram-v2
    [*] --> Created: Customer places order

    Created --> PaymentPending: Initialize payment
    PaymentPending --> PaymentFailed: Payment declined
    PaymentPending --> Paid: Payment successful

    PaymentFailed --> Cancelled: Auto-cancel after 15min
    
    Paid --> Processing: Begin fulfillment
    Processing --> InventoryCheck: Check stock
    
    InventoryCheck --> InStock: Items available
    InventoryCheck --> OutOfStock: Items unavailable
    
    OutOfStock --> Refunded: Refund customer
    InStock --> Picking: Reserve inventory
    
    Picking --> Packed: Items picked
    Packed --> Shipped: Carrier pickup
    
    Shipped --> InTransit: Tracking active
    InTransit --> OutForDelivery: Last mile
    OutForDelivery --> Delivered: Customer receives
    
    Delivered --> Completed: No issues (7 days)
    Delivered --> ReturnRequested: Customer initiates return
    
    ReturnRequested --> ReturnApproved: Approve return
    ReturnRequested --> ReturnDenied: Deny return
    
    ReturnApproved --> ReturnInTransit: Customer ships back
    ReturnInTransit --> ReturnReceived: Warehouse receives
    ReturnReceived --> Refunded: Process refund
    
    ReturnDenied --> Completed: Close request
    
    Cancelled --> [*]
    Refunded --> [*]
    Completed --> [*]

    note right of PaymentPending
        15 minute timeout
        3 retry attempts
    end note

    note right of Processing
        Fraud check
        Address validation
        Inventory reservation
    end note
```

## State Descriptions

| State | Description | Next Actions |
|-------|-------------|--------------|
| **Created** | Order submitted but not paid | Payment processing |
| **PaymentPending** | Waiting for payment confirmation | Success or failure |
| **PaymentFailed** | Payment was declined | Cancel or retry |
| **Paid** | Payment confirmed | Begin processing |
| **Processing** | Order validation and checks | Inventory check |
| **InStock** | Items available | Begin picking |
| **OutOfStock** | Items unavailable | Refund |
| **Picking** | Warehouse picking items | Pack |
| **Packed** | Ready for shipment | Ship |
| **Shipped** | Carrier has package | Track |
| **InTransit** | Package in delivery network | Deliver |
| **Delivered** | Customer received package | Complete or return |
| **ReturnRequested** | Customer wants to return | Approve/deny |
| **Refunded** | Money returned to customer | End |
| **Completed** | Successfully fulfilled | End |
| **Cancelled** | Order cancelled | End |

## Transition Rules

### Auto-Transitions
- PaymentPending → Cancelled after 15 minutes
- Delivered → Completed after 7 days (no return)

### Manual Triggers
- ReturnRequested → ReturnApproved/Denied (CS team)
- Any state → Cancelled (by customer or admin)

## SLA Targets

- **Payment Processing:** < 5 minutes
- **Inventory Check:** < 30 seconds
- **Picking:** < 4 hours
- **Packing:** < 2 hours
- **Shipping:** Same business day
- **Refund Processing:** < 48 hours
102 lines • 3203 characters

PDF Output

output.pdf
PDF preview of Order State Machine
Page 1 of 1 • Click image to zoom in

CSS Styling

style.css
/* Reuse the technical architecture style from example 003 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 10.5pt;
  line-height: 1.7;
  color: #1f2937;
  max-width: 8.5in;
  margin: 0.75in auto;
  padding: 0;
}

h1 {
  font-size: 24pt;
  font-weight: 700;
  color: #111827;
  margin: 0 0 0.08in 0;
}

h1 + p {
  font-size: 11pt;
  font-weight: 600;
  color: #6b7280;
  margin: 0 0 0.15in 0;
}

hr {
  border: none;
  border-top: 2px solid #e5e7eb;
  margin: 0.2in 0;
}

h2 {
  font-size: 15pt;
  font-weight: 700;
  color: #1e40af;
  margin: 0.25in 0 0.12in 0;
  border-bottom: 2px solid #dbeafe;
  padding-bottom: 0.05in;
}

h3 {
  font-size: 12pt;
  font-weight: 600;
  color: #374151;
  margin: 0.18in 0 0.08in 0;
}

p {
  margin: 0.08in 0;
}

ul, ol {
  margin: 0.08in 0;
  padding-left: 0.3in;
}

pre {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  padding: 0.15in;
  margin: 0.15in 0;
  border-radius: 6px;
}

code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5pt;
  background: #f3f4f6;
  padding: 0.02in 0.05in;
  border-radius: 3px;
  color: #dc2626;
}

pre code {
  background: none;
  padding: 0;
  color: #1f2937;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.15in 0;
  font-size: 9.5pt;
  border: 1px solid #e5e7eb;
}

th {
  background: #f3f4f6;
  padding: 0.08in;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid #d1d5db;
}

td {
  padding: 0.08in;
  border-bottom: 1px solid #e5e7eb;
}

.mermaid {
  margin: 0.2in 0;
  padding: 0.15in;
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

Explore More Examples

Check out our full gallery for more inspiration

View All Examples