Integration / RabbitMQ Interview Questions
Why should you use prefetch count in RabbitMQ?
Prefetch count (set via basic.qos) limits how many unacknowledged messages RabbitMQ will push to a consumer at once, instead of flooding it with the entire queue.
Without a limit, a fast producer can hand a slow consumer thousands of messages it hasn't even started processing yet, which:
- wastes memory buffering unprocessed work on the consumer side,
- causes uneven load when several consumers share a queue, since one consumer can hog most of the backlog,
- increases the blast radius if that consumer crashes, since all of its unacked messages get redelivered at once.
A small prefetch value (often 1 for slow/expensive jobs, higher for lightweight ones) keeps work spread fairly across consumers and keeps memory bounded.
More Related questions...