Create and manage streams

Create and manage streams

Create buckets and streams from Go, TypeScript, or HTTP, then list them and change their settings.

A bucket groups streams and holds the settings new streams take by default. Create the bucket first, then its streams, either explicitly or on first use. This page creates, lists, and changes both; Trim and delete removes them. Buckets and Streams explain the ideas. The API reference has the stream and bucket routes, and the CLI has nova stream and nova bucket.

Create a bucket

EnsureBucket / ensureBucket creates the bucket, or returns it when it already exists, so it is safe to call at startup. This bucket creates a stream on its first append and keeps records for 7 days by default:

bucket, err := c.EnsureBucket(ctx, client.Bucket{
	Name:           "demo",
	CreateOnAppend: true, // the first append to a missing stream creates it
	Defaults: client.StreamOptions{
		Retention: client.RetentionPolicy{MaxAge: 7 * 24 * time.Hour},
	},
})
if err != nil {
	return err
}

days := bucket.Defaults.Retention.MaxAge.Hours() / 24
fmt.Println(bucket.Name, "in", bucket.Location, "keeps records for", days, "days")
Output
demo in local keeps records for 7 days

An existing bucket keeps its settings, so ensuring it again changes nothing. UpdateBucket / updateBucket (PUT /v1/buckets/{bucket}) replaces them. The two flags apply at once, and new defaults apply to streams created afterwards.

NameNameRequired
The bucket's name; over HTTP, the last part of the path
CreateOnAppendCreate on appendDefaultfalse
The first append to a missing stream creates it
CreateOnReadCreate on readDefaultfalse
The first read or subscription of a missing stream creates it, empty
DefaultsDefaultsDefaultStandard, any producer, client-prefer, no limits
The settings a new stream takes when it leaves one unset. Over HTTP each is its own field, such as default_class
LocationLocationDefaultThe cluster's
Where the bucket lives, fixed at creation. A client configured with a location sends it on every create and update, and a mismatch fails
CreationTokenCreation tokenDefaultNone
A retry that sends the same token gets the bucket the first try created

Create a stream

CreateStream / createStream creates a stream at its address, a bucket and a key. A setting you leave unset takes the bucket's default; here, the 7-day retention comes from the bucket:

created, err := c.CreateStream(ctx, client.StreamOptions{
	Bucket:   "demo",
	Key:      "events",
	Class:    client.Standard,
	Producer: client.ProducerFenced, // one writer at a time
})
if err != nil {
	return err
}

days := created.Retention.MaxAge.Hours() / 24
fmt.Println(created.Key, created.Class, created.Producer, days, "days")
Output
events standard fenced 7 days
KindKindDefaultplain
plain, one sequence, or scalable, ranges behind one address. Fixed at creation; see scalable streams
InitialRangesInitial rangesDefault1
The ranges a scalable stream opens with, at most 256. Refused on a plain stream
ClassStorage classDefaultThe bucket's
standard or express; see storage classes
ProducerProducer policyDefaultThe bucket's
any lets many writers append at once; fenced admits one at a time. See coordinate writers
RetentionRetentionDefaultThe bucket's
Drops records older than a maximum age, or the oldest past a maximum size
ThroughputThroughputDefaultThe bucket's
The most bytes a second the stream takes; appends above it wait
TimestampingTimestampingDefaultThe bucket's
Whose clock stamps records; see timestamps
CreationTokenCreation tokenDefaultNone
A retry that sends the same token gets the stream the first try created

At creation, a zero value means unset, so it takes the bucket's default. Uncapped timestamping and an age limit cannot be combined. An address that is taken fails, unless the creation token matches.

A bucket can also create a missing stream when it is first appended to or read (create on first use). A tail check, a fence, or a trim needs a stream that exists. GetStream / getStream (GET /v1/streams/{bucket}/{key}) returns a stream's settings and its ID, which names the stream in logs. Requests always use the address.

List buckets and streams

A listing returns one bucket's streams in key order, at most 1,000 a page, and can keep only the keys that start with a prefix. Ask for pages until the cursor comes back empty:

opts := client.ListOptions{KeyPrefix: "events", Limit: 100}

for {
	page, next, err := c.ListStreams(ctx, "demo", opts)
	if err != nil {
		return err
	}

	for _, s := range page {
		fmt.Println(s.Key, s.Class)
	}

	if len(next) == 0 {
		break // the last page
	}

	opts.After = next
}
Output
events standard
events/archive standard

ListBuckets / listBuckets (GET /v1/buckets) lists buckets the same way, in name order, with a name prefix. It needs a grant to list every bucket the prefix covers, so a token for one bucket cannot list buckets. No listing spans buckets.

Change a stream's settings

ReconfigureStream / reconfigureStream (PATCH) changes only the settings you name. Here a zero means "no limit", which a create cannot say:

noAgeLimit := time.Duration(0)
perSecond := int64(1 << 20)

st, err := c.ReconfigureStream(ctx, stream, client.StreamReconfiguration{
	RetentionMaxAge: &noAgeLimit, // keep records for any age
	Throughput:      &perSecond,  // at most 1 MiB a second
})
if err != nil {
	return err
}

fmt.Println("max age:", st.Retention.MaxAge.Hours(), "hours")
fmt.Println("throughput:", st.Throughput.MaxBytesPerSecond, "bytes a second")
Output
max age: 0 hours
throughput: 1048576 bytes a second
ClassStorage class
The class later appends use. Stored records keep theirs
ProducerProducer policy
any or fenced
TimestampingModeTimestamping mode
client-prefer, client-require, or arrival
TimestampingUncappedUncapped
Stops capping client timestamps at arrival time
RetentionMaxAgeMaximum age
Zero removes the limit
RetentionMaxBytesMaximum size
Zero removes the limit
ThroughputThroughput
Zero removes the limit

A retention change applies at once, with one exception: a shorter age on a stream that already has an age and no size limit applies only once the oldest kept records pass the old age. Trim to the new cutoff to apply it sooner. A change of class, producer policy, timestamping, or throughput passes the stream's writes through a short handoff: an open producer reconnects once, and every append after the call uses the new settings. A setting you leave out stays as it is. In Go the fields are pointers, so leave it nil. In TypeScript, leave the field out. Settings lists every setting with its default.

When a call is refused

Refusal: Go, TypeScript, HTTPWhenWhat to do
AlreadyExists gRPC status, TransportError with code ALREADY_EXISTS, 409The bucket name or stream address is takenUse another name, or retry with the same creation token
ErrStreamNotFound, StreamNotFoundError, 404The bucket or stream does not existCreate it
FailedPrecondition gRPC status, TransportError with code FAILED_PRECONDITION, 503The node cannot serve the class you asked for, such as Express on a node without Express storageAsk the operator to set up the class
ErrLocation, LocationMismatchErrorThe bucket names a location other than the client'sCreate the bucket from a client in its location
ErrPrefixUnsupported, PrefixUnsupportedErrorThe server is too old to list by prefixUpgrade the server

The SDKs check settings before they send them, and refuse a wrong one with an error that names it, such as initial ranges on a plain stream or uncapped timestamping with an age limit. Handle errors lists every error.

See also

On this page