Adapters
Pluggable infrastructure components that enable horizontal scaling and custom implementations
Adapters are pluggable infrastructure components that let you replace Motia's default implementations with your own. They enable horizontal scaling, custom storage backends, and production-ready deployments.
What Are Adapters?
Motia uses adapters to abstract infrastructure concerns. Instead of hardcoding file storage or in-memory queues, Motia uses adapter interfaces that you can swap out.
Four adapter types:
- State Adapter → Persistent key-value storage (default: file-based)
- Stream Adapter → Real-time data streams (default: file-based)
- Event Adapter → Event-based communication (default: in-memory queue)
- Cron Adapter → Distributed cron job locking (default: in-memory)
Why Use Adapters?
Default Adapters (No Configuration Needed)
For single-instance deployments, Motia works out of the box with default adapters:
- FileStateAdapter → Stores state in
.motia/motia.state.json - FileStreamAdapter → Stores streams in
.motia/streams/ - InMemoryQueueEventAdapter → Events in process memory
- InMemoryCronAdapter → Single-instance cron locking
Default adapters are perfect for development, testing, and single-instance deployments. No configuration needed!
Distributed Adapters (For Production)
When you need to scale horizontally or run multiple instances, switch to distributed adapters:
- Redis State Adapter → Shared state across instances
- Redis Stream Adapter → Real-time streams across instances
- RabbitMQ Event Adapter → Distributed event queue
- Redis Cron Adapter → Distributed cron locking
Use distributed adapters when running multiple Motia instances. Without them, each instance has its own isolated state and events.
How Adapters Work
Adapters implement interfaces defined in @motiadev/core. Your application code doesn't change - just swap the adapter implementation.
Example: Switching from file storage to Redis
Your Step code stays exactly the same:
When to Use Custom Adapters
Use default adapters when:
- Running a single Motia instance
- Local development
- Testing
- Simple deployments
Use distributed adapters when:
- Running multiple Motia instances
- Need horizontal scaling
- Production deployments
- High availability requirements
- Need shared state/events across instances
Available Adapters
Official Packages
@motiadev/adapter-redis-state- Redis-based state storage@motiadev/adapter-redis-streams- Redis streams implementation@motiadev/adapter-redis-cron- Redis distributed locking for cron@motiadev/adapter-rabbitmq-events- RabbitMQ event handling
Default Implementations
Included in @motiadev/core (no external dependencies):
FileStateAdapter- File-based state (default)MemoryStateAdapter- In-memory state (testing)FileStreamAdapter- File-based streams (default)MemoryStreamAdapter- In-memory streams (testing)InMemoryQueueEventAdapter- In-memory event queue (default)InMemoryCronAdapter- Single-instance cron locking (default)
Architecture
Adapters follow the interface pattern:
- Interfaces define contracts in
@motiadev/core - Implementations satisfy these contracts
- Composition is used throughout - adapters are injected, not extended
This design means:
- ✅ Easy to swap implementations
- ✅ Type-safe with full TypeScript support
- ✅ Testable with in-memory adapters
- ✅ Extensible for custom backends
What's Next?
📖 Using Adapters
Learn how to configure and use adapters in your application
🔧 Creating Adapters
Build custom adapters for your infrastructure
📦 State Management
Learn how state adapters work with state management