How to stream Postgres to Redis Streams
Create real-time data pipelines with Redis Streams and Postgres change data capture (CDC). Stream database changes for caching, analytics, and event distribution.
This guide shows you how to set up Postgres change data capture (CDC) and XADD
changes to a Redis stream using Sequin.
With Postgres data streaming to Redis, you can trigger workflows, keep services in sync, build audit logs, maintain caches, and more.
By the end of this how-to, you’ll have database changes flowing to a Redis stream.
Prerequisites
If you’re self-hosting Sequin, you’ll need:
- Sequin installed
- A database connected
- A Redis instance ready to go
If you’re using Sequin Cloud, you’ll need:
- A Sequin Cloud account
- A database connected
- A Redis instance ready to go
Create Redis Stream sink
Navigate to the “Sinks” tab, click “Create Sink”, and select “Redis Stream Sink”.
Configure the source
Select source tables
Under “Source”, select the schemas and tables you want to stream data from.
Add filters (optional)
Add filters to the sink to control which database changes are sent to your Redis stream.
Add transform (optional)
Add a transform to the sink to modify the payload before it’s sent to Redis.
Specify backfill
You can optionally indicate if you want Redis to receive a backfill of all or a portion of the table’s existing data. Backfills are useful if you want to use Redis to process historical data.
You can backfill at any time. If you don’t want to backfill, toggle “Backfill” off.
Specify message grouping
Under “Message grouping”, you’ll most likely want to leave the default option selected to ensure events for the same row are sent to Redis in order.
Configure Redis Stream
Enter Redis connection details
Fill in your Redis connection details:
- Host (required): The hostname of your Redis server
- Port (required): The port number (1-65535)
- Stream key (required): The name of the stream where messages will be published (max 255 characters)
- Username: Redis username for authentication (optional)
- Password: Redis password for authentication (optional)
- Database: Redis database number (optional, defaults to 0)
- TLS: Enable TLS/SSL encryption for the connection (optional, defaults to false)
Create the sink
Give your sink a name, then click “Create Redis Stream Sink”.
Verify & debug
To verify that your Redis Stream sink is working:
- Make some changes in your source table
- Verify that the count of messages for your sink increases in the Sequin web console
- Using Redis CLI or another Redis client, check your stream:
You should see the messages from Sequin appear in the stream.
If messages don’t seem to be flowing:
- Click the “Messages” tab to view the state of messages for your sink
- Click any failed message
- Check the delivery logs for error details, including any Redis connection errors
Next steps
-
Setup a processor
Now that your Postgres data is flowing into Redis, you can setup a processor to read from the stream and process the data. See the Redis docs on
XREAD
.Refer to the Redis Stream sink reference for the shape of messages that Sequin will publish to Redis.
-
Deploy your implementation
When you’re ready to deploy your implementation, see “How to deploy to production”.
-
Advanced configuration
For more about how Redis Stream sinks work, see the Redis Stream sink reference.