Architecture overview
Core modules
REST API module
Class:modules::api::RestApiModule
Handles HTTP requests and routes them to your step handlers. Features include:
- Path parameter extraction (e.g.,
/users/:id) - Query parameter parsing
- Request body parsing (JSON)
- CORS support
- Configurable timeouts
- Request concurrency limits
Stream module
Class:modules::stream::StreamModule
Provides real-time WebSocket-based streaming:
- Client connection management
- Group and item-based subscriptions
- Atomic update operations
- Authentication hooks
onJoin/onLeavelifecycle events
ctx.streams.
State module
Class:modules::state::StateModule
Manages the key-value state store:
- Get, set, update, delete operations
- Group-based organization
- Atomic updates with
UpdateOp - State change triggers
- Persistent or in-memory storage
Queue module
Class:modules::queue::QueueModule
Handles asynchronous message processing:
- Topic-based routing
- Configurable retry logic
- FIFO and standard queues
- Visibility timeouts
- Dead letter queues
- Concurrent or sequential processing
ctx.enqueue(), and the queue module routes them to subscribed steps.
Cron module
Class:modules::cron::CronModule
Executes scheduled tasks:
- 7-field cron expressions (second precision)
- Distributed execution (single instance)
- Persistent job state
- Condition-based filtering
Observability module
Class:modules::observability::OtelModule
Provides OpenTelemetry integration:
- Distributed tracing
- Metrics collection
- Structured logging
- Memory or OTLP exporters
- Configurable sampling
SDK integration
The iii engine communicates with SDK processes using a function registration protocol:Function registration
When your Motia app starts, the SDK:- Loads all step files
- Registers each step’s handler as a function with the engine
- Registers trigger configurations (HTTP, queue, cron, etc.)
- Waits for incoming events
Function invocation
When a trigger fires (HTTP request, queue message, cron schedule), the engine:- Identifies the registered function for that trigger
- Invokes the function via IPC with the event data
- Waits for the function to return a response
- Handles retries, timeouts, and errors
Process management
Themodules::shell::ExecModule manages your SDK process:
- Executes commands in the
execarray sequentially - Watches files in the
watcharray for changes - Restarts the process when files change (hot reload)
- Manages process lifecycle (startup, shutdown, crashes)
Multi-language support
The iii engine is language-agnostic. SDKs are available for:- JavaScript/TypeScript (
motianpm package) - Python (
motiaPyPI package) - Ruby (beta)
- Go (coming soon)
Communication protocol
The SDK communicates with the engine using JSON-RPC over stdin/stdout:Performance characteristics
Rust core
The engine is written in Rust for:- Low latency: Microsecond-level routing and dispatch
- High throughput: Thousands of requests per second
- Memory efficiency: Minimal overhead per connection
- Reliability: Memory safety and crash recovery
SDK overhead
Your handler code runs in a separate process:- Node.js/Bun: Fast startup, efficient for I/O-bound workloads
- Python: Slower startup, good for CPU-bound workloads with native libraries
- Ruby: Similar to Python, optimized for scripting
Deployment considerations
Single-process deployment
For small applications, run the engine and SDK in a single container:Distributed deployment
For larger applications, run multiple SDK processes:Debugging
Engine logs
The engine outputs structured logs to stdout:SDK logs
Your application logs (viactx.logger) are sent to the engine and visible in the iii Console.
iii Console
The web-based console provides:- Real-time trace visualization
- Step execution timelines
- State operation history
- Log aggregation by trace ID
http://localhost:3113 (default port).
Next steps
- Configure observability
- Implement middleware
- Learn about deployment