Sequin - Open Source Message Stream Built On Postgres |
Written by Nikos Vaggalis | |||
Thursday, 31 October 2024 | |||
Sequin is a tool for capturing changes and streaming data out of your Postgres database, guaranteeing exactly once processing. What does that mean? Sequin leverages Postgres's Write-Ahead Log (WAL) to transform it into a stream or message queue, providing a more efficient alternative to Kafka and Simple Queue Service (SQS). This means that you can:
It achieves this by monitoring the Postgres WAL to track changes in your table's rows. This can be done at a granular level, capturing every create, update,nd delete operation, or more efficiently, by simply retrieving the latest version of each row. In the first case Sequin acts as a replacement for
and in the latter as a replacement for
In either case it manages to replace many cases of DIY or difficult setups, like those involving Kafka or Debezium, with a single all encompassing service. To stream data using Sequin, you create "sequences" for each table you want to stream so that on the other end you can consume those rows from the sequence using clients that work with HTTP Push like Webhooks or HTTP Pull like SQS. Sequin takes care of the clients too since it lets you create them from withing the platform, guaranteeing exactly once processing. On that matter, while no system can guarantee exactly-once delivery , at-least-once delivery and exactly-once processing can work together: Processing is the the full message life-cycle: the message was delivered to the receiver, the receiver did its job, and then the receiver acknowledged the message. With that definition, SQS, Kafka, and Sequin are all systems that guarantee exactly-once processing. The term processing captures both the delivery of the message and the successful acknowledgment of the message; "exactly-once processing" indicates it's a messaging system with at-least-once delivery and acknowledgments. Practically with Sequin in place :
Diverging from the usual practice of extending Postgres's functionality with extensions, Sequin offers a Docker image coming with a web console/UI for configuration that you can run next to your Postgres database. It works with any Postgres database version 12+ onwards. Of course it is open source, therefore the easiest way to get started is to grab the docker/docker-compose. yaml file from the repository which bundles a Postgres and Redis instance as well as a Sequin server. Note that Sequin is also offered as a cloud-managed service. Since Sequin is written in Elixir, there's also an accompanying lightweight Elixir SDK for sending, receiving, and acknowledging messages in Sequin streams. Utilizing it , an example of sending , receiving, and acknowledging messages in Sequin streams looks like : I left the most exciting features yet to be announced, Transforms; that is you can transform message payloads by writing functions in Lua, JavaScript, or Go before they’re delivered to your consumers. This is useful for transforming data into a format more suitable for your receiving end of the application. That is, instead of your app's end point consuming json output in wal2json format (coming out of Sequin), you can write code that transforms the package to a custom format that your app can work with before it exits Sequin. Contrast that with the trouble I had to go through when manually implementing a CDC/Webhook functionality that involved a complex pipeline of triggers, database events and Perl transformation code, under the Ingres dbms in order to transform and manipulate data collected by SQL queries into HL7 packets before they got automatically sent to a Web service at the end of the pipeline. That is GUI/App-->Enter Data-->SQL-->HL7-->Web Service, automatically when a value gets inserted. Read "Connecting To The Outside World with Perl and Database Events" if you want to find out how it was done. In conclusion Sequin is a one-stop solution that takes a lot of pain out of replicating and synchronizing data, broadcasting events, distributing workloads and decoupling services
More InformationRelated ArticlesConnecting To The Outside World with Perl and Database Events To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |
|||
Last Updated ( Thursday, 31 October 2024 ) |