HomeBlogHow to Add Usage-Based Pricing to...

Engineering Guide · 8 min read · October 29, 2026

How to Add Usage-Based Pricing to Your SaaS Product

Adding usage-based pricing to a SaaS product fails when teams simply increment a counter on a database row or fire synchronous billing API calls inside user requests. This guide covers idempotent event ledgers, low-latency quota checks, hybrid base-plus-usage models, and Stripe Billing reconciliation.

Author
Smit Desai
Published
October 29, 2026
Read time
8 min read
Topic
SaaS Engineering
Services
Custom Web · Mobile Apps · All Services

Flat-rate seat pricing stops aligning with your margins the moment your SaaS starts wrapping expensive external resources—LLM tokens, SMS deliveries, document OCR pages, or heavy background compute. One power user paying $49/month can quietly consume $180/month in API and server bills unless your pricing tracks consumption.

Adding usage-based pricing (or a hybrid base-plan + usage model) sounds straightforward in a pricing deck, yet the engineering implementation trips teams up in three places: double-counting retries, slowing down hot API paths, and losing customer trust over opaque invoices.


1. Choose the Right Usage Model for Your Cost Structure

Before designing tables or Stripe Billing meters, pick a billing pattern that matches both how customers buy and how your underlying costs behave.

Pricing Model How It Works Engineering Complexity Risk Profile
Included Quota + Soft Overage Base monthly fee includes N units; extra units billed at period end Medium (ledger + meter sync) Moderate; requires spend alerts
Prepaid Credit Wallet Customer buys credit packs upfront; actions deduct atomically Medium-High (atomic balance ledger) Lowest fraud / runaway cost risk
Pure Pay-As-You-Go Zero base fee; billed strictly per metered unit High (billing disputes, micro-invoices) High churn & card-failure friction
Tiered Usage Brackets Automatic upgrade or volume discount tiers per billing cycle Medium Predictable revenue, easy to explain

For most B2B SaaS founders transitioning off flat plans, Base Subscription + Included Quota + Prepaid Top-Ups (or Hard/Soft Caps) gives predictable recurring revenue while protecting gross margins.


2. Build an Append-Only, Idempotent Usage Ledger

Never model metered billing as UPDATE tenants SET api_calls = api_calls + 1. Under concurrent webhook or queue traffic, hot-row locking slows down unrelated requests, and if a retry happens—or a customer disputes an invoice—you have zero forensic trail showing which API call or background job generated the charge.

Append-Only Usage Events Schema

CREATE TABLE usage_events (
    id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    tenant_id BIGINT NOT NULL,
    metric_key VARCHAR(64) NOT NULL,
    quantity BIGINT NOT NULL CHECK (quantity > 0),
    idempotency_key VARCHAR(128) NOT NULL,
    source_type VARCHAR(64) NOT NULL,
    source_id VARCHAR(128) NOT NULL,
    billed_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    CONSTRAINT uq_usage_idempotency UNIQUE (tenant_id, idempotency_key)
);

CREATE INDEX idx_usage_unbilled
    ON usage_events (tenant_id, metric_key, created_at)
    WHERE billed_at IS NULL;

Every time a billable unit finishes—an invoice PDF rendered, a workflow step completed, or 1,000 tokens consumed—insert into usage_events with ON CONFLICT DO NOTHING. If a worker crashes and retries, the unique idempotency_key guarantees the customer is billed exactly once.


3. Separate Real-Time Quota Enforcement from Billing Sync

Customers hate surprise $900 bills, and founders hate absorbing $900 in third-party API costs from an unverified trial card. That means you need real-time quota checks on the request path, while keeping actual billing reporting asynchronous.

Fast Quota Guard Using Redis + Ledger Reconciliation

Do not run SELECT SUM(quantity) FROM usage_events on every incoming API request. Instead:

  1. Maintain a fast current-period counter in Redis (quota:{tenant_id}:{period}:{metric_key}) with atomic INCRBY / Lua check-and-increment logic.
  2. Emit the durable usage_events row asynchronously onto a queue (or batch insert every few seconds) so Postgres write load stays smooth.
  3. Run a periodic reconciliation job every 15 minutes (and on billing-cycle reset) that re-syncs Redis counters from the authoritative SQL ledger in case Redis restarts.
-- Atomic check-and-consume quota script in Redis
local current = tonumber(redis.call("GET", KEYS[1]) or "0")
local limit = tonumber(ARGV[1])
local cost = tonumber(ARGV[2])

if current + cost > limit then
    return -1
end

