Skip to content

Can you guarantee exactly one confirmation email per booking?

1 min read · main part only; folded sections are optional

After this you can answer: Can you guarantee exactly one confirmation email per booking?

The email job key identifies the business effect: booking.confirmed for one booking. DynamoDB reads are strongly consistent, and the completion write is conditional. Those details stop stale completion reads and conflicting writes; they do not reserve the job before sending.

Two workers can both read no completion record, both send, and then race to record completion. Only one record is created, but two external effects may already have happened. A single worker can also send successfully and fail before saving completion.

Records carry a thirty-day TTL for eventual cleanup, so duplicate suppression is not permanent history. A manual replay after the record disappears can send again. A lease could reduce simultaneous sends, but a crashed sender with an uncertain provider outcome still needs a policy. Also distinguish provider acceptance from actual inbox delivery: neither this record nor a successful API call proves receipt.

Why not mark completion before sending?
A crash after that write but before the email call would make future retries skip an email never sent. The present choice prefers possible duplicates to that loss window.
Would a conditional put after send stop the race?
It stops duplicate completion records. It happens too late to stop two workers from having already sent their emails.
What would you promise the product team?
Durable retries and best-effort suppression within retained history, with known duplicate windows. A stricter contract needs explicit provider capabilities, outcome reconciliation and a decision about ambiguous sends.

Read Dynamodb, then inspect the processed-jobs-table piece →.

apps/worker/src/handlers/booking-confirmed.ts → handleBookingConfirmed

Compare the duplicate-email case.

Read this book online: https://book.theversehub.in/