
I Built a Usage-Based Billing Engine From Scratch — Here's How It Works
I spent the last few weeks building MeterFlow — a usage-based billing engine that handles event ingestion, deduplication, aggregation, fraud detection, tiered pricing, and Stripe invoice generation. This post walks through the technical decisions behind each component, including how the architecture maps to a production AWS deployment. Why Build This? I work on subscription infrastructure at my day job — Stripe integrations, webhook handlers, entitlement APIs. But I wanted to understand how billing platforms like Lago, Metronome, and Stripe Billing work internally . Not just calling the API, but building the metering and pricing layer myself. MeterFlow covers the full lifecycle: Events → Dedup → Store → Aggregate → Price → Invoice → Stripe Stack: TypeScript, Fastify, Redis, ClickHouse, MinIO (S3-compatible), Docker Compose. Architecture ┌──────────────┐ │ Fastify │ │ API │ │ │ │ POST /events │──┬──────────────────────┐ │ GET /usage │ │ │ └───────────────┘ │ │ ▼ ▼ ┌──────────────┐ ┌────
Continue reading on Dev.to
Opens in a new tab

