Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 37 ยท Projects and Practice

Practice: Design Review and Pattern Choices

Practice RabbitMQ architecture decisions: queue or stream, quorum or classic, work queue or pub/sub, RPC or events, and a production design checklist, with worked scenarios and runnable helpers.

Knowing every RabbitMQ feature is not the same as choosing the right ones. This last lesson of the track trains design judgment. You get a decision guide, five scenarios to solve before reading the suggested answer, and a review checklist to run over any design. The material draws on all the earlier chapters: reliability, clustering, patterns and operations.

RabbitMQ cannot run on this page, so the topology snippets are read-only. The runnable blocks are plain Python stand-ins that encode the decision rules as small functions, so you can argue with them and change them.

Decision guide

Pick the messaging shape

Task for one worker Work queue, ack, retry.
Fact for many services Topic exchange, queue per service.
Need an answer now RPC, or better, HTTP or an event.
History and replay A stream.
1 / 2

Ask these questions in order:

  1. Is it a command or an event? A command ("generate invoice 7") has one handler and goes to a work queue. An event ("order 7 placed") has many possible listeners and goes to an exchange with a queue per subscriber.
  2. How bad is losing it? If it is unacceptable: quorum queue, persistent, confirms, manual acks. If it is fine: classic queue, transient, auto ack.
  3. Does anyone need to re-read it? Replay, audits, many independent readers, or analytics: a stream.
  4. Does the caller wait? If yes, ask whether messaging adds value; if you still want it, use RPC with timeouts.
  5. How many failures must it survive? One node: 3-node cluster with quorum queues. Two nodes or a site: 5 nodes, or federation between sites.
  6. What happens when it is poison or slow? Dead letter queue, retry queues, length limits, alerts.
Python Stand-in: a decision helper you can tweak

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Scenarios

Try each on paper first: queue types, exchanges, acks, failure handling.

1. Newsletter sending. 200,000 emails per night, each takes about 300 ms with an external provider that sometimes returns 429.

Suggested answer: a work queue of one message per recipient (or per small batch), quorum or classic durable, prefetch_count 20, manual acks. A 429 is transient: send to a retry queue with a delay and honor Retry-After. Permanent failures (invalid address) go to a DLQ and are marked in the database. Idempotency key per (campaign, recipient) so retries never double-send. Scale workers to hit the provider's rate limit but never above it; put the limit in the workers (token bucket) rather than relying on the queue.

2. Sensor telemetry. 50,000 devices send a reading every second; dashboards need live data and analysts need a month of history.

Suggested answer: a stream with x-max-age: 30D and a super stream partitioned by device id for throughput. Dashboards read from next, analysts replay from a timestamp. Use the stream protocol for publishing. A classic queue would hold the same data, but could not serve several independent readers or replay.

3. Checkout flow. Placing an order must reserve stock, charge a card and email a receipt. The card step can take 10 s.

Suggested answer: the shop stores the order, publishes order.placed through the outbox pattern. Warehouse, billing and notifications each have a quorum queue. Return "order received" to the customer immediately; show the final status later by polling or a push event. Billing publishes payment.captured or payment.failed, and warehouse compensates on failure (Project: Order Processing Pipeline). Avoid an RPC chain that makes the web request wait for three services.

4. Microservice calls on a hot path. A product page needs a price from a pricing service within 100 ms.

Suggested answer: use HTTP or gRPC with timeouts and a cache. If pricing must stay behind the broker, use RPC with Direct Reply-To, a 200 ms timeout and a request TTL, plus a fallback price. Do not place a synchronous page render on a queue that can back up.

5. Cross-region replication. Orders in Frankfurt must also reach analytics in Virginia.

Suggested answer: do not stretch one cluster over a WAN. Run a cluster per region and move the data with the Shovel or Federation plugin (both reconnect and resend), or publish to a stream and consume it remotely. Accept a few seconds of lag and make consumers idempotent.

Python Stand-in: sizing a worker pool

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Design review checklist

Use it on every new queue or exchange.

Python Stand-in: a review checklist you can run

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Beyond the code, ask the organizational questions: who owns each queue, who gets paged when the DLQ fills, how are messages versioned, how is a broker upgraded without downtime, and how do you rebuild the topology (definitions in version control).

Where to go next

You now have the full picture: AMQP concepts, exchanges and queues, reliability, clustering, patterns, operations and projects. To go deeper, build the projects against a real broker (the official Docker image rabbitmq:4-management runs on a laptop), read the release notes of the version you deploy, and try one failure drill per week until recovering from a node loss feels routine. The track overview is at RabbitMQ.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Dashboards need live data and analysts need to replay last month's readings. Which fits best?

    Streams are non-destructive logs: many readers, any offset, retention by age or size.
  2. 2. A web page must show a price within 100 ms. What is the sound design?

    Hot-path synchronous reads should not depend on queue backlog; if you use RPC, add timeouts, TTLs and fallbacks.
  3. 3. Why not stretch one RabbitMQ cluster across two distant regions?

    Clusters assume a reliable low-latency network. Shovel and Federation tolerate WAN links and retry.
  4. 4. In the newsletter scenario, what protects against sending an email twice?

    Retries and redeliveries can repeat a job; the key makes the side effect happen once.

Summary

  • Decide by shape first (command, event, request, history), then by loss tolerance and replay needs.
  • Quorum queues are the safe default for important data; streams for history and fan-out; classic queues for throwaway work.
  • Avoid synchronous chains over queues; prefer events, outbox and compensation.
  • Run every design through a checklist: durability, confirms, acks, prefetch, DLQ, limits, idempotency, monitoring, node count.

Next: RabbitMQ track overview