Skip to content
All writing

Zero unsubscribes was a counting bug, not a clean campaign

My lead email campaign reported zero unsubscribes. I wanted to believe that meant the email was good. It meant a counter was reading a table that nothing had written to.

The shape

The masterclass at masterclass.coachesdev.com is the CrossFit coaching prep platform I built with Pat Barber. Behind the product sits a plainer thing I also built: a lead email system that sends nurture campaigns, then tracks every delivery, open, bounce, and unsubscribe. It runs on Node and Express with Postgres through Drizzle, and SendGrid does the actual sending. Consent for a person lives in 3 places: the contact record, the per-send recipient row, and an append-only tracking-event log. The campaign's unsubscribe number is counted off the recipient rows. This week I found it reading 0 while 1 real person had opted out, traced it to a single handler, and shipped the fix to production.

old: my own unsubscribe link updated the contact record only, the analytics counted a different table, and one real opt-out read as zero.
new: every unsubscribe path marks the recipient row, logs the event, and refreshes the count, so the number matches what the person did.

Two doors to unsubscribe, one of them silent

There are two ways a person leaves a campaign. SendGrid has its own unsubscribe handling, and when someone uses it, SendGrid posts an event back to my webhook. That path was correct: it marked the recipient row as unsubscribed, flipped the contact record, and refreshed the campaign analytics. The other door is my own unsubscribe link, the one in the footer of the email that hits my endpoint directly. That path did less than I thought. It updated the contact record, so the person was suppressed and would never get another send, but it never went back to mark the recipient row for the campaign they were already part of. Same intent, two code paths, and only one of them touched the table the report counts.

The count was reading a table nobody wrote to

The campaign's unsubscribe number is a single query, and it counts recipient rows whose status is unsubscribed. When the opt-out came through SendGrid, that row got marked and the number moved. When it came through my own link, the row stayed exactly as it was on the day the email went out, and the number stayed at zero. Nothing was broken about the suppression. The person was gone, correctly, and safe from any future send. What was broken was my view of the campaign. A zero sat in the unsubscribe column, and a zero in that column reads as "nobody minded," which is the most flattering and least trustworthy thing a compliance metric can say.

Fixing the handler did not fix the number

The patch was small. My unsubscribe link now does what SendGrid's path already did: it marks every recipient row for that person as unsubscribed, skips the rows that already bounced or failed so I do not overwrite a real delivery outcome, writes a manual-unsubscribe event into the tracking log, and re-runs the campaign analytics. But shipping that only fixed the next person to leave. The one who had already left still counted as zero, because the fix changed the writer, not the history. So I backfilled that one record by hand, marked the old recipient row, re-ran the analytics, and watched the column finally turn to 1. The number was small. The point was that it was now true.

What I learned

When two paths do the same thing, they have to write the same rows. SendGrid's unsubscribe and my own unsubscribe link both meant "this person is out," but only one of them marked the recipient row, so the campaign's number depended on which door a person happened to use. If more than one path can produce a state, give them the same checklist of writes, or one of them will quietly skip the table your report is counting on.

Distrust a compliance number that reads zero. A high complaint rate screams and gets looked at. A zero looks like a win, so nobody opens the query behind it. On a real send to real people, zero unsubscribes is far more likely a counter reading an empty table than an email everyone loved. Treat a suspiciously clean consent number as a bug until you have traced the write that is supposed to move it.

Fixing the writer does not fix the past. Patching the handler corrected every opt-out from that moment forward, but the person who had already unsubscribed still read as zero, because the count lives in rows that were written before the fix existed. A counter fix that ignores the existing records leaves the past lying while the future tells the truth. Backfill the history, then check the number.

If you are running your own email and you are not certain that every path to "this person opted out" writes to the same place your reports read from, that is the kind of plumbing Autosterea builds.

First published on ravikantdewangan.com.

Tell us what eats your week.

A free 20-minute call. We'll show you what we would take off your plate.

Book a call