"Self-Hosted Stripe Billing Anomaly Detection with FastAPI"
Self-Hosted Stripe Billing Anomaly Detection with FastAPI Billing anomalies are silent killers. Failed charges that go unnoticed, webhook delivery gaps, sudden MRR drops at 2 AM — by the time you s...

Source: DEV Community
Self-Hosted Stripe Billing Anomaly Detection with FastAPI Billing anomalies are silent killers. Failed charges that go unnoticed, webhook delivery gaps, sudden MRR drops at 2 AM — by the time you see them in your dashboard, the customer is already gone. In this post I'll walk through BillingWatch — a self-hosted FastAPI service that listens to Stripe webhooks and fires alerts the moment something looks wrong. The Problem Stripe's own dashboard is reactive. You find out about billing issues after they've happened, often hours later. What you want is a system that: Detects failed charges in real time Spots unusual refund spikes Alerts when subscription churn exceeds baseline Runs on your infrastructure (no SaaS subscription) Architecture Stripe Webhooks → FastAPI /webhook → Anomaly Engine → Alerts (WhatsApp / Slack / email) The service is intentionally minimal — a single FastAPI app, SQLite for event storage, and a threshold-based anomaly detector. Webhook Handler from fastapi import Fas