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.

EasyTechnical
23 practiced

Why do liveness and readiness checks need to be defensive about what they actually verify, and what's an example of a health check that lies about system health?

EasyTechnical
35 practiced

A debug log statement accidentally includes a raw API key or password in plaintext, and it ships to production before anyone catches it in review. How do you prevent this class of bug systematically, not just rely on catching it in the next code review?

EasyTechnical
29 practiced

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.

HardTechnical
30 practiced

For a public API, design a policy that decides what error detail is safe to return to CLIENTS versus what stays only in internal logs. Include examples of safe client-facing error formats, how to include a correlation id without leaking internals, and whether/when to include a stack trace in a log versus an API response. Propose an automated test that ensures no sensitive field ever leaks into a client-facing response.

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.

Unlock Full Question Bank

Get access to all 15 Code Quality, Error Handling, and Defensive Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.