← All schemas
Schema Library

Stripe Billing Database Schema Diagram

This is a modeled Stripe billing schema, not Stripe's internal database. Customers own subscriptions and payment methods; subscriptions are composed of subscription items that reference prices; prices belong to products; invoices collect line items and link to payment intents. It is the shape you would build when syncing Stripe objects into your own database or designing a Stripe-like billing system from scratch.

Written by Varun Krishnan · Founder, dbdiagramr

Published · Updated

Source: Original design by dbdiagramr, modeled on the Stripe billing API

Tables
9
Core table
customers
Billing flow
Customer → Subscription → Invoice

Modeled billing schema based on the Stripe API, not Stripe's internal database.

Stripe does not publish its internal schema. Nested API objects are flattened (for example price.recurring.interval becomes recurring_interval), and _id columns represent API object references. Stripe API reference.

Stripe database schema diagram showing every table, column, and foreign key

Scroll horizontally to see the full diagram. Click it to open at full size.

Open in DBdiagramr to edit →

Embed this diagram

Paste this HTML into a README, docs page, or blog post. The image links back to the full schema page.

<a href="https://www.dbdiagramr.space/schema/stripe">
  <img src="https://www.dbdiagramr.space/schemas/stripe-er-diagram.svg" alt="Stripe Billing Database Schema Diagram" width="1642" height="1361" />
</a>
<p><a href="https://www.dbdiagramr.space/schema/stripe">Stripe Billing Database Schema Diagram</a> by dbdiagramr</p>

Tables in the Stripe schema

ColumnTypeNullableKey
customers
idtextNoPK
emailvarcharYes-
namevarcharYes-
phonevarcharYes-
descriptiontextYes-
currencyvarchar(3)Yes-
balanceintegerNo-
metadatajsonbYes-
createdtimestamptzNo-
deleted_attimestamptzYes-
products
idtextNoPK
namevarcharNo-
descriptiontextYes-
activeboolNo-
typevarcharNo-
metadatajsonbYes-
createdtimestamptzNo-
updatedtimestamptzYes-
prices
idtextNoPK
product_idtextNoFK → products.id
unit_amountintegerYes-
currencyvarchar(3)No-
recurring_intervalvarcharYes-
recurring_interval_countintegerYes-
activeboolNo-
typevarcharNo-
createdtimestamptzNo-
subscriptions
idtextNoPK
customer_idtextNoFK → customers.id
statusvarcharNo-
collection_methodvarcharNo-
current_period_starttimestamptzNo-
current_period_endtimestamptzNo-
cancel_at_period_endboolNo-
canceled_attimestamptzYes-
trial_starttimestamptzYes-
trial_endtimestamptzYes-
default_payment_method_idtextYesFK → payment_methods.id
metadatajsonbYes-
createdtimestamptzNo-
subscription_items
idtextNoPK
subscription_idtextNoFK → subscriptions.id
price_idtextNoFK → prices.id
quantityintegerNo-
createdtimestamptzNo-
invoices
idtextNoPK
customer_idtextNoFK → customers.id
subscription_idtextYesFK → subscriptions.id
statusvarcharNo-
amount_dueintegerNo-
amount_paidintegerNo-
currencyvarchar(3)No-
attempt_countintegerNo-
due_datetimestamptzYes-
paid_attimestamptzYes-
hosted_invoice_urltextYes-
createdtimestamptzNo-
invoice_line_items
idtextNoPK
invoice_idtextNoFK → invoices.id
price_idtextYesFK → prices.id
amountintegerNo-
currencyvarchar(3)No-
descriptiontextYes-
quantityintegerNo-
period_starttimestamptzYes-
period_endtimestamptzYes-
payment_methods
idtextNoPK
customer_idtextNoFK → customers.id
typevarcharNo-
card_brandvarcharYes-
card_last4varchar(4)Yes-
card_exp_monthsmallintYes-
card_exp_yearsmallintYes-
billing_countryvarchar(2)Yes-
createdtimestamptzNo-
payment_intents
idtextNoPK
customer_idtextYesFK → customers.id
invoice_idtextYesFK → invoices.id
amountintegerNo-
currencyvarchar(3)No-
statusvarcharNo-
payment_method_idtextYesFK → payment_methods.id
client_secrettextYes-
createdtimestamptzNo-

Table relationships

13 relationships connect the tables in this schema. Each entry shows the child columns, the parent columns they reference, and the cardinality.

One-to-many

prices.product_id → products.id

One product can have many prices (prices.product_id -> products.id, required).

One-to-many

