Message Queues: Follow-Up Questions Interviewers Ask (and How to Answer)
When a candidate brings up a message queue, interviewers see an opening to explore how you think about asynchronous pipelines. Queues sit at the heart of many high-scale services, so the next questions dig into durability, ordering, latency, and operational complexity. The goal is to gauge whether you can pick the right queue technology, size it for traffic, and anticipate failure modes.
A senior-level answer will name the right AWS service, give a ballpark capacity, and explain the main trade-offs. A staff-level answer will also quantify cost, discuss monitoring, and describe how the design evolves as traffic grows.
How do you guarantee message ordering?
I would choose a FIFO queue when strict ordering matters, such as processing financial transactions. With Amazon SQS FIFO, each message group ID preserves order, and the queue drops duplicate sends within a five-minute deduplication window (AWS calls this exactly-once processing). If the workload can tolerate partial ordering, a standard queue is cheaper and can scale to higher throughput. For example, I’d use a FIFO queue with high-throughput mode enabled for a payment pipeline that processes ~5,000 transactions per second (a default FIFO queue allows 300 calls per second per API action, or 3,000 messages a second in batches of 10), ensuring each account’s events stay in order.
What is the typical latency you can expect?
Latency depends on the queue type and region. In practice, a managed queue like SQS typically adds a few tens of ms for a single hop; I would measure it rather than quote a figure, and expect a FIFO queue to cost a few more ms due to stricter ordering. If the application needs sub-10 ms latency, I’d benchmark a streaming log such as Kafka on Amazon MSK, which writes to disk but lets consumers fetch continuously, and check whether the delay I measure stays under 10 ms under moderate load.
How do you size the queue for peak traffic?
First, I estimate the peak request rate. Suppose the service receives 200 k requests per second during a flash sale. If each request generates one message, the queue must ingest 200 k messages per second. I’d provision multiple partitions (or shards) to spread the load—I’d assume about 1 KB per message and budget a conservative 1 MB/s per partition, so I’d start with at least 200 partitions, then monitor and add more as needed. For SQS, a standard queue scales automatically, so the sizing work moves to the consumers: I’d scale them on queue depth and the age of the oldest message, and keep the dead-letter queue for messages that keep failing.
How do you handle message duplication?
Even “exactly-once” services can occasionally deliver duplicates under rare failure scenarios. My approach is to make the consumer idempotent: store a hash of the message ID and reject repeats. For a payment system, I’d pass the transaction ID to the payment provider as its idempotency key, or record it in the same database transaction as the charge; a conditional write of the ID on its own, before the charge, turns a crash between the two into a lost charge instead of a double one. This adds a small overhead—roughly a few milliseconds per message—but protects against costly duplication bugs.
What happens if a consumer crashes while processing a message?
If a consumer crashes after pulling a message but before acknowledging it, the message becomes visible again after the visibility timeout expires. I set the timeout slightly longer than the typical processing time—say 30 seconds for a batch job that usually finishes in 10 seconds. To avoid long-running tasks holding the queue, I break large jobs into smaller chunks, each idempotent, and use a retry back-off strategy.
How do you ensure durability of messages?
Durability is handled by the underlying storage. SQS stores messages redundantly across multiple AZs automatically (delivery is at-least-once, a separate property). For Kafka, I would configure a replication factor of three with acks=all and min.insync.replicas=2, so a broker failure does not lose acknowledged data, and set retention to cover the longest replay I need. In a critical system, I’d also mirror the stream to an S3 bucket using a connector, providing an immutable backup.
How do you monitor queue health?
I instrument three key metrics: queue depth, consumer lag, and error rate. Queue depth shows backlog; if it exceeds a threshold—say 10 % of the expected processing capacity—I trigger an alarm. Consumer lag (difference between latest offset and consumer offset) tells me if consumers are falling behind. I also track the number of messages sent to the dead-letter queue; a sudden spike indicates a processing problem. All metrics feed into a CloudWatch dashboard for rapid visibility.
What are the cost implications of your design?
Costs scale with throughput and storage. For SQS standard, you pay per API request and for data transferred out, not for storage. Each message needs at least three requests (send, receive, delete), so 200 k messages per second, about 17.3 billion a day, is roughly 52 billion requests a day before batching; batching up to 10 messages per call is the first cost lever. Retention adds nothing, because SQS does not bill for stored messages. Kafka on MSK has a higher base cost (instances and storage) but can be cheaper at very high throughput because you amortize the per-request cost across many messages. I’d run a cost model to pick the cheaper option for the expected load.
How would you evolve the system as traffic grows?
I would start with a modest number of partitions and enable auto-scaling for the consumer group. As traffic climbs, I’d increase partition count to avoid hot spots and add more consumer instances to the consumer group. If latency becomes a concern, I might introduce a tiered architecture: a fast-path in-memory queue for latency-sensitive requests and a durable queue for bulk processing. Periodic capacity testing ensures the scaling plan stays valid.
How to practice this
- The worked design on message queues, Design a Message Queue like Amazon SQS, is part of Pro ($10/month); it walks through a full end-to-end pipeline with diagrams and notes.
- Draw your own queue architecture on paper or a whiteboard, focusing on ordering, latency, and failure handling.
- Run through the nine follow-up questions aloud, timing yourself to keep answers concise and data-driven.
Questions people ask
What is the difference between a standard and FIFO queue?
Standard queues give high throughput and at-least-once delivery but no ordering guarantee. FIFO queues preserve order per message group and drop duplicate sends within a five-minute deduplication window, at the cost of lower throughput.
Can I mix multiple queue types in one system?
Yes. Use FIFO for critical ordered flows like payments and standard queues for bulk, unordered processing such as log aggregation. This balances cost and performance.
How do dead-letter queues help?
Dead-letter queues capture messages that repeatedly fail processing, preventing them from blocking the main queue. You can later analyze these messages to fix bugs or adjust retry policies.
When should I consider moving from a cloud-managed queue to a self-hosted broker?
When you need fine-grained control over partitioning or replication, or when your cost model shows the managed service’s per-request bill exceeding the cost of running and staffing your own brokers at your volume.