Learning/AWS SQS/29 — Hands-on Labs/Lab 14 — Implement idempotency
Advanced outline
This chapter is an outline. The curriculum, learning objectives and structure are settled; the prose, diagrams and code are still being written. What is below is the plan for the chapter, not the chapter.

Lab 14 — Implement idempotency

Goal

Deliberately deliver the same message twice and prove the effect happened once.

Setup

To be written — CLI commands and an IaC equivalent for every resource, all prefixed sqs-course-.

Steps

  1. Write a consumer that increments a counter — deliberately non-idempotent
  2. Force a redelivery (as in Lab 04); observe the counter double-counted
  3. Add an idempotency table keyed on a business id
  4. Commit the effect and the idempotency record in one transaction
  5. Force the redelivery again; observe the second attempt short-circuits
  6. Now split them into two transactions and force a crash between — observe the hole reopen
  7. Add a TTL and verify it exceeds maxReceiveCount × visibilityTimeout

What you should observe

  • Two transactions is not the same as one
  • The guard must key on something from the message
  • A too-short TTL lets late duplicates through

Why it happened

To be written — ties each observation back to the mechanism in 09 — Delivery Semantics and Idempotency.

Experiments to try

To be written — deliberate variations that change the outcome.

Teardown

To be written — every resource created above, in dependency order.


Back to: 29 — Hands-on Labs