InterviewStack.io LogoInterviewStack.io

Error Handling and Defensive Programming Questions

Covers designing and implementing defensive, fault tolerant code and system behaviors to prevent and mitigate production failures. Topics include input validation and sanitization, null and missing data handling, overflow and boundary protections, exception handling and propagation patterns, clear error reporting and structured logging for observability, graceful degradation and fallback strategies, retry and backoff policies and idempotency for safe retries. Also address concurrency and synchronization concerns, resource and memory management to avoid exhaustion, security related input checks, and how to document and escalate residual risks. Candidates should discuss pragmatic trade offs between robustness and complexity, show concrete defensive checks and assertions, and describe test strategies for error paths including unit tests and integration tests and how monitoring and operational responses tie into robustness.

MediumSystem Design
23 practiced
Design an idempotency strategy for a public POST endpoint that creates orders. Explain how you would accept idempotency keys, store them, handle retries, eviction policies, and guarantee that repeated requests with the same key do not create duplicate orders even under concurrent processing.
MediumTechnical
21 practiced
Write a small function in JavaScript that safely parses JSON from an untrusted source and performs defensive checks: size limit in bytes, allowed fields whitelist, and returns a sanitized object or a structured error object with code and summary. Explain where you would run this check (client, server, or gateway) and why.
MediumTechnical
29 practiced
Design a Redis-backed idempotency store for API requests: explain key structure, TTL choices, atomic write/read semantics, and how to handle Redis failover or partitions to avoid creating duplicate resources during transient failures.
EasyTechnical
27 practiced
Write a short Python decorator `@retry_once_on_exception` that retries a function one time on exception and raises the last exception if it still fails. Keep it generic, thread-safe, and suitable for idempotent functions. Show example usage and explain why this is only appropriate for idempotent operations.
HardSystem Design
22 practiced
Propose an approach to make a complex multi-step workflow idempotent end-to-end when some steps are non-idempotent by nature (e.g., sending emails, charging cards). Discuss designing compensating transactions, deduplication windows, and user-visible consequences of retries or compensations.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.