A Flask app runs with `app.run()` in production and falls over under load. What do you change?
BeginnerScenarioTesting, CI/CD, packaging & services
Answer
Situation read → The development server is single-process and not built for production.
What I'd do →
- Run under gunicorn:
gunicorn -w 4 -k gthread --threads 4 -b 0.0.0.0:8000 --timeout 30 app:app. - Size workers to CPU (roughly 2 x cores + 1 as a start) and measure.
- Put it behind a reverse proxy or load balancer; add health endpoints.
- Set
--graceful-timeoutand handle SIGTERM for clean deploys.
Why → A real WSGI server handles concurrency, worker restarts and timeouts.
Interview tip → Mention the dev server warning itself says not to use it in production.
More on Testing, CI/CD, packaging & services
You join a team whose Python automation repo has no tests. Where do you start?BeginnerYour pytest suite takes 12 minutes. How do you speed it up?IntermediateA test passes locally but fails in CI only when run with the rest of the suite. What do you suspect?IntermediateYou want a reusable CI pipeline for 15 Python tool repos. What goes in it?IntermediateYour Python Docker image is 1.1 GB. How do you shrink it?IntermediateYou want to distribute an internal CLI to 200 engineers. What are your options?Intermediate