Bookmarks

Bookmarks

A bookmark is a reader's saved place in a stream, as a string you store and pass back to resume.

A bookmark is a reader's place in a stream: where its next read should start. Every read, subscription batch, and tail check returns one, and every read and subscription can start from one. You save it with your own progress, and after a restart you pass it back to continue. On a plain stream a bookmark is the next sequence number. On a scalable stream it is an opaque string:

GET /v1/streams/demo/clicks/records/tail, on a scalable stream
{
  "bookmark": "CAESKAokMDFhMjA0ODYtYjNkYy03MWZmLTllMGItNTgzNjg5MWM4YWQxEAESKAokMDFhMjA0ODYtYjNkYy03MjAzLWE3YWMtNTRiNTU4YzNiYTk2EAI"
}

A plain stream needs no more than a sequence number to resume. A scalable stream has one sequence per range, and its ranges change as they split and merge. One number cannot say where a reader is in all of them, so the bookmark does.

What a bookmark holds

Kind of streamText of the bookmarkIt holds
PlainThe next sequence number in decimal, such as "2"One place
ScalableAn opaque string of URL-safe charactersFor each range the reader follows, the next sequence number there, or a mark that the range is finished

A scalable stream's bookmark stays valid after later splits and merges. A reader that resumes from it continues in each range where it stopped, then moves on to the ranges that replaced it. Treat the string as opaque: store it and pass it back unchanged. It is safe to put in a URL, a database column, or a file.

Where bookmarks come from and go

OperationReturns a bookmarkTakes a bookmark
ReadThe place after the last record of the pageAs its start
SubscribeWith each batch, the place after its recordsAs its start
Check tailThe end of the streamNo
Fence, on a scalable streamEach range's position when the token took effectNo
TrimNoAs the point to trim to

On a scalable stream, a read must start from a bookmark, the beginning, the tail, or a time. A bare sequence number is refused with 400, because it does not say which range it belongs to. On the command line, nova check-tail prints a scalable stream's bookmark, then the next sequence number of each range.

Resuming after a restart

Save the bookmark after you have processed the records before it, in the same place as the results of that processing when you can. After a restart, subscribe from the saved bookmark. Records you processed but whose bookmark you had not yet saved are delivered again, so make processing safe to repeat, or save the two together.

To replay from one record you logged, such as a record that failed, the SDKs can change one range's place in a bookmark and keep the others. See read across the ranges.

See also

On this page