Follow-up · depth 1
What metrics prove dataclasses and __slots__ is healthy in prod?
What metrics prove dataclasses and __slots__ is healthy in prod?
Answers use simple, clear English.
Audio N/AQuick interview answer
Prove dataclasses and __slots__ is healthy with latency (p50/p95/p99), error/saturation rates, and queue/event-loop lag — not just CPU. Context: Use dataclasses and __slots__ as the core idea. Example shape: DTO layer: @dataclass(slots=True) OrderItem(sku: str, qty: int, price: Decimal)..
Detailed answer
Production health signals for dataclasses and __slots__: • Latency: p50/p95/p99 of the critical path that uses dataclasses and __slots__. • Errors: failure rate, timeouts, and retry storms. • Saturation: queue depth, event-loop delay, thread/pool utilization. • Business SLIs: request success and user-visible freshness where relevant. Trade-off lens: Pros: Less boilerplate than manual classes; slots reduce per-instance dict overhead. Cons: Inheritance with slots tricky; default mutable fields need default_factory. Explain thresholds + alerts, then how you triage. 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
Good answers name measurable signals and what “bad” looks like for dataclasses and __slots__. @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 →