All posts
Tag

backend

25 posts

Tutorial

Clean Code Python: Full-Stack DI with dependency-injector, FastAPI, and SQLAlchemy

FastAPI's Depends() handles per-request wiring. dependency-injector handles everything else — configuration, singletons, factories, and a declarative container that makes your entire object graph visible in one file.

15 min read
Tutorial

Clean Code Python: Connection Pooling and Database Resilience Under Load

Your pool_size=5 default just met Black Friday traffic. 200 concurrent requests, 5 connections, 195 coroutines waiting on pool checkout — then timeouts cascade into a full outage. Here is how to configure connection pooling, read replicas, and circuit breakers for production traffic.

14 min read
Tutorial

Clean Code Python: Configuration, Feature Flags, and Secrets That Scale

Hardcoded config breaks the moment your 200 tenants need different rate limits, feature access, and API keys. Here is a hierarchical configuration system with per-tenant overrides, percentage-based feature rollouts, and encrypted secrets — all hot-reloadable without restarts.

14 min read
Tutorial

Clean Code Python: Rate Limiting and Noisy Neighbor Prevention

Without rate limiting, one tenant's bulk import consumes all your database connections and API throughput. Here is how to build tiered, sliding-window rate limiting in Python with Redis — protecting every tenant from every other tenant.

11 min read
Tutorial

Clean Code Python: Locking, Idempotency, and Sagas

At 1M transactions per day, two requests modifying the same inventory record is not an edge case. Here is how to prevent lost updates with optimistic locking, double charges with idempotency keys, and partial failures with the saga pattern.

13 min read
Tutorial

Clean Code Python: Multi-Tenant Migrations Without Downtime

A naive ALTER TABLE on a 100M-row table locks it for minutes. Multi-tenant makes it worse: one failed migration across 200 schemas leaves tenants on inconsistent versions. Here is the expand-contract pattern and the tooling to migrate safely.

14 min read
Tutorial

Clean Code Python: API Versioning and Backward-Compatible Evolution

A breaking API change that 'only' affects 5% of tenants still breaks real businesses. Without versioning, you can never evolve your API. Here is how to version a multi-tenant FastAPI backend with per-tenant version pinning, deprecation workflows, and contract testing.

12 min read
Tutorial

Clean Code Python: From git init to Production Traffic

Theory without deployment is fiction. This capstone assembles all 22 prior patterns into a deployed, monitored, incident-ready multi-tenant Python backend — from Docker Compose to runbooks to your first production incident.

22 min read
Tutorial

Clean Code Python: Type Safety with Protocols Over ABCs

Python's ABC machinery adds inheritance overhead you do not need. Protocols give you structural subtyping — type-safe duck typing with zero coupling between your repository interfaces and implementations.

8 min read
Tutorial

Clean Code Python: Structured Error Handling Across the Stack

Scattered try/except blocks and generic 500 errors signal a system that was not designed. Here is how to define domain exceptions, translate them to HTTP responses, and give your API clients errors they can act on.

7 min read
Tutorial

Clean Code Python: Dependency Injection Without Magic

FastAPI's Depends() is the most underused tool in the framework. Here is how to use it to wire repositories, services, and authentication into your route handlers with no global state and no service locator pattern.

7 min read
Tutorial

Clean Code Python: Async Patterns That Actually Scale

asyncio.gather() is not always the answer. Here is when to parallelize database calls, when NOT to, and how to avoid the most common SQLAlchemy async session mistakes that cause subtle production bugs.

9 min read
Tutorial

Clean Code Python: Testing Strategies for the Full Stack

Unit tests, integration tests, and API tests — each has a role in a Python backend. Here is a complete testing strategy for a FastAPI + SQLAlchemy project, showing what to test at each layer and how the patterns from this series make testing effortless.

10 min read