Amazon SQS can deliver a meter-reading message more than once, and blindly inserting each delivery would double-bill residents. How should the consumer be designed?
Select an answer to reveal the explanation.
Short Explanation
Treat each meter reading like a check that shouldn't clear twice—stamp a dedupe key or conditional write so a second delivery is a no-op. SQS is at-least-once; you can't wish that into exactly-once by turning off retries or stretching visibility forever.
Full Explanation
Amazon SQS can deliver a meter-reading message more than once; blindly inserting each delivery would double-bill residents. Consumers must be idempotent with dedupe keys or conditional writes so repeats do not double-bill. Use a natural key (meter ID + billing period) with DynamoDB conditional PutItem, a unique ledger constraint, or an explicit processed-message store so at-least-once delivery becomes safe at-least-once processing. Utility billing integrity depends on this application-level guarantee more than on broker marketing language.
Disabling SQS retries entirely so every message is processed at most once by the broker sacrifices durability when consumers fail after receiving but before committing side effects. Using a standard queue with no deduplication keys while trusting exactly-once broker delivery is incorrect—standard queues are at-least-once. Increasing visibility timeout to seven days does not make redelivery impossible and can hide failed processing far beyond operational SLAs.
Exam caveat: FIFO content-based deduplication reduces duplicate deliveries for identical bodies within the deduplication interval, but it is not a substitute for idempotent business writes—especially when semantically identical readings arrive with different message IDs. Always design the ledger write as the system of record for uniqueness.
Operational check: define a uniqueness key for each billable reading; implement conditional writes; replay the same SQS message in test and confirm a single ledger row; metricate duplicate-attempt counts; and document the runbook when a duplicate is rejected.