InterviewStack.io LogoInterviewStack.io

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.

MediumTechnical
25 practiced

Write unit tests (with mocking) that verify retry/error-handling logic executes correctly: a transient failure followed by success triggers the retry path and returns the right result; a permanent failure after max retries raises the expected exception and does not duplicate a successful side effect; and backoff delays increase as expected, asserted algorithmically rather than by sleeping in the test. Also design a lightweight mock/stub for an external dependency (a feature store, a message sender) that can simulate transient failures deterministically.

MediumTechnical
21 practiced

You're leading a team with recurring bugs caused by poor error handling and sparse tests (or balancing shipping new features against investing time in defensive engineering). How would you introduce team-level practices to improve this over a quarter: code-review rules, linters, templates, testing quotas, and a phased rollout that gets buy-in from product? Describe your prioritization framework and how you'd measure success.

MediumTechnical
28 practiced

Design an SLO-based alerting strategy that minimizes pager/alert fatigue: what metrics feed the SLO, symptom alerts versus cause alerts, using an error budget to gate alerting, minimum sample sizes, and grouping/sampling strategies for a noisy downstream integration that would otherwise drown out real signals. Sketch a PromQL-like expression for 'error ratio exceeds 1% over 5 minutes with at least 1000 requests'.

HardSystem Design
27 practiced

Design a mechanism to coordinate retry and backoff behavior across a fleet of clients calling a shared downstream service, so a partial outage doesn't trigger a synchronized thundering-herd of retries. Compare client-side randomized backoff, a centralized rate-limiter, and a token-bucket approach, including how you would support per-dependency policies and adapt backoff parameters based on observed error budgets or latency, and the operational complexity of each.

MediumTechnical
26 practiced

Explain concrete runtime strategies to avoid GPU out-of-memory during training or large-model inference: dynamic batch-size adaptation, gradient accumulation, gradient checkpointing, model sharding, mixed precision, activation offloading, and monitoring GPU memory pressure. For each strategy, describe safe failure handling when memory is still insufficient (checkpoint-and-abort, automatic batch reduction).

Unlock Full Question Bank

Get access to all Error Handling and Defensive Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.