LaserData Cloud
Laser SDKAdvanced

Changes in depth

The change feed reader, change record fields, resume rules, delivery guarantees, and capability checks

This is the full reference for Changes. Start there for the short version.

The change feed tells you when an operational view advanced. Each change record says which index moved, over which source offsets, and how many rows landed. It does not carry the rows. Read the feed, then query the index only when it moved. The feed is an ordinary topic read by offset over the connection you already have, so it adds no new connection or push channel.

Turn it on

Call notify() on the projection binding. After each committed projector batch for that binding, the managed backend publishes one change record. A binding without notify() serves queries only. Watch the same index name that you query.

The feed needs the watch capability, which Laser Stack and LaserData Cloud advertise. Reading the rows afterward also needs the query capability. In Rust, the reader needs the watch feature, which the managed feature includes.

Where records go

Change records go to the changes topic on the ops stream, _agdx, the stream the managed services use for their own records. On a deployment that reports stream_tenancy, each stream has its own change topic, stream:<stream>/_agdx/changes. A client with a default stream reads its stream's topic, and each record names its stream. A client with a default stream also scopes the index name it filters on, the same way a query scopes it.

Open a reader

LanguageOpen a reader for one indexRead every indexReturns
Rustlaser.watch().index(name).records().await?laser.watch().records().await?Result<WatchReader, LaserError>
TypeScriptawait laser.watch().index(name).records()await laser.watch().records()Promise<WatchReader>
Pythonawait laser.watch(index=name)await laser.watch()WatchReader

When the deployment does not publish the feed, opening the reader fails with an unsupported error. Opening a reader checks the capabilities again, so a deployment that starts publishing the feed after the client connected is seen. The SDK never waits on a topic that nothing writes to.

A new reader starts at the first change the feed still retains. Add .from_end() in Rust, .fromEnd() in TypeScript, or from_end=True in Python to start at the current end of every partition, so the reader receives only changes published after it opened. Open the reader before the write you want to await.

.index(name) keeps one index. The filter runs in the client, so the reader still reads every record on the topic. The reader skips any record that does not decode as a change record and counts it in skipped.

Read records

Your application owns the loop. The SDK tracks the position between polls and has no push callbacks.

  1. Call poll(). It returns every matching change that arrived since the last poll, or an empty list when the reader is caught up. It never waits.
  2. Or call poll_within(timeout) (Rust takes a Duration, Python timeout_ms, TypeScript pollWithin(timeoutMs, { signal })). It reads again every 100 ms until a change lands or the timeout passes, and returns an empty list when none landed in time.
  3. Handle the changes. Query the index if it moved.

Each item is a watched change: the change record, its message_id (TypeScript messageId), and its position on the feed, the partition and offset.

To read one record at a time, Rust's stream() returns a futures::Stream, TypeScript's stream() returns an async generator, and the Python reader is itself an async iterator. All three end when the reader is caught up. In TypeScript and Python a later loop on the same reader resumes where the last one stopped. Rust's stream() takes ownership of the reader, so save its offsets first if you need them.

const feed = await laser.watch().index("readings_v1").records()
for await (const { change } of feed.stream()) {
  console.log(`${change.index} advanced ${change.rows} row(s) on partition ${change.partitionId}`)
}
use futures::StreamExt;

let feed = laser.watch().index("readings_v1").records().await?;
let mut changes = std::pin::pin!(feed.stream());
while let Some(watched) = changes.next().await {
    let change = watched?.change;
    println!(
        "{} advanced {} row(s) on partition {}",
        change.index, change.rows, change.partition_id
    );
}
feed = await laser.watch(index="readings_v1")
async for watched in feed:
    change = watched.change
    print(f"{change.index} advanced {change.rows} row(s) on partition {change.partition_id}")

Change record fields

FieldTypeScriptMeaning
indexindexThe index that advanced
partition_idpartitionIdThe source partition
from_offsetfromOffsetFirst source offset in the batch, inclusive
to_offsettoOffsetLast source offset in the batch, inclusive
rowsrowsRows the batch wrote
streamstreamThe source stream, set only when the deployment keeps one feed per stream
vvThe change record version, currently 1

A record whose v is not the version the client reads stops its partition at that record. The changes before it are returned, and a poll with nothing else to return fails with a command error whose code is VersionSkew, so an older client never misreads a newer record. Upgrade the client to continue.

In TypeScript, fromOffset and toOffset are bigint values and stream is optional. In Rust, stream is an Option<String>. In Python, it is None when absent.

Resume after a restart

Save the reader's offsets and restore them in a new reader. Where you store them is up to you.

LanguageRead the positionRestore it
Rustfeed.offsets(), a slice with one u64 per partition.from_offsets(saved) on a new reader, with a Vec<u64>
TypeScriptThe feed.offsets property, a ReadonlyMap<number, bigint> from partition to offset.fromOffsets(saved) on a new reader
PythonThe feed.offsets property, a list of integers.from_offsets(saved), or await laser.watch(index=name, from_offsets=saved)

Each offset is the next one to read on that partition. A new reader without restored offsets starts at the first retained change. In Rust, a saved list shorter than the partition count reads the missing partitions from the start.

After a resume the reader counts the feed records retention removed before it reached them, in missed. A count above zero means changes were lost: query the view directly instead of trusting the feed.

const saved = feed.offsets

// After a restart
const resumed = (await laser.watch().index("readings_v1").records()).fromOffsets(saved)
await resumed.poll()
if (resumed.missed > 0n) await laser.query("readings_v1").fetch()
let mut feed = laser.watch().index("readings_v1").records().await?;
feed.poll().await?;
let saved = feed.offsets().to_vec();

// After a restart
let mut resumed = laser
    .watch()
    .index("readings_v1")
    .records()
    .await?
    .from_offsets(saved);
resumed.poll().await?;
if resumed.missed() > 0 {
    laser.query("readings_v1").fetch().await?;
}
saved = feed.offsets

# After a restart
resumed = await laser.watch(index="readings_v1", from_offsets=saved)
await resumed.poll()
if resumed.missed:
    await laser.query("readings_v1").fetch()

Delivery guarantees

  • Notifications are best effort after commit. A lost notification does not lose projected data, because the rows are already in the view.
  • The same change always carries the same message id, derived from its content. A retried batch can publish a change twice, so drop a change whose message_id you already handled.
  • A reader that falls behind the feed's retention window misses the records that expired, and its missed count says how many. Query the view directly to catch up.
  • The feed reports progress. It does not prove that a specific write is in the view. To make sure a query includes your own write, use a read-your-writes query. See Consistency.
  • The feed reports operational view changes only. It does not report key-value or session changes. Sessions have their own change feed on the session reads.

Key operations

VerbWhat it does
notify() on a bindingTurn on change records for that index
watch().index(name).records()Open a reader for one index (Rust, TypeScript)
watch(index=name)Open a reader for one index (Python)
watch().records() / watch()Read every index on one feed
from_end() / fromEnd() / from_end=TrueStart at the current end of the feed
poll()Read the changes that arrived since the last poll
poll_within(timeout) / pollWithin(timeoutMs)Wait for the first change, up to a timeout
missed / skippedRecords retention removed before the reader reached them, records that were not change records
stream()Read records one at a time until caught up (Rust, TypeScript. Python: async for)
offsets / from_offsets(saved)Save and restore the position across restarts (TypeScript: fromOffsets)

On this page