BayLearnBayAreaLa8s

Beginner · About 10 minutes · Reliable applications

One Order. Two Emails.

Maya ordered once. Her confirmation arrived twice. How would you prevent the second email?

Answers stay in this browser until you save them on this device.

What happened?

Maya buys a pair of shoes online. Her order number is 4821.

The store receives a message saying that the order was placed. It sends her a confirmation email.

A few seconds later, the same order message arrives again. The store sends another email.

Maya placed one order, but received two confirmation emails.

1. One order

Maya places Order #4821.

Order

#4821

2. The same message arrives twice

Two messages to the store, both for Order #4821.

Message to store

Order #4821

Message to store

Order #4821

3. Two confirmation emails

Two emails to Maya for Order #4821.

Email to Maya

Order #4821

Email to Maya

Order #4821

Sent twice

Maya placed one order. The store received the same message twice and emailed twice.

Your task

How would you stop the second confirmation email while still allowing emails for new orders?

Assumptions for this first challenge

Keep this first challenge simple: messages are handled one at a time. Sending an email and saving its record both succeed.

You do not need to write code. Explain your idea in your own words.

0/2000
0/2000
0/2000

Related path: System Design Interview Sprint

Interview answer

Explain it in an interview

Maya placed shoe order 4821 once and got two confirmation emails. How would you stop the second send?

Maya bought one pair of shoes and the store assigned order 4821. The first order-placed message triggered a confirmation email to her. A few seconds later the same message arrived again, and the store sent a second email. I treat order 4821 as the identity of that confirmation, not each arrival of the message.

How to walk the interviewer through the answer1Order 4821 was confirmed twice2A memory check misses the next copy3One saved confirmation per order4Commit the row after the send returns5Retry only when the row is known6Do not claim exactly-once email
Walk these steps in order. Each box is one thing to say before you move on.
  1. Step 1

    Order 4821 was confirmed twice

    The store handled one order-placed message for 4821, sent Maya the confirmation, and then saw that same message again. The second delivery was processed as a new event, so another email went out. Maya did not place a second order. The duplicate came from the message being delivered twice.

  2. Step 2

    A memory check misses the next copy

    Skipping the send because this process already saw 4821 fails after a restart, and it fails if another handler takes the repeat. A primary key on the order stops a second row, but it does not make the email send and the insert one operation. If I send and crash before the save, the retry looks new and Maya can get another email.

  3. Step 3

    One saved confirmation per order

    Before I send, I look up order 4821. When a row already exists for the same recipient, I return already_sent and I do not call the sender. When the stored recipient is different, I return a conflict and leave the row alone. A different order number is a new confirmation, even for the same person.

  4. Step 4

    Commit the row after the send returns

    The handler calls the simulated sender and only then inserts the confirmation row. The caller hears success after that insert commits. The row means this order was confirmed for that exact recipient, and there is no separate status field. Comparison of the address is exact, so I do not trim or rewrite it.

  5. Step 5

    Retry only when the row is known

    If the row is already there, a repeat is safe and returns the earlier result. If the sender fails, I save nothing, so a later attempt can try again. A failure after the send may mean the email went out and the save did not, so I do not automatically retry and I do not tell Maya the outcome is certain.

  6. Step 6

    Do not claim exactly-once email

    I can promise at most one saved confirmation row for order 4821 in this local store. I cannot promise her inbox received that message once, because the send and the save are separate steps. This is one sequential process with a simulated sender. It is not a mail provider, and a 500 response leaves the result uncertain.

Interviewers listen for the boundary between the tempting shortcut and the rule you actually enforce.

Leave these claims out

  • Exactly-once email delivery
  • The primary key makes send and save atomic
  • A 500 means the email was not sent

For order 4821 I would show the lookup, the already_sent path, and the gap between the simulated send and the commit. That gap is the boundary I can defend from this lab.

Now say the same idea in your own words, using the story from this challenge.