Kokonatt Blog

A distributed durable log of random developer events

Immutability and Defensive State Design in Python

python typing · 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 only earns its place when the ecosystem integration matters.

Cross-Cutting Concerns Without Constructor Over-Injection

python architecture · by Adrian Benavides · August 3, 2026 · 5 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.