Adapters Overview
Introduction to Motia's adapter system for pluggable infrastructure
Adapters are the infrastructure layer of Motia. They abstract storage, event handling, streams, and cron locking so you can swap implementations without changing your application code.
What Are Adapters?
Adapters implement interfaces that Motia uses for core infrastructure operations:
- State Adapter → Persistent key-value storage
- Stream Adapter → Real-time data streams
- Event Adapter → Event-based communication
- Cron Adapter → Distributed cron job locking
Why Adapters Matter
Single Instance (Default)
By default, Motia uses file-based and in-memory adapters perfect for single-instance deployments:
- State stored in
.motia/motia.state.json - Streams stored in
.motia/streams/ - Events in process memory
- Cron locking in process memory
Default adapters work great for development, testing, and single-instance production deployments. No configuration needed!
Multiple Instances (Distributed)
When you run multiple Motia instances, you need distributed adapters:
- Shared state across instances
- Distributed events so all instances can process them
- Real-time streams synchronized across instances
- Distributed cron locking to prevent duplicate executions
Without distributed adapters, each Motia instance has isolated state and events. Use Redis or RabbitMQ adapters for multi-instance deployments.
Adapter Architecture
Adapters follow a clean interface pattern:
- Interfaces define contracts in
@motiadev/core - Implementations satisfy these contracts
- Composition - adapters are injected, not extended
This design provides:
- ✅ Easy swapping of implementations
- ✅ Type safety with full TypeScript support
- ✅ Testability with in-memory adapters
- ✅ Extensibility for custom backends
Quick Example
Default (no config):
With Redis:
Your code stays the same:
What's Next?
📖 Using Adapters
Learn how to configure and use adapters
🔧 Creating Adapters
Build custom adapters for your infrastructure