
Answer-first summary for fast verification
Answer: Store the order in the database. Send a message that includes the order number to an Amazon Simple Queue Service (Amazon SQS) FIFO queue. Set the payment service to retrieve the message and process the order. Delete the message from the queue.
## Explanation The correct answer is **D** because it addresses the core problem of duplicate orders through a reliable, idempotent processing pattern. ### Why Option D is Correct: 1. **SQS FIFO Queue**: Amazon SQS FIFO queues ensure exactly-once processing and preserve the order of messages. This prevents duplicate processing of the same order. 2. **Idempotent Processing**: By storing the order first in the database and then sending a message to SQS, the payment service can process orders reliably. If the payment service fails, the message remains in the queue for retry. 3. **Message Deletion**: The explicit deletion of messages after successful processing ensures that messages aren't reprocessed. 4. **Timeout Handling**: When users experience timeouts and resubmit, the workflow can check for existing orders before creating new ones, or the SQS FIFO queue can deduplicate based on message deduplication IDs. ### Why Other Options Are Incorrect: - **Option A**: Kinesis Data Firehose is designed for streaming data to destinations like S3, Redshift, or Elasticsearch. It's not suitable for reliable, exactly-once message processing in this scenario. - **Option B**: Using CloudTrail for application-level workflow processing is inefficient and inappropriate. CloudTrail is for API auditing, not application workflow orchestration. - **Option C**: Amazon SNS is a pub/sub service that doesn't guarantee exactly-once delivery. Multiple subscribers could process the same message, and there's no built-in deduplication mechanism. ### Key Design Principles: - **Decoupling**: Separating order creation from payment processing improves resilience. - **Idempotency**: Ensuring that processing the same order multiple times doesn't create duplicate orders. - **Reliability**: Using a queue with visibility timeouts and retry logic handles transient failures gracefully. This solution aligns with AWS best practices for building resilient, decoupled architectures that can handle partial failures without creating inconsistent states.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
A company has an ecommerce checkout workflow that writes an order to a database and calls a service to process the payment. Users are experiencing timeouts during the checkout process. When users resubmit the checkout form, multiple unique orders are created for the same desired transaction.
How should a solutions architect refactor this workflow to prevent the creation of multiple orders?
A
Configure the web application to send an order message to Amazon Kinesis Data Firehose. Set the payment service to retrieve the message from Kineses Data Firehose and process the order.
B
Create a rule in AWS CloudTrail to invoke an AWS Lambda function based on the logged application path request. Use Lambda to query the database, call the payment service, and pass in the order information.
C
Store the order in the database. Send a message that includes the order number to Amazon Simple Notification Service (Amazon SNS). Set the payment service to poll Amazon SNS, retrieve the message, and process the order.
D
Store the order in the database. Send a message that includes the order number to an Amazon Simple Queue Service (Amazon SQS) FIFO queue. Set the payment service to retrieve the message and process the order. Delete the message from the queue.