Usage-based & metered billing database schema

Metered billing modelled properly: price plans built from components, tiered and volume and graduated pricing as rows, meters and raw usage, per-period aggregation, invoices with line items, prepaid credits, proration and dunning.

Usage Based Billing ER diagram

Usage-based & metered billing database schema n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 customers idBIGINT external_refVARCHAR nameVARCHAR emailVARCHAR currency_codeCHAR tax_idVARCHAR balance_minorBIGINT payment_provider_…VARCHAR created_atTIMESTAMP meters idBIGINT keyVARCHAR nameVARCHAR unit_labelVARCHAR aggregationVARCHAR roundingVARCHAR created_atTIMESTAMP price_plans idBIGINT codeVARCHAR nameVARCHAR currency_codeCHAR billing_intervalVARCHAR versionINTEGER is_publicBOOLEAN effective_fromTIMESTAMP archived_atTIMESTAMP plan_components idBIGINT plan_idBIGINT meter_idBIGINT nameVARCHAR charge_typeVARCHAR tier_modeVARCHAR unit_amount_minorBIGINT flat_amount_minorBIGINT package_sizeINTEGER included_unitsDECIMAL proration_modeVARCHAR plan_tiers idBIGINT component_idBIGINT tier_indexSMALLINT up_to_unitsDECIMAL unit_amount_minorBIGINT flat_amount_minorBIGINT subscriptions idBIGINT customer_idBIGINT plan_idBIGINT statusVARCHAR quantityINTEGER billing_anchor_daySMALLINT current_period_st…TIMESTAMP current_period_endTIMESTAMP started_atTIMESTAMP canceled_atTIMESTAMP ended_atTIMESTAMP subscription_changes idBIGINT subscription_idBIGINT from_plan_idBIGINT to_plan_idBIGINT from_quantityINTEGER to_quantityINTEGER change_typeVARCHAR effective_atTIMESTAMP proration_credit_…BIGINT proration_charge_…BIGINT created_atTIMESTAMP usage_records idBIGINT subscription_idBIGINT meter_idBIGINT quantityDECIMAL occurred_atTIMESTAMP idempotency_keyVARCHAR propertiesJSONB usage_aggregates idBIGINT subscription_idBIGINT meter_idBIGINT period_startTIMESTAMP period_endTIMESTAMP quantityDECIMAL billable_quantityDECIMAL is_finalBOOLEAN computed_atTIMESTAMP invoices idBIGINT customer_idBIGINT subscription_idBIGINT numberVARCHAR statusVARCHAR currency_codeCHAR period_startTIMESTAMP period_endTIMESTAMP subtotal_minorBIGINT credit_applied_mi…BIGINT tax_minorBIGINT total_minorBIGINT amount_paid_minorBIGINT due_atTIMESTAMP finalized_atTIMESTAMP paid_atTIMESTAMP invoice_line_items idBIGINT invoice_idBIGINT plan_component_idBIGINT meter_idBIGINT credit_grant_idBIGINT line_typeVARCHAR descriptionVARCHAR tier_indexSMALLINT quantityDECIMAL unit_amount_minorBIGINT amount_minorBIGINT period_startTIMESTAMP period_endTIMESTAMP credit_grants idBIGINT customer_idBIGINT amount_minorBIGINT remaining_minorBIGINT currency_codeCHAR reasonVARCHAR prioritySMALLINT effective_atTIMESTAMP expires_atTIMESTAMP dunning_attempts idBIGINT invoice_idBIGINT attempt_numberSMALLINT scheduled_atTIMESTAMP attempted_atTIMESTAMP outcomeVARCHAR failure_codeVARCHAR next_actionVARCHAR

Related database schemas