---
title: "Deploy Mastra Durable Agents"
description: "Durable AI agents with resumable streams via Redis and Inngest."
category: "AI/ML"
url: https://railway.com/deploy/mastra-durable-agents
---

# Deploy Mastra Durable Agents

Durable AI agents with resumable streams via Redis and Inngest.

**[Deploy Mastra Durable Agents on Railway](https://railway.com/template/mastra-durable-agents)**

- **Creator:** leodev
- **Category:** AI/ML

## Template content

### Mastra Server https://unpkg.com/mastra/dist/studio/mastra.svg

- **Source:** https://github.com/leoisadev1/mastra-template-durable-agents
- **Health check:** /health
- **Public domain:** Yes

### Redis https://cdn.sanity.io/images/sy1jschh/production/0ce0bfdcfbdbf69662b1116671f97c2dd788b655-157x157.svg

- **Image:** redis:8.2.1
- **Start command:** `/bin/sh -c "rm -rf $RAILWAY_VOLUME_MOUNT_PATH/lost+found/ && exec docker-entrypoint.sh redis-server --requirepass $REDIS_PASSWORD --save 60 1 --dir $RAILWAY_VOLUME_MOUNT_PATH"`

### Inngest https://devicons.railway.com/inngest

- **Image:** inngest/inngest:v1.34.0
- **Start command:** `/bin/sh -c "inngest dev -p 8288 -u $MASTRA_INNGEST_URL --poll-interval=1"`

## Documentation

# Deploy and Host Mastra Durable Agents on Railway

[Mastra](https://mastra.ai) is the open-source TypeScript framework for building AI agents and workflows. This template deploys a Mastra server that runs one research agent in four durability modes side by side: a plain `Agent`, a `createDurableAgent` with Redis-backed resumable streams, a `createEventedAgent` that adds fire-and-forget execution, and a `createInngestAgent` with full Inngest durable execution. Disconnect mid-stream, reconnect with the same `runId` and offset, and the stream resumes where it stopped.

## About Hosting Mastra Durable Agents

The template provisions three services: the Mastra server, a Redis instance for the resumable stream cache, and an Inngest server for durable workflow execution. The Mastra server connects to Redis and Inngest over Railway's private network. Agent state and history persist in LibSQL on an attached volume. The Inngest service runs in dev mode and keeps its run state in the container, so a restart of that service drops runs that have not finished. Generate a public domain on the Mastra server and that URL serves both the REST API and Mastra Studio. Set one variable — your OpenAI API key — and deploy.

## Common Use Cases

- Compare durability strategies for agent streaming before you commit to one
- Build chat UIs that survive tab refreshes, network drops, and server restarts
- Run long agent tasks in the background and observe them from any client
- Learn the Mastra durable agent APIs from a working reference

## Dependencies for Mastra Durable Agents Hosting

- OpenAI API key (agent model)

### Deployment Dependencies

- [Mastra durable agents docs](https://mastra.ai/docs)
- [Inngest](https://www.inngest.com/)

### Implementation Details

Reconnect to a running stream:

```bash
curl -X POST https://YOUR-DOMAIN.up.railway.app/api/agents/durable-research-agent/observe \
  -H "Content-Type: application/json" \
  -d '{"runId": "your-run-id", "offset": 5}'
```

## Why Deploy Mastra Durable Agents on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Mastra Durable Agents on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.
- [Hermes Agent | OpenClaw Alternative with Dashboard](https://railway.com/deploy/hermes-agent-or-openclaw-alternative-wit) — Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

Open this page in a browser: https://railway.com/deploy/mastra-durable-agents
