Intermediate · INTERACTIVE LESSON

Message queues

Watch producers fill a work queue and competing consumers drain it; compare backlog, capacity and processing speed.

The interactive player is loading. If it does not appear, you can still read the explanation below.

THE IDEA BEHIND THE STEPS

How it works

A message queue separates producers from consumers. Producers publish work and receive a broker acceptance confirmation. That confirmation does not mean a consumer has finished the job. Consumers acknowledge the queue separately after processing. Applications that need results must track them independently.

In a competing-consumers work queue, each message goes to one consumer, rather than being broadcast to every consumer as in pub/sub. This simulation chooses idle consumers by numeric ID, with one in-flight message per consumer. Waiting messages are delivered in first-in-first-out order. Consumer speeds can differ, so delivery order does not guarantee completion order.

Queue capacity here counts waiting messages only, excluding work already being processed. New messages dispatch immediately if a consumer is idle. When waiting storage is full, new publishes are explicitly rejected; they are not retried or silently dropped. A bigger buffer can absorb a burst but cannot increase processing speed.

Choose one publish at a time or concurrent bursts. Total message count spans all producers, assigned round-robin. Single-publish mode sends one message every publish interval without waiting for processing. Concurrent mode sends a total burst every interval. Consumer processing may overlap in both modes. Enter one processing duration for all consumers or one duration per consumer.

At the same timestamp, consumers complete and acknowledge first, then take older waiting work before new publishes arrive. Simultaneous publishes use message-ID order. Animated network hops take no simulated time; only processing and publish intervals advance the clock.

This is a no-failure teaching model, not a broker emulator or an exactly-once delivery guarantee. It omits persistence, crashes, redelivery, visibility timeouts, dead-letter queues and network latency. Real delivery and overflow policies vary by broker. At-least-once systems can redeliver messages, so consumers often need idempotency. More consumers improve this model only when work is independent; real systems also face broker and downstream bottlenecks.