RetainIQ is a real-time customer lifecycle intelligence engine. It monitors every customer's purchase behaviour against their personal repurchase pattern, calculates a dynamic churn score daily, detects the exact moment a customer crosses into danger, and automatically deploys a personalised retention email matched to their specific lifecycle stage.

The system runs on two parallel tracks: an event-driven track that responds to individual customer actions in real time, and a nightly intelligence track that rescores every customer in the database and catches anyone who drifted without triggering an explicit event.


The Five Lifecycle Stages

RetainIQ tracks every customer across five stages, calculated dynamically based on their individual repurchase interval:

Stage Definition Churn Score Range
NEW First purchase within the last 14 days 1–10
ACTIVE Last order within 1.5× their avg repurchase cycle 1–20
AT_RISK Last order between 1.5× and 2.5× their avg cycle 60–82
LAPSED Last order between 2.5× and 4× their avg cycle 85–94
CHURNED Last order beyond 4× their avg cycle 95–99

Four Layers of the System


The Full Flow

Customer Event → Webhook → Validate → Fetch Customer → Calculate Stage & Score → Update Supabase → Generate Email → Send via Brevo → Log Intervention → Slack Alert → Dashboard Refresh


Technical Stack

Tool Role
n8n Two-workflow orchestration
Supabase PostgreSQL database — customers, orders, interventions, products tables
Brevo Transactional email delivery
Slack Webhooks Real-time team notifications
Cloudflare Zero Trust Persistent webhook tunnel uptime
Oracle Cloud Linux VM Zero-cost cloud hosting
Lovable Two frontend applications
React Frontend framework

Workflow 1 latency: Under 3 seconds from webhook to Supabase update.

Workflow 2 bulk processing: Under 15 seconds for 26 customers.