This guide covers deploying the pneumonia detection web application to Railway.
- GitHub repository with the application code
- Railway account (https://railway.app)
- Model API endpoint URL (from the model team)
- Log in to Railway
- Click "New Project" → "Deploy from GitHub repo"
- Select your repository
- Railway will auto-detect the Python project
In Railway dashboard, go to your service → Variables tab and add:
Required:
MODEL_API_URL=https://your-model-api.railway.app/predict
SECRET_KEY=<generate-a-random-32-char-string>
Optional:
MODEL_API_HEALTH_URL=https://your-model-api.railway.app/health
MODEL_API_KEY=<if-authentication-required>
API_TIMEOUT_SECONDS=10
MAX_FILE_SIZE_MB=10
DEBUG=False
To generate a secret key:
python -c "import secrets; print(secrets.token_hex(16))"- Railway automatically deploys when you push to main branch
- Or manually trigger deploy from the dashboard
- Wait for build to complete (usually 1-2 minutes)
- Click the generated URL in Railway dashboard
- Check the health endpoint:
https://your-app.railway.app/health - Expected response:
{"status": "healthy", "model_api": "connected"}
- Open the app URL in browser
- Upload a test X-ray image
- Verify you receive a prediction result
- Check error handling with invalid files
Railway uses these files:
- Procfile:
web: gunicorn app.main:app - runtime.txt:
python-3.10.12 - requirements.txt: Python dependencies
- Go to Railway dashboard → your service
- Click "Logs" tab
- Filter by deployment or view live logs
Railway automatically monitors your app. The /health endpoint provides:
- Overall application status
- Model API connectivity status
- Push changes to main branch
- Railway automatically redeploys
- Zero-downtime deployment
If a deployment has issues:
- Go to Railway dashboard → Deployments
- Find the previous working deployment
- Click "Rollback" to restore
- Go to Settings → Domains
- Add your custom domain
- Configure DNS CNAME record as instructed
- Check Procfile syntax
- Verify requirements.txt is complete
- Check logs for import errors
- Verify MODEL_API_URL is correct
- Check if model API is deployed and running
- Try the health check endpoint directly
- Model inference can take a few seconds
- First request after idle may be slower (cold start)
- Consider keeping the API warm
- Railway free tier has limits
- Optimize image handling to reduce memory
- Consider upgrading plan for production use
| Setting | Development | Production |
|---|---|---|
| DEBUG | True | False |
| SECRET_KEY | dev-key | Random secure key |
| MODEL_API_URL | localhost or test | Production API URL |