CSE Roadmap

Core tier · about 4 hours · 8 parts

Part 7 of 8 · 3 min read

When a queue is the wrong tool

A queue trades speed of answer and simplicity for resilience.

When a queue is the wrong tool

Think of asking a colleague a question. If you need the answer to continue, you wait at their desk. Writing it on a note and leaving does not help, because you still cannot proceed.

Queues suit work where the caller does not need the result right now. They do not suit these cases:

Situation Better choice Reason
The user is waiting for the answer on screen Direct call A queue adds delay and a second step to fetch the result
Data must be kept for years A database Brokers delete data after delivery
Strict global ordering of all messages A single log or one queue Load balancing with redelivery reorders
A very small system with one server Direct call The queue adds a part to run, watch and pay for

The Building Microservices book warns against adopting asynchronous designs too eagerly. They add complexity. Debugging a chain of messages takes more tooling than debugging a chain of calls.

Read it as

A queue is a trade. It gives resilience and smoother load, and it costs delay, extra parts and harder debugging. Use it where the caller can truly move on.

Some work can be split. A checkout can validate the card and write the order in the request, and put "send the confirmation email" on a queue. The user sees "order placed" at once, and the email arrives a little later.

Interview angle

Answer in your head first, then open it.

Why add a queue between services?

To decouple them in time, speed and failure, and to level load spikes.

What happens if consumers are slower than producers?

The backlog grows. Check queue depth, add consumers, or shed load.

What is a dead letter queue?

A place for messages that keep failing, so they do not block the rest.

Does a queue guarantee order?

Not with several consumers and redelivery. Use one consumer or a log.

Queue or direct call?

Direct when the caller needs the answer now. Queue when it can move on.

Check yourself:

  • Give one task from a web shop that fits a queue and one that does not.
  • What extra thing must a team build before running a queue-based system in production?

Words you will meet

Word Plain meaning
Message queue A buffer between programs that holds messages until a consumer takes them
Producer, publisher The program that adds messages
Consumer, subscriber The program that takes messages and acts on them
Asynchronous The sender does not wait for the work to finish
Message broker A server that stores and hands out messages
Load levelling Using a queue so a service works at a steady rate
Backlog, queue depth Messages waiting to be processed
Backpressure Slowing the sender when the receiver is full
Topic A named stream that many parties can subscribe to
Load balancing Each message goes to one consumer in a group
Fan-out Each message goes to all subscribers
Acknowledgment (ack) A consumer telling the broker it finished a message
Visibility timeout Time a taken message stays hidden before it reappears
Poison message A message that fails its consumer every time
Dead letter queue Where messages go after too many failed tries
Correlation ID A tag that follows one request across services
Command, event "Do this" versus "this happened"