How does RabbitMQ handle message ordering and exactly-once delivery?

Answer

RabbitMQ's ordering and delivery guarantees: Message ordering: messages in a single queue are FIFO — a single consumer receives them in order. Ordering violation: if a message is nacked and requeued, it is placed back at the head of the queue — ahead of messages published after it. With multiple consumers, messages are consumed concurrently in any order. For strict global ordering, use a single consumer. For per-entity ordering, use consistent hashing (route same entity to same consumer) or a single consumer per entity. Exactly-once delivery: RabbitMQ guarantees at-least-once delivery by default (with publisher confirms + consumer acks). True exactly-once requires idempotent consumers. Implementation: include a unique messageId in each message. Consumers check a processed-IDs store (Redis, DB) before processing. If already processed, skip and acknowledge. This deduplication at the consumer layer achieves exactly-once processing even if delivery is at-least-once. There is no native exactly-once delivery in RabbitMQ — unlike Kafka's transactional producer.