The engineering notebook
RSS feed#python
Articles, practical guides, and engineering notes on python.
By Ashish Bhakhand 108 published articles
Explore the articles
20 articles
Reset filtersProduction FastAPI Middleware: Order Matters
Build request context, body limits, host checks, CORS, compression, and logging in an order that preserves reliable behavior.
Designing a Stable API Envelope in FastAPI
Give mobile and web clients one predictable success, error, retry, and request-correlation contract.
Who Owns the Transaction in a FastAPI Application?
Place transaction boundaries around complete business operations without pushing orchestration into routes or hiding it inside unrelated queries.
Direct SQL with asyncpg: Why I Do Not Add an ORM Automatically
Direct PostgreSQL access can make queries, constraints, and atomic behavior clearer when the team is willing to own the SQL.
FastAPI Lifespan: Managing Databases, Schedulers, and Shared Clients
Give long-lived resources clear startup and shutdown ownership instead of constructing them inside requests.
Fail Fast with Pydantic Settings
Validate environment variables, production transport security, and operational limits once during startup.
Practical Pydantic Validation Beyond Basic Field Types
Use strict objects, constrained fields, normalization, literals, and model validators without moving business logic into schemas.
Pydantic Is a Boundary, Not Your Entire Domain Model
Separate API schemas, internal domain types, and database rows so each representation serves the job it was designed for.
Thin FastAPI Routers: What Belongs in an Endpoint?
Use routes as typed HTTP adapters while services own decisions, transactions, and orchestration.