0

I am trying to use rabbitmq as a part of the notification system. I have an exchange called "notification_events" and the queues in the exchange are based on the types of events, for example, 'send_account_notification_queue' or 'send_tickets_notification_queue'. In order to send to specific user(s) I plan on binding userId to the appropriate queue as a routing key. And I'm sure the number of routing keys will grow with more users...

I read that it is bad to have thousands or millions of queues, but how about routing keys? Are there better ways of doing this? Any help is appreciated and thanks in advance for your time :)

Mike Yim
  • 19
  • 1
  • 4

1 Answers1

0

Do you really need queueing per user? Have you considered having a single queue per type of event and using userId to notify the appropriate user? It assumes that a given user notification is fast and cannot fail just for the subset of users.

If you need more complex per-user logic (like reordering events) or dealing with a specific user not being able to receive an event then queueing system is not the right abstraction. Look for an orchestration system like temporal.io that supports per-user object with as complex logic as necessary.

See this answer that explains how Temporal solves it for a system with similar requirements.

Maxim Fateev
  • 6,458
  • 3
  • 20
  • 35
  • Thank you for the response! In this use case I would have few queues but have many routing keys. Each routing key representing a user. Like u said this is not the way to do this so I decided to do user-specific filtering "normally" in a graphql subscription resolver, but now I'm just curious about the limits of routing keys. I read many warning against having too many queues and that consuming too much resources, but how about routing keys? Just in case I have future use case where I would need like maybe a hundred routing keys. – Mike Yim May 10 '22 at 07:05
  • It depends on what operation you do per routing key. If you want to see all the messages for the given user as a query then you have to have a data structure per user. You either have to store a user messages in a DB or use something like Temporal. – Maxim Fateev May 10 '22 at 17:45