System Design Problem

Design a Distributed Worker Queue (RabbitMQ / SQS)

Commonly Asked By:AmazonMicrosoftUberStripe

  • Enqueue messages: Producers publish messages to named queues via exchanges/routers.
  • Dequeue & process: Workers receive messages, process them, and send an ACK; the message is deleted permanently after ACK.
  • At-least-once delivery: Unacknowledged messages are automatically redelivered to prevent data loss.
  • Visibility timeout: When a worker retrieves a message, it becomes hidden from other workers for a configurable window; if no ACK is received before timeout, it becomes visible again.
  • Dead Letter Queue (DLQ): Messages that fail processing N times are moved to a DLQ for offline analysis and debugging.
  • Delay queues: Messages can be scheduled to become visible to consumers only after a configurable delay (up to 15 mins).
  • Priority queues: Higher-priority messages (0-9 range) are processed before lower-priority ones.
  • Message TTL: Messages automatically expire and are discarded if not consumed within a specified Time-To-Live window.
  • Fan-out (pub/sub): One published message can be replicated to multiple bound queues via exchange routing.
  • Flexible Routing: Support content-based routing (direct routing keys, wildcard topics, headers, or fan-out broadcasts).
  • Request-Reply (RPC): Support synchronous-over-async communication using correlation IDs and temporary reply queues.
  • Strict FIFO ordering: Optional strict ordering within a message group (using group IDs) with automatic deduplication.

The HLD comprises four major layers: Producers, the Exchange/Router Layer, the Queue Store (Broker Cluster), and the Worker Pool. Unlike a log, the Broker actively tracks the state of each message.

Loading...