Three deployment paths, three very different trade-offs. Here is a plain-English guide to which one fits your situation.
The Confusion
Mastra has three deployment paths: Mastra Cloud (managed), self-hosted (Docker or Node), and Vercel (serverless). The docs cover each separately but do not compare them, and the community regularly asks which one to use -- and why deploying to Vercel breaks things that work locally.
This article gives you the honest comparison, explains what breaks where, and tells you which path fits which situation.
Option 1: Mastra Cloud (Managed)
Mastra Cloud is the managed hosting service run by the Mastra team. You push your Mastra project and it handles infrastructure, scaling, persistence, and the Mastra Studio UI.
| Aspect | Detail |
|---|---|
| What you get | Managed PostgreSQL storage, auto-scaling, built-in Studio access, zero infra management |
| What you give up | Control over infrastructure, data residency flexibility, cost transparency at scale |
| Best for | Teams who want to ship fast without managing servers |
| Limitations | Early access as of 2026; pricing not fully public; US data residency only initially |
# Deploy to Mastra Cloud
npx mastra deploy --cloud
# Set up cloud credentials first:
npx mastra loginMastra Cloud includes the Studio UI out of the box. If your team needs visibility into workflow runs, agent traces, and evals without setting up your own observability stack, Cloud is the fastest path.Option 2: Self-Hosted (Docker / Node)
Self-hosting gives you full control. You run Mastra as a Node.js server (or in a Docker container) on any infrastructure: Railway, Render, Fly.io, EC2, your own VPS.
# Build your Mastra project for self-hosting
npx mastra build
# This outputs a .mastra/ directory with a standalone Node server
# Run it:
node .mastra/output/index.mjs
# Or with Docker (create your own Dockerfile):FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY .mastra/ .mastra/
EXPOSE 3000
CMD ["node", ".mastra/output/index.mjs"]Key things to configure for self-hosted production:
- Set a persistent storage adapter (LibSQL or PostgreSQL) -- without this, workflow state is lost on restart
- Set MASTRA_LOG_LEVEL=info in production (debug logging is very verbose)
- Expose the Mastra API on a specific port and put a reverse proxy (nginx, Caddy) in front
- The Studio UI is available at /studio in development but disabled in production builds by default -- enable with MASTRA_STUDIO=true if needed
The Studio UI in self-hosted mode is a development tool. Do not expose it publicly without authentication. In production, either disable it (default) or put it behind your auth layer.Option 3: Vercel (Serverless)
Mastra can be embedded inside a Next.js app and deployed to Vercel. This is the most common path for teams that are already on Next.js. It is also where the most confusion and bugs come from.
How the integration works
In a Next.js + Mastra setup, your Mastra instance is initialised in a server-side module and your agents/workflows are exposed via Next.js API routes or Route Handlers. The Mastra Studio runs as a separate route group.
// src/mastra/index.ts -- your Mastra instance
import { Mastra } from '@mastra/core';
import { myAgent } from './agents/myAgent';
export const mastra = new Mastra({
agents: { myAgent },
// IMPORTANT: Vercel does not support LibSQL in serverless --
// use a remote database (Turso, Neon, Supabase) instead:
storage: new PostgresStore({ connectionString: process.env.DATABASE_URL }),
});
// src/app/api/agent/route.ts -- expose as API route
import { mastra } from '@/mastra';
export async function POST(req: Request) {
const { message } = await req.json();
const result = await mastra.getAgent('myAgent').generate(message);
return Response.json({ result: result.text });
}What breaks on Vercel
| Issue | Why it happens | Fix |
|---|---|---|
| In-memory storage wipes between requests | Vercel functions are stateless -- no persistent memory | Use Turso, Neon, or Supabase as storage backend |
| Long-running workflows time out | Vercel Hobby/Pro functions have a 10s/60s max duration | Use Vercel Pro + maxDuration config, or move workflows off Vercel |
| Studio not accessible | Studio is a dev-only feature, not deployed by default | Access Studio locally; do not rely on it in Vercel production |
| Cold start latency | Large Mastra bundles cause slow cold starts | Use Next.js bundle analyser to tree-shake unused integrations |
// next.config.ts -- increase function timeout for workflow routes
const nextConfig = {
experimental: {
serverActions: {
bodySizeLimit: '2mb',
},
},
};
// In route handler for long-running workflows:
export const maxDuration = 60; // seconds (requires Vercel Pro)
export const dynamic = 'force-dynamic';Decision Guide
| Your situation | Recommended path |
|---|---|
| Want to ship fast, no infra to manage | Mastra Cloud |
| Need full data control / custom infra | Self-hosted (Docker + Railway/Render/Fly) |
| Already on Next.js + Vercel, simple agents | Vercel (with remote DB) |
| Need long-running or suspended workflows | Self-hosted or Mastra Cloud (not Vercel) |
| Need Studio UI in production | Mastra Cloud or self-hosted with MASTRA_STUDIO=true |
| Enterprise / regulated environment | Self-hosted with PostgreSQL |
Quick Reference
- Mastra Cloud: fastest to ship, managed infra, Studio included -- best for most teams
- Self-hosted: full control, needs persistent DB config, suits regulated or complex deployments
- Vercel: works for simple agents in Next.js, breaks for long-running or suspended workflows
- Always configure a remote storage backend on Vercel (Turso, Neon, Supabase)
- Studio UI is a dev tool -- do not expose without authentication in production