Design a Fault-Tolerant Cloud Queue Service
Design a durable multi-tenant worker queue with understandable network-failure semantics, bounded exponential-backoff retries, dead-letter handling, and explicit priority trade-offs.
Problem statement
For this exercise, design the queue service itself rather than using Kafka or another off-the-shelf broker as the authoritative queue implementation. The client transport is your choice: HTTP, RPC, streaming, or another interface may expose the same contracts.
For this exercise, assume tenants create durable queues, producers enqueue bounded messages, and competing consumers receive and acknowledge messages.
A receive operation creates a visibility lease; acknowledgement permanently removes the leased message, and an expired lease makes the message visible again, so delivery is at least once.
Enqueue and acknowledgement accept client-generated idempotency keys so retries after ambiguous network outcomes produce one logical transition.
Messages become eligible for first delivery in FIFO order within a queue partition, but redelivery and concurrent processing may change completion order; no ordering is promised across partitions or queues. Unacknowledged messages remain durable for seven days.
For this exercise, workers process leased messages as jobs. Each queue has a bounded retry policy with a maximum delivery-attempt count, exponential-backoff base and cap, and an optional bounded jitter policy. A failed or expired attempt becomes eligible only at its persisted next-attempt time.
When the configured attempt limit is exhausted, the service atomically removes the message from ordinary delivery and records it in a configured dead-letter queue with its source identity, attempt history, and terminal reason; a retry or failover must not create two logical dead-letter records.
For the priority follow-up, clients may assign one validated value from a small fixed set of priority levels. Compare at least two viable layouts: one priority-ordered logical queue and separate physical queues for the fixed priority levels.
State the partitioning, ordering, isolation, fairness, starvation, and operational trade-offs of the selected design. Retried work keeps its declared priority but does not become eligible before its persisted backoff deadline.
What to build
- Authorized tenants can create, inspect, and delete durable queues with immutable identity and bounded configuration.
- Producers can idempotently enqueue bounded messages and learn whether the service durably accepted the logical message.
- Consumers can receive visible messages under time-bounded leases and extend a current lease without granting permanent ownership.
- Consumers can idempotently acknowledge a current lease so the message is never delivered again, while expired or abandoned leases cause redelivery.
- Workers can report failure or let a lease expire; the service schedules a bounded exponential-backoff retry and atomically dead-letters work that exhausts its configured attempt limit.
- Producers can choose a validated fixed priority, and consumers receive eligible work according to a documented priority and fairness policy without bypassing retry deadlines.
At scale
- For this exercise, assume 100,000 active queues and one million aggregate enqueue, receive, lease-extension, and acknowledgement operations per second.
- For this exercise, messages are at most 256 KiB and an individual queue may be partitioned for throughput when its clients accept partition-local ordering.
- For this exercise, target 50 millisecond p99 regional operation latency and 99.99% service availability.
- For this exercise, acknowledged enqueue results must survive a single-zone failure, and unacknowledged messages expire after seven days.
- For this exercise, support five fixed priority levels, queue-configured maximum attempts from 2 through 20, and retry-delay caps up to 15 minutes; exact defaults are policy rather than source facts.