Deploy Reflex
Full-stack Python web app with Reflex, Postgres and Redis.
Redis
Just deployed
/data
Just deployed
/var/lib/postgresql/data
reflex-railway
Just deployed
Deploy and Host Reflex with Railway
Reflex 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 0.10
- Postgres for application data, accessed with SQLModel and migrated with Alembic
- Redis for shared session state
- Caddy for static file serving and reverse proxying
Deployment Dependencies
- Reflex self-hosting guide
- Reflex database docs
- Railway private networking
- Railway 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:
Dockerfilerunsreflex export --frontend-onlyin a build stage. The runtime image has the prebuilt frontend, the Python environment and Caddy, but no bun ornode_modules.start.shstarts Caddy on$PORTandreflex run --env prod --backend-onlyon127.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_URLor 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.
Template Content
Redis
redis:8.2reflex-railway
reflex-dev/reflex-railway