A comprehensive demonstration of Temporal's Priority Scheduling and Fairness features using Node.js, Express, and React. This project showcases how Temporal manages workflow execution priorities and ensures fair resource distribution across different workload classes.
This project demonstrates two key Temporal scheduling capabilities:
Workflows are distributed across 5 priority levels (1-5, where 1 is highest priority). Temporal schedules higher-priority workflows first, ensuring critical tasks complete before lower-priority ones.
Use Case: Emergency orders (P1) should be processed before standard orders (P3-P5).
Multiple tenant classes share worker capacity fairly based on weight ratios. Prevents resource starvation where one tenant monopolizes all workers.
Use Case: VIP customers (weight 20) receive more capacity than economy customers (weight 1), but economy still gets guaranteed processing.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CLIENT LAYER โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ React UI โโโโโโโโโโโค Express API Server โ โ
โ โ (Port 5173) โ โ (Port 3001) โ โ
โ โโโโโโโโโโโโโโโโ โ - REST endpoints โ โ
โ โ - Temporal client โ โ
โ โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ gRPC
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
โ TEMPORAL SERVER โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Temporal Core Engine โ โ
โ โ - Workflow Scheduler โ โ
โ โ - Priority/Fairness Queue Manager โ โ
โ โ - State Machine Manager โ โ
โ โ - History Service โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ PostgreSQL Database โ โ
โ โ - Workflow execution history โ โ
โ โ - Search attributes โ โ
โ โ - Task queue state โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Temporal UI (Port 8080) - Monitoring & Debugging โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ gRPC Long Poll
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ WORKER LAYER โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Temporal Worker Process โ โ
โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Priority Worker โ โ Fairness Worker โ โ โ
โ โ โ Queue: priority- โ โ Queue: fairness- โ โ โ
โ โ โ queue โ โ queue โ โ โ
โ โ โโโโโโโโโโฌโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ โ โ
โ โ โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโค โ โ
โ โ โ โ โ
โ โ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Workflow Implementations โ โ โ
โ โ โ - priorityWorkflow() โ โ โ
โ โ โ - fairnessWorkflow() โ โ โ
โ โ โโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ โ
โ โ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Activity Implementations โ โ โ
โ โ โ - runPriorityActivity() โ โ โ
โ โ โ - runFairnessActivity() โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. CLIENT STARTS WORKFLOW
โโ API sends gRPC request to Temporal Server
โโ Server creates workflow execution record in DB
โโ Server adds workflow task to task queue
โโ Returns workflow ID to client
2. WORKER POLLS FOR TASKS
โโ Worker sends gRPC long poll request
โโ Server matches task to worker based on priority/fairness
โโ Server returns workflow task to worker
3. WORKER EXECUTES WORKFLOW
โโ Worker runs workflow code (deterministic)
โโ Workflow schedules activities
โโ Worker reports events back to server via gRPC
โโ Server persists events to history
4. ACTIVITY EXECUTION
โโ Server adds activity task to queue
โโ Worker polls and receives activity task
โโ Worker executes activity code (can be non-deterministic)
โโ Worker reports activity result via gRPC
โโ Server updates workflow state
5. WORKFLOW COMPLETION
โโ Workflow completes after all activities
โโ Worker reports completion to server
โโ Server marks workflow as completed
โโ Client can query final state
cd server
# Install dependencies
npm install
# Register search attributes (one-time setup)
chmod +x setup-search-attributes.sh
./setup-search-attributes.sh
# Start API server
npm run dev
# API Server: http://localhost:3001cd server
# Start Temporal worker
npm run worker
# Worker polls from priority-queue and fairness-queuecd ui
npm install
npm run dev
# UI: http://localhost:5173- โ Distributes workflows across 5 priority levels (1=highest, 5=lowest)
- โ Higher priority workflows complete first
- โ Visualize completion rates by priority level
- โ Real-time progress tracking via search attributes
- โ Multiple tenant classes with configurable weights
- โ Fair capacity distribution (prevents starvation)
- โ Pre-configured scenarios (airline classes, service tiers)
- โ Compare fairness ON vs OFF
- โ React UI with Material-UI components
- โ Real-time workflow monitoring
- โ Historical results visualization
- โ RESTful API for workflow management
- โ Docker Compose for easy setup
Start a batch of workflows in priority or fairness mode.
Request Body (Priority Mode):
{
"workflowIdPrefix": "priority-test-1",
"numberOfWorkflows": 100,
"mode": "priority"
}Request Body (Fairness Mode):
{
"workflowIdPrefix": "fairness-test-1",
"numberOfWorkflows": 220,
"mode": "fairness",
"disableFairness": false,
"bands": [
{ "key": "vip", "weight": 20, "count": 10 },
{ "key": "first-class", "weight": 10, "count": 20 },
{ "key": "business-class", "weight": 5, "count": 40 },
{ "key": "economy-class", "weight": 2, "count": 75 },
{ "key": "standby-list", "weight": 1, "count": 75 }
]
}Get priority mode test results.
Response:
{
"totalWorkflows": 100,
"completedWorkflows": 85,
"priorityDistribution": {
"1": { "total": 20, "completed": 20, "rate": 1.0 },
"2": { "total": 20, "completed": 19, "rate": 0.95 },
"3": { "total": 20, "completed": 18, "rate": 0.90 },
"4": { "total": 20, "completed": 16, "rate": 0.80 },
"5": { "total": 20, "completed": 12, "rate": 0.60 }
}
}Get fairness mode test results.
Response:
{
"totalWorkflows": 220,
"fairnessBands": {
"vip": { "count": 10, "completed": 9, "avgActivities": 4.5 },
"first-class": { "count": 20, "completed": 18, "avgActivities": 4.2 },
"business-class": { "count": 40, "completed": 35, "avgActivities": 3.8 }
}
}# Start 100 workflows with priority scheduling
curl -X POST http://localhost:3001/start-workflows \
-H "Content-Type: application/json" \
-d '{
"workflowIdPrefix": "test-241124",
"numberOfWorkflows": 100,
"mode": "priority"
}'
# Wait 30 seconds, then check results
curl "http://localhost:3001/run-status?runPrefix=test-241124"- Open http://localhost:5173
- Select "Fairness Mode"
- Choose "Airline Classes" preset
- Click "Start Workflow Test"
- View results in real-time
- Open http://localhost:8080
- Navigate to Workflows
- Filter by workflow ID prefix
- View execution history and search attributes
- ๐ Priority & Fairness Explained
- ๐ Quick Start Guide
- ๐ง Server Documentation
- ๐ Temporal Documentation
This is a demonstration project. Feel free to fork and experiment!
ISC