Transforms
Reference for Sequin’s transforms. Use transforms to modify the structure of your messages before they are sent to sinks.
Transforms allow you to modify the structure of your messages before they are sent to the sink destination. This is useful for:
- Simplifying message payloads to reduce bandwidth and storage costs
- Converting from the database’s format to a format compatible with your sink destination or downstream systems
- Maintaining the same message format as you migrate from e.g. Debezium to Sequin
- Keeping payloads under size limits (e.g., SQS’ 256KB limit)
Path transform
Path transforms are the simplest kind of transform. Path transforms allow you to extract one field from your message using a dot-notation path. This is useful for:
- Sending just the latest record to the destination (e.g., for materialized views in Postgres or data warehouses)
- Extracting just the record ID to keep payloads small (e.g., for SQS with its 256KB limit)
Path syntax
The first part of the path is always one of the four keys of the message object: record
, changes
, action
, or metadata
.
You can optionally add additional keys to traverse the message structure. For example, record.id
will extract the id
field from the record
object.
Some examples:
Path | Description | Example Value |
---|---|---|
record | The full record object | {"id": 123, "address": {"city": "Anytown"}} |
record.id | A specific field from the record | 123 |
record.address.city | A nested field from the record | "Anytown" |
Paths can be as deep as you need them to be. For example, record.address.city
will extract the city
field from the address
JSONB column in the record
object.
Function transform
Function transforms allow you to write custom Elixir code to transform your messages. This is useful for more complex transformations that are not possible with the path transform, such as:
- Specifying a format that is necessary for your sink destination
- Sanitizing sensitive data, such as PII or payment card data
- Converting timestamp formats
- Adding computed fields
- And much more!
Function syntax
Every function transform is implemented as an Elixir transform/4
function:
The transform/4
function receives each key from the message object as an argument:
record
: The full record objectchanges
: The changes objectaction
: The action type (insert, update, delete)metadata
: The metadata object
Your transform must define the transform/4
function and may not define any
other functions.
Elixir standard library
The function transform allows you to use a subset of the Elixir standard library, including:
Other parts of the Elixir standard library are not yet supported. If you need something specific, please let us know and we will be happy to help.
Examples
Here are some examples of how to use the function transform:
Extract the record ID
Format for webhook
Both record
and changes
use string keys for access (ie. record["id"]
).
In contrast, the metadata
object uses atom keys (ie. metadata.table_schema
).
This is because the record
and changes
objects are dynamically typed––they depend on the schema of the connected Postgres table. Metadata, on the other hand, is statically typed and will always have the same keys.
See the Elixir Map docs for more information on the difference between string and atom keys.
Sanitize sensitive data
Add computed property
Convert timestamp formats
Coming soon
- Webhook transform: Send messages to a webhook for transformation before delivery
Testing transforms
When creating or editing a transform, Sequin will automatically capture up to 10 recent events from your database. You can see how your transform affects these events in real-time.
When changes occur in a connected database and you have the transform editor open, Sequin will capture events and display them in the editor:
This live preview helps ensure your transform will work correctly with your actual data.
Example use cases
Keeping payloads small
When using SQS (which has a 256KB payload limit), you can use a path transform to extract just the record ID:
Your consumer can then query the full record details as needed.
Maintaining Debezium-like format
For systems expecting a Debezium-like format, use a path transform to extract just the record:
This ensures your messages match the expected format without additional metadata.
Related
Messages reference
Learn about message shapes and how annotations appear in change messages.
sequin.yaml transforms
Learn about the sequin.yaml file and how to use it to configure your Sequin instance.
Filters
Learn about filters and how to use them to filter messages before they are sent to your destination.
Sinks
Learn how to use sinks to send messages to your destination.