Series Track

Modern Python Architecture: Type Safety, Boundaries & Async

A track on building robust Python systems: type-safe data modeling, modular architecture with enforced boundaries, and structured async concurrency.

← Back to all posts

01Type Safety & Data Modeling

Language-level primitives: immutable state, static and runtime type checking, value objects that make invalid states unrepresentable, and schema contracts for dataframes.

Immutability and Defensive State Design in Python

pythontyping·by Adrian Benavides·August 6, 2026·8 min read

Frozen dataclasses are the default for domain value objects, but they don't validate at runtime. msgspec.Struct closes that gap with a single type that decodes, validates, and stays immutable across the wire boundary and the domain layer. attrs and cattrs cover the same ground in two libraries, and pydantic is only worth it when the ecosystem integration matters.

02Modular Architecture & Boundaries

Patterns that turn those primitives into modular systems: DDD, hexagonal architecture, enforced import boundaries, dependency injection, and cross-cutting concerns.

Cross-Cutting Concerns Without Constructor Over-Injection

pythonarchitecture·by Adrian Benavides·August 3, 2026·6 min read

Use contextvars.ContextVar for cross-cutting concerns that almost every service needs, without threading them through every constructor. Covers per-task isolation, structlog and opentelemetry designs, sync-vs-async leaks, and the failure modes that show up in production.