9
8 Comments

Suggested database architecture for my first SaaS with Stripe?

I've begun working on a SaaS idea I've had lately - it's simple but I'm excited about building it and hopefully turning it into something people want to use.

I'm slightly back-and-forth on what to store in the DB and how for it to scale well based on features I'll need eventually.

I'm using Stripe too.

Here's all I've got so far:

A Users table with:

  • Email
  • Encrypted Password
  • Stripe Customer ID

When a customer signs up I ask for their Email and Password and create a new Stripe Customer and create a subscription to the only plan I've created so far with a 14 day trial.

I then store the Stripe Customer ID in the database.

What sort of information should I store regarding payments and billing in my own database? I was thinking about a new table called Billing and store when the users trial will expire (provided from Stripe), am I thinking about this wrong? Anything else pivotal?

on June 15, 2019
  1. 1

    Hi, if you're still interested in this, here is how we are handling the Stripe data at NLP Cloud: https://juliensalinas.com/en/storing-stripe-payment-data-database/
    Basically, we store everything in local DB as a PostgreSQL JSONB field as soon as we make a request or receive a webhook.

    Doing this you have the best of both worlds:

    • Speed (since you are reading local data instead of remote data)
    • Ease of development (you don't have to think to much about which Stripe data you are going to save)
    • You're safe in case of disaster on the Stripe side
    • You data is always up to date

    Hope it helps

  2. 1

    Just stumbled onto this thread as I am at the same decision point wiht my product.

    I think I'm going to start off with just storing the Stripe customer ID on the user, with a subscription object that holds the subscription ID, status, expiry date.

    I'll extend the expiry each time I get a successful payment event from Stripe.

    Not sure if anyone will see this, but thoughts?

  3. 1

    Hello! What did you end up doing? Do you have any feedback on your choice? I'm currently reflecting on this exact subject regarding our SaaS and cannot wrap my head around the best option between:

    • Dedicated table to keep track of subscriptions (at first, feels a bit like double accounting)
    • Hitting Stripe API for any billing related info (at first, feels slow/resource intensive)
      Any feedback could probably help. Thanks in advance :)
  4. 1

    I wouldn't recommend hitting Stripe's API to fetch billing information as-needed. For example, if you wanted to check if the current user has a subscription, that will add latency if you hit Stripe's API every time you needed to know that. It's very simple to keep local billing data in sync with Stripe's system using webhooks, e.g. customer.updated, customer.source.created, customer.subscription.created, etc.

    I have a billing table that looks something like this:

    billings {
      string customer_id
      string subscription_id
      string subscription_status
      datetime subscription_period_start
      datetime subscription_period_end
      datetime card_expiry
      string card_brand
      string card_last4
      datetime created_at
      datetime updated_at
    }
    

    That's all the information I've ever needed to know.

    1. 1

      cc @csallen, code blocks don't really look right recently. A lot of extra white space is added.

      1. 1

        I'll check it out, thanks for the heads up

  5. 1

    For our billing pages, we just pull in the history from Stripe. If you can get away with it, a single source of truth is best.

    ~25,000 Stripe users later and I don't regret it. We've had to create a FakeCharge and a ShopifyCharge in our main DB (Postgres) to fudge it a little for alternate billing. Hopefully you never need to do that. When getting user.charges (Rails ActiveRecord syntax here), it just grabs data from those two tables plus Stripe then sorts them all by date.

    When creating charges/users in Stripe, I suggest storing some metadata like User id so you can figure out what happened if a user is deleted/updated.

    1. 2

      I agree, I would try to leverage Stripe APIs to fetch any subscription or payment data if needed.

Trending on Indie Hackers
I spent $0 on marketing and got 1,200 website visitors - Here's my exact playbook User Avatar 70 comments Veo 3.1 vs Sora 2: AI Video Generation in 2025 🎬🤖 User Avatar 31 comments I built eSIMKitStore — helping travelers stay online with instant QR-based eSIMs 🌍 User Avatar 21 comments 🚀 Get Your Brand Featured on FaceSeek User Avatar 20 comments Day 6 - Slow days as a solo founder User Avatar 16 comments Solo SaaS Founders Don’t Need More Hours....They Need This User Avatar 11 comments