subscriptions.customer_id → customers.id

One customer can have many subscriptions (subscriptions.customer_id -> customers.id, required).

One-to-many

subscriptions.default_payment_method_id → payment_methods.id

One payment method can have many subscriptions (subscriptions.default_payment_method_id -> payment_methods.id, optional).

One-to-many

subscription_items.subscription_id → subscriptions.id

One subscription can have many subscription items (subscription_items.subscription_id -> subscriptions.id, required).

One-to-many

subscription_items.price_id → prices.id

One price can have many subscription items (subscription_items.price_id -> prices.id, required).

One-to-many

invoices.customer_id → customers.id

One customer can have many invoices (invoices.customer_id -> customers.id, required).

One-to-many

invoices.subscription_id → subscriptions.id

One subscription can have many invoices (invoices.subscription_id -> subscriptions.id, optional).

One-to-many

invoice_line_items.invoice_id → invoices.id

One invoice can have many invoice line items (invoice_line_items.invoice_id -> invoices.id, required).

One-to-many

invoice_line_items.price_id → prices.id

One price can have many invoice line items (invoice_line_items.price_id -> prices.id, optional).

One-to-many

payment_methods.customer_id → customers.id

One customer can have many payment methods (payment_methods.customer_id -> customers.id, required).

One-to-many

payment_intents.customer_id → customers.id

One customer can have many payment intents (payment_intents.customer_id -> customers.id, optional).

One-to-many

payment_intents.invoice_id → invoices.id

One invoice can have many payment intents (payment_intents.invoice_id -> invoices.id, optional).

One-to-many

payment_intents.payment_method_id → payment_methods.id

One payment method can have many payment intents (payment_intents.payment_method_id -> payment_methods.id, optional).

Common queries

These PostgreSQL queries run against the schema shown on this page.

Monthly recurring revenue

Sum active monthly subscription items in dollars.

select round(sum(p.unit_amount * si.quantity) / 100.0, 2) as mrr
from subscriptions s
join subscription_items si on si.subscription_id = s.id
join prices p on p.id = si.price_id
where s.status = 'active'
  and p.recurring_interval = 'month';

Unpaid invoices

List invoices that are still open or past due.

select i.id, c.email, i.status, i.amount_due
from invoices i
join customers c on c.id = i.customer_id
where i.status <> 'paid'
order by i.created;

Failed payment attempts

Show payment intents that still need a payment method.

select pi.id, c.email, pi.amount, pi.status
from payment_intents pi
left join customers c on c.id = pi.customer_id
where pi.status = 'requires_payment_method'
order by pi.created desc;

Canceling subscriptions

Subscriptions already canceled or scheduled to cancel.

select s.id, c.email, s.status, s.cancel_at_period_end, s.canceled_at
from subscriptions s
join customers c on c.id = s.customer_id
where s.canceled_at is not null or s.cancel_at_period_end
order by s.canceled_at desc nulls last;

The billing flow as joins

Once the tables exist, most billing questions are joins. This query finds what a customer is subscribed to and at what price:

select c.email, pr.name as product, p.unit_amount, si.quantity
from customers c
join subscriptions s on s.customer_id = c.id
join subscription_items si on si.subscription_id = s.id
join prices p on p.id = si.price_id
join products pr on pr.id = p.product_id
where s.status = 'active';

This one lists unpaid invoices with their latest payment attempt:

select i.id, i.amount_due, pi.status as payment_status
from invoices i
left join payment_intents pi on pi.invoice_id = i.id
where i.status != 'paid';

The join path is the model: customer to subscription, subscription to items, items to prices, prices to products. Invoices and payment intents hang off the customer and subscription rather than replacing them.

Design details worth copying

  • Nested fields are flattened. Stripe's price.recurring.interval and interval_count become recurring_interval and recurring_interval_count; card and billing details are flattened with prefixes such as card_last4.
  • Prices, not products, are what you bill. One product ("Pro Plan") can have many prices ($10/month, $100/year). Subscription items reference prices, not products directly.
  • Subscription items allow multi-product subscriptions. One subscription can contain multiple prices (base plus add-on) with independent quantities.
  • Invoices are snapshots. invoice_line_items copies the price and amount at invoice time, so an old invoice stays truthful after a price change.
  • Payment intents are the audit trail. Every charge attempt is a row, including failed ones. Join them to invoices to see what was paid and what was not.

Frequently asked questions

Related schema diagrams

Visualize your own database

Paste your PostgreSQL connection string and get an interactive ER diagram of your own schema in under 10 seconds. No signup required.

Try it free →