Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
Python & Django

Getting a Python Service Running Reliably

Last updated:

Never run the development server in production

The built-in development servers in Python frameworks are single-threaded, unoptimised and explicitly not intended for production. They are also frequently found running production systems.

Behind a production application server, with a reverse proxy in front and a process supervisor keeping it alive. That is the minimum viable arrangement.

The deployment stack

  1. A production application server running the Python code
  2. A reverse proxy handling TLS, static files and buffering
  3. A process supervisor restarting anything that exits
  4. Separate worker processes for background tasks
  5. Log output collected rather than written to a file nobody reads

Configuration from the environment

  • No credentials in the repository, ever
  • Different configuration per environment without code changes
  • Configuration validated at startup, failing fast if something is missing
  • Secrets managed properly rather than in a plain file

An application that starts successfully with a missing configuration value and fails at three in the morning is a preventable problem.

Deploy from version control

RequirementWhy
Deploy a specific commitYou know what is running
Dependencies installed at deployReproducible
Migrations run in orderSchema matches code
Atomic switchNo half-deployed state
Tested rollbackRecovery is routine

Health checks and graceful shutdown

A health endpoint lets monitoring and load balancers know whether the service is actually working, not just running. It should check dependencies rather than always returning success.

Graceful shutdown — finishing in-flight requests before exiting — means deployments do not drop work. Both are small pieces of work with disproportionate operational value.

Frequently asked questions

Containers or plain deployment?

Containers give consistency and add operational complexity. For a single service and a small team, a plain deployment is frequently simpler.

How do we handle secrets?

Environment variables at minimum, a secrets manager where the environment supports it. Never in the repository.

What about zero-downtime deployment?

Achievable with an atomic switch and graceful shutdown. Worth it where downtime has a cost.

Should workers deploy with the application?

Usually together, so code and tasks stay in step. Watch for in-flight tasks during the switch.

Keep reading

Running the development server in production?

It happens more than you would expect. Worth checking, and quick to fix properly.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Custom Software DevelopmentWeb DevelopmentMachine Learning