Soru

Zorluk: ZorMessage-Based Integration using Amazon SQS and SNS

A developer is implementing a smart lock security system. Commands (such as `LOCK` and `UNLOCK`) sent to individual locks must be processed in the exact order they are received to prevent race conditions. The commands are published to an Amazon SNS FIFO topic, which fans out to Amazon SQS FIFO queues consumed by a fleet of processing workers. During testing, the developer notices that commands for different smart locks are occasionally blocking each other, causing high latency. Furthermore, consecutive identical commands for the same lock (e.g., two `LOCK` commands) are occasionally discarded. How should the developer configure the SNS FIFO topic and SQS FIFO queue parameters to resolve these issues?

  1. A
    Route the messages from the SNS FIFO topic to an Amazon SQS Standard queue instead of a FIFO queue, and increase the queue's VisibilityTimeout to a value greater than the consumer function's timeout.
  2. Set the MessageGroupId to the smart lock's unique identifier (LockIDLockID), and generate a unique UUID for each command to serve as the MessageDeduplicationId.Cevap
  3. C
    Set the MessageGroupId to a static string like 'LockCommandGroup' to ensure global ordering, and enable content-based deduplication on the Amazon SQS FIFO queue.
  4. D
    Set the MessageGroupId to the command name (such as 'LOCK' or 'UNLOCK'), and initialize the AWS SDK clients by embedding credentials from the developer's IAM user directly in the code.

Cevap

Set the MessageGroupId to the smart lock's unique identifier (LockIDLockID), and generate a unique UUID for each command to serve as the MessageDeduplicationId.
Setting the MessageGroupId to the smart lock's unique identifier (LockIDLockID) ensures that messages for a given lock are grouped and processed sequentially, preventing race conditions for that device while allowing messages for other locks to be processed concurrently. Using a unique UUID for the MessageDeduplicationId prevents separate, identical commands (like consecutive LOCK commands) sent within the 55-minute deduplication window from being incorrectly discarded as duplicates.

Adım Adım Çözüm

1
Analyze the concurrency and ordering requirements.
Ordering must be guaranteed per individual lock, but locks should process independently.
To prevent head-of-line blocking and allow parallel processing across different devices, a unique identifier per device (LockIDLockID) must be used as the MessageGroupId.
2
Address the deduplication behavior for identical payloads.
A unique deduplication ID (like a UUID) must be passed for each request.
If content-based deduplication is enabled or a hash of the payload is used, consecutive identical commands (e.g., locking a door twice) sent within 55 minutes will be filtered out as duplicates by the SQS FIFO queue.
3
Validate the chosen architecture against AWS best practices.
Avoid hardcoded IAM credentials and standard SQS queues.
Standard queues do not guarantee order, and hardcoded credentials violate basic security principles.

Anahtar Kavram

Message Grouping and Deduplication in SNS/SQS FIFO Architectures
Bu soruyu puanla