HeadlinesBriefing HeadlinesBriefing.com

Engineers Nightmare Notification Systems

Hacker News •
×

Sending one email is one line of code. Sending them properly is a whole other thing. Here's how that one line grows, one support ticket at a time, and seven times it went wrong for real companies.

Every notification system starts the same way. Someone files a ticket: send a receipt email when someone places an order. Say you work at Halden, an online shop that sells lamps.

You've got an order placed: send receipt email Ana in Lisbon orders a lamp (order #8812), the receipt shows up in her inbox, you close the ticket and go get lunch. Easy. Every team that wrote send Email() and called it done.

It's not easy. I ran into a bunch of these problems myself, which is why I built notifkit. I looked at the hosted options first.

Courier, Knock and Novu Cloud all charge per message, so they get stupid expensive once you're sending real volume. Self-hosting Novu fixes the bill but not the server: it's a handful of services plus Mongo DB, it needs a big box to run, and it was slow when I tested it. So I can promise you that one line is going to grow.

Let's follow it for three months. Every step below is a problem you hit once you send enough notifications, and most of them come with a public incident from a company that hit it first: Salesloft, Zoho, Asana, Buttondown, Starbucks, HBO Max and Everbridge. Quick note before we start.

I don't know how any of these companies built their systems, and I'm not calling anyone careless. Several of them published honest write-ups about what broke, which takes guts. The code below is my version, not a guess at what they should have done.

My point is just that this stuff is hard, and careful teams still get bitten. Week one · Support: 'A customer says her receipt never arrived.' The provider timed out, so you add retries. You check the logs.

The provider took too long to answer, the call threw, and nothing went out. Networks do that. Fine, retries: send receipt: try 3 times: send the email if it worked: done wait a bit longer each time # 1s, 2s, 3s give up: 'receipt not sent' Done.

Except that loop can take ten seconds, and it's running inside the checkout request, so Ana is staring at a spinner while you wait on an email. So you move the send into a background job, and now you've got a job queue to look after. For one email.

Two days later · Support: 'Now she has two receipts.' The retry sent it twice, so you give each message an ID. Here's what happened. A timeout only means you didn't get an answer.

It doesn't mean the provider didn't send the email. It did, and then your retry sent it again. Ana's inbox after one timeout and one retry.

What you need is an ID for each message that stays the same every time you retry it, like order-8812-confirmed. (A random ID won't work, because every retry gets a fresh one.) Before you send, you check whether that ID already went out. Without an ID. The retry looks like a new email.

Checkout Provider Ana's inbox 12 timeout → retry With order-8812-confirmed. The retry is recognised. Checkout ID check Provider Ana's inbox 1 timeout → retry seen it, skip Figure 1.

Same timeout, same retry. Green is the first attempt, amber is the retry. send receipt: id = 'order-8812-confirmed' # the same on every retry if id was already sent: stop try 3 times: send the email, passing id to the provider mark id as sent # after the send, not before done One thing in there is sneaky: the 'sent' mark goes after the send. Write it before, and a crash in between means the receipt never goes out.

Write it after, and a crash in between means the retry sends a second one. You don't get an option where neither can happen. That second case is pretty much what Zoho described: the email went out, they couldn't mark it as processed, so it got retried.

You can't fully fix that from your side. The provider has to accept your ID and refuse the repeat, which is why the ID gets passed to the provider too. And honestly, none of this would have saved Salesloft.

Gmail reported errors for emails it had actually delivered, so anyone woul...

Source: Hacker News · Summarized by HeadlinesBriefing