FastAPI → Temporal Workflow → Worker → External “services” (activities)
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
Run Temporal server + UI + PostgreSQL:
docker compose up -dVerify containers:
docker psYou should see:
- temporal
- temporal-ui
- postgres
python -m venv venv
venv\Scripts\activatepython3 -m venv venv
source venv/bin/activatepip install -r requirements.txtThis worker executes workflow activities.
python app/worker.pyExpected output:
Worker running...Keep this terminal running.
Open a new terminal:
uvicorn api:app --reloadOR
uvicorn app.api:app --reload --port 8000Expected output:
Uvicorn running on http://127.0.0.1:8000Trigger workflow via API:
curl -X POST http://localhost:8000/order/101Response:
{
"message": "order_started",
"workflow_id": "order-101",
"order_id": "101"
}curl http://localhost:8000/order/101While 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"
}
}Open:
You’ll see:
- Workflow ID →
order-101 - Workflow status
- Activity execution logs
- Full event history
- Retry attempts (if failures happen)
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 FastAPI:
CTRL + CStop Worker:
CTRL + CStop Docker services:
docker compose downdocker compose down
docker compose up -d
python app/worker.py
uvicorn app.api:app --reload --port 8000Check:
netstat -ano | findstr :8000Kill process if needed.
Make sure:
- Worker is running
- API triggered workflow
- Task queue names match
Check logs:
docker logs temporalThis same architecture can be extended for:
- E-commerce orders
- Payment processing
- Loan approval systems
- CI/CD deployment orchestration
- Ride booking systems
- Subscription billing workflows
- Add retry policies
- Add rollback workflows (Saga pattern)
- Replace mock activities with real microservices
- Add Prometheus/Grafana monitoring