RabbitMQ & AMQP (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Consumer Prefetch (`basic.qos`): Setting global vs channel vs consumer prefetch to prevent worker starvation and memory blowups.
senior LevelSystem DesignRabbitMQGolang
In Simple Words: By default, RabbitMQ pushes messages to connected consumers as fast as possible (unbounded prefetch). If a consumer is slow, thousands of unacked messages accumulate in the consumer's RAM, causing out-of-memory crashes.
basic.qos(prefetch_count): Caps the number of unacknowledged messages assigned to a consumer socket:prefetch_count = 1: Perfect fair dispatch for slow, uneven CPU-intensive tasks.prefetch_count = 50 - 200: Optimal sweet spot for high-throughput, low-latency consumers.global = true: Shares the prefetch limit across all channels on the AMQP connection.