Skip to content

kashan-01/temporal-realtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

System Workflow

FastAPI → Temporal Workflow → Worker → External “services” (activities)

Temporal E-Commerce Workflow Demo

This project demonstrates a real-world Temporal workflow integration using:

  • FastAPI → API layer
  • Temporal → workflow orchestration
  • Worker → executes activities
  • Docker Compose → runs Temporal infrastructure
  • Order workflow → Payment → Inventory → Shipping → Email

FULL RUN COMMANDS (END-TO-END)


Step 1: Start Temporal Infrastructure

Run Temporal server + UI + PostgreSQL:

docker compose up -d

Verify containers:

docker ps

You should see:

  • temporal
  • temporal-ui
  • postgres

Step 2: Create Python Virtual Environment

Windows

python -m venv venv
venv\Scripts\activate

Linux/macOS

python3 -m venv venv
source venv/bin/activate

Step 3: Install Dependencies

pip install -r requirements.txt

Step 4: Start Temporal Worker

This worker executes workflow activities.

python app/worker.py

Expected output:

Worker running...

Keep this terminal running.


Step 5: Start FastAPI Application

Open a new terminal:

 uvicorn api:app --reload

OR

uvicorn app.api:app --reload --port 8000

Expected output:

Uvicorn running on http://127.0.0.1:8000

Workflow Testing


Create Order Workflow

Trigger workflow via API:

curl -X POST http://localhost:8000/order/101

Response:

{
  "message": "order_started",
  "workflow_id": "order-101",
  "order_id": "101"
}

Check Order Status

curl http://localhost:8000/order/101

While workflow is running:

{
  "status": "running"
}

After completion:

{
  "status": "completed",
  "result": {
    "order_id": "101",
    "payment": "payment_success:101",
    "inventory": "inventory_reserved:101",
    "shipping": "shipment_created:101",
    "email": "email_sent:101",
    "status": "COMPLETED"
  }
}

Temporal UI

Open:

http://localhost:8080

You’ll see:

  • Workflow ID → order-101
  • Workflow status
  • Activity execution logs
  • Full event history
  • Retry attempts (if failures happen)

End-to-End Workflow Flow

User/API Request
       ↓
FastAPI receives order request
       ↓
Temporal starts workflow
       ↓
Worker picks task from queue
       ↓
process_payment()
       ↓
reserve_inventory()
       ↓
create_shipping()
       ↓
send_email()
       ↓
Workflow completed
       ↓
Status visible in API + Temporal UI

Stop Everything

Stop FastAPI:

CTRL + C

Stop Worker:

CTRL + C

Stop Docker services:

docker compose down

Restart Fresh

docker compose down
docker compose up -d
python app/worker.py
uvicorn app.api:app --reload --port 8000

Common Issues


Port already in use

Check:

netstat -ano | findstr :8000

Kill process if needed.


Temporal UI empty

Make sure:

  • Worker is running
  • API triggered workflow
  • Task queue names match

Docker issues

Check logs:

docker logs temporal

Real-World Use Cases

This same architecture can be extended for:

  • E-commerce orders
  • Payment processing
  • Loan approval systems
  • CI/CD deployment orchestration
  • Ride booking systems
  • Subscription billing workflows

Future Improvements

  • Add retry policies
  • Add rollback workflows (Saga pattern)
  • Replace mock activities with real microservices
  • Add Prometheus/Grafana monitoring

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages