Inspiration

SaaS companies are losing 30-50% of preventable churn because they discover problems after customers cancel. By the time a customer churns, it's too late. We wanted to flip the script: predict churn before it happens and catch customers at risk 30-60 days in advance.

The problem is clear from the data:

  • 5-7% average monthly churn rate for SaaS companies without health monitoring
  • 0 days detection lead time — most discover churn AFTER cancellation
  • 30-50% of churn could be prevented with early intervention
  • $100K/month revenue at risk for a $1M ARR company at 10% churn rate

We needed a platform that would give CS teams real-time visibility into customer health globally.


What it does

ChurnGuard is an AI-powered customer health intelligence platform that:

  1. Real-Time Health Scoring — Tracks 15+ behavioral signals (logins, feature usage, support tickets, inactive days) and updates a 0-100 health score every time a customer event occurs, globally consistent via Aurora DSQL

  2. Predictive Churn Risk — Uses machine learning to identify customers at risk 30-60 days before they cancel based on health trends and behavioral anomalies

  3. Automated Playbooks — When health drops or churn risk increases, automatically:

    • Send Slack alerts to CSMs
    • Trigger email sequences
    • Assign renewal tasks
    • Log events to dashboards
  4. Live Dashboard — Real-time visualization of:

    • Total MRR and MRR at risk
    • Customer health scores by segment
    • Churn probability rankings
    • Revenue impact by customer
  5. Event-Driven API — REST API + JavaScript SDK for tracking any customer event (login, feature_used, support_ticket, etc.)


How we built it

Technology Stack:

  • Frontend: Next.js 14 (App Router), React 18, TypeScript, Tailwind CSS, Framer Motion, Lucide Icons
  • Backend: Next.js API Routes (serverless)
  • Database: Aurora DSQL (serverless PostgreSQL with global consistency) in eu-central-1
  • AI/ML: Amazon Bedrock (Claude 3 Haiku) for churn insights and analysis
  • Authentication: NextAuth.js v4 with Google OAuth (optional)
  • Hosting: Vercel Edge Network (sub-100ms response times)
  • Infrastructure: AWS CloudFormation, EventBridge, Lambda, Secrets Manager
  • Monitoring: CloudWatch Dashboards

Architecture:

Client (Browser) 
  → Vercel Edge (API Routes)
    → Aurora DSQL (Multi-region, strong consistency)
    → Amazon Bedrock (Claude AI analysis)
    → AWS Secrets Manager (Credentials)
    → EventBridge (15-min batch health score refresh)
    → Lambda (Playbook execution, Slack alerts)

Key Implementation Details:

  • Built multi-tenant B2B SaaS with 7 database tables: tenants, customers, events, health scores, playbooks, executions
  • Custom calculate_health_score() PostgreSQL function analyzes 4 signals: login frequency, feature adoption, support interactions, inactivity duration
  • Lazy-loaded database connections to avoid build-time environment variable requirements
  • Live demo dashboard queries real customer data from Aurora DSQL, refreshing every 10 seconds
  • 27 optimized indexes for sub-100ms queries across tenant hierarchies

Challenges we ran into

  1. Aurora DSQL Endpoint Format — Initially used wrong DSQL endpoint format; had to switch to RDS cluster endpoint with correct PostgreSQL driver
  2. Database Connection at Build Time — DATABASE_URL required at npm build time; refactored to lazy-loaded getDb() function
  3. Missing PostCSS Config — Tailwind CSS not processing during Vercel deployment; created postcss.config.js to fix CSS styling
  4. IAM Permissions — CloudFormation deployment failed due to missing permissions; updated IAM policy with character-optimized rules
  5. TypeScript Constraints — NextAuth authOptions couldn't be exported from route handler due to index signature constraints; moved to separate lib file
  6. pgcrypto Extension — UUID generation failed until pgcrypto extension was explicitly created in database initialization
  7. Network Isolation — Aurora DSQL cluster required proper VPC security group and subnet configuration for Vercel connectivity
  8. Quoted SQL in PowerShell — Complex nested quotes in inline Python execution; worked around with separate Python script file

Accomplishments that we're proud of

Complete Production B2B SaaS deployed to Vercel + AWS in single day ✅ Real-time Health Scoring with 250+ lines of SQL, 7 tables, 27 indexes, global consistency via Aurora DSQL ✅ AI-Powered Insights integrated with Amazon Bedrock Claude 3 Haiku for churn analysis ✅ Live Demo Dashboard pulling real customer data from database, updating every 10 seconds ✅ Full Authentication with NextAuth.js, Google OAuth, JWT sessions (optional for MVP) ✅ Serverless Architecture — zero ops overhead, auto-scaling, pay-per-event pricing ✅ Professional UI with dark theme, gradients, animations, responsive design ✅ Comprehensive Docs with API reference, SDK examples (JavaScript, Python) ✅ Infrastructure as Code — CloudFormation template for reproducible deployments ✅ Multi-tenant from Day 1 — full tenant isolation, API key authentication, role-based access


What we learned

  1. Aurora DSQL is Powerful — Active-active global replication + strong consistency is game-changing for distributed SaaS, no eventual consistency compromises
  2. Serverless Scales — Vercel Edge + Lambda can handle thousands of concurrent customers with zero server management
  3. PostCSS Matters — CSS frameworks need proper build pipeline; one missing config file breaks entire styling
  4. Lazy Loading Wins — Deferring database connections to runtime instead of build time gives more flexibility for cloud deployments
  5. Schema Design is Critical — Well-indexed tables (27 indexes!) make the difference between fast dashboards and slow queries
  6. Event-Driven is Essential — EventBridge + Lambda for asynchronous playbook execution scales better than synchronous API calls
  7. AI Integration is Simple — Bedrock makes it trivial to add Claude AI analysis without managing models or infrastructure
  8. MVP is Real — Customer health scoring + Slack alerts solves 80% of churn problems; advanced features (playbooks, automated actions) are 20%

What's next for ChurnGuard

Short Term (Next 2-4 Weeks):

  • ✅ Enable Google OAuth for production logins
  • ✅ Create dashboard page with authenticated access
  • ✅ Add CSV export for customer health scores
  • ✅ Set up Slack OAuth for app marketplace
  • ✅ Create onboarding flow for first tenant signup

Medium Term (Next 1-2 Months):

  • 📊 Advanced analytics (cohort analysis, churn by segment, LTV prediction)
  • 🎯 Custom playbook builder UI with drag-and-drop triggers/actions
  • 📧 Email template editor for automated CSM sequences
  • 🔄 Webhook support for integration with Salesforce, HubSpot
  • 📈 Revenue impact calculator (shows $ saved per customer at risk)

Long Term (Next 3-6 Months):

  • 🤖 Fine-tuned ML models on customer behavioral data for better accuracy
  • 🌍 Multi-region failover (replicate Aurora DSQL to us-east-1, ap-southeast-1)
  • 💰 Stripe integration for billing and metered usage
  • 🏢 Enterprise features (SSO/SAML, audit logs, custom roles, SLA guarantees)
  • 📱 Mobile app for CSMs to view alerts on-the-go

Built With

  • 27
  • amazon-bedrock
  • anthropic
  • api
  • aws-(aurora-dsql
  • aws-aurora-dsql-(serverless-postgresql
  • bedrock
  • claude-3-haiku-(cross-region-inference)
  • cloudformation
  • cloudwatch)
  • eu-central-1)
  • eventbridge
  • framer-motion-11.3
  • github
  • google-oauth-2.0
  • indexes
  • jwt
  • lambda
  • lucide-icons
  • next.js-14.2.5
  • next.js-api-routes
  • nextauth.js
  • node.js
  • optimized
  • pgcrypto-extension
  • postgres.js-3.4.4-(connection-pooling)
  • react-18.3.1
  • recharts
  • secrets-manager
  • tailwind-css-3.4
  • typescript-5.5
  • vercel-edge
  • zod-validation
Share this project:

Updates