Error Handling and Defensive Programming Questions
Making code robust against bad input and failure: exceptions versus error returns, input validation, guard clauses, graceful degradation, and designing for the unhappy path. Covers where to handle versus propagate errors and how to fail safely without hiding bugs. A recurring probe of production maturity.
Design a system to reduce alert fatigue for on-call engineers by deduplicating, grouping, prioritizing, and enriching alerts from model-serving and data-pipeline error signals: deduplication windows, grouping by root cause, severity assignment, and runbook linking. Explain how you would measure whether alert fatigue is actually decreasing over time.
Tail latency has increased because of downstream timeouts. Explain how you would implement timeouts and deadlines at multiple layers to protect the system: client SDK timeouts, HTTP client timeouts, worker thread-pool task deadlines, and a request-level deadline propagated via context or headers across service calls. Include pseudocode showing how you would enforce a global deadline and cancel subtasks when it expires, and walk through an example timeline for a request touching three services.
Design a layered test strategy specifically for ERROR PATHS: unit tests that simulate a dependency failure, integration tests using test doubles, contract tests for downstream behavior, and failure-injection/chaos tests for real dependencies (for example testing retry/fallback logic against a flaky external API, or fallback behavior when a cache tier fails). Give concrete test cases for each layer and describe how you'd automate this in CI (gating versus non-gating) without introducing flakiness.
Design user-facing error messaging for a web or ML-serving application when a request fails (temporary server overload, a validation failure, a corrupted model file, a GPU OOM). The message must be helpful (what happened, what the user can do) without exposing internal details; provide platform variants (mobile vs desktop, screen-reader accessibility) and describe retry UX (automatic retry, a 'try again' button with backoff). For each failure case, give a one-line example of the safe user-facing message and note what extra diagnostic metadata belongs only in the logs.
Design a circuit breaker for a FLEET of service instances (not a single process) that must prevent cascading failures from a shared downstream dependency. Define the breaker states and per-instance failure thresholds, and propose how you would synchronize (or deliberately NOT synchronize) breaker state across instances without introducing a single point of failure. Discuss the trade-offs of local-only vs. globally-shared breaker state, and of fail-open vs. fail-closed defaults.
Unlock Full Question Bank
Get access to all Error Handling and Defensive Programming interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.