KatInterview

Designing a Resilient Asynchronous Task Worker with Exponential Backoff and DLQ

System DesignModel answer
MediumModel answerSystem Designsystem-designdistributed-systemsqueues

Last updated

Architect a reliable queue consumer system featuring exponential backoff retries, dead-letter queues, idempotent execution, and crash recovery mechanisms.

Design an asynchronous task worker framework responsible for consuming messages from a broker, executing external side effects, handling transient errors safely, and ensuring durable error logging/replay.

Requirements & Expectations

  1. Lifecycle & State Machine: Define the explicit state transitions of a message from ingress to completion or terminal failure.
  2. Retry Strategy & Backoff: Detail how to implement exponential backoff with jitter, distinguishing between transient vs. non-retryable (poison pill) errors.
  3. Fault Tolerance & Crash Recovery: Explain how the system handles worker crashes occurring at different execution boundaries (e.g., after side-effect execution but prior to message acknowledgment).
  4. Dead-Letter Queue (DLQ) & Replay: Describe the persistence layer, metadata tracking, and operational tooling needed for manual/automated DLQ inspection and re-injection.
  5. Idempotency Guarantees: Outline mechanisms to prevent duplicate side effects given at-least-once delivery semantics.

Clarifying Assumptions

Be explicit about your broker assumptions (e.g., SQS visibility timeouts vs. Kafka offsets), maximum execution attempts, and persistence storage guarantees.

Hints

Hint 1

Distinguish clearly between retryable errors (network timeouts, rate limits) and terminal errors (validation failures, malformed payloads).

Hint 2

Consider how visibility timeouts or lease locks prevent multiple workers from processing the same message simultaneously during retries.

Hint 3

How do unique execution IDs or idempotency keys ensure side effects are not duplicated upon process crashes?