- FastAPI – Getting It Into Production
From a working image to something serving users. Workers and what they cost in database connections, a reverse proxy in front, configuration and secrets from the environment, running migrations as a step rather than at boot, and rolling out without dropping requests. Plus what to check first when it works locally and not in the cluster.
- FastAPI – Containerising It Properly
A multi-stage Dockerfile that leaves the compiler behind, a .dockerignore that cuts the build context from hundreds of megabytes and keeps .env out of a layer, and a non-root user. Then the settings that decide whether it works: --host 0.0.0.0, PYTHONUNBUFFERED, how many workers, and a healthcheck. With the resulting image size and build time measured rather than estimated.
- FastAPI – Logging, Health Checks and Request Tracing
Making a running API explainable. Structured JSON logs with a correlation id carried by a ContextVar so it survives both async routes and the threadpool, a health check that reports each dependency separately, and what to log per request. Includes two things that bite in a container: uvicorn quietly replacing your log config, and a test that asserted on log content while reading another handler's work.
- FastAPI – Testing the Whole Stack
TestClient against the real ASGI stack, dependency_overrides to swap the database and the current user, and a fixture that runs every test inside a transaction it rolls back. Which tests belong at the service layer and which can only be written through HTTP — including the class of bug that lives entirely in configuration and is invisible to everything below TestClient.
- FastAPI – Middleware, Ordering and CORS
Middleware for the things every request needs: a correlation id, a timing header, one access log line. Then ordering, which reads backwards — add_middleware inserts at the front, so the last call is the outermost layer. Getting that wrong shipped a real bug here: every 500 reached the browser without CORS headers, so the frontend reported a CORS failure and never saw the error body.