---
title: "Deploy Reflex"
description: "Full-stack Python web app with Reflex, Postgres and Redis."
category: "Starters"
url: https://railway.com/deploy/reflex
---

# Deploy Reflex

Full-stack Python web app with Reflex, Postgres and Redis.

**[Deploy Reflex on Railway](https://railway.com/template/reflex)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/reflex/manifest.json

- **Creator:** Reflex
- **Category:** Starters
- **Total deploys:** 1

## Template content

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

- **Image:** redis:8.2
- **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"`

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### reflex-railway

- **Source:** reflex-dev/reflex-railway
- **Health check:** /_health
- **Public domain:** Yes

## Documentation

# Deploy and Host Reflex with Railway

[Reflex](https://reflex.dev) is an open-source framework for building full-stack web apps in pure Python. You write the UI and the backend logic in Python, and Reflex compiles the frontend to a fast React app. This template deploys a production-ready Reflex app with Postgres and Redis on Railway.

## About Hosting Reflex

A Reflex app has two parts: a static frontend (HTML, CSS, and JavaScript) and a Python backend that keeps a WebSocket open to every browser session. This template builds the frontend once, when the image is built, so deploys, restarts and new replicas start in seconds without compiling anything. At runtime the **Reflex** service serves everything on one port: Caddy serves the prebuilt frontend and forwards backend routes to the Reflex backend in the same container. **Postgres** stores application data and **Redis** stores session state, each as its own Railway service, so you can add Reflex replicas. Database migrations run once per deploy, before the new version takes traffic.

## Common Use Cases

- Internal tools and admin dashboards built entirely in Python
- Data and AI apps (chat interfaces, model playgrounds, analytics) with a real database
- Customer-facing SaaS products and portals
- Prototypes that need to grow into production apps without a rewrite

## Dependencies for Reflex Hosting

- Python 3.11+ and [Reflex](https://reflex.dev) 0.10
- [Postgres](https://www.postgresql.org) for application data, accessed with [SQLModel](https://sqlmodel.tiangolo.com) and migrated with [Alembic](https://alembic.sqlalchemy.org)
- [Redis](https://redis.io) for shared session state
- [Caddy](https://caddyserver.com) for static file serving and reverse proxying

### Deployment Dependencies

- [Reflex self-hosting guide](https://reflex.dev/docs/hosting/self-hosting/)
- [Reflex database docs](https://reflex.dev/docs/database/overview/)
- [Railway private networking](https://docs.railway.com/networking/private-networking)
- [Railway pre-deploy command](https://docs.railway.com/deployments/pre-deploy-command)

### Implementation Details

```
           Internet (HTTPS, Railway edge)
                        │
        ┌───────────────▼────────────────┐
        │ Reflex service  (port $PORT)    │
        │                                 │
        │  Caddy ── static frontend,      │  built at image build time
        │    │      precompressed, cached │
        │    │ /_event /ping /_health     │
        │    ▼ /_upload                   │
        │  Reflex backend (127.0.0.1)     │  Granian workers
        └───────┬─────────────────┬───────┘
     private net│                 │private net
        ┌───────▼──────┐   ┌──────▼────────┐
        │   Postgres   │   │     Redis     │
        │  (app data)  │   │ (state store) │
        └──────────────┘   └───────────────┘
```

| Service  | Source | Public | Health check | Notes |
|----------|--------|--------|--------------|-------|
| Reflex   | `Dockerfile` | Yes | `/_health` | Pre-deploy runs `alembic upgrade head`. `/_health` returns 503 until Postgres and Redis are reachable, so a deploy goes live only when it can serve traffic. |
| Postgres | Railway Postgres | No | n/a | Persistent volume. Referenced as `${{Postgres.DATABASE_URL}}`. |
| Redis    | Railway Redis | No | n/a | Persistent volume, password protected. Referenced as `${{Redis.REDIS_URL}}`. |

Reflex service variables:

| Variable | Value | Purpose |
|----------|-------|---------|
| `PORT` | `8080` | Public port. Railway routes the domain here. |
| `DATABASE_URL` | `${{Postgres.DATABASE_URL}}` | Private Postgres connection. `rxconfig.py` selects the psycopg driver. |
| `REFLEX_REDIS_URL` | `${{Redis.REDIS_URL}}` | Private Redis connection for session state. |
| `GRANIAN_WORKERS` | `2` | Backend worker processes per replica. Raise it for larger instances, or add replicas. |

How the container runs:

- `Dockerfile` runs `reflex export --frontend-only` in a build stage. The runtime image has the prebuilt frontend, the Python environment and Caddy, but no bun or `node_modules`.
- `start.sh` starts Caddy on `$PORT` and `reflex run --env prod --backend-only` on `127.0.0.1:8000`. If either process exits, the container exits and Railway restarts it.
- The page and the backend share one origin, so no `REFLEX_API_URL` or CORS setup is needed.

## Why Deploy Reflex 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 Reflex 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

- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [caring-vibrancy](https://railway.com/deploy/caring-vibrancy) — Deploy and Host caring-vibrancy with Railway
- [Appsmith](https://railway.com/deploy/appsmith-1) — Low-code platform for internal tools, dashboards, and admin panels.

Open this page in a browser: https://railway.com/deploy/reflex
