18. Final Tips
Senior-level habits that demonstrate ownership, clarity, and sound trade-offs.
- Lead with the answer; justify briefly.
- State trade-offs explicitly (GIL: threads for I/O, processes for CPU).
- Pick the right concurrency primitive; never block the asyncio event loop.
- Always set timeouts and use retries with jitter for network calls.
- Quantify assumptions (latency, throughput, expected scale).
- Log structured JSON with correlation IDs; never log secrets or PII.
- Use specific exceptions and
raise ... from e
for causal context. - Validate inputs and schemas at the boundaries of your system.
- Design idempotent writes; use Idempotency-Key for POST; standardize error payloads.
- Prevent ORM N+1 with eager loading; use pooling; keep transactions short.
- Cache intentionally; pick an eviction strategy; prevent stampedes (jitter, single-flight).
- Measure before optimizing; profile CPU, I/O, and memory separately.
- Prefer composition over inheritance; keep functions small and pure.
- Use context managers for resources; implement graceful shutdown on SIGTERM.
- Document decisions; keep config in env; automate checks in CI.