⚒️ Sync PostgreSQL customer changes with HubSpot, Mailchimp, and Slack
⚡ 1 views · ⚒️ Engineering
Description
Quick overview
This workflow captures INSERT/UPDATE/DELETE changes from PostgreSQL via an outbox table and syncs them to HubSpot, Mailchimp, and Slack on a 1-minute schedule, with leasing, retries with exponential backoff, dead-letter alerting, and a webhook endpoint to requeue failed events.
How it works
- Runs every minute and loads sync settings such as batch size, enabled targets, and retry/backoff limits.
- Claims a batch of eligible rows from the PostgreSQL
cdc_outboxtable using a lease so multiple workers can process safely while preserving per-row ordering. - Expands each claimed change into one delivery task per enabled target (HubSpot upsert, Mailchimp member sync/unsubscribe, and/or Slack notification), skipping targets that already succeeded.
- Sends each task sequentially to HubSpot, Mailchimp, or Slack via HTTP requests and records whether the call succeeded, failed temporarily, or failed permanently.
- Updates each outbox event in PostgreSQL as delivered, scheduled for retry with exponential backoff, or dead-lettered, and posts a Slack alert when any events become dead.
- Accepts
POST /cdc-requeuerequests to reset dead-lettered event IDs back to pending in PostgreSQL and returns how many were requeued.
Setup
- Add PostgreSQL credentials, update the source table name in the setup query (default
public.customers), and run the manual setup once to createcdc_outboxplus the capture function and trigger. - Create HubSpot authentication using HTTP Header Auth (
Authorization: Bearer <token>) and Mailchimp authentication using HTTP Basic Auth (any username, API key as password). - Set your Mailchimp data center and list ID, and provide Slack incoming webhook URLs for both change notifications and dead-letter alerts.
- Adjust the field mapping used for HubSpot and Mailchimp payloads (for example
email,first_name,last_name,phone,company) to match your PostgreSQL row schema. - Copy the workflow’s
cdc-requeuewebhook URL and use it to requeue dead-letter IDs after fixing the underlying error.
🔗 Nodes Used
HTTP Request, Postgres, Webhook, Schedule Trigger
📥 Import
Download workflow.json and import into n8n:
Workflow menu → Import from File