Skip to content

Instantly share code, notes, and snippets.

@ashishjullia
Created September 12, 2023 15:08
Show Gist options
  • Save ashishjullia/c04b2d8cefdf6e05060ddd802c5418e3 to your computer and use it in GitHub Desktop.
Save ashishjullia/c04b2d8cefdf6e05060ddd802c5418e3 to your computer and use it in GitHub Desktop.

Certainly! Let's dive into the details for MessageDeduplicationId, MessageGroupId, and MessageId in the context of Amazon SQS:

  1. MessageId:

    • Purpose: This is a unique identifier for each message that is generated by SQS once a message is successfully added to the queue.
    • Usage:
      • Standard Queue: Every message that is sent to a standard queue gets a unique MessageId.
      • FIFO Queue: Similar to standard queues, every message that's sent to a FIFO queue gets a unique MessageId.
    • Set By: Amazon SQS (not user-settable).
  2. MessageDeduplicationId:

    • Purpose: Used by SQS to determine if a message is a duplicate of another message.
    • Usage:
      • Standard Queue: Not applicable; standard queues do not have built-in deduplication based on a deduplication ID.
      • FIFO Queue: The MessageDeduplicationId is required unless the message deduplication is based on the content of the message. If you don't provide it, SQS uses an MD5 hash of the message body as the MessageDeduplicationId. This ID is used to ensure that a message is delivered only once (no duplicates).
    • Set By: User (optional for FIFO if using content-based deduplication).
  3. MessageGroupId:

    • Purpose: Used to group messages in a FIFO queue. Messages with the same group ID are always processed one by one, in a strict order relative to the message group (however, messages with different group IDs might be processed out of order).
    • Usage:
      • Standard Queue: Not applicable; standard queues do not use message groups.
      • FIFO Queue: MessageGroupId is mandatory for FIFO queues. This ensures that if multiple messages belong to the same group ID, they are processed in the order in which they were sent.
    • Set By: User (mandatory for FIFO).

Comparison:

  • MessageId is an identifier provided by SQS for every message, irrespective of the type of queue. It's essentially a receipt that a message was accepted into the queue.
  • MessageDeduplicationId is user-provided (or generated from the message content) and is unique for each message in a 5-minute interval for FIFO queues. It's used to prevent sending the same message multiple times in quick succession.
  • MessageGroupId is used to specify a group for a set of messages in FIFO queues. This allows for maintaining order within each group while allowing for parallel processing across different groups.

It's worth noting that the deduplication and grouping concepts are specifically for supporting the "exactly once" and "strict ordering" semantics of FIFO queues, and they are not applicable to standard SQS queues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment