Integration / RabbitMQ Interview Questions
Why is TTL important for queues and messages in RabbitMQ?
Time-to-live (TTL) settings prevent stale data and idle resources from accumulating forever, at both the message level and the queue level.
- Message TTL (
x-message-ttl, or a per-messageexpirationproperty) removes a message once it has waited too long to be useful - a good fit for time-sensitive data like OTP codes or live pricing, where a stale message is worse than no message. - Queue TTL (
x-expires) automatically deletes an entire queue after it has sat idle (no consumers, no gets) for the configured period - useful for temporary reply queues or per-session queues that would otherwise leak.
Combining message TTL with a dead-letter exchange is also a common pattern for building delayed-retry logic: a failed message sits in a "retry" queue with a TTL, and once it expires it is dead-lettered back into the main processing queue.
More Related questions...