SpinTheMic
Pro

Snowflake · Intermediate

How do Snowflake streams work for change data capture?

By Anurag Pandey, Lead Data Engineer ·

The short answer

A stream records the inserts, updates and deletes made to a table since an offset. Reading it in a DML statement that commits moves the offset forward, so each change is processed once.

Practice this out loud

Opens this question on SpinTheMic. Start without signing up; sign in free for an AI report card.

Say it like this

About 55 seconds out loud. Use it as a model, then put it in your own words.

A stream tracks changes made to a source table. It doesn't copy the data; it stores an offset, a point in the table's version history, and when I query it I see every row changed since that point. Each row comes with metadata columns: METADATA$ACTION says INSERT or DELETE, and METADATA$ISUPDATE tells me if that row is part of an update, because an update shows up as a delete of the old row plus an insert of the new one. The offset only moves when I use the stream in a DML statement, like a MERGE into a target table, and that transaction commits. A plain SELECT doesn't move it. One risk: if a stream isn't read within the table's data retention period, it can become stale, and then it has to be recreated.

What interviewers look for

  • You explain the offset and that a stream holds no copy of the data.
  • You know updates appear as a DELETE and INSERT pair with METADATA$ISUPDATE.
  • You know the offset only advances when a DML transaction using it commits.

Common mistakes

  • Saying a SELECT on the stream consumes it. Only committed DML does.
  • Forgetting staleness. An unread stream can become unusable.
  • Mixing up streams and tasks. A task schedules work; a stream tracks changes.

Follow-up questions to expect

  1. 1How would you combine a stream with a task to load a target table?
  2. 2What is an append-only stream, and when would you use one?
  3. 3How would you stop a stream from going stale?
Practice this out loud

Opens this question on SpinTheMic. Start without signing up; sign in free for an AI report card.

Checked against

All interview question guides