Series · 9 parts · 63 min
FastAPI in Production
A Python backend that holds up: layered architecture, migrations, background jobs, auth, email and object storage.
- Part 01FastAPI Layered Architecture — Routes, Services, and RepositoriesFlat FastAPI routes that do everything are fast to write and painful to maintain. This post covers the three-layer architecture that keeps query logic, business logic, and HTTP concerns cleanly separated.5 min read
- Part 02Alembic with SQLAlchemy 2.0 Async — Migrations That Hold in ProductionSQLAlchemy async models and Alembic fight each other until you wire them correctly. This post covers the full setup: env.py for async engines, autogenerate that actually catches your changes, and a safe rollback strategy. 7 min read
- Part 03Alembic Async Migrations and Idempotent Database Seeding in FastAPIAlembic's default env.py is synchronous. This post covers the async migration setup, auto-database creation, and an idempotent seed script that is safe to re-run at any point.8 min read
- Part 04Stateless OTP Login in FastAPI with JWT and RedisPassword databases are a liability. Build a stateless OTP login flow in FastAPI using signed JWTs as verification tokens and Redis for single-use enforcement.8 min read
- Part 05Async Email Delivery in FastAPI — Two SMTP Paths, One Jinja2 Template SystemOTP emails and welcome emails have different latency requirements. This post covers a dual-path SMTP design where time-sensitive emails send inline with aiosmtplib and background emails queue through Celery with smtplib.7 min read
- Part 06Celery + Redis in Production — Task Reliability with acks_late and Retry BackoffDefault Celery configuration loses tasks silently when workers die. This post covers the four settings that make Celery safe under real failure conditions, with the exact configuration from a production FastAPI backend.7 min read
- Part 07Monitoring Celery with Flower — Local Setup and SSH Tunnel for Remote ServersFlower exposes your Celery queue to the public internet if configured carelessly. This post covers local development setup and a secure SSH tunnel approach for remote production monitoring.6 min read
- Part 08Mailpit as a Dev SMTP Catch-All Behind TraefikOutbound emails in dev either silently fail or hit real inboxes. Run Mailpit as an SMTP catch-all in Docker, routed through Traefik with auth, persistence, and a Web UI.7 min read
- Part 09MinIO as a Self-Hosted S3 Backend in DockerAWS egress costs and vendor lock-in are avoidable. Run MinIO as a drop-in S3-compatible object store in Docker, wired into your existing infra stack with zero app-code changes.8 min read