Skip to content
tezvyn:

All bites

The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.

8664 bites

Page 13

Python & FastAPI1 min read

Pydantic computed fields in response models

A @computed_field decorated property is excluded from input and validation but included in serialization and the OpenAPI schema, ideal for values like full_name derived from other fields.

Python & FastAPI1 min read

Mapping camelCase JSON to snake_case Pydantic fields

Set an alias_generator (to_camel) plus populate_by_name in model config, accept aliases on input, and serialize with by_alias=True so responses come out camelCase.

Python & FastAPI1 min read

Pydantic BaseModel vs dataclasses in FastAPI

BaseModel validates and coerces data at runtime, parses and serializes JSON, integrates with OpenAPI schema generation, and supports rich validators; dataclasses only store data with no validation.

Python & FastAPI1 min read

Testing a DB endpoint via dependency override

Use app.dependency_overrides to swap the real get_db for one yielding a test database session, run against a disposable SQLite or test Postgres, and assert through TestClient.

Python & FastAPI1 min read

Secure refresh token flow for access renewal

Short-lived access token, longer-lived refresh token stored server-side, a refresh endpoint that validates and rotates the refresh token issuing a new pair.

Python & FastAPI1 min read

Zero-downtime blue-green deploys on Kubernetes

Run blue and green deployments, switch a Service or ingress selector to the new color after readiness probes pass, drain old pods gracefully, and handle backward-compatible DB migrations.

Python & FastAPI1 min read

Limits of BackgroundTasks vs Celery or ARQ

BackgroundTasks run in the same worker with no persistence, retries, or visibility, and die with the process; Celery or ARQ add durability, retries, scheduling, and separate workers.

Python & FastAPI2 min read

Diagnosing a slow FastAPI endpoint under load

Add timing and tracing to isolate the slow span, watch CPU vs wait time and event-loop lag, then use profilers like py-spy or cProfile and DB EXPLAIN.

Python & FastAPI1 min read

WebSocket connection manager and broadcast

A manager class holding a list of active connections, connect accepts and appends, disconnect removes, broadcast iterates sending to each, all wrapped in try/finally to handle disconnects.

Python & FastAPI1 min read

BackgroundTasks dependency vs response.background

The injected BackgroundTasks parameter lets endpoints and dependencies stack tasks and is the common path; response.background attaches a single Starlette task when you return a Response object…

Python & FastAPI1 min read

Propagating a correlation ID without parameter passing

Middleware reads or generates the header, stores it in a contextvars.ContextVar, service code reads it anywhere, and logging filters inject it.

Python & FastAPI1 min read

Revoking stateless JWTs on logout

A server-side denylist of revoked token IDs checked per request, or short-lived access tokens paired with revocable refresh tokens.

Python & FastAPI1 min read

SQLAlchemy connection pooling across Uvicorn workers

Each worker has its own pool; total DB connections equal workers times (pool_size plus max_overflow); overflow connections are temporary; misconfiguration exhausts DB…

Python & FastAPI1 min read

MongoDB async ODM vs SQLAlchemy sessions

Motor client as a connection pool with no SQLAlchemy-style session or transaction; Beanie document models over Motor; initialize once at startup and await find queries.

Python & FastAPI1 min read

asyncio.gather vs asyncio.wait

Gather returns ordered results and propagates the first exception (or captures them); wait returns done/pending sets and never raises, you inspect each.

Python & FastAPI1 min read

How FastAPI uses type hints for validation

Hints drive parsing, validation, and conversion; a path declared int is coerced or returns 422; OpenAPI is auto-generated.

Product Strategy1 min read

Making the case for reliability over a risky feature

Quantify reliability cost in churn and revenue, show the feature's risk to existing customers, propose a sequenced path.

Product Strategy1 min read

Keeping a level playing field for partners

First-party consumes the same public APIs, equal rate limits and data access, technical walls against privileged data, transparent changes.

Product Strategy1 min read

Strict tenant isolation in a multi-tenant data layer

Choose silo, pool, or bridge by risk; enforce tenant scoping at multiple layers with RLS; encrypt and audit.

Product Strategy1 min read

Monorepo vs polyrepo for a product portfolio

Monorepo eases atomic shared-component changes and consistency but needs tooling; polyrepo gives autonomy but version drift; tie choice to deploy independence.