InterviewStack.io LogoInterviewStack.io

Code Quality, Error Handling, and Defensive Programming Questions

Writing robust, high-quality code that fails safely. Covers defensive programming, input validation, error handling and fault tolerance, logging for diagnosability, and general engineering-quality standards. Includes anticipating failure modes and making code resilient to bad inputs and unexpected states.

MediumTechnical
28 practiced

Discuss strict dependency pinning versus flexible version ranges in an ML project: implications for reproducibility, security patches, and build stability, and propose a policy for safely automating dependency updates. Then describe how you would make ML experiments reproducible across a dev workstation, CI, and a multi-GPU cluster: seeding every source of randomness (numpy, framework, system), deterministic-ops flags, containerization, and a small reproducibility checklist/test that validates two runs produce comparable artifacts.

HardTechnical
38 practiced

Production just exhausted its error budget due to cascading 5xx errors triggered by a downstream change, and you must ship defensive changes quickly to prevent a repeat. Which mitigations do you prioritize first and why: request timeouts, retries with backoff and jitter, circuit breakers, bulkheads/isolated thread pools, backpressure, or graceful degradation? Explain how you would measure whether each change is actually working.

EasyTechnical
29 practiced

A boundary check validates that a value (an index, an offset, a size) falls within the range the code actually handles correctly, and it routinely catches real production bugs before they cause damage. Pick three DIFFERENT kinds of boundary bugs you've seen or can construct realistically, and for each: describe the bug it would cause if unchecked, the specific defensive check you'd add, and a unit test that would catch a regression if the check were later removed.

HardTechnical
24 practiced

Implement save_checkpoint/load_checkpoint (or a large-model-file download) that performs atomic, resumable transfers to both local disk and an S3-like object store: temp-file-then-rename for local FS, a unique temp key plus atomic copy or object versioning for S3, streaming SHA-256 checksum verification without loading the whole file into memory, detection and retry of partial uploads/downloads with range-request resume, and protection against concurrent writers corrupting the artifact.

HardTechnical
21 practiced

Describe how to achieve numerical stability specifically for MIXED-PRECISION training across frameworks and GPU generations: dynamic versus static loss scaling, numerically-stable layer implementations (LayerNorm), keeping fp32 master copies of weights/optimizer state, avoiding in-place ops that break autograd, and how you would test that a mixed-precision run is numerically correct.

That is every published Code Quality, Error Handling, and Defensive Programming question for AI Engineer so far. Browse the other topics in this category, or practice this one interactively.