Preparing for Production
Production environments are not like your laptop.
A production-ready Flask app typically needs:
flowchart TD
subgraph Development
A["flask run"] --> B["one process, reloader on"]
B --> C["debug=True -- interactive debugger"]
end
subgraph Production
D["nginx or the platform's proxy"] --> E["TLS, static files, timeouts"]
E --> F["gunicorn / waitress, N workers"]
F --> G["your app object"]
G --> H["debug OFF, SECRET_KEY from the environment"]
end
C -.->|"never ship this"| I["the debugger console runs arbitrary code"]
Must-do checklist
Section titled “Must-do checklist”- Debug mode disabled
- Secrets stored in environment variables
- A production WSGI server (Gunicorn) instead of
flask run - Proper logging
- HTTPS termination (usually via Nginx or platform)
- Error handling (friendly pages or JSON)
- Database migrations
- Static file handling
The biggest production mistake
Section titled “The biggest production mistake”Running:
flask run
on a production server.
Use Gunicorn (or another WSGI server) instead.
Configuration mindset
Section titled “Configuration mindset”Your app should be configured by:
- environment variables
Not by editing code per environment.
Health endpoints
Section titled “Health endpoints”Many deployments benefit from:
/healthendpoint returning 200
So monitoring systems can detect downtime.
Observability
Section titled “Observability”Have some plan for:
- request logs
- error logs
- basic metrics
Even a simple setup is better than none.
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading