Design a Basic Messaging Queue Service

System Design
Easy
Uber
104.7K views

Design the simplest possible distributed queue using a database. Discuss message visibility, consumer polling, and basic fault tolerance.

Why Interviewers Ask This

Interviewers ask this to assess your ability to translate abstract distributed systems concepts into concrete database interactions. At Uber, where reliability is paramount, they evaluate if you understand the trade-offs of using a SQL database for queuing versus dedicated message brokers like Kafka or RabbitMQ.

How to Answer This Question

1. Clarify requirements immediately: define throughput needs, ordering guarantees, and whether messages are fire-and-forget or require acknowledgment. 2. Propose the schema: Design a simple table with columns for id, payload, status (pending/processing/done), and visibility_timeout. 3. Explain the polling mechanism: Describe how consumers query for 'pending' messages and atomically update status to 'processing' upon retrieval. 4. Address visibility timeouts: Detail how a background job re-queues messages that exceed the timeout without explicit acknowledgment, preventing data loss on crashes. 5. Discuss limitations: Honestly admit why this approach lacks high throughput compared to specialized brokers but works for low-volume internal tasks.

Key Points to Cover

  • Explicitly defining the database schema with status fields and timestamps
  • Explaining atomic transactions to prevent duplicate message consumption
  • Detailing the visibility timeout mechanism for handling consumer failures
  • Acknowledging the trade-off between simplicity and high-performance throughput
  • Demonstrating understanding of eventual consistency in a polling model

Sample Answer

To design a basic messaging queue using a database, I would start by defining the core entities. We need a 'messages' table containing an ID, the payload, a status field, and a visibility timestamp. The status can be 'PE…

Common Mistakes to Avoid

  • Ignoring the race condition problem when multiple consumers poll simultaneously
  • Failing to explain how the system recovers from a crashed consumer process
  • Assuming the database provides native locking without specifying transaction isolation levels
  • Overcomplicating the design with complex indexing strategies unnecessary for a 'basic' request

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 190 System Design questionsBrowse all 57 Uber questions