Follow-up · depth 10
How do you make dataclasses and __slots__ safer under partial failure?
How do you make dataclasses and __slots__ safer under partial failure?
Answers use simple, clear English.
Quick interview answer
Harden dataclasses and __slots__ with timeouts, retries with jitter, isolation, and graceful degradation. Use dataclasses and __slots__ as the core idea. Example shape: DTO layer: @dataclass(slots=True) OrderItem(sku: str, qty: int, price: Decimal)..
Detailed answer
Resilience for dataclasses and __slots__ under partial failure: • Timeouts + budgets on every dependency call • Retries only when idempotent, with jitter/backoff • Isolation: bulkheads/queues so one failure does not cascade • Degradation: serve stale/cached/limited mode when needed Practices: Use field(default_factory=list); kw_only=True for clarity in large models. Parent context: Use dataclasses and __slots__ as the core idea. Example shape: DTO layer: @dataclass(slots=True) OrderItem(sku: str, qty: int, price: Decimal)..
Full explanation
Partial failure is the default in distributed systems — show how dataclasses and __slots__ stays useful anyway. @dataclass auto-generates __init__, __repr__, __eq__. slots=True (Py3.10+) fixes attributes and saves memory. frozen=True makes instances hashable if all fields hashable.
Follow-up questions
Only answered follow-ups are shown — click to open with full answers
Parent context — dataclasses and __slots__
Use dataclasses and __slots__ as the core idea. Example shape: DTO layer: @dataclass(slots=True) OrderItem(sku: str, qty: int, price: Decimal)..
View full parent question →