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
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'.

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.

MediumTechnical
40 practiced

Propose a minimal set of error/reliability metrics every service (or model-serving system) should emit: counters, gauges, and histograms (error_rate_total, retry_count, latency buckets, schema_mismatch_total). Discuss how to label them (service, region, endpoint, model_version) while avoiding high-cardinality labels, and how you would tie these metrics to an experiment or A/B test that proves a specific error-handling change actually improved customer-facing outcomes (error rate, mean time to recovery, retries per request).

HardSystem Design
21 practiced

Design a crash-consistent, resumable checkpointing scheme for a long-running training job or model artifact: atomic writes (write to a temp file/key then rename), checkpoint frequency trade-offs, lease-based locking so only one exclusive writer runs at a time, safe concurrent reads while a writer is active, backward-compatible artifact format with manifest/version files and checksums for integrity, and a rollback plan if checkpoint verification fails. Explain how you avoid duplicate downstream side effects (metrics, DB writes) when a job resumes after a retry.

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.

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.