Skip to content

Commit 3597b79

Browse files
* blog post * fix typos * update blog post diagram * rss
1 parent c522721 commit 3597b79

File tree

7 files changed

+145
-4
lines changed

7 files changed

+145
-4
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: 'Stripe-To-Postgres Sync Engine as standalone Library'
3+
description: 'Sync Stripe webhook data directly to Postgres using standalone TypeScript library.'
4+
categories:
5+
- product
6+
- launch-week
7+
tags:
8+
- launch-week
9+
- stripe
10+
date: '2025-07-15:15:00'
11+
toc_depth: 3
12+
author: kevcodez
13+
image: launch-week-15/day-2-stripe-engine/og.jpg
14+
thumb: launch-week-15/day-2-stripe-engine/thumb.png
15+
launchweek: 15
16+
---
17+
18+
We're excited to announce that [`stripe-sync-engine`](https://github.com/supabase/stripe-sync-engine) is now available as a standalone npm package: [`@supabase/stripe-sync-engine`](https://www.npmjs.com/package/@supabase/stripe-sync-engine)!
19+
20+
Previously distributed only as a Docker image (`supabase/stripe-sync-engine`), you can now plug this into any backend project—whether you're using Node.js, running Express on a server, or even deploying on Supabase Edge Functions.
21+
22+
Stripe-Sync-Engine is a webhook listener that transforms Stripe webhooks into structured Postgres inserts/updates. It listens to Stripe webhook events (like `invoice.payment_failed`, `customer.subscription.updated`, etc), normalizes and stores them in a relational format in Postgres.
23+
24+
<Img
25+
src={{
26+
dark: '/images/blog/launch-week-15/day-2-stripe-engine/stripe-sync-engine-dark.png',
27+
light: '/images/blog/launch-week-15/day-2-stripe-engine/stripe-sync-engine-light.png',
28+
}}
29+
alt="Stripe Sync Engine Diagram"
30+
/>
31+
32+
## Why sync Stripe data to Postgres?
33+
34+
While Supabase offers a convenient [foreign data wrapper](https://supabase.com/partners/integrations/supabase_wrapper_stripe) (FDW) for Stripe, sometimes you want your Stripe data _locally available_ in your Postgres database for:
35+
36+
- **Lower latency**: Avoid round-trips to the Stripe API.
37+
- **Better joins**: Query subscriptions, invoices, and charges together.
38+
- **Custom logic**: Build fraud checks, billing dashboards, and dunning workflows directly from your own database.
39+
40+
## New: Use it as an npm package
41+
42+
You can now install and run the Stripe sync engine directly inside your backend:
43+
44+
```bash
45+
npm install @supabase/stripe-sync-engine
46+
```
47+
48+
And use it like this:
49+
50+
```tsx
51+
import { StripeSync } from '@supabase/stripe-sync-engine'
52+
53+
const sync = new StripeSync({
54+
databaseUrl: 'postgres://user:pass@host:port/db',
55+
stripeSecretKey: 'sk_test_...',
56+
stripeWebhookSecret: 'whsec_...',
57+
})
58+
59+
// Example: process a Stripe webhook
60+
await sync.processWebhook(payload, signature)
61+
```
62+
63+
For a full list of configuration options, refer to our [stripe-sync-engine README](https://github.com/supabase/stripe-sync-engine/blob/main/packages/sync-engine/README.md).
64+
65+
## Use via Supabase Edge Function
66+
67+
To use the Stripe-Sync-Engine in an [Edge Function](https://supabase.com/edge-functions), you first have to ensure that the schema and tables exist. While you can technically do this inside the Edge Function, it is recommended to run the schema migrations outside of that. You can do a one-off migration via
68+
69+
```tsx
70+
import { runMigrations } from '@supabase/stripe-sync-engine'
71+
;(async () => {
72+
await runMigrations({
73+
databaseUrl: 'postgresql://postgres:..@db.<ref>.supabase.co:5432/postgres',
74+
schema: 'stripe',
75+
logger: console,
76+
})
77+
})()
78+
```
79+
80+
or include the [migration files](https://github.com/supabase/stripe-sync-engine/tree/main/packages/sync-engine/src/database/migrations) in your regular migration workflow.
81+
82+
Once the schema and tables are in place, you can start syncing your Stripe data using an Edge Function:
83+
84+
```tsx
85+
import 'jsr:@supabase/functions-js/edge-runtime.d.ts'
86+
import { StripeSync } from 'npm:@supabase/[email protected]'
87+
88+
// Load secrets from environment variables
89+
const databaseUrl = Deno.env.get('DATABASE_URL')!
90+
const stripeWebhookSecret = Deno.env.get('STRIPE_WEBHOOK_SECRET')!
91+
const stripeSecretKey = Deno.env.get('STRIPE_SECRET_KEY')!
92+
93+
// Initialize StripeSync
94+
const stripeSync = new StripeSync({
95+
databaseUrl,
96+
stripeWebhookSecret,
97+
stripeSecretKey,
98+
backfillRelatedEntities: false,
99+
autoExpandLists: true,
100+
})
101+
102+
Deno.serve(async (req) => {
103+
// Extract raw body as Uint8Array (buffer)
104+
const rawBody = new Uint8Array(await req.arrayBuffer())
105+
106+
const stripeSignature = req.headers.get('stripe-signature')
107+
108+
await stripeSync.processWebhook(rawBody, stripeSignature)
109+
110+
return new Response(null, {
111+
status: 202,
112+
headers: { 'Content-Type': 'application/json' },
113+
})
114+
})
115+
```
116+
117+
1. Deploy your Edge Function initially using `supabase functions deploy`
118+
2. Set up a Stripe webhook with the newly deployed Supabase Edge Function url
119+
3. Create a new .env file in the `supabase` directory
120+
121+
```
122+
# Use Dedicated pooler if available
123+
DATABASE_URL="postgresql://postgres:..@db.<ref>.supabase.co:6532/postgres"
124+
STRIPE_WEBHOOK_SECRET="whsec_"
125+
STRIPE_SECRET_KEY="sk_test_..."
126+
```
127+
128+
1. Load the secrets using `sh supabase secrets set --env-file ./supabase/.env`
129+
130+
As webhooks come in, the data is automatically persisted in the `stripe` schema. For a full guide, please refer to our [repository docs](https://supabase.github.io/stripe-sync-engine/).
131+
132+
## Final thoughts
133+
134+
If you're building with Stripe and Supabase, [`stripe-sync-engine`](https://github.com/supabase/stripe-sync-engine) gives you a reliable, scalable way to bring your billing data closer to your database and application. Whether you want better analytics, faster dunning workflows, or simpler integrations—this package is built to make that seamless.

apps/www/components/LaunchWeek/15/data/lw15_build_stage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ export const days: BuildDay[] = [
5252
],
5353
},
5454
{
55-
title: '',
55+
title: 'Introducing stripe-sync-engine npm package',
5656
description: '',
57-
id: '',
58-
is_shipped: false,
57+
id: 'stripe-engine',
58+
is_shipped: true,
5959
links: [
6060
{
61-
url: '/blog/',
61+
url: '/blog/stripe-engine-as-sync-library',
6262
label: 'Blog post',
6363
target: '_blank',
6464
},
180 KB
Loading
112 KB
Loading
114 KB
Loading
63 KB
Loading

apps/www/public/rss.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
<lastBuildDate>Tue, 15 Jul 2025 00:00:00 -0700</lastBuildDate>
99
<atom:link href="https://supabase.com/rss.xml" rel="self" type="application/rss+xml"/>
1010
<item>
11+
<guid>https://supabase.com/blog/stripe-engine-as-sync-library</guid>
12+
<title>Stripe-To-Postgres Sync Engine as standalone Library</title>
13+
<link>https://supabase.com/blog/stripe-engine-as-sync-library</link>
14+
<description>Sync Stripe webhook data directly to Postgres using standalone TypeScript library.</description>
15+
<pubDate>Tue, 15 Jul 2025 00:00:00 -0700</pubDate>
16+
</item>
17+
<item>
1118
<guid>https://supabase.com/blog/analytics-buckets</guid>
1219
<title>Supabase Analytics Buckets with Iceberg Support</title>
1320
<link>https://supabase.com/blog/analytics-buckets</link>

0 commit comments

Comments
 (0)