Module 12 / Project 01 — Deploy to Railway¶
Home: README · Module: Cloud Deployment
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | Walkthrough | — | Flashcards | — | — |
Focus¶
- Deploying a FastAPI app to Railway
- Environment variables on a cloud platform
- Procfile and runtime configuration
- Viewing logs in production
Why this project exists¶
This is the moment your code goes from "runs on my laptop" to "runs on the internet." You will deploy a real FastAPI app to Railway and see it respond to requests from any browser in the world.
Prerequisites¶
- A Railway account (free tier available)
- Git installed and configured
- A GitHub account (Railway deploys from GitHub repos)
Project files¶
01-deploy-to-railway/
├── app.py # FastAPI app
├── requirements.txt # Python dependencies
├── Procfile # Tells Railway how to start the app
├── runtime.txt # Python version
├── .env.example # Template for environment variables
└── notes.md
Step-by-step deployment¶
1. Test locally first¶
cd projects/modules/12-cloud-deploy/01-deploy-to-railway
pip install -r requirements.txt
python app.py
# Visit http://127.0.0.1:8000/docs
2. Push to GitHub¶
Create a new GitHub repo and push this project to it.
3. Deploy on Railway¶
- Go to https://railway.app and sign in with GitHub.
- Click "New Project" → "Deploy from GitHub repo."
- Select your repository.
- Railway detects the
Procfileand starts building. - Once deployed, Railway gives you a public URL.
4. Set environment variables¶
In Railway dashboard → your service → Variables:
- APP_ENV=production
- APP_NAME=my-fastapi-app
5. Verify¶
Visit https://your-app.up.railway.app/health — you should see a JSON response.
Expected output¶
After deployment, visiting your Railway URL returns:
Alter it¶
- Add a new endpoint and redeploy. Watch Railway's automatic deploy trigger.
- Add a
PORTenvironment variable and make the app read it (Railway sets this automatically). - Add basic rate limiting using an in-memory counter.
Break it¶
- Remove the
Procfile. Can Railway still start the app? - Set a wrong Python version in
runtime.txt. What happens during build? - Push code with a syntax error. Check the deploy logs.
Fix it¶
- Add the Procfile back and redeploy.
- Fix the Python version to match what Railway supports.
- Fix the syntax error, push, and verify auto-deploy succeeds.
Explain it¶
- What does the Procfile do and why is it needed?
- Why should you read configuration from environment variables instead of hardcoding?
- What is the difference between a build step and a run step in deployment?
- How does Railway know when to redeploy your app?
Mastery check¶
You can move on when you can: - deploy a FastAPI app to Railway from GitHub, - set and read environment variables, - check deploy logs to debug issues, - explain the deploy workflow.