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.

HardTechnical
27 practiced

A distributed service (or a containerized process) periodically shows increased out-of-memory crashes or crash loops. Outline a pragmatic debugging plan: which logs, metrics, and heap dumps to collect; how to analyze GC logs and heap dumps to find retained references (for example caches populated on an error path, or exception objects retaining large contexts); and defensive changes you'd make in the short term (memory limits, OOM handlers, graceful shutdown, backpressure) to reduce risk while you find the root cause.

MediumTechnical
24 practiced

Implement a graceful-shutdown handler for a model server (or a distributed GPU training job): on SIGTERM/SIGINT, stop accepting new requests, allow in-flight requests to complete up to a timeout, save a model checkpoint atomically, release GPU resources safely, notify the orchestrator, and exit with the appropriate code. Sketch the signal-handler and context-manager logic, and explain how you avoid deadlocks when multiple processes checkpoint concurrently.

HardSystem Design
31 practiced

Design a safe canary rollout and automated-rollback strategy for a new model version: canary/health and correctness checks, automated rollback triggers (error rate, latency, a model-quality delta metric), traffic-shifting/ramp rules, data and label shadowing for verification, and how you'd avoid false-positive rollbacks during transient infra problems. Describe how you'd stage model artifacts and handle a model-related incident during business-critical hours.

EasyTechnical
31 practiced

You're designing structured error logging for a service (a REST API, or an ML inference endpoint). An on-call engineer investigating an incident should be able to go from one error log line to a full picture of what happened and to whom, without needing to reproduce the bug. Design the log entry's field set to make that possible, and explain why each field you chose earns its place. Contrast a plain stdout print with a structured JSON logging framework, and describe how you would avoid logging sensitive PII while preserving diagnostic value.

HardSystem Design
25 practiced

Design a testing and automation strategy for feature-wise DATA DRIFT detection and automated mitigation of production model degradation: statistical tests (KS, chi-squared) and baseline windows, thresholds tuned to reduce false positives, automated retraining pipelines with canary evaluation, and human-in-the-loop checkpoints before a rollback. Include the monitoring alerts and on-call runbook for triage when input schema mismatches or performance drift are detected.

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.