Philipp Sumi
Philipp Sumi

Reputation: 987

RabbitMQ with many small queues to enforce sequential execution (pattern or anti-pattern)?

Hypothetical (but simpler) scenario:

I'm currently toying with the idea of leveraging RabbitMQ with a setup similar to this:

Those queues would be short-lived, so I wouldn't end up with millions of them, but it should scale anyway (let's say lower one-digit thousands if the project grows substantially). Question is whether that's an absolute anti-pattern as far as RabbitMQ (or similar) systems goes, or if there's better solutions to ensure sequential execution anyway.

Thanks!

Upvotes: 0

Views: 547

Answers (1)

Sukhmeet Sethi
Sukhmeet Sethi

Reputation: 713

In my opinion creating ephemeral queues might not be a great idea as there will considerable overhead of creating and delete queues. The focus should be on message consumption. I can think of following solutions:

  • You can limit the number of queues by building publishing strategy like all orders with orderId divisible by 2 goes to queue-1, divisible by 3 goes to queue-2 and so forth. That will give you parallel throughput as well as finite number queues but there is some additional publisher logic you have to handle

  • The same logic can be transferred to consumer side by using single pub-sub style queue and then onus lies on consumer to filter unwanted orderIds

  • If you are happy to explore other technologies, you can look into Kafka as well where you can use orderId as partitionKey and use multiple partitions to gain parallel throughput.

Upvotes: 1

Related Questions