<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-build-an-event-driven-lead-scoring-pipeline-with-node-js-and-postgresql-wtsvomut8" -->

---
title: How to Build an Event-Driven Lead Scoring Pipeline with...
description: A hands-on tutorial builds a Node.js and PostgreSQL service that scores leads from product events like trial starts, project creation, and demo requests. It...
canonical: https://daily.dev/posts/how-to-build-an-event-driven-lead-scoring-pipeline-with-node-js-and-postgresql-wtsvomut8
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Build an Event-Driven Lead Scoring Pipeline with Node.js and PostgreSQL | daily.dev
og:description: A hands-on tutorial builds a Node.js and PostgreSQL service that scores leads from product events like trial starts, project creation, and demo requests. It...
og:url: https://daily.dev/posts/how-to-build-an-event-driven-lead-scoring-pipeline-with-node-js-and-postgresql-wtsvomut8
og:image: https://api.daily.dev/og/posts/WTSvoMuT8.png
og:image:alt: How to Build an Event-Driven Lead Scoring Pipeline with Node.js and PostgreSQL
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Build an Event-Driven Lead Scoring Pipeline with Node.js and PostgreSQL

**[SitePoint](https://daily.dev/sources/sitepoint)** · 18 min read · 0 upvotes · 0 comments

## Summary

A hands-on tutorial builds a Node.js and PostgreSQL service that scores leads from product events like trial starts, project creation, and demo requests. It covers idempotent webhook processing, HMAC-SHA256 signature verification, row-level locking with FOR UPDATE, a transactional outbox pattern for reliable handoff to sales/CRM systems, and integration test scenarios for concurrency and failure cases. Uses Node.js 24, PostgreSQL 17, Express 5, and pg 8.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.sitepoint.com/how-to-build-an-event-driven-lead-scoring-pipeline-with-node-js-and-postgresql>

## Questions this post answers

### How do I prevent a webhook from being processed twice in Node.js and PostgreSQL?

Use a globally unique event ID stored with a primary key or unique constraint, then insert with ON CONFLICT (id) DO NOTHING inside a database transaction. If the insert affects zero rows, treat it as a duplicate and compare the stored event against the incoming payload; mismatched data should return an HTTP 409 rather than silently succeeding.

_daily.dev surfaces engineering deep dives like this for teams hardening webhook processing pipelines._

### How do I keep a scoring update and an outbox message consistent in PostgreSQL?

Wrap the event insert, the lead score update, and the outbox row insert inside a single database transaction so they commit or roll back together. Lock the lead row with SELECT ... FOR UPDATE before reading its score to serialize concurrent writers, and use Read Committed isolation so subsequent queries see prior committed changes within the same transaction.

_developers designing outbox patterns can track transactional consistency techniques like this on daily.dev._

### How do I verify a webhook signature securely in Node.js using HMAC-SHA256?

Sign the delivery timestamp concatenated with a period and the raw request body using HMAC-SHA256, then compare it with Node's timingSafeEqual after validating that the timestamp and signature match expected formats and that the delivery is within a five-minute window. Buffers must be equal length before calling timingSafeEqual, since it throws otherwise.

_daily.dev helps developers stay sharp on webhook signature verification patterns like this one._

## Similar posts on daily.dev

- [How to Build a PostgreSQL-to-LLM Analytics Pipeline with Node.js](https://daily.dev/posts/how-to-build-a-postgresql-to-llm-analytics-pipeline-with-node-js-7chyuxlhx) · SitePoint · 1 upvotes · 0 comments
- [How to Build a Complete SaaS Payment Flow with Stripe, Webhooks, and Email Notifications](https://daily.dev/posts/how-to-build-a-complete-saas-payment-flow-with-stripe-webhooks-and-email-notifications-5a7lpzzjr) · freeCodeCamp · 1 upvotes · 0 comments
- [Scaling AI-Driven Marketing Processes with PostgreSQL](https://daily.dev/posts/scaling-ai-driven-marketing-processes-with-postgresql-xch1znvbu) · CYBERTEC PostgreSQL · 0 upvotes · 0 comments
- [Stripe Webhooks in Production: A 2026 Developer Guide](https://daily.dev/posts/stripe-webhooks-in-production-a-2026-developer-guide-k2uxwifgt) · Alex CloudStar · 0 upvotes · 0 comments
- [All you need is PostgreSQL](https://daily.dev/posts/all-you-need-is-postgresql-atlaui5pf) · Lobsters · 3 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#nodejs](https://daily.dev/tags/nodejs), [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/how-to-build-an-event-driven-lead-scoring-pipeline-with-node-js-and-postgresql-wtsvomut8)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Build an Event-Driven Lead Scoring Pipeline with Node.js and PostgreSQL","url":"https://daily.dev/posts/how-to-build-an-event-driven-lead-scoring-pipeline-with-node-js-and-postgresql-wtsvomut8","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-build-an-event-driven-lead-scoring-pipeline-with-node-js-and-postgresql-wtsvomut8"},"datePublished":"2026-09-17T15:23:42.381Z","dateModified":"2026-09-17T17:50:09.158Z","description":"A hands-on tutorial builds a Node.js and PostgreSQL service that scores leads from product events like trial starts, project creation, and demo requests. It...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/21bf148200f892953b28cb5c520d443b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/21bf148200f892953b28cb5c520d443b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"SitePoint","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SitePoint","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/sitepoint","url":"https://daily.dev/sources/sitepoint"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-build-an-event-driven-lead-scoring-pipeline-with-node-js-and-postgresql-wtsvomut8","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"architecture,nodejs,postgresql","timeRequired":"PT18M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SitePoint","item":"https://daily.dev/sources/sitepoint"},{"@type":"ListItem","position":3,"name":"How to Build an Event-Driven Lead Scoring Pipeline with Node.js and PostgreSQL"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-build-an-event-driven-lead-scoring-pipeline-with-node-js-and-postgresql-wtsvomut8#faq","mainEntity":[{"@type":"Question","name":"How do I prevent a webhook from being processed twice in Node.js and PostgreSQL?","acceptedAnswer":{"@type":"Answer","text":"Use a globally unique event ID stored with a primary key or unique constraint, then insert with ON CONFLICT (id) DO NOTHING inside a database transaction. If the insert affects zero rows, treat it as a duplicate and compare the stored event against the incoming payload; mismatched data should return an HTTP 409 rather than silently succeeding. daily.dev surfaces engineering deep dives like this for teams hardening webhook processing pipelines."}},{"@type":"Question","name":"How do I keep a scoring update and an outbox message consistent in PostgreSQL?","acceptedAnswer":{"@type":"Answer","text":"Wrap the event insert, the lead score update, and the outbox row insert inside a single database transaction so they commit or roll back together. Lock the lead row with SELECT ... FOR UPDATE before reading its score to serialize concurrent writers, and use Read Committed isolation so subsequent queries see prior committed changes within the same transaction. developers designing outbox patterns can track transactional consistency techniques like this on daily.dev."}},{"@type":"Question","name":"How do I verify a webhook signature securely in Node.js using HMAC-SHA256?","acceptedAnswer":{"@type":"Answer","text":"Sign the delivery timestamp concatenated with a period and the raw request body using HMAC-SHA256, then compare it with Node's timingSafeEqual after validating that the timestamp and signature match expected formats and that the delivery is within a five-minute window. Buffers must be equal length before calling timingSafeEqual, since it throws otherwise. daily.dev helps developers stay sharp on webhook signature verification patterns like this one."}}]}
```

