Sequin streams the latest versions of rows from your tables. But sometimes you want to capture every discrete change to your tables, not just the latest state of each row. With Change Capture Pipelines, Sequin can capture inserts, updates, and deletes as they happen, storing them in an event log table in your database. You can then stream these events to your applications using Sequin’s existing consumption methods.

This quickstart assumes you’ve already installed and setup Sequin in the prior quickstart. It refers to the public.regions table from that guide.

Create a Change Capture Pipeline

Create a Change Capture Pipeline to capture changes:

  1. Navigate to the Change Capture Pipelines tab and click the Create Change Capture Pipeline button.

  2. Under “Source configuration”, the public.regions table should be selected already:

  3. Select which operations you want to capture. For this example, you can leave all three selected: insert, update, and delete:

  4. You can skip “Add filter.”

  5. Under “Destination configuration”, click “Create event table.” Here, Sequin shows you the steps for creating a table for your events:

  6. Name the table sequin_events. Don’t specify a retention policy. Then, to create the table, open a console to the sequin_playground database:

    psql 'postgresql://postgres:postgres@localhost:7377/sequin_playground?sslmode=disable'
    
  7. You can type \e and press Enter to open up the SQL editor. Then, paste in the SQL operations that Sequin provided to create the event table. (If your editor is Vim, type :wq to quit and run the commands.)

  8. After creating your event table, click “Done” to close the modal. Your new table should now appear in the destination list. Select it:

  9. Give your Change Capture Pipeline a name (i.e. region_to_sequin_events) and click Create Change Capture Pipeline.

Sequin will now capture every change to the regions table and write it to your event log.

Make some changes

Let’s see the Change Capture Pipeline in action:

  1. Open a terminal and connect to the sequin_playground database:

    psql 'postgresql://postgres:postgres@localhost:7377/sequin_playground?sslmode=disable'
    
  2. Turn on “extended display” mode by typing \x and pressing Enter.

  3. Insert a new region:

    insert into public.regions (name, timezone)
    values ('us-gov-west-1', 'pst');
    
  4. Query your event log table to see the insert:

    select action, record_pk, record, changes
    from sequin_events
    order by id desc
    limit 1;
    

    You should see something like:

    action    | insert
    record_pk | 9
    record    | {"id": 9, "name": "us-gov-west-1", "timezone": "pst", "updated_at": "2024-10-28T21:37:53", "inserted_at": "2024-10-28T21:37:53"}
    changes   |
    
  5. Update the region:

    update public.regions
    set timezone = 'mst'
    where name = 'us-gov-west-1';
    
  6. Query your event log again:

    select action, record_pk, record, changes
    from sequin_events
    order by id desc
    limit 1;
    

    Now you’ll see the update, including both the new values (record) and what changed (changes):

    action    | update
    record_pk | 9
    record    | {"id": 9, "name": "us-gov-west-1", "timezone": "mst", "updated_at": "2024-10-28T21:39:21", "inserted_at": "2024-10-28T21:37:53"}
    changes   | {"timezone": "pst", "updated_at": "2024-10-28T21:37:53"}
    
  7. Finally, delete the region:

    delete from public.regions
    where name = 'us-gov-west-1';
    
  8. Query your event log one more time to see the delete event:

    select action, record_pk, record, changes
    from sequin_events
    order by id desc
    limit 1;
    

    The delete event includes the final state of the row before deletion:

    action    | delete
    record_pk | 9
    record    | {"id": 9, "name": "us-gov-west-1", "timezone": "mst", "updated_at": "2024-10-28T21:39:21", "inserted_at": "2024-10-28T21:37:53"}
    changes   |
    

You’ve captured insert, update, and delete events into your event log table!

Stream your events

Now that you’re capturing changes, you can create a Stream for your event log table and stream the events to consumers:

  1. Navigate to the Streams tab and click Create Stream.
  2. Select your sequin_events table.
  3. seq will be auto-selected as your sort column.
  4. Click Create Stream.

You can now use the Consume Group API or webhooks to stream these events to your applications.

Next steps

You’ve seen how to capture changes to your tables and stream those changes to consumers. Now you can: