SQLStreams

the messaging platform that is just Postgres

You last visited on 9999-99-99 Show what's new since then

Payload versions and raw JSON

Edit this page
Stream · Related pages
Posted: 2026-09-16 · Report this thread
brandon Site Admin brandon profile Posts: 96
type Versioned interface {
SchemaVersion() int
}

A message payload type implements Versioned and can be encoded as JSON. Its schema version is stored with each produced message. A consumer instance processes messages matching the version declared by its payload type.

Define a payload

Use a value receiver that returns a constant of at least 1.

type PaymentRequestedV1 struct {
OrderId string `json:"order_id"`
}
func (p PaymentRequestedV1) SchemaVersion() int { return 1 }

Declare a new version for incompatible payload changes, such as removing or renaming a field or changing its type. The payload version is separate from the database schema version managed by migrations.

RawPayload

type RawPayload []byte

Use RawPayload for administrative reads that should preserve stored JSON without decoding it into an application struct. It implements JSON marshal and unmarshal methods and returns 0 from SchemaVersion.

payments := client.Stream[sqlstreams.RawPayload]("payments.requested")
stream, err := payments.Get(ctx)
if err != nil {
return err
}
if stream != nil {
fmt.Println(stream.Id, stream.Name)
}

This example uses an initialized client to inspect the payments.requested stream.

Use Supported with RawPayload
Read stream registration Yes. The lookup does not decode messages.
Read retained keyed messages or compaction heads Yes. The payload remains JSON bytes.
Register a consumer group No. Consumer payload versions must be at least 1.
Produce a message No. Version 0 cannot be produced.