What are Workers?
Workers are consumers of the iii architecture that:- Connect to the Engine via WebSocket (default:
127.0.0.1:49134) - Register functions they can execute
- Register triggers that map to those functions
- Receive invocation requests from the Engine
- Return results back to the Engine
- Node.js/TypeScript:
iii-sdk(low-level) andiii(high-level framework) - Python:
iii(low-level) andmotia(high-level framework)
Worker Lifecycle
Lifecycle Overview
1. Connection
Worker establishes WebSocket connection to the Engine:2. Registration
Worker registers functions and triggers:3. Execution
Engine invokes functions when triggers fire:Worker Registry
The Engine maintains a registry of connected workers:| Component | Description |
|---|---|
WorkerRegistry | Thread-safe map storing active workers by UUID |
Worker | Represents a connected client with WebSocket channel |
function_ids | Set of functions the worker can execute |
invocations | Active request IDs being processed |
Worker State
Each worker tracks:- UUID: Unique identifier assigned on connection
- Function IDs: List of registered functions (e.g.,
users::create,api::echo) - Active Invocations: Currently executing requests
- WebSocket Channel: Communication channel to the Engine
Multiple Workers
You can run multiple workers simultaneously: Benefits:- Language Diversity: Use different languages for different services
- Service Isolation: Separate concerns across workers
- Scalability: Scale specific workers independently
- Fault Isolation: Failure in one worker doesn’t affect others
Example: Complete Worker
Node.js
Python
Best Practices
Function Naming
Function Naming
Use double-colon notation to organize functions:
service::actionExamples:users::createusers::updateauth::loginpayments::process
Error Handling
Error Handling
Always handle errors gracefully and return structured error responses:
Connection Management
Connection Management
Monitor connection state changes using the SDK:
Function Organization
Function Organization
Group related functions by namespace: