This demo showcases a complete incident response workflow using Motia's event-driven architecture with three key steps:
- Ingest (API Step) - Receives incident alerts
- Analyze (Event Step) - AI-powered analysis and decision making
- Remediate (Event Step) - Durable workflow with idempotency
HTTP POST → 1-ingest.step.ts → [incident.detected] → 2-analyze.step.ts → [fix.approved] → 3-remediate.step.ts
steps/1-ingest.step.ts- API endpoint for incident ingestionsteps/2-analyze.step.ts- AI analysis enginesteps/3-remediate.step.ts- Durable remediation workflow
npm run devThis will start:
- The Motia backend server
- The Workbench UI (visual workflow designer)
curl -X POST http://localhost:3000/incidents \
-H "Content-Type: application/json" \
-d '{
"serviceName": "payment-service",
"severity": "critical",
"message": "High memory usage detected - 95% utilization"
}'Expected response:
{
"status": "accepted",
"incidentId": "incident-1234567890-abc123"
}You'll see the workflow progress through the logs:
- Ingest Step: Incident received and emitted
- Analyze Step (after ~2 seconds): AI analysis complete, fix approved
- Remediate Step (after ~10 seconds): Remediation completed
To demonstrate durability and idempotency:
- Send an incident alert (as above)
- Watch the logs - you'll see "
⚠️ DURABILITY TEST: Kill the server now to test recovery!⚠️ " - Kill the server (Ctrl+C) during the 10-second wait
- Restart the server with
npm run dev - The remediation step will automatically resume from where it left off!
The step checks the state and logs: "Resuming remediation after server restart..."
- API Step emits
incident.detectedevent - Analyze Step subscribes to
incident.detected, emitsfix.approved - Remediate Step subscribes to
fix.approved
- All steps use Zod schemas for validation
- TypeScript types auto-generated in
types.d.ts - Full type inference across the workflow
- State management tracks remediation progress
- Server crashes don't lose work
- Steps can resume from checkpoints
- 2-second delay simulates AI processing
- Decision logic based on severity:
critical→ restart podwarning→ scale resourcesinfo→ monitor only
curl -X POST http://localhost:3000/incidents \
-H "Content-Type: application/json" \
-d '{
"serviceName": "auth-service",
"severity": "critical",
"message": "Service unresponsive"
}'curl -X POST http://localhost:3000/incidents \
-H "Content-Type: application/json" \
-d '{
"serviceName": "api-gateway",
"severity": "warning",
"message": "High latency detected"
}'curl -X POST http://localhost:3000/incidents \
-H "Content-Type: application/json" \
-d '{
"serviceName": "cache-service",
"severity": "info",
"message": "Cache hit rate below threshold"
}'- Open the Workbench UI (URL shown in terminal after
npm run dev) - Navigate to the workflow visualization
- See the three steps connected by events
- Watch real-time execution as incidents flow through
The remediation step uses Motia's state management:
- Group ID:
remediation-status - Key:
fix-{serviceName} - Values:
rebooting→healthy
Check state in logs or via Workbench state inspector.
Potential enhancements:
- Add real LLM integration (OpenAI, Anthropic)
- Connect to actual Kubernetes API
- Add streaming status updates to frontend
- Implement rollback logic
- Add approval workflow before remediation
- Create dashboard for incident history
Types not found?
npm run generate-typesServer won't start?
- Check if port 3000 is available
- Ensure Redis is running (if using BullMQ)
Steps not executing?
- Check logs for errors
- Verify event topic names match between emits and subscribes