Skip to main content
InterviewHubPRO
Section Overview
Q31

Question 31 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

62%
RabbitMQ & AMQP (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Idempotent Consumer Design in RabbitMQ.

senior LevelCode ExampleSystem DesignRabbitMQMicroservices

In Simple Words: Because RabbitMQ operates on At-Least-Once delivery semantics, network timeouts or consumer crashes after processing but before basic.ack will cause the broker to re-deliver the message. Every consumer must be idempotent:

  1. Every message includes a unique message_id (UUID).
  2. Before processing, the consumer checks Redis or PostgreSQL:
    sql
    INSERT INTO processed_messages (message_id, created_at)
    VALUES ($1, NOW())
    ON CONFLICT (message_id) DO NOTHING;
    
  3. If the insert returns 0 rows affected, the message is a duplicate: immediately call ch.ack(msg) and return without executing business logic.