What is RabbitMQ's prefetch and QoS?
Answer
Prefetch (Quality of Service / QoS) in RabbitMQ limits the number of unacknowledged messages delivered to a consumer at one time. Set it: channel.basicQos(prefetchCount: 10) — the broker sends at most 10 messages to this consumer that haven't been acknowledged yet. Purpose: Fair dispatch: without prefetch, a busy consumer is flooded with messages while idle consumers wait. With prefetch=1, RabbitMQ gives each consumer one message at a time — when it's acknowledged, the next is sent. Back pressure: prevents a consumer from being overwhelmed with more work than it can handle. Memory management: limits in-flight messages per consumer. Prefetch vs batch size: prefetch is not "process N messages at once" — it's "have at most N unacknowledged messages in flight." A consumer can still acknowledge them one by one. For maximum throughput, use a higher prefetch (100-300). For maximum fairness, use prefetch=1. In production, tune prefetch based on message processing time and consumer count.