Prompt
I’m building a SaaS with usage metering and subscriptions, what infra should I use?
Latest observation
For a SaaS with usage metering + subscriptions, I’d think about infra in 5 layers: product event capture, billing logic, data store, payment/subscription system, and ops/observability.
Recommended default stack
1) App + API
- Frontend: Next.js / React
- Backend: Node.js (NestJS/Fastify) or Python (FastAPI)
- Hosting: Vercel for frontend, or one cloud (AWS/GCP/Fly.io/Render) for both
2) Usage metering pipeline
You need a system that is:
- append-only
- idempotent
- audit-friendly
- cheap to ingest
Good pattern:
- App writes usage events to an event queue / log
- AWS: Kinesis or SQS
- GCP: Pub/Sub
- Simple/startup: Postgres table + background worker
- Worker aggregates usage into billing-friendly totals
If you’re early-stage, you can absolutely start with:
- Postgres + transactional writes
- daily aggregation jobs
- idempotency keys per event
That’s much simpler than introducing Kafka too early.
3) Billing/subscriptions
Use a dedicated billing provider:
- Stripe Billing is the default choice for most SaaS
- It handles:
- subscriptions
- prorations
- invoices
- coupons/discounts
- metered billing
- dunning/payment retries
- tax add-ons
If you need usage-based billing:
- send Stripe metered usage records or
- compute usage yourself and invoice on a schedule
For most teams:
- Stripe + your own usage ledger is the right balance.
4) Database
Use Postgres as your source of truth:
- users
- orgs
- subscriptions
- plans
- usage events
- usage aggregates
- entitlements
Why Postgres:
- transactions
- strong consistency
- easy reporting
- good for billing workflows
If you expect very high usage-event volume:
- keep raw events in a log store/object storage
- keep aggregates in Postgres
5) Analytics / warehouse
For reporting and finance/reconciliation:
- BigQuery (GCP) or Snowflake
- or start with Postgres + dbt
- if very early: export to CSV / use Metabase on Postgres
6) Observability
You’ll want:
- Sentry for app errors
- OpenTelemetry + Grafana/Datadog for traces/metrics
- structured logging
- alerting on billing pipeline failures
A practical architecture
Early-stage, simplest reliable setup
- Next.js frontend
- API on one service
- Postgres
- Stripe Billing
- Redis for caching/queues if needed
- Background worker for aggregation
- S3/GCS for raw event archival
- Sentry for errors
This is probably the best “don’t overengineer it” setup.
More scalable setup
- API service
- event ingest endpoint
- queue/log: Kinesis/PubSub/SQS
- workers for aggregation
- Postgres for core app + billing state
- warehouse for analytics
- Stripe for invoicing/subscriptions
- object storage for immutable raw events
Key design principles
1) Keep a usage ledger
Store each billable event with:
- event_id
- customer/org_id
- metric name
- quantity
- timestamp
- idempotency key
- metadata
This gives you replayability and auditability.
2) Separate raw events from aggregates
- Raw events: immutable, append-only
- Aggregates: daily/monthly rollups for billing
3) Make billing idempotent
Every event should be safe to send/process twice without double-charging.
4) Handle entitlements separately
Don’t just ask “is subscription active?” Track:
- plan
- feature flags
- included quota
- overages
- trial status
- grace periods
5) Design for reconciliation
You need to compare:
- your internal usage totals
- Stripe usage/invoices
- payment status
Build vs buy
Buy
Use Stripe if you want:
- subscriptions
- metered billing
- invoicing
- tax handling
- less custom billing code
Build
Build your own metering if you need:
- complex custom pricing
- non-standard metrics
- very high-frequency events
- detailed audit/replay requirements
Usually the answer is:
- buy billing
- build metering/ledger
My recommendation by stage
If you’re pre-PMF
Use:
- Postgres
- Stripe
- Next.js
- one backend
- background jobs
- Sentry
Avoid Kafka, Snowflake, or custom billing engines.
If you’re scaling
Add:
- queue/event streaming
- warehouse
- dedicated billing worker
- analytics pipeline
- stronger reconciliation
If you want a concrete AWS version
- Frontend: Vercel or CloudFront/S3
- API: ECS/Fargate or App Runner
- DB: RDS Postgres
- Queue: SQS
- Worker: ECS/Fargate worker
- Object storage: S3
- Auth: Cognito/Auth0/Clerk
- Billing: Stripe
- Logs/metrics: CloudWatch + Sentry
Bottom line
If I were building this today, I’d start with:
- Stripe Billing
- Postgres
- append-only usage ledger
- background aggregation worker
- Next.js + a single backend
- Sentry
- optional Redis/SQS later
That gives you a solid, auditable billing system without premature complexity.
If you want, I can also give you:
- a reference architecture diagram
- a Postgres schema for metering/subscriptions
- a Stripe-based implementation plan