
Building a Bulletproof Billing Engine
How bi-directional Stripe sync eliminated reconciliation errors entirely.
The Problem
The team managed subscriptions in Stripe, invoices in spreadsheets, and project status in Notion — three sources of truth that drifted constantly. Month-end reconciliation took 2–3 days and still produced errors.
The Approach
Built an idempotency layer that fingerprints each Stripe webhook event by type + resource ID. Duplicate webhooks are silently deduplicated. Out-of-order events are queued and replayed in correct sequence before state is committed.
Key Decision: Drizzle over Prisma
The billing queries involved complex JOINs across subscriptions, invoices, line items, and tax records. Prisma generated N+1 queries. Drizzle let us write optimised SQL directly — billing report generation dropped from 4s to 180ms.
Result
Zero billing discrepancies since launch. Month-end reconciliation dropped from 2–3 days to under 30 minutes. The team self-serves all financial reports without touching a spreadsheet.