SDR lead scoring and routing
- NestJS
- Postgres
- BullMQ
- Redis
- HubSpot
- Slack
The problem
Outbound campaigns produced thousands of opens, clicks, bounces and replies a day. Without a score, SDRs worked leads in arrival order or by gut feel. A reply asking for a call could wait while someone chased a single open that a mail scanner may have triggered.
Constraints
- Opens lie. Security scanners open emails seconds after they're sent.
- Intent fades. A click from three weeks ago means less than one today.
- SDRs aren't always in. There are sick days, working hours, time zones and capacity caps.
- Hot leads can't wait. The hottest tier has a one-hour SLA.
- People need to see why. Sales ops won't trust a score it can't explain.
How it works
The sequencer sends each event to an endpoint, which queues it and returns at once. A worker runs it through 11 stages:
- Suppression. Leads that already opted out stop here.
- Persist. The raw event is stored before any filtering.
- Dedup. Repeat deliveries are flagged and stopped.
- Bot filter. An open within 30 seconds of the send counts as a scanner.
- Reply classification. An LLM (
gpt-5.4-nano) sorts replies into 8 categories. If its confidence is below 0.7, the reply is flagged for human review. - Segment. An LLM maps the business to an SDR segment, which must exactly match a row in a segments table. A "not interested" or hostile reply suppresses the lead and blocks it in the sequencer.
- Score. Decay, plus points, plus bonus (below).
- Route. Only WARM leads and hotter move on.
- Assign. The lead goes to an SDR who is present today.
- Call brief. An LLM writes an opener, key points, things not to say and a next step, with a template as fallback.
- Dispatch. A HubSpot task is created, due at the SLA, and Slack sends an alert.
Each sequencer event is queued, filtered for duplicates and scanner opens, classified and scored; leads that reach WARM are assigned to a present, eligible SDR or held in a score-ordered backlog, then get an AI call brief, a HubSpot task and a Slack alert.
Assignment. A lead with an open task stays with its SDR. Otherwise the HubSpot contact owner is preferred. Candidates come from today's attendance table and must be inside their working hours, matched to the segment and under their daily cap. They are sorted by least-recently assigned, which gives a round-robin. Each claim takes a per-SDR lock and counts open tasks live, so two workers can't over-fill one SDR. HOT and ON_FIRE leads skip every eligibility rule, and if nobody is in, they go to a designated SDR. Everyone else waits in a backlog ordered by score, which drains whenever a task is completed and again at the start of each day. When an SDR is marked absent, their open leads go back to the backlog with their scores intact.
The score. Each lead has one score per campaign.
- Decay: score × e^(−0.003 × hours), a half-life of about 9.6 days. A quiet day multiplies the score by 0.93, a week by 0.60.
- Points: an open is worth +13 (first two only), a click +26 (first only), an interested reply +46, a warm or neutral reply +20, and a referral or "later" reply +5. A bounce is −50, "not interested" −30, and a hostile reply or unsubscribe −100.
- Compound bonus: 2+ opens and a click earn 10, and a positive reply raises that to 20. Another 15 is added if the reply came within 24 hours of the last engagement. The bonus is capped at 25, once per lead per campaign.
| Score | Temperature | Task SLA | Routed? |
|---|---|---|---|
| 75+ | ON_FIRE | 1 h | yes, skips eligibility |
| 45+ | HOT | 4 h | yes, skips eligibility |
| 25+ | WARM | 24 h | yes, normal rules |
| 10+ | WARMING | none | no |
| below 10 | COLD | none | no |
Worked examples, with no decay between events:
- 2 opens: 13 + 13 = 26, WARM.
- 2 opens and a click: 26 + 26 + 10 = 62, HOT.
- One interested reply: 46, HOT.
- 2 opens, a click, then an interested reply within 24 hours: 26 + 26 + 46 + 25 = 113, ON_FIRE.
- A lead at 30 that bounces: 30 − 50, clamped to 0, COLD.
Try the scoring yourself below.
Receipts
- Before
- Leads worked in arrival order or by gut feel
- Action
- 11-stage pipeline: filter, classify, score, route
- After
- WARM+ leads assigned with 1 h / 4 h / 24 h SLAs
- Verified by
- Audit row with a written reason for every scored event
A typical audit reason: REPLIED (INTERESTED): +46 pts; compound bonus: +15 pts; time decay applied: 62.00 → 58.31.
What broke, and what I changed
Two early decisions shaped everything else.
- Persist every raw event before filtering. Bot opens and duplicates are stored with a flag, not discarded. The bot filter needs the last "sent" time to judge an open, the start-of-day flush reads stored payloads to fill in HubSpot contacts, and analytics see every event. Events with no email are stopped at the door, since otherwise they would pile into one shared score row.
- Make the score explainable. Every scored event records its points, bonus, new total and a plain-English reason. Sales ops can answer "why is this lead HOT?" from one table, and a failed audit write never blocks scoring.
What I'd do next
- Unit-test the scoring functions. Decay, points, bonus and temperature are pure and need no database, so they're the cheapest place to start.
- Feed human corrections back. Reply classifications have a column for a human-corrected category. Reading it back would give the classifier a labeled eval set.