Day 6: Put it online

Python Backend Basics: Build the ShopStream API ~5 min read 30 min hands-on

Run the API like production — workers, readiness, secrets in .env, JSON logs — and share it with a public URL.

Your API works on your laptop. Today it runs the way a production service does — several worker processes, a database password that isn't in the code, health checks a load balancer can use, one JSON log line per request, the demo-only endpoints switched off — and then you put it on the internet with a public https URL you can open on your phone. No cloud account needed.

What you build

  • gunicorn with 2 uvicorn workers (gunicorn.conf.py, WEB_CONCURRENCY). One process per CPU core is the usual start; if a worker crashes, the manager starts a new one.

  • Migrations run once before the workers start (python -m app.migrate in the container's command), so two workers never race to change the schema.

  • /health and /health/ready: liveness (the process answers) and readiness (it can reach the database). The Docker health check uses readiness.

  • Secrets from .env: start.sh generates a random 24-character database password into .env, which is listed in .gitignore and .dockerignore. compose.yaml refuses to start without it (${DB_PASSWORD:?...}).

  • A JSON access log: one line per request with method, path, status and milliseconds.

  • Demo endpoints off: the string-built search from Day 2 and the naive orders from Day 3 now return 404.

  • A Cloudflare quick tunnel (cloudflared, compose profile public): a temporary https://<random>.trycloudflare.com URL that forwards to your API.

The production command

Check configuration, migrate, then exec the server so it becomes PID 1 and receives the stop signal from Docker directly — that's what lets it finish in-flight requests on shutdown.

What we measured

Verify on Docker Desktop:

Through the tunnel, 20 requests each for GET /products/{id}:

Read the full lesson free

This lesson is one of the first 3 in its course, free with an account — the full article, implementation guide and scripts. No card needed.

Already a member? Sign in