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
31 practiced
Design the flow for an e-commerce checkout that involves Order, Payment, and Inventory microservices. Explain how you would handle partial failures so the system doesn't become inconsistent. Compare 2PC, SAGA/compensating transactions, and the outbox/event-driven approach, and recommend one based on trade-offs such as latency, complexity, and operational cost.
MediumTechnical
29 practiced
Implement (or write clear pseudocode for) a Python function send_request_with_retries(url, payload, idempotency_key=None) that POSTs to an external service, retries transient network errors using exponential backoff with jitter, and uses an idempotency_key to avoid duplicate processing. Assume access to a Redis-like key/value store for idempotency records. Focus on control flow, expiry of idempotency records, and testability; avoid third-party HTTP client specifics.
HardSystem Design
26 practiced
Design a globally distributed backend API that must remain available despite partial regional outages. Describe defensive programming practices across gateways, service meshes, caches, and data stores. Cover graceful degradation, data consistency trade-offs (strong vs eventual), retry and idempotency approaches, observability needs, and how you would escalate residual risks to SRE and product teams.
EasyTechnical
28 practiced
Explain resource cleanup best practices for backend code handling file handles, database connections, thread pools, and timers. Provide examples in at least one language (for example Python context managers or Java try-with-resources), explain why timely cleanup matters in production, and list detection strategies for leaked resources.
EasyTechnical
23 practiced
Design a minimal structured error log schema for backend services. What fields would you always include when logging an error to aid SRE and developer debugging (for example timestamps, service, trace id), how would you avoid leaking personal or secret data in logs, and how would you correlate logs across distributed services?

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.