Routing — one queue per consumer group
Queue-world fanout is not multiple cursors on one log: it's a router (exchange / SNS topic) that copies each message into one physical queue per consumer group, each with its own backlog, acks, and DLQ.
Within a queue we partitioned for ordered parallelism. Across queues we need the opposite: one event reaching multiple independent consumer pools, each with its own backlog and retry policy.
Scene 11
Routing — one event, one queue per consumer group
- Watch
- Try it
- Predict
- Capture
Watch the producer publish one message at a time. The exchange flashes, then the same payload duplicates into every bound queue at once. Notice that analytics piles up while email and audit drain — each queue has its own backlog.
Highlighted lines are the ones running in the diagram right now.
def publish(msg, routing_key):for queue, bind_key in bindings[self]:if self.type == 'fanout':queue.tail.append(msg) # everyoneelif self.type == 'direct':if bind_key == routing_key:queue.tail.append(msg) # exact matchelif self.type == 'topic':if pattern_match(bind_key, routing_key):queue.tail.append(msg) # wildcard# N matches => N physical copies, N backlogs
def bind(queue, routing_key=''):bindings[self].append((queue, routing_key))# producer code unchanged — no redeploy# queue starts receiving from the NEXT publish# (it does NOT replay history — each queue# stores its own messages)
def matches(exchange_type, bind_key, routing_key):if exchange_type == 'fanout':return True # ignore key entirelyif exchange_type == 'direct':return bind_key == routing_keyif exchange_type == 'topic':# bind_key has wildcards: 'order.*'return pattern_match(bind_key, routing_key)
Where this sits in Build a Message Queue (RabbitMQ / SQS)
Scene 11 of 14. Fanout in queue-world is an exchange/SNS topic that copies each message into N physical queues — opposite of Kafka's N cursors on one log.
Up next. We have all the mechanics: ack, nack, DLQ, timeout, prefetch, ordering, routing. In production you don't see those mechanics — you see three dashboards. Which numbers actually wake you up?
All 14 scenes in Build a Message Queue (RabbitMQ / SQS) · Every curriculum