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
21 practiced

Explain optimistic locking versus pessimistic locking for concurrent updates in a backend service (for example, updating a user profile, or safely incrementing an account balance under retries to avoid double-spends). For each approach, describe how conflicts are detected, typical implementation (version columns/CAS versus row locks), and which scenarios favor one over the other. Mention idempotency tokens and compensating transactions as complementary techniques under high contention.

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.

HardTechnical
31 practiced

A nightly batch job (or a multi-stage data-preprocessing DAG) processes millions of records and occasionally crashes mid-run. Design a resume/restart mechanism so that on restart, processing continues from the last consistent checkpoint without duplicating side effects on already-processed records. Discuss checkpoint granularity, idempotent re-runs, transactional updates, state management for a DAG with dependent tasks, and the throughput-versus-checkpoint-frequency trade-off.

EasyBehavioral
40 practiced

Describe a specific code-review interaction where you improved a teammate's pull request by focusing on error handling and messaging. What comments did you leave, how did the author respond, and what rules or patterns did you introduce to the team as a result?

MediumTechnical
21 practiced

How do you ensure error messages and logs never leak sensitive information (PII, secrets, tokens)? Propose a redaction strategy: identifying PII fields, redacting or tokenizing at log-ingestion time, sanitizing exception messages specifically, and CI or test-time safeguards that catch accidental sensitive data before it ships. Discuss the trade-off between debuggability and privacy compliance, and how techniques like hashing/tokenization with salts or differential privacy fit in for ML-system logs.

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.