DEV Community

naval
naval

Posted on

What would you need to see before trusting a small Stripe sync library?

I've spent two weeks on a small open source module that keeps a Postgres copy of Stripe subscription state in sync. It handles duplicate events, out of order events, workers that crash halfway, and a scheduled reconcile for missed events. MIT license, TypeScript, plain Postgres or Supabase.

I'm not writing this to ask for stars. I want to learn what makes a developer comfortable depending on someone else's code for billing, because billing bugs cost real money.

Here's what I did to make it easier to trust:

  • A demo that runs on a fake Stripe, no account needed. npm run demo takes about a minute.
  • Tests for the ugly cases, like a late update after a delete, and two deliveries at once.
  • A KNOWN_LIMITATIONS file that lists what it doesn't handle, including thin events.

What I don't know is whether any of that is what you look for. So, a few questions:

  1. What would you check first in a library like this: the tests, the demo, how recently it was committed, who maintains it, something else?
  2. Would you rather copy the code into your project or install it as a package? Why?
  3. What billing edge case worries you that you haven't seen a library handle?
  4. What would make you say "no, I'll write it myself"?

I'll reply to every comment, and good answers will become issues or changes in the repo.

Repo: https://github.com/navalpro8-lgtm/stripe-subscription-sync

Top comments (7)

Collapse
 
smtahosin profile image
S M Tahosin •

Hey naval! 'replays late, duplicate, and out-of-order events' lol that's the demo I'd run first. I watched my own sync code fail the duplicate one once, same event twice, user got credited twice. twice!! fixed it with a boring little dedupe table and a lot of shame. on writing it myself, if there's no dry-run for the reconcile I'd probably still roll my own tbh. thanks for the honest limitations file :)

Collapse
 
navalpro8lgtm profile image
naval •

Ha, the credited twice one is a classic. There's no dry-run on reconcile yet, and that's fair feedback. Right now it writes and then reports counts. Would a report-only mode that lists what it would change (the row, Stripe's state, the difference) and writes nothing be what you'd want before trusting it? I'd add it as an issue and credit you.

Collapse
 
smtahosin profile image
S M Tahosin •

yes naval!! that mode lol... 1am pen-and-paper me approves xD look first, write after

Collapse
 
userxnom profile image
Abdullah Naseer •

The demo on a fake Stripe is the strongest trust signal on your list, naval — it lets me see the failure modes without handing you my keys, and that matters more than the tests, because tests only prove the cases you thought of. But the first thing I'd actually check is the reconcile job: how it decides a missed event is really missed, and what it does when Stripe and Postgres disagree after the fact. A sync library lives or dies on that one decision.

On your questions: I'd install it as a package if the upgrade path is clean, but copy it in if the logic is small enough to own — billing code I can't read in an afternoon is billing code I don't trust. The edge case that worries me most is the one you named: a late update after a delete. What does your module do when a subscription.updated arrives after subscription.deleted — resurrect the row, or drop it and log it?

And the 'write it myself' line for me: no story for what happens when the reconcile job itself crashes halfway. What's the recovery there?

Collapse
 
navalpro8lgtm profile image
naval •

Late update after a delete: once Stripe shows a terminal state the row is tombstoned and never changes again, so the late update is skipped and logged, not resurrected. Reconcile crash halfway: each subscription is its own claim and write, so finished ones stay written and the rest are untouched. Re-run with the same since date and it redoes the rest, skipping rows that already match Stripe. Missed events: it lists Stripe's events since a date, re-fetches each subscription once and writes only if Stripe differs. Stripe keeps events about 30 days. Details are in docs/SYNC_MODEL.md.

Collapse
 
keyharbor profile image
Arthur | Keyharbor •

From the side of someone who'd be depending on it, roughly in this order:

  1. KNOWN_LIMITATIONS before the tests. It shows you know where the edges are, and it's the fastest way for me to check whether my setup falls inside them.
  2. What happens when it's wrong. Sync will drift at some point, so I want the reconcile rules spelled out: Stripe is the source of truth, and does it overwrite local rows or flag the difference first?
  3. The schema. If the tables are plain and documented, I can query them directly and walk away later, which makes the dependency much smaller.

Copy vs package: for billing I'd copy it, or at least pin an exact version. I want to read every line that touches subscription state, and I don't want a minor bump changing how a cancel is handled.

Edge cases I'd ask about: a trial that converts but the first invoice fails, pauses, and mid-cycle plan changes with proration, where the subscription can show the new plan before that invoice is paid unless you use pending updates.

What would make me write it myself: if the library also decided access. Mirroring Stripe is generic; who gets what is product logic and belongs in my code.

Collapse
 
navalpro8lgtm profile image
naval •

Thanks Arthur, this is the most useful list yet. On reconcile: it overwrites the local row with what Stripe says, through the same revision-checked write a webhook uses. It does not flag first. A report-only mode is the second request for that today, so I'll add it. The schema is plain tables in sql/schema.sql, nothing hidden. On access: the library mirrors Stripe state, and the entitlement policy is one replaceable file, so your product rules stay in your code. Pauses and mid-cycle proration aren't covered in KNOWN_LIMITATIONS yet and I haven't run them against real Stripe, so treat them as unverified. I'll add them there.