Web ·
Multi-Tenant Billing Platform
Designed and shipped a usage-metered billing system for a B2B SaaS, cutting invoice disputes by 70% and supporting 12k+ tenants on a single Laravel codebase.
Laravel React PostgreSQL Redis Stripe AWS
Problem
The client’s homegrown billing logic lived inside controllers, made flat-rate assumptions, and broke every time sales negotiated a custom plan. Finance spent days each month reconciling invoices by hand.
Architecture
I extracted billing into a dedicated domain layer with an append-only usage ledger. Metered events stream into Redis, roll up nightly into PostgreSQL, and feed a deterministic invoice builder.
// Every metered event is immutable; invoices are pure projections over the ledger.
UsageEvent::record($tenant, 'api.request', quantity: 1, occurredAt: now());
- Multi-tenancy: single database, row-level scoping with a global tenant guard.
- Idempotency: Stripe webhooks deduplicated by event id before mutating state.
- Auditability: invoices are reproducible from the ledger at any point in time.
Impact
- Invoice disputes down 70% quarter-over-quarter.
- Onboarding a custom plan went from a code deploy to a config row.
- Sustained 12,000+ active tenants with p95 invoice render under 400ms.