Adapter Configuration
Configure distributed adapters for horizontal scaling in production
This guide shows you how to configure distributed adapters for Motia to enable horizontal scaling and production-ready deployments. We'll cover setting up Redis and RabbitMQ adapters for state, streams, events, and cron.
Why Distributed Adapters?
By default, Motia uses file-based and in-memory adapters that work great for single-instance deployments. However, when you need to:
- Run multiple Motia instances
- Scale horizontally
- Share state/events/streams across instances
- Deploy to production with high availability
You need distributed adapters that use shared infrastructure like Redis or RabbitMQ.
Quick Setup
1. Install Adapter Packages
2. Configure Adapters
Configuration Options
Each adapter supports additional configuration options for production use:
Redis State Adapter
Configuration Options:
| Option | Type | Default | Description |
|---|---|---|---|
host | string | 'localhost' | Redis server host |
port | number | 6379 | Redis server port |
password | string | undefined | Redis authentication password |
username | string | undefined | Redis authentication username |
database | number | 0 | Redis database number |
keyPrefix | string | 'motia:state:' | Prefix for all state keys |
ttl | number | undefined | Time-to-live in seconds for state entries |
socket.reconnectStrategy | function | Auto-retry | Custom reconnection strategy |
socket.connectTimeout | number | 10000 | Connection timeout in milliseconds |
Redis Stream Adapter
Configuration Options:
| Option | Type | Default | Description |
|---|---|---|---|
host | string | 'localhost' | Redis server host |
port | number | 6379 | Redis server port |
password | string | undefined | Redis authentication password |
username | string | undefined | Redis authentication username |
database | number | 0 | Redis database number |
keyPrefix | string | 'motia:stream:' | Prefix for all stream keys |
socket.reconnectStrategy | function | Auto-retry | Custom reconnection strategy |
socket.connectTimeout | number | 10000 | Connection timeout in milliseconds |
RabbitMQ Event Adapter
Configuration Options:
| Option | Type | Default | Description |
|---|---|---|---|
url | string | Required | RabbitMQ connection URL (e.g., amqp://localhost) |
exchangeName | string | Required | Name of the exchange to use |
exchangeType | 'direct' | 'topic' | 'fanout' | 'headers' | Required | Type of exchange |
durable | boolean | true | Whether the exchange should survive broker restarts |
autoDelete | boolean | false | Whether to delete the exchange when all queues are unbound |
connectionTimeout | number | 10000 | Connection timeout in milliseconds |
reconnectDelay | number | 5000 | Delay before attempting reconnection in milliseconds |
prefetch | number | 10 | Number of messages to prefetch |
Redis Cron Adapter
Configuration Options:
| Option | Type | Default | Description |
|---|---|---|---|
host | string | 'localhost' | Redis server host |
port | number | 6379 | Redis server port |
password | string | undefined | Redis authentication password |
username | string | undefined | Redis authentication username |
database | number | 0 | Redis database number |
keyPrefix | string | 'motia:cron:lock:' | Prefix for all lock keys |
lockTTL | number | 300000 | Lock time-to-live in milliseconds (5 minutes) |
lockRetryDelay | number | 1000 | Delay between lock retry attempts in milliseconds |
lockRetryAttempts | number | 0 | Number of times to retry acquiring a lock |
instanceId | string | Auto-generated UUID | Unique identifier for this instance |
enableHealthCheck | boolean | true | Whether to perform periodic health checks |
socket.reconnectStrategy | function | Auto-retry | Custom reconnection strategy |
socket.connectTimeout | number | 10000 | Connection timeout in milliseconds |
Docker Compose Setup
For local development and production, use Docker Compose to run Redis and RabbitMQ:
Start the services:
Partial Adapter Configuration
You don't need to configure all adapters. Mix and match based on your needs:
Only State Adapter
If you only need shared state across instances:
Only Event Adapter
If you only need distributed events:
Production Deployment
Scaling Multiple Instances
With distributed adapters, you can run multiple Motia instances:
All instances share the same state, events, and streams.
Cloud Provider Configuration
For cloud deployments, use managed services:
AWS ElastiCache (Redis):
CloudAMQP (RabbitMQ):
Testing Adapter Configuration
Your application code doesn't change when switching adapters. Test with defaults first:
Then switch to distributed adapters for production without changing your code.
What's Next?
📖 Using Adapters
Learn more about using adapters in your application
🔧 Creating Adapters
Build custom adapters for your infrastructure
🚀 Deployment Guide
Learn about deploying Motia to production
AI Research Agent
A powerful research assistant that leverages the Motia Framework to perform comprehensive web research on any topic and any question.
Project Structure
Learn about Motia's project structure, file organization, and automatic step discovery system for building scalable workflow applications.