Stream Timescale data with Sequin
Use Sequin to stream data from your Timescale database.
TimescaleDB is an open-source database built on Postgres that’s optimized for time-series data. You can use Sequin to stream data from TimescaleDB. You can setup HTTP endpoints that let consumers subscribe to changes in your TimescaleDB tables. Or you can receive webhooks when rows are inserted.
The two together are a formidable, Postgres-based alternative to Kafka.
In this guide, you’ll learn how to set up Sequin with TimescaleDB to stream your time-series data.
Setting up TimescaleDB
First, set up a local TimescaleDB instance:
Start TimescaleDB container
Run the following command to start a TimescaleDB container:
Configure WAL level
Sequin requires logical replication to be enabled. To do this, you need to set wal_level
to logical
:
Connecting Sequin to TimescaleDB
Now that TimescaleDB is set up, connect it to Sequin:
Connect Sequin to your database
- In the Sequin console, click Databases > Connect Database.
- Enter the connection details for your TimescaleDB instance:
- Host:
localhost
(or your Docker machine IP) - Port:
5432
- Database:
postgres
- Username:
postgres
- Password:
postgres
- Host:
Create publication and replication slot
Run the following SQL commands in your TimescaleDB instance:
These commands create a publication for all tables and a replication slot for Sequin to use.
Complete the connection
Name your database connection in Sequin and click the Connect Database button.
Creating a Stream for a TimescaleDB Hypertable
TimescaleDB uses hypertables to optimize time-series data storage. Hypertables work like any other table in Sequin. Let’s create a Stream for a hypertable:
Create a hypertable
First, create a hypertable in TimescaleDB:
Create a Stream in Sequin
- In the Sequin console, go to the Streams tab and click Create Stream.
- Select the
sensor_data
hypertable. - Choose
time
as the sort column. - Click Create Stream.
Consuming TimescaleDB Data with Sequin
Now that you have a Stream set up, you can consume data using Sequin’s Consumer Group API, webhooks, or Sync API (coming soon).
Here’s an example of how to consume data using the Consumer Group API:
This will return up a batch of up to 10 messages from your sensor_data
hypertable. The response will look something like this:
After processing these messages, you can acknowledge them using the /ack
endpoint:
With Sequin’s Consumer Group API or Webhook Subscriptions, you can process your TimescaleDB data in real-time, with exactly-once processing guarantees.
Next steps
Explore Sequin further by checking out our documentation. Join our Discord community for support.
Was this page helpful?