Streams
A Kafka topic, queried with ordinary SQL. SQLDesk keeps a window of the last few minutes and nothing older — and consumes only while somebody is watching.
What this is, and what it is not
It is not a pipeline. SQLDesk does not land your topic anywhere, does not replay history, and does not promise to have seen every message. If you want the last six months, land the topic in your warehouse and point SQLDesk at that. What this is for is the question you have during an incident, about the last ten minutes.
What it keeps is a window, held in DuckDB, sized from the row budget and the rate actually observed: a slow topic gets an hour, a fast one gets four minutes. Above a ceiling the stream is sampled, and everything drawn from it says so — a count from a sampled stream is an estimate, and silence about that is the worst outcome.
Trying it: the stream demo
To try streams without a producer of your own, run the demo: a Kafka broker with a schema registry, and a small shop’s events on six topics, in every format a stream reads. The events refer to each other, so a query can join two topics.
| Topic | Format | Message format to choose |
|---|---|---|
orders | JSON | Automatic |
payments | Avro, through the registry | Automatic |
shipments | Protobuf, through the registry | Automatic |
page_views | JSON Schema, through the registry | Automatic |
inventory | Avro, no registry header | Avro, with inventory.avsc |
refunds | Protobuf, no registry header | Protobuf, with refund.proto and
money.proto, message sqldesk.demo.Refund |
With Docker Compose:
docker compose -f examples/stream-demo/compose.yaml up -d
On Kubernetes, beside a SQLDesk installed with the chart:
kubectl apply -f examples/stream-demo/kubernetes.yaml
The broker is Redpanda’s own image. The events come from ghcr.io/bot-netizen/sqldesk-stream-demo.
The demo’s README has
the addresses to use, how to put a SQLDesk running in Docker on the demo’s network, the schema files
to upload, and queries to start from.
Clusters and topics
An administrator adds a cluster as a data source: brokers, and whatever the cluster needs to let us in. Its topics are its tables.
Which topics can be queried is chosen under Settings → Streaming Data Sources, by somebody with the streams permission — it sits beside Data Sources because it configures a connection, and the cluster itself is added on the tab next to it. That is the real access decision: the data source permission is per cluster, so whatever is enabled there is what everybody with access to that cluster can query. A cluster carrying a topic not everyone should see wants a second data source of its own with a restricted list, granted to another group.
Analyse a topic before enabling it. It reads the last few hundred messages and says what the columns are, how many could not be parsed, how fast they arrive, how much history that buys, and whether it will be sampled. None of those can be guessed from a topic’s name, and finding out an hour later is the bad way.
A cluster on TLS
Choose SSL or SASL_SSL as the security protocol. If the brokers’
certificates come from a public CA there is nothing else to do. If they come from your own — an
internal PKI, a self-signed cluster — upload that CA certificate. If the brokers want
a client certificate, upload the client certificate and its key, and the
key’s password if it has one. All of them are PEM files.
Turn off check the broker’s certificate matches its name only for brokers reached by an address their certificate does not name, such as an IP or an internal alias. The certificate is still checked against the CA; only whose it is, is not.
How a topic looks to the broker
By default SQLDesk joins no consumer group and commits nothing, so lag monitoring never sees it. Kafka clients have to be given a group id, so one is set, but the consumer assigns itself every partition instead of joining, and the broker never registers it.
Each topic can change that where it is analysed and enabled, under How it reads:
- Consumer group — a name to join, for monitoring that ignores consumers by prefix and would rather see SQLDesk under one.
- Save position — commit offsets after each flush, so the stream resumes where it stopped. Off by default, and it needs a group name.
- Start from — latest, earliest, or where it left off. It applies when a stream starts from cold; between one consuming job and the next it carries on from where it stopped.
A topic the broker does not have, or will not describe, stops the stream with that reason on its page rather than leaving it looking quiet.
JSON, Avro and Protobuf
What a topic’s messages are is chosen under How it reads, as its message format. Automatic covers most topics with nothing to set.
| Format | Reads | Needs |
|---|---|---|
| Automatic | JSON as it is. Avro, Protobuf and JSON Schema written through a schema registry — each message carries a five-byte header naming its schema. | For registry topics, the registry’s URL on the Kafka data source. |
| Avro | Avro with no registry header. | The .avsc the producer writes with. Several, if they refer to each other’s
types. |
| Protobuf | Protobuf with no registry header. | The .proto file and any it imports, and which message the topic carries. The
google/protobuf types are built in. |
A schema registry is set once, on the Kafka data source: its URL, and a username and password if it wants them — Confluent Cloud takes its API key and secret there. Confluent’s, Redpanda’s, Karapace and Apicurio’s compatibility API all work. Over HTTPS it trusts the public authorities and the cluster’s own CA certificate, since a registry usually sits on the same PKI as the brokers. Saving the data source checks the registry answers.
Uploaded files are checked the moment they are chosen: a .proto that does
not compile says where, under the button, and the topic cannot be enabled until it does. An import is
found by the path it names, so import "common/money.proto" finds an uploaded
money.proto.
Fields come out as columns DuckDB types properly: timestamps as TIMESTAMP, 64-bit integers
as numbers, enums by name, bytes as base64, nested messages and records as structs you reach with a dot.
Every field is a column whether or not a message set it; unset, it is null.
Changing the format starts the window again. Its columns came from the old reading, so they are inferred afresh from the next messages; a running consumer picks the change up at its next flush. When nothing on a topic can be read — a registry header with no registry set, bytes that are neither JSON nor anything the schema describes — the stream’s page and the analysis say which, rather than counting every message as malformed in silence.
JSON costs what it always did: it is never parsed on the way in. Avro and Protobuf are decoded after sampling, at around 45,000 messages a second on one core, so a stream at its ceiling spends about a tenth of a core on it.
Querying one
Create → New Streaming Query opens the query editor, with the schema browser listing the enabled topics and the same visualizations as anywhere else. Two differences: the button says Start streaming rather than Execute, and no result is ever stored.
A streaming query is a query. It is listed under Queries → Streaming Queries, with the same All, Favorites, Mine and Archived views as any other — and nowhere else: the two halves of that list do not overlap, so a query has one place it lives. The same is true of Dashboards → Streaming Dashboards; a dashboard built on streams carries a streaming chip beside its name and a band down the side of the page, which turns green while its topics are actually being consumed.
The query is saved like any other; the rows are not. A window is what a consumer saw while somebody was watching, and writing it down would be making a copy of the one thing whose point is that it is current.
Streams cannot be scheduled and cannot be alerted on, for the same reason: at three in the morning nobody is watching, so there is nothing to refresh and nothing for an alert to check.
Every topic has _received_at
The time SQLDesk took the event off the topic, added to every window. It is the column to group by for a rate, and the column to order by for anything drawn over time:
select _received_at, region, sum(amount)
from orders
group by 1, 2
order by 1
Not the time the event happened — that is whatever field your producer puts in the message, and SQLDesk does not guess which one. Use yours where the difference matters; a late or replayed event has an arrival time of now.
A window comes back in no particular order. It is a file read by DuckDB, and
without an ORDER BY the rows arrive in whatever order the engine found them. A table does
not care; a line chart drawn over time does, which is why charts sort their points by the X column
unless you turn sorting off in the visualization editor. Adding order by is still worth
it: it makes the result right rather than only the picture.
Running, paused, cold
A stream is running while somebody has checked in within the last 45 seconds; paused when nobody has, keeping its window so coming back resumes in seconds rather than from an empty chart; and cold after ten minutes, when the window is dropped and starting again is a deliberate act.
Resuming seeks to the end of the topic, as starting does. Replaying the gap would stamp old events with an arrival time of now, which would be a chart that lies — so a pause leaves a hole, and the chart says it was paused.
Rollups, for the part worth keeping
A window is minutes long, so “how does now compare with this morning” has nowhere to
read the answer from. A rollup is the answer: one row per minute per group, counted
as the events arrive and kept for 24 hours
(SQLDESK_STREAM_ROLLUP_HOURS). The raw window lives in DuckDB and does not survive a
restart; the rollup lives in Postgres and does.
A stream declares the columns it groups by and the measures it keeps. The measures are
count, sum, min, max, avg,
approx_distinct and distinct — and distinct counts default to the
approximate one, a HyperLogLog that costs almost nothing, because an exact distinct over a minute of
a busy topic can cost more than everything else together. A dashboard counting unique visitors per
minute does not need exact; the one rollup that does can say so.
Cardinality is what kills a rollup. Grouped by user_id on a
ten-million-user stream it is not a rollup, it is the stream again with extra steps. So the distinct
groups kept per minute are capped at a thousand — already more lines than a chart can draw
— and everything past the cap lands in one other bucket that the chart
shows. A total missing its long tail is wrong while looking right.
A definition is checked against the stream’s real columns when it is saved, so a column that is not there is a sentence you read immediately rather than a DuckDB error in a worker’s log once a minute with nobody watching.
There is no editor for this yet. Rollups are defined through the API, by an administrator, against the stream:
POST /api/data_sources/<data_source_id>/stream/<stream_id>
{"group_by": ["region"],
"measures": [{"name": "orders", "kind": "count"},
{"name": "revenue", "kind": "sum", "column": "amount"}]}
and read back from
GET /api/data_sources/<data_source_id>/stream/<stream_id>/rollup, which
answers with the minutes it holds. A page for it is a later release; the store, the job and the
checking are here now.
Slots
A slot is a topic, not a viewer. Five people watching orders share one
consumer and one window and take one slot between them, which is what makes a limit mean five topics
rather than five tabs — and makes a team round one dashboard during an incident nearly free.
There are three limits: how many topics may be consumed at once across the install, how many one person may start, and how long one runs before somebody says they still want it. Past them you are told what is running and who started it, because “no slots” is only actionable if you can see who to ask. The editor says all N stream slots in use beside the button that will not start, and Admin → Streaming Queries shows every topic, who is watching it, and the budgets.
Who may do what
- Administrators
- Add the cluster, and pin a topic so it consumes with nobody watching.
manage_streams- Choose which topics can be queried, and how much of each is kept.
use_streams- Start a stream, which takes a slot.
- Anybody with access to the cluster
- Query what is enabled, and watch a stream somebody else started — no slot is taken and nothing new becomes visible.
On a dashboard
A dashboard shows streams or saved queries, never both, and a streaming one is still until it is made live.