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

MediumSystem Design
28 practiced

Describe a safe graceful-shutdown and connection-draining sequence for a stateless HTTP service running in containers behind a load balancer: stop accepting new requests, drain in-flight requests within a timeout, handle any background jobs, and configure Kubernetes readiness/liveness probes to support this lifecycle. Which OS signals should be trapped, and how do you coordinate shutdown across worker threads or asyncio tasks?

HardTechnical
24 practiced

In distributed data-parallel training, one or more workers crash mid-epoch. Explain strategies for detecting the failure (including silent worker failures like a stuck NCCL collective op), checkpointing to allow a clean resume, ensuring optimizer state (for example Adam's moment estimates) stays consistent after resume, and master/coordinator failover. Discuss the trade-offs of synchronous versus asynchronous (stale) parameter updates for tolerating a crashed worker without corrupting model state.

MediumTechnical
24 practiced

Implement a thread-safe token-bucket rate limiter (tryAcquire()/refill()) supporting configurable burst capacity and a sustained replenishment rate. Then describe how you'd apply per-tenant rate limiting, backpressure, and resource isolation (CPU/GPU/QoS) in a multi-tenant online-inference service so one noisy tenant can't degrade others, including the error-handling policy for a rejected request (429 versus queueing versus a degraded response).

MediumTechnical
25 practiced

Design a retry strategy for client-side requests to a downstream dependency: exponential backoff, jitter, a maximum attempt count, and integration with a circuit breaker. Give a function signature or pseudocode, and explain how this combination avoids the thundering-herd problem and protects the downstream service under load.

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.