Mhonn YbañezSRE, DevOps, AI Engineer
 Today I Learned
Read the full page

When should you use a message broker instead of a load balancer?

Posted
Tags
system-design, message-brokers, load-balancing, scaling

A load balancer spreads live requests and gives up in seconds. A message broker turns requests into stored data that can wait for hours. Brokers are a tool for work that can wait, not the default answer to scaling.

I'm working toward mastering system design, and somewhere along the way I started treating message brokers as the answer to everything. Need it to scale? Put a queue in front of it. Need it to be reliable? Queue. So I sat down to compare a broker with the thing I already understood, the load balancer.

The question I had

Is a message broker just a better load balancer, and should it be my default for scalable systems?

What I found

Message broker: the post office

A message broker sits between services so they can talk asynchronously. Producers send messages, the broker stores and routes them, and consumers receive and process them when they are ready.

There are two main patterns:

  • Point-to-point (queues): each message is handled by exactly one consumer. RabbitMQ is the usual example.
  • Publish-subscribe (topics): each message goes to every subscribed service. Apache Kafka is the usual example.

Both tools can do both patterns (RabbitMQ has fanout exchanges, Kafka has consumer groups), but those are the defaults people reach for.

The key behavior is buffering. A broker turns live traffic into passive data and writes it to memory or disk. A traffic spike just makes the backlog longer. Kafka in particular can keep large volumes on disk for as long as its retention settings and disk space allow.

Load balancer: the traffic enforcer

A load balancer spreads live network traffic across healthy servers in real time. It works synchronously: the client is waiting on the other end the whole time. With health checks, connection limits, or a least-connections algorithm, it avoids sending requests to servers that cannot take them.

It is not a storage engine. Anything it holds is a live connection in memory, with a clock running. When every server is busy and the wait runs out (usually somewhere between 15 and 60 seconds), it gives up and returns an error:

  • 503 Service Unavailable: no healthy server, or the queue is full.
  • 504 Gateway Timeout: a server took too long to answer.
  • 502 Bad Gateway: a server sent back a broken response or dropped the connection.

Side by side

Message brokerLoad balancer
What a waiting request isPassive data, stored on disk or in memoryAn active connection, with a clock running
How long it can waitHours or days, configurableSeconds, capped by timeouts
Under a traffic spikeAbsorbs it as a longer backlogRejects the excess with 503 or 504
If it crashesMessages recover from disk or replicasRequests in flight are lost, and clients have to retry

What the user sees while waiting

The two buffers feel very different from the user's side.

  • Waiting in a load balancer: the user is stuck. The spinner keeps going, the page will not load, and they cannot do anything else in that flow. If the wait runs out, they get an error page and have to try again themselves. Every second in this buffer is a second the user feels.
  • Waiting in a message broker: the user has already moved on. They got an answer right away ("Your report is being generated", "Upload received"), and the real work happens in the background. They find out it is done through a notification, an email, or a status that changes on the page. A long backlog does not freeze their screen, it just means the result arrives later.

So a load balancer buffer is a wait the user has to sit through, while a broker buffer is a wait the user can walk away from. That only works if the product is honest about it. If the user is told "done" and the job then fails in the queue, they find out much later, and that is a worse experience than an error page right away.

The rule of thumb

  • Use a load balancer when the user needs an answer right away to continue. Logging in, checking an account balance.
  • Use a message broker when the work can finish seconds or minutes later. Generating a report, sending a confirmation email, processing an uploaded video.

Where my epiphany came in

A broker is not free scalability. It comes with its own requirements:

  • The user does not get the result right away. The task completes later, so the product has to be designed around that (a "processing" status, a notification when it's done).
  • Messages can arrive more than once. Most brokers deliver at least once, so consumers have to handle duplicates safely.
  • Ordering and failures need handling. Retries, dead-letter queues, and messages that keep failing all become my problem.
  • It is one more system to run. The broker needs its own monitoring, capacity planning, and on-call care.
  • Debugging needs proper distributed tracing. With a load balancer, one request is one connection, and the logs line up in time. With a broker, one user action turns into a message that might be picked up minutes later by a different service, retried, or sent to a dead-letter queue. Plain logs cannot answer "what happened to this user's upload?" anymore. I would need a trace ID (for example with OpenTelemetry) carried inside the message headers, so the producer, the broker hop, and every consumer show up as one trace. Without that, a stuck job is a search through several systems' logs.

And the two are not competitors. A common setup uses both: the load balancer sends the upload request to an API server, the API saves the file, puts a "process this video" message on the broker, and returns 202 Accepted right away. Workers pick up the job whenever they have capacity.

Other questions I had

Can I get a queue-like system without running a dedicated broker machine?

Yes. The async benefits come from the pattern, not from a separate box. There are four common ways to do it with things I probably already run:

  • A database table. The web server inserts a row into a background_jobs table with status pending, and a background worker picks it up and marks it completed. In PostgreSQL (and MySQL 8), SELECT ... FOR UPDATE SKIP LOCKED lets several workers pull jobs at the same time without grabbing the same row. The job is as durable as the rest of my data, and it can be written in the same transaction as the change that created it.
  • An in-memory queue inside the app. Go channels, Python's asyncio.Queue, Node worker threads, C# Channel<T>. The request returns right away and a background worker on the same server does the heavy part. The catch: if the server crashes or restarts during a deploy, every job still in memory is gone.
  • Redis, if it is already there. Lists (LPUSH with BRPOP) and Redis Streams work well as queues and are very fast. It can persist to disk, but the defaults can still lose the last few writes. A plain BRPOP also removes the job before the worker finishes it, so a worker crash loses it. Streams with consumer groups fix that with acknowledgements.
  • A managed queue like AWS SQS. It is still a broker, but AWS runs it. There is no machine for me to provision, patch, or scale, and I pay per request.

Takeaway

I thought message brokers were the default for building scalable, reliable systems. They are not. They are the right tool when the work can wait and the system can handle duplicates, delays, and the extra infrastructure and tracing. If the user needs the answer now, a load balancer and enough servers is the simpler and correct choice. The real skill is splitting each request into the part that has to answer now and the part that can wait.