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.
When an authorization check throws an unexpected error, should the system fail open and allow the action, or fail closed and deny it? Walk me through how you'd decide, using a concrete example.
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.
Your daily ETL pipeline processes millions of records where roughly 0.1% are malformed in unanticipated ways, and the job occasionally crashes mid-batch when the orchestrator restarts it. Describe your defensive design for both problems: how bad records get isolated instead of corrupting downstream tables, and how a restart avoids double-processing or losing records.
You need to verify that a payment endpoint is safe to retry, meaning a client that times out and retries doesn't create a duplicate charge. How would you test this, and what would the endpoint need to implement to make it testable?
Compare and contrast graceful degradation and fail-fast design approaches for production systems. For each approach, explain a typical use case (for example a customer-facing API versus an internal pipeline), the operational trade-offs, how you would instrument each approach with metrics, logs, and traces, and how you would communicate degraded functionality to clients or downstream systems.
Unlock Full Question Bank
Get access to all 12 Code Quality, Error Handling, and Defensive Programming interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.