Stream changes from your Neon database to anywhere
Learn how to capture and stream changes and rows from your database to anywhere with Sequin
Neon's Logical Replication features makes it possible to detect every change in your database. It can be used to power read-replicas and backups, but can also be used to add streaming characteristics to Neon.
Sequin uses Neon's logical replication to sends records and changes in your database to your applications and services, in real-time. It's designed to never miss an insert
, update
, or delete
and provide exactly-once processing of all changes.
Changes are sent as messages via HTTP push (webhooks) or pull (SQS-like, with Sequin SDKs). Out of the box, you can start triggering side-effects when a new record is created, fan out work to cloud functions, or activate workflows in services like trigger.dev.
In this guide, we'll show you how to connect your Neon database to Sequin to start sending changes anywhere you need.
Prerequisites
- A Sequin account
- A Neon account
- Read the important notices about logical replication in Neon before you begin
Enable logical replication in Neon
Sequin uses the Write Ahead Log (WAL) to capture changes from your Postgres database. In this step, we'll enable logical replication for your Neon Postgres project.
important
Enabling logical replication modifies the Postgres wal_level
configuration parameter, changing it from replica to logical for all databases in your Neon project. Once the wal_level
setting is changed to logical, it cannot be reverted. Enabling logical replication also restarts all computes in your Neon project, meaning active connections will be dropped and have to reconnect.
To enable logical replication in Neon:
- Select your project in the Neon Console.
- On the Neon Dashboard, select Settings.
- Select Logical Replication.
- Click Enable to enable logical replication.
You can verify that logical replication is enabled by running the following query from the Neon SQL Editor:
Connect your Neon database to Sequin
After enabling logical replication on Neon, you'll now connect your Neon database to Sequin. Follow these steps:
-
In Neon, copy your database connection string from the Connection Details section on the Project Dashboard, which will look similar to this:
-
In the Sequin Console, click on the Connect Database button, and then auto-complete your database credentials by clicking the Autofill with URL button and pasting in your database connection string.
-
Use the SQL Editor in your Neon project to create a replication slot by executing the following SQL query:
This creates a replication slot named
sequin_slot
. -
Create a publication to indicate which tables will publish changes to the replication slot. Run the following SQL command:
This will publish changes from all tables. If you want to publish changes from specific tables only, you can use:
Defining specific tables lets you add or remove tables from the publication later, which you cannot do if you've created a publication with
FOR ALL TABLES
. -
Back in the Sequin Console, enter the name of the replication slot (
sequin_slot
) and publication (sequin_pub
) you just created. Then, name your database (e.g.neondb
) and click Create Database.
With these steps completed, your Neon database is now connected to Sequin via a replication slot and publication. Sequin is now detecting changes to your tables.
Create a consumer
Set up a consumer in Sequin to stream changes from your database.
-
In the Sequin Console, navigate to the Consumers page and click Create Consumer.
-
Select the Neon database you just created and then select the specific table you want to process changes for.
-
Define any filters for the changes you want to capture. For example, you might want to only process orders with a value greater than a certain amount, or accounts with a certain status.
-
Choose whether you want your consumer to process rows or changes:
- Rows: Captures the latest state of records when a row is inserted or updated.
- Changes: Captures every
insert
,update
, anddelete
, includingOLD
values for updates and deletes.
-
Select your preferred method for receiving changes:
- HTTP Push (Webhooks): Sequin sends changes to your specified endpoint.
- HTTP Pull (similar to SQS): Your application pulls changes from Sequin.
-
Enter the final details for your consumer:
- Give your consumer a name (e.g.,
neon-changes-consumer
). - If using HTTP Push, provide the endpoint URL where Sequin should send the changes. You can also provide encrypted headers.
- Optionally, set a timeout and add an endpoint path.
- Give your consumer a name (e.g.,
-
Click Create Consumer to finalize the setup.
Your consumer is now created and will start processing changes from your Neon database according to your specified configuration.
Where to next?
You're now using Sequin with Neon to capture and stream changes from your database. From here, you can tailor your implementation for your use case:
- Use Sequin to trigger workflows in tools like Inngest or trigger.dev, activate side-effects in your app, setup audit logs, or generate denormalized views.
- Tailor your consumer's filtering and settings to meet your requirements.
- Try a pull consumer with our SDKs to completely manage how you retrieve changes at scale.
- Use Sequins observability and monitoring to debug and keep production humming.
Learn more in our docs. And if you need anything, Sequin is open source - just open an issue or reach out to us: founders@sequinstream.com.