This is the how-to guide for streaming Postgres to Kafka. See the quickstart for a step-by-step walkthrough or the reference for details on all configuration options.
Prerequisites
If you’re self-hosting Sequin, you’ll need:- Sequin installed
- A database connected
- A Kafka cluster ready to go
- A Kafka cluster ready to go
Basic setup
Prepare your Kafka cluster
You’ll need a Kafka cluster and topic ready for Sequin to stream changes to. You can use either a local cluster for development or a cloud-hosted Kafka service in production.Local development with Docker
For local development with Sequin, you can quickly spin up a Kafka cluster using Docker Compose:docker-compose.yaml
docker-compose.yaml
Production Kafka
For production environments, Sequin works with major managed Kafka providers as well as self-hosted Kafka clusters. To prepare your Kafka cluster for Sequin, you’ll need to:- Create a dedicated topic for Sequin to publish to
- Create credentials (username/password) for Sequin to use
- Configure appropriate ACLs to allow Sequin to publish to your topic
Sequin currently supports SASL PLAIN, SCRAM-SHA-256, and SCRAM-SHA-512 authentication mechanisms with TLS encryption. Custom client certificates for verifying TLS connections are coming soon, let us know if you need them.
- Bootstrap server addresses
- Topic name
- Authentication credentials
- Whether TLS is required
Create Kafka sink
Navigate to the “Sinks” tab, click “Create Sink”, and select “Kafka Sink”.Configure the source
1
Select source tables
Under “Source”, select the schemas and tables you want to stream data from.
2
Add filters (optional)
Add filters to the sink to control which database changes are sent to your Kafka topic.
3
Specify backfill
You can optionally indicate if you want to backfill of all or a portion of the table’s existing data into Kafka. Backfills are useful if you want to use Kafka to process historical data. For example, if you’re materializing a cache, you might want to warm it with existing rows.You can backfill at any time. If you don’t want to backfill, toggle “Backfill” off.
4
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 Kafka in order.
Configure Kafka
1
Enter Kafka connection details
Fill in your Kafka connection details:
- Hosts (required): A comma-separated list of
host:port
pairs (e.g.,kafka1.example.com:9092,kafka2.example.com:9092
)- This can be either the full list of Kafka brokers or just the bootstrap server
- Topic (required): The Kafka topic to publish messages to (max 255 characters)
- Username: Username for SASL PLAIN authentication (optional)
- Password: Password for SASL PLAIN authentication (optional)
- TLS: Enable TLS/SSL encryption for the connection
2
Create the sink
Give your sink a name, then click “Create Kafka Sink”.
Verify & debug
To verify that your Kafka 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 your Kafka consumer tools, check your topic:
You should see the messages from Sequin appear in the topic.
- 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 Kafka connection errors
Next steps
- Setup a processor Now that your Postgres data is flowing into Kafka, you can setup a consumer group to read from the topic and process the data. Refer to the Kafka sink reference for the shape of messages that Sequin will publish to Kafka.
- Deploy your implementation When you’re ready to deploy your implementation, see “How to deploy to production”.
- Advanced configuration For more about how Kafka sinks work, see the Kafka sink reference.