Subscription Website with On-Device ML & Fault-Tolerant Billing

Objective

The brief was demanding: a consumer platform that had to acquire users from cold paid traffic, monetize within minutes, and hold recurring revenue, all while running non-trivial machine learning and astronomical computation in production. The engineering objective was to deliver this as one coherent, fault-tolerant system rather than a stack of disconnected integrations. Concretely, that meant solving four engineering problems that most teams underestimate: A correct billing state machine: a single, authoritative source of truth for entitlement that stays consistent across two payment providers, out-of-order webhooks, and at-least-once event delivery. Exactly-once side effects: analytics, conversion pixels, and lifecycle email that never double-fire when a webhook is inevitably retried. On-device inference: real ML in the browser, with no server GPU and no sensitive image ever leaving the client. Instrumentation as a first-class feature: a data model designed so the funnel is measurable and A/B-testable from day one, not retrofitted later.

Solution

We built the platform as a single Next.js application, with a clean split between the marketing funnel and the transactional core. Six engineering decisions carried the project: One source of truth for access. A single entitlement table, written only by payment webhooks and enforced on the server, decides who's a subscriber, guarded against duplicate and out-of-order events, and shared by both payment providers. Everything fires exactly once. Conversion tracking, lifecycle email, and asset delivery are protected by dedup ledgers, so retried webhooks never double-charge, double-email, or double-count. Machine learning in the browser. The palm scanner runs a computer-vision model fully on-device via ONNX Runtime (WebAssembly). No inference server, no GPU cost, and no user images ever leaving the client. Real computation, not canned content. Birth charts and astrocartography are calculated from live astronomical data rather than pulled from static text. No lost customers. Anonymous visitors are tracked from the first click and merged into their account at signup, so one person is never split into two profiles or two billing records. Built to be measured. Every funnel step is logged with stable, versioned keys, so drop-off is visible per step and experiments stay comparable over time.

Results

The deliverable is a production system whose correctness holds under real load and real failure modes: Consistent entitlement: access stays correct across retried and out-of-order payment events and across multiple payment providers, driven by one authoritative source with server-enforced gating. Exactly-once side effects: conversion tracking and lifecycle messaging stay accurate through webhook retries, so ad platforms and reporting optimize on truth. On-device, zero-cost ML: image analysis runs entirely client-side, eliminating GPU inference cost and keeping user images off our servers. Automated revenue recovery: a grace-and-retry mechanism reclaims subscriptions that would otherwise churn on a transient card decline, with no manual intervention. A measurable funnel: versioned, per-step instrumentation makes drop-off visible and experiments comparable, delivered as reusable reporting. Security by default: row-level security on all user data, isolation of privileged access, and server-side session handling.

Technologies used

TypeScript
Next.js 15
React 19
Tailwind CSS 4
Framer Motion
ONNX Runtime Web
WebAssembly
YOLO-pose model
stape
Google tag manager
react-simple-maps
Supabase
PostgreSQL
Row-Level Security
SSR auth sessions
SQL analytics views
Stripe
Revolut
Customer.io
Meta Conversions API
Vercel
Edge Middleware
Webhooks
Cron