FastAPI Cheatsheet 19 — Health, Probes, and Lifespan
Cheatsheet: liveness vs readiness, deep health checks, lifespan resource management, startup probes.
Cheatsheet: liveness vs readiness, deep health checks, lifespan resource management, startup probes.
Pre-launch checklist: deps, config, observability, security, data, deployment, on-call.
Practical FastAPI DI: scoped dependencies, async DB sessions, auth chains, request-scoped state, lifespan resources, and where DI starts to bite.
Choosing background processing for FastAPI: BackgroundTasks for fire-and-forget, ARQ for Redis-backed simplicity, Celery for ecosystem, Dramatiq for ergonomics.
Practical FastAPI streaming: SSE for one-way real-time, NDJSON for streamed JSON, LLM token streaming, backpressure handling, and reconnect patterns.
A complete, opinionated production layout for FastAPI in 2026. Pydantic v2, async SQLAlchemy 2.0, Alembic, dependency injection, structured errors, settings, logging, and the project skeleton that survives the first 50 endpoints.
An opinionated, side-by-side comparison of Django and FastAPI covering philosophy, features, performance, and when to pick each (or both).
A practical guide to testing FastAPI: pytest configuration, async HTTP client, transactional database isolation per test, and fixtures for authentication.
An end-to-end JWT auth walkthrough for FastAPI: bcrypt password hashing, access + refresh tokens, dependency-injected current user, and how to avoid common pitfalls.
Build a production-ready FastAPI + SQLAlchemy 2.0 + PostgreSQL stack with async sessions, dependency-injected DB access, and Alembic migrations.