Workflows
Learn how to build automated workflows that manage complex business logic with Motia
What You'll Build
A pet lifecycle management system that automatically guides pets through their journey at your shelter:
- Automated Status Transitions - Pets move through stages automatically when conditions are met
- Staff Decision Points - Critical checkpoints where staff make the calls
- Smart Progressions - Some transitions trigger follow-up actions automatically
- Validation Rules - Prevents invalid status changes to keep data consistent
Getting Started
Clone the example repository:
Install dependencies:
Start the Workbench:
Your Workbench will be available at http://localhost:3000.
Project Structure
Files like features.json and tutorial/tutorial.tsx are only for the interactive tutorial and are not part of Motia's project structure.
All code examples in this guide are available in the build-your-first-app repository.
You can follow this guide to learn how to build workflow orchestration with Motia step by step, or you can clone the repository and dive into our Interactive Tutorial to learn by doing directly in the Workbench.

Understanding Workflows
So far, you've built API endpoints that respond to requests and background jobs that handle async tasks. But what about coordinating complex business processes that involve multiple steps and decision points?
That's where workflows come in. It's the conductor of your system - making sure things happen in the right order, at the right time, and only when it makes sense.
In our pet shelter example, a pet goes through many stages:
- New arrivals need health checks
- Healthy pets become available for adoption
- Sick pets need treatment before they're ready
- Adoption applications require staff approval
A workflow manages all these transitions, enforcing the rules and keeping everything consistent.
The Pet Lifecycle Journey
When you create a pet, it starts as new. Once the feeding reminder job completes, it automatically moves to in_quarantine. Staff then checks on it and marks it healthy, which automatically progresses to available. When someone wants to adopt, it goes pending, then finally adopted.
The key here is some transitions happen automatically (like healthy → available), while others need staff approval (like in_quarantine → healthy).
What about sick pets?
If staff finds a pet is ill, it automatically moves to under_treatment. When staff marks it recovered, it chains through automatic transitions: recovered → healthy → available.
This mix of automatic progressions and human decision points is what makes workflows powerful - the system handles the routine stuff while keeping people in control of important calls.
Creating the Workflow
The workflow orchestrator is a single Event Step that manages all pet lifecycle transitions. Here's the complete implementation:
View on GitHub:
How the Orchestrator Works
The orchestrator has three main responsibilities:
- Validate Transitions - Ensures pets can only move to valid next statuses
- Apply Transitions - Updates the pet's status in the store
- Trigger Automatic Progressions - Some statuses automatically progress to the next stage
Key Points:
emits: []- The orchestrator doesn't declare emits because it only manages state internally- JavaScript/Python emit events for workflow tracking (optional pattern)
- TypeScript focuses purely on state management
- All languages validate transitions using the same
TRANSITION_RULES
Testing Your Orchestrator
The best way to test your orchestrator is through Workbench. It lets you send requests, watch the workflow execute in real-time, and see all the logs in one place.
Create a Pet
Open Workbench and test the CreatePet endpoint:

You'll see in the logs:
Prefer using curl? You can also test with command line:
Staff Health Check
Test the UpdatePet endpoint in Workbench to mark the pet as healthy:

Watch the automatic progression:
Using curl?
Test Invalid Transitions
Try to skip a step in Workbench:

The orchestrator rejects it:
Using curl?
Test the Illness Workflow
Mark a pet as ill in Workbench:

Watch the automatic treatment start:
Using curl?
Then mark the pet as recovered in Workbench:

Watch the chained automatic progressions:
Using curl?
Monitoring Your Orchestrator
Use the Workbench to visualize the entire flow:
Tracing
See how events flow through your system:

Each trace shows:
- The initial API call
- Background job processing
- Orchestrator transitions
- Automatic progressions
- Total time for each step
Logs
Filter by pet ID to see the complete lifecycle:

The logs tell the story of each pet's journey through your shelter.
🎉 Congratulations! You've built a complete workflow orchestrator that manages complex business logic while keeping your code clean and maintainable.
What's Next?
Your pet shelter now has a complete backend system with workflow orchestration! But what about decisions that aren't black and white? Should this pet's symptoms require treatment?
In the next guide, we'll add Agentic Workflows that make intelligent decisions within your workflows:
- Health Review Agentic Step - Analyzes symptoms and decides if treatment is needed
- Adoption Review Agentic Step - Assesses if pets are ready for adoption
- AI Profile Enrichment - Automatically generates engaging pet profiles
- Agentic Decision Making - AI that chooses which workflow path to take
Let's continue building by adding intelligent decision-making to your workflows.
