Motia Icon
Development Guide/Adapters

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:

  1. Interfaces define contracts in @motiadev/core
  2. Implementations satisfy these contracts
  3. 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):

// Uses FileStateAdapter, FileStreamAdapter, etc.
export default config({})

With Redis:

import { RedisStateAdapter } from '@motiadev/adapter-redis-state'
 
export default config({
  adapters: {
    state: new RedisStateAdapter({ host: 'localhost', port: 6379 })
  }
})

Your code stays the same:

// Works with both file and Redis adapters
await state.set('orders', 'order-123', { id: 'order-123' })

What's Next?

Need help? See our Community Resources for questions, examples, and discussions.

On this page