Motia Icon
Development Guide

Adapters

Pluggable infrastructure for state, streams, events, and cron

Adapters let you swap infrastructure implementations without changing your code. Use defaults for single-instance deployments or distributed adapters for scaling.

How It Works

Configure adapters in motia.config.ts. If you don't specify any, Motia uses defaults.

motia.config.ts
import { config } from '@motiadev/core'
import { RedisStateAdapter } from '@motiadev/adapter-redis-state'
 
const redisUrl = `redis://${process.env.REDIS_HOST || 'localhost'}:6379`
 
export default config({
  adapters: {
    state: new RedisStateAdapter({ url: redisUrl })
  }
})

Your Step code stays the same:

await state.set('orders', 'order-123', { id: 'order-123' })

Adapter Types

TypeWhat it handlesDefaultDistributed
StateKey-value storageFileRedis
StreamsReal-time dataFileRedis
EventsEvent queuesIn-memoryRabbitMQ
CronJob lockingIn-memoryRedis

Default Adapters

For single-instance deployments. No configuration needed.

motia.config.ts
import { config } from '@motiadev/core'
 
export default config({
  // Uses defaults:
  // - FileStateAdapter for state
  // - FileStreamAdapter for streams
  // - InMemoryQueueEventAdapter for events
  // - InMemoryCronAdapter for cron
})

Where data goes:

  • State: .motia/motia.state.json
  • Streams: .motia/streams/
  • Events: Process memory
  • Cron: Process memory

Distributed Adapters

For multi-instance deployments. Shares state and events across instances.

Redis State

motia.config.ts
import { config } from '@motiadev/core'
import { RedisStateAdapter } from '@motiadev/adapter-redis-state'
 
const redisUrl = `redis://${process.env.REDIS_HOST || 'localhost'}:${process.env.REDIS_PORT || '6379'}`
 
export default config({
  adapters: {
    state: new RedisStateAdapter(
      { url: redisUrl },
      { keyPrefix: 'myapp:', ttl: 3600 }
    )
  }
})

Install:

npm install @motiadev/adapter-redis-state

Redis Streams

motia.config.ts
import { config } from '@motiadev/core'
import { RedisStreamAdapterManager } from '@motiadev/adapter-redis-streams'
 
const redisUrl = `redis://${process.env.REDIS_HOST || 'localhost'}:${process.env.REDIS_PORT || '6379'}`
 
export default config({
  adapters: {
    streams: new RedisStreamAdapterManager({ url: redisUrl })
  }
})

Install:

npm install @motiadev/adapter-redis-streams

RabbitMQ Events

motia.config.ts
import { config } from '@motiadev/core'
import { RabbitMQEventAdapter } from '@motiadev/adapter-rabbitmq-events'
 
export default config({
  adapters: {
    events: new RabbitMQEventAdapter({
      url: process.env.RABBITMQ_URL || 'amqp://localhost',
      exchangeName: 'motia.events',
      exchangeType: 'topic'
    })
  }
})

Install:

npm install @motiadev/adapter-rabbitmq-events

Redis Cron

motia.config.ts
import { config } from '@motiadev/core'
import { RedisCronAdapter } from '@motiadev/adapter-redis-cron'
 
const redisUrl = `redis://${process.env.REDIS_HOST || 'localhost'}:${process.env.REDIS_PORT || '6379'}`
 
export default config({
  adapters: {
    cron: new RedisCronAdapter({ url: redisUrl })
  }
})

Install:

npm install @motiadev/adapter-redis-cron

All Together

Using all distributed adapters:

motia.config.ts
import { config } from '@motiadev/core'
import { RedisStateAdapter } from '@motiadev/adapter-redis-state'
import { RedisStreamAdapterManager } from '@motiadev/adapter-redis-streams'
import { RabbitMQEventAdapter } from '@motiadev/adapter-rabbitmq-events'
import { RedisCronAdapter } from '@motiadev/adapter-redis-cron'
 
const redisUrl = `redis://${process.env.REDIS_HOST || 'localhost'}:6379`
 
export default config({
  adapters: {
    state: new RedisStateAdapter(
      { url: redisUrl },
      { keyPrefix: 'myapp:state:' }
    ),
    streams: new RedisStreamAdapterManager({ url: redisUrl }),
    events: new RabbitMQEventAdapter({
      url: process.env.RABBITMQ_URL || 'amqp://localhost',
      exchangeName: 'motia.events',
      exchangeType: 'topic'
    }),
    cron: new RedisCronAdapter(
      { url: redisUrl },
      { keyPrefix: 'myapp:cron:' }
    )
  }
})

When to Use What

Default adapters:

  • Single Motia instance
  • Development
  • Testing
  • Simple deployments

Distributed adapters:

  • Multiple Motia instances
  • Horizontal scaling
  • Production deployments
  • High availability

Configuration Tips

Redis URL Format

Build Redis URLs from environment variables:

// Basic connection
const redisUrl = `redis://localhost:6379`
 
// With password
const redisUrl = `redis://:password@localhost:6379`
 
// With username and password
const redisUrl = `redis://user:password@localhost:6379`
 
// From environment variables
const redisUrl = `redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`

Adapter Options

Redis adapters accept two parameters:

new RedisStateAdapter(
  { url: redisUrl },              // Connection config
  { keyPrefix: 'app:', ttl: 3600 } // Adapter options
)

Common options:

  • keyPrefix - Prefix for all keys (helps organize data)
  • ttl - Time-to-live in seconds (auto-expire old data)
  • lockTTL - Lock timeout for cron jobs

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

On this page

Adapters | motia