return redis.call("INCRBY", KEYS[1], cost)

If the script returns -1, fail fast with HTTP 429 (or 402 Payment Required) and a clear upgrade or top-up CTA—before you make the expensive downstream LLM or external API call.


4. Sync Aggregated Usage Cleanly to Your Billing Provider

Calling Stripe's meter event API synchronously inside every user request adds network latency and creates partial-failure states when a payment provider returns a 502 or rate-limits your server.

Batch and Forward Safely

  • Run a scheduled worker every 1–5 minutes that selects rows where billed_at IS NULL, aggregates or forwards them with deterministic event identifiers, and marks billed_at = NOW() inside a database transaction upon provider acknowledgment.
  • Align your internal usage periods with the customer's actual current_period_start and current_period_end synced from subscription webhooks—never assume everyone bills on the 1st of the month.
  • Handle mid-cycle upgrades and cancellations explicitly: when a tenant upgrades mid-month, preserve their prior usage ledger against the active billing period rather than wiping counters silently.

If you are connecting web checkout and subscription state back into separate client apps, our breakdown of web subscription flows for a mobile SaaS shows how to keep entitlement state authoritative in your own database.


5. Give Customers Transparent Usage Visibility Before Invoicing

Usage-based pricing reduces churn when customers understand what they are paying for—and spikes support tickets when they feel ambushed. Build three customer-facing safeguards right alongside the meter:

  • Live Usage Meter in Workspace Settings: Show included quota, current consumption, reset date, and projected overage in plain numbers.
  • Automated Threshold Alerts: Trigger webhooks and emails at 75%, 90%, and 100% of included allowance.
  • Configurable Spend Caps: Let workspace admins toggle between "Hard Stop at Limit" and "Allow Overage up to $X/month" so finance teams feel safe adopting your product.

As Martin Fowler's architectural guidance on SaaS systems highlights, tenant-level resource governance is both a technical stability control and a commercial trust mechanism.


Ship Reliable Usage-Based Billing Without Margin Leaks

Whether you are migrating an existing flat-rate product to hybrid seat + usage pricing or launching an AI-driven SaaS with credit wallets from day one, SmitDev builds production metering pipelines, Redis quota guards, and Stripe Billing integrations. Work directly with a senior engineer through Growth consulting or custom web application development at $55/day (8–9 hours) or $1,999/month dedicated delivery across 170+ shipped case studies.

Planning a pricing model transition? Let's review your metering architecture.

Written by Smit Desai · Principal Full-Stack & FDSE

8+ years shipping production systems · 171 case studies · 300+ WordPress servers managed for Finland partners.

Next Steps and Recommended Resources

Next Steps · Recommended Resources

Pillar 1 · Custom Web & SaaS

Custom Web Application Development

Production Laravel, Next.js, API, and multi-tenant SaaS systems engineered end to end at $55/day (8–9 hrs) or $1,999/mo.

Comparison · Buyer Guide

SmitDev vs Software Agencies

See side-by-side economics, senior code ownership, and onboarding speed vs traditional dev shops and marketplaces.

01 — Frequently asked questions

saas engineering

Why shouldn't we just increment a usage_count column on the tenant table?

Row-level counters create hot-row lock contention under concurrent API traffic, lose audit history when disputes happen, and make retries unsafe because a retried job can double-count usage.

Should we use prepaid credits or postpaid metered billing?

Prepaid credit packs protect startups against runaway compute or LLM costs and fraudulent cards, while postpaid metered billing works better for predictable enterprise accounts on verified payment methods. Many SaaS products use a hybrid: a monthly base plan with included quota plus prepaid top-ups or capped overages.

How do we prevent double-charging if a background job retries?

Attach a deterministic idempotency_key (for example, job_id or request_uuid) to every usage event row with a UNIQUE database constraint, and forward the same identifier to your billing provider's meter ingestion endpoint.

Can SmitDev add metered billing and quota enforcement to our existing SaaS?

Yes. SmitDev integrates usage metering pipelines, Stripe Billing Meters, and real-time quota guards at $55/day (8–9 hours) or $1,999/month dedicated delivery.

03 — Have an engineering need?

hire the right expertise

Let's talk tech.

Deciding between an embedded forward deployed engineer or a senior full stack developer? Share your technical context and timeline.

Solitaire Corporate Park, Makarba, Ahmedabad, Gujarat 380015, India · IST (UTC+5:30) · --:-- IST · Mon–Fri 09:00–18:00 IST · US & EU overlap daily

No newsletter, no CRM. Just a reply.