Deploy Reflex

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

Deploy Reflex

Just deployed

/data

/var/lib/postgresql/data

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

Deployment Dependencies

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) │
        └──────────────┘   └───────────────┘
ServiceSourcePublicHealth checkNotes
ReflexDockerfileYes/_healthPre-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.
PostgresRailway PostgresNon/aPersistent volume. Referenced as ${{Postgres.DATABASE_URL}}.
RedisRailway RedisNon/aPersistent volume, password protected. Referenced as ${{Redis.REDIS_URL}}.

Reflex service variables:

VariableValuePurpose
PORT8080Public 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_WORKERS2Backend 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.


Template Content

More templates in this category

View Template
open-excalidraw
Self-hostable collaborative drawing built on Excalidraw

Prateek Mohanty
5
View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

5
View Template
Appsmith
Low-code platform for internal tools, dashboards, and admin panels.

Agaz Self-Host
1