Quick revision
The short answer
We publish user.notified events to one topic exchange and give each consuming service its own durable queue bound to it, so email, SMS and push each receive every event. The five email instances consume from the same email queue as competing consumers, so they share the work instead of each getting a copy. The audit queue binds with a pattern such as user.notified.eu when the region is in the routing key, or through a headers exchange when it is a header. In production the queues are quorum queues with length limits, TTLs and dead-lettering per queue, so one slow service cannot affect the others.
What to remember
In this answer, we designed a notification topology from two RabbitMQ rules: every matching queue receives a copy, and consumers on one queue compete. A topic exchange receives user.notified.<region> events, email, SMS and push each have their own durable queue bound with user.notified.#, the five email instances share one queue, and the audit queue binds with user.notified.eu, or uses a headers exchange if the region is a header. Quorum queues give replication, and per-queue length limits, TTLs and dead-lettering keep a slow service from hurting the others.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We publish user.notified events to one topic exchange and give each consuming service its own durable queue bound to it, so email, SMS and push each receive every event. The five email instances consume from the same email queue as competing consumers, so they share the work instead of each getting a copy. The audit queue binds with a pattern such as user.notified.eu when the region is in the routing key, or through a headers exchange when it is a header. In production the queues are quorum queues with length limits, TTLs and dead-lettering per queue, so one slow service cannot affect the others.
Why this question is asked
Notification systems are a textbook RabbitMQ design, and they test the one idea people most often get wrong: the difference between giving every service a copy of a message and sharing messages among instances of one service. Getting it wrong either sends every email five times or leaves the SMS service without events. Interviewers ask this design question to see whether we can choose exchanges, queues and bindings from the requirements and add the production safeguards. In this answer, we will recap the two delivery patterns, design the exchange and queues, route EU events to the audit service, choose queue types, and protect the services from each other.
1A Quick Recap: A Copy per Queue, Shared Within a Queue
Two rules of RabbitMQ give us everything we need here. First, an exchange puts one copy of a message into every queue whose binding matches. So if three queues are bound, the message is copied three times. Second, within one queue, each message is delivered to only one consumer. If five consumers read the same queue, they compete, and each message goes to one of them, roughly in turn.
So publish-subscribe across services means one queue per service, and load sharing within a service means many consumers on one queue. Our design is just these two rules applied to the requirements.
2The Exchange and One Queue per Service
We create a topic exchange called notifications. The producer publishes each event with a routing key that carries the event type and the region, such as user.notified.eu or user.notified.us. Each service gets its own durable queue, named after the service, and binds it with user.notified.#, which matches every user.notified event in any region.
- Producerpublishes
user.notified.<region> - Topic exchange notificationscopies to every matching queue
- Queues email, sms, pushbound with
user.notified.# - Queue audit.notifications.eubound with
user.notified.eu - Consumers5 email instances share one queue
5 layers, from the top down. Step through them one at a time.
Notice why a topic exchange rather than fanout. Fanout would also give email, SMS and push a copy, but it ignores the routing key, so the audit service could not ask for EU events only. A topic exchange serves both needs, and later services, such as a US-only reporting queue, can be added with a new binding and no change to the producer.
3Sharing the Email Work Across Five Instances
All five email instances run the same @RabbitListener on notifications.email. They are competing consumers: RabbitMQ delivers each message to one of them, so with 1,000 events per minute each instance handles about 200. If one instance dies, its unacknowledged messages go back to the queue and the remaining four take them. Scaling is just adding instances.
The prefetch setting matters here. Spring AMQP's default prefetch of 250 lets one instance hold up to 250 unacknowledged messages, which for slow email sends piles work on whichever instance connected first. A smaller value, such as 10 or 20, spreads the work more evenly. If emails for one user must be sent in order, competing consumers break that, and we would use single active consumer or split the queue by user hash, but notifications rarely need strict order.
4Routing EU Events to Audit
The audit binding depends on where the region lives. If the producer puts the region in the routing key, as here, the binding user.notified.eu is enough, and no other event reaches the audit queue. If the region is only a message header, the topic exchange cannot see it. Then we add a headers exchange, either bound from the topic exchange with an exchange-to-exchange binding or published to directly, and bind the audit queue with region=eu and x-match all. Putting the routing information in the routing key is usually simpler, so I would agree the key format, type.action.region, with the producer team as part of the contract.
5Quorum Queues and Protecting Services From Each Other
For production I would use quorum queues. They replicate each queue across, typically, three nodes using the Raft protocol, so a node failure loses no acknowledged messages, which classic mirrored queues no longer offer in RabbitMQ 4. They also have a delivery limit that stops endless redelivery of a poison message.
Then each queue gets its own limits, so a problem in one service stays in its queue. If the SMS provider is down for an hour, the sms queue grows while email and push continue normally. A length limit, for example x-max-length of 500,000 with overflow drop-head, stops the queue from filling the broker's memory and disk by dead-lettering the oldest messages; reject-publish would be the wrong choice here, because a full SMS queue would nack the producer's publish even though email and push stored it, and the producer's retry would duplicate their notifications; a message TTL, such as one hour for push notifications that are useless when late, drops stale work; and a dead-letter exchange keeps rejected and expired messages for inspection. We alert on queue depth and consumer count per queue.
| Queue | Limit | TTL | Dead-letter |
|---|---|---|---|
notifications.email | 1,000,000 messages | 24 hours | notifications.dlx |
notifications.sms | 500,000 messages | 1 hour | notifications.dlx |
notifications.push | 500,000 messages | 15 minutes | notifications.dlx |
audit.notifications.eu | none, must keep all | none | audit.dlx, alert on any |
6Follow-up questions
What happens to the other services if the SMS service is down for a day?
Nothing, as long as its queue has a sensible limit. Its queue grows until the length limit, after which, with overflow drop-head, the oldest SMS messages are dead-lettered to make room, while the email and push queues are separate and keep flowing. The producer keeps getting acks, because every queue accepted the message. When SMS returns it drains its backlog, or the TTL has already removed messages that are too old to be useful.
Why not let each email instance have its own queue?
Then each instance would receive a copy of every event, and every email would be sent five times. Separate queues are for separate services that each need all events; instances of one service share a queue.
7Conclusion
In this answer, we designed a notification topology from two RabbitMQ rules: every matching queue receives a copy, and consumers on one queue compete. A topic exchange receives user.notified.<region> events, email, SMS and push each have their own durable queue bound with user.notified.#, the five email instances share one queue, and the audit queue binds with user.notified.eu, or uses a headers exchange if the region is a header. Quorum queues give replication, and per-queue length limits, TTLs and dead-lettering keep a slow service from hurting the others.
Open with
I would use one topic exchange, say notifications, and have the producer publish with a routing key like user.notified dot region, for example user.notified.eu. Each consuming service gets its own durable queue: one for email, one for SMS, one for push, each bound with user.notified.hash, because an exchange puts a copy into every matching queue, so each service gets every event.
Then, if they want more
The five email instances all consume from the same email queue. Within a queue, each message goes to only one consumer, so they act as competing consumers and share the load; I would lower the prefetch from the default of 250 to something like 10 or 20 so the work spreads evenly.
The audit service gets its own queue bound with user.notified.eu, so it only receives EU events. If the region were only a header and not in the routing key, I would route through a headers exchange instead, but I prefer agreeing on a routing key format with the producer.
In production I would make all of them quorum queues for replication and a delivery limit, and give each queue its own length limit, TTL where late messages are useless, and a dead-letter exchange. That way, if the SMS provider is down, only the SMS queue grows, and email, push and audit are unaffected. I would alert on queue depth per queue.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- RabbitMQ documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design the RabbitMQ topology for a notification system where email, SMS and push...": https://scrivio-interview-library.netlify.app/spring-boot/rabbitmq-and-jms/6a1b72ceb3/