Replicate Postgres to Tinybird
How to use a Sequin webhook sink to replicate Postgres tables to Tinybird in real-time.
Tinybird is a powerful real-time analytics platform built on ClickHouse. It allows you to ingest, transform, and query large volumes of data with low latency.
Often, you want to stream changes from your Postgres database to Tinybird for real-time analytics. For instance, you might want to analyze order data as it’s created or updated in your database:
In this guide, you’ll learn how to use a Sequin webhook sink to stream Postgres changes to Tinybird in real-time.
Prerequisites
You are about to create a simple Tinybird data source that receives database changes. You’ll set up a webhook sink in Sequin that sends HTTP POST requests to Tinybird’s Events API with the payload of database changes.
You’ll need the following:
- A Tinybird account
- Sequin installed locally or a Sequin Cloud account
- A database connected to Sequin
Create a Tinybird Data Source
Start by creating a new Data Source in Tinybird that will receive database changes from Sequin.
Log in to Tinybird
Log in to your Tinybird dashboard and navigate to the “Data Sources” tab.
Create new Data Source
Click on “Create Data Source”.
Select source type
Choose “Events API” as the source type.
Copy credentials
Copy the endpoint URL and Authorization token. You’ll need these for the next steps.
You’ve successfully created a Tinybird Data Source that can receive data via HTTP POST requests.
Create a webhook sink
Create a webhook sink that captures changes to your database and sends them to your Tinybird Data Source:
Create a new sink
Navigate to the “Sinks” tab, click the “Create Sink” button, and select “Webhook Sink”.
Select source table
Select the table you want to capture changes from (i.e public.orders
).
Choose message type
Specify whether you want to receive changes or rows from the table.
In this example, you should choose “Rows” since you want to replicate the state of the table to Tinybird.
Configure backfill
You can optionally indicate if you want your webhook endpoint to receive a backfill of all or a portion of the table’s existing data. Since you want to replicate the state of the table, select to backfill all data.
Configure message grouping
Under “Message grouping”, leave the default option selected to ensure events for the same row are sent to your webhook endpoint in order.
Configure delivery settings
Under “Delivery configuration”, choose a conservative value for “Request timeout” and set “Batch size” to 1 since we’re just sending data to Tinybird.
Configure HTTP endpoint
Under “HTTP Endpoint”, enter the Tinybird Events API URL you copied earlier. Then click to “Add Encrypted Header” with the key Authorization
and the value Bearer YOUR_TINYBIRD_TOKEN
.
Name and create sink
Give your sink a name (i.e. tinybird_sink
) and click “Create Webhook Sink”.
Your webhook sink is now created and ready to send events to Tinybird.
Test end-to-end
Create a row in your database
For example, insert a row into your table:
Trace the change in the Sequin dashboard
In the Sequin console, open the Messages tab on your webhook sink and confirm that a message was delivered.
Confirm the data in Tinybird
- Go to your Tinybird dashboard
- Navigate to your Data Source
- Run a query to verify the data was received:
You’ve successfully streamed database changes to Tinybird!
Next steps
Build on this foundation:
- Create Pipes in Tinybird to transform your data
- Set up API endpoints in Tinybird to query your data
- Create real-time dashboards with your streaming data
- Configure additional webhook sinks for other tables
Was this page helpful?