SQLDesk

Architecture

Three SQLDesk processes — the server, the workers and the scheduler — and two databases, Postgres and Redis. None of them is unusual, and knowing which one is doing what explains almost every question about why something is slow, stale, or missing.

Browser React single page HTTPS Server Flask · gunicorn runs no queries Scheduler rq-scheduler · puts due work on the queue due work Redis job queues, locks, schema cache takes work Workers RQ · run every query, send every alert enqueues reads / writes Postgres users, queries, dashboards, query results, the catalog writes the result back your SQL Your warehouse Postgres, Trino, BigQuery…

The server never touches your warehouse. It hands work to Redis and answers from Postgres, which is why a slow warehouse makes dashboards stale rather than making SQLDesk unresponsive.

All of it, including the parts that are off

The three processes above are what always runs. Everything else is an add-on, drawn dashed here and absent from a default install — see what is on when you change nothing. The shape does not change when you switch one on: it is another consumer of the same Redis, and it writes where the others write.

Browser React single page MCP client an agent you bring /mcp · OAuth Server Flask · gunicorn · runs no queries enqueues Redis job queues · locks · schema cache · stream slots · who is watching what Scheduler puts due work on Workers every query, every alert add-on Renderer a headless browser add-on MCP worker a queue of its own add-on Stream worker one process per topic reads / writes the result your SQL the window Postgres everything but the rows Your warehouse Postgres, Trino, BigQuery… Shared volume DuckDB files: uploads, windows Kafka your cluster reads it back

Dashed is optional. The one edge worth following is the long one on the right: the stream worker writes a topic's window to the shared volume and the server reads it back to answer a stream query — which is why that volume has to be the same one for both, and why turning streams on turns it on too.

The server

Flask behind gunicorn. It serves the single-page application, answers the REST API, and checks permissions. It reads and writes its own Postgres and it enqueues jobs — but it does not run your queries. A request that would take four minutes against Trino would hold a web worker for four minutes, so it does not happen here.

gunicorn runs gthread: four processes, eight threads each. Not every request is instantaneous even when it touches no warehouse — testing a data source's connection, asking MCP to run something, sharing to Slack, starting a stream — and with four single-threaded workers, four of those at once meant the fifth person got nothing. Including the health probe, which is how a busy install arranges its own restart.

Its connections to Postgres carry a 30-second statement timeout. Nothing a request does should take longer; without it, one lock or one plan that went wrong after a table grew held a worker until gunicorn killed the worker outright, taking the other requests it was serving with it. The workers below deliberately have no such limit.

Postgres — the metadata database

SQLDesk's own. Not your warehouse, and not a copy of it. It holds:

Query results are usually the largest thing in it by a wide margin. A maintenance job removes results nothing points at any more; how long they are kept is configurable.

Redis — queues, locks and cache

Three distinct jobs, which is worth separating because people assume it is only a cache:

Job queues
Every query execution, scheduled refresh, alert check and email is a job on an RQ queue. The server puts them on; workers take them off. MCP's queries can have a queue of their own (SQLDESK_MCP_QUEUE) and workers that take only that.
Locks
If five people open a dashboard at once, one job runs and the others wait on its result rather than each hammering the warehouse with the same SQL.
Query pool slots
How many queries each data source’s pool is running, and who holds them. A slot expires unless the query holding it renews it, so a killed worker frees its slots on its own. The shared pools made in the app and the default size are cached here too, so a query reads its pool’s size with one lookup.
Schema cache
The table and column list shown by the editor's autocomplete, with a time to live. It is a cache in the real sense: losing it costs a refresh, not data.

Redis holds nothing you cannot afford to lose. If it is wiped, in-flight jobs are lost and schedules resume; no query, dashboard or result goes with it. That is deliberate — it means Redis can be a plain container with no persistence configured.

Workers

Separate processes running RQ. They take jobs off the queues, open connections to your data sources, run the SQL, and write results back to Postgres. Everything slow happens here. Scale them when queries queue up; scale the server when pages are slow to load. Those are different problems and the fix is rarely the same one.

There are two kinds, and the split is the point:

The query worker — queries, scheduled_queries, schemas
Somebody's SQL against somebody's warehouse. A job here can take minutes, and is expected to.
The periodic worker — periodic, emails, default
Deciding what to refresh, evaluating alerts, sending mail, the clean-ups. None of it is heavy; it is a few seconds of work a minute. What it needs is to be running.

They were one worker until 0.7.7, and two slow queries were enough to stop the second kind happening at all: nothing deciding what to refresh, no alerts evaluated, no mail sent — with every health check still passing, so the only symptom was staleness nobody could account for.

A query a worker is running is cancellable, and bounded: fifteen minutes for a query somebody is waiting on, thirty for a scheduled one. Before 0.7.7 there was no limit at all, and a query against a warehouse that never answered held its worker until somebody noticed.

Before it runs a query, a worker takes a slot in that data source’s pool, or refuses with a sentence if the pool is full. A query that carries an estimate can take more than one slot. After the query, the worker keeps what the engine said the query used, priced at the data source’s rates, with the result. Trino sends that with its last page, so there is no second query. See what each engine says about cost.

The scheduler

It watches the clock and puts due work on the queue — scheduled query refreshes, live dashboards, schema and catalog refreshes, cleanup. Alerts are not on the clock: one is checked when its query's new result is stored. The scheduler runs nothing itself.

More than one is safe, though one is the default. rq-scheduler takes a lock in Redis before each pass and enqueues only while it holds it; the others log that the lock was taken and skip. So a second replica is a warm spare for the minutes between a node going away and the pod being rescheduled — minutes in which, with one, nothing is scheduled and nothing says so.

What happens when you open a dashboard

  1. The browser asks the server for the dashboard and its widgets.
  2. The server reads them from Postgres, along with the stored result for each query, and returns them. Nothing has touched your warehouse.
  3. The page draws. The age shown under each widget is the age of that stored result.
  4. If you press Refresh, the server enqueues a job and the page waits for it. A worker runs the SQL, writes the new result, and the widget redraws.

Two widgets on the same query with the same parameters share a single fetch. A dashboard with five views of one query asks once.

What the page sends back is one request, not one per tile. The browser batches the events it recorded over the last second and posts them together; the server turns that into a single job and a single transaction. Opening a dashboard of thirty widgets used to queue about seventy-five jobs, each with its own round trip to Redis, its own worker pick-up and its own transaction, for one small insert each. Two of the three events per tile are gone as well — the widget's own id and the visualization's, which nothing on any page or in any report ever read.

DuckDB — the second database

SQLDesk runs a second database engine, inside itself, for two jobs that Postgres is the wrong shape for. It is worth understanding because it is the piece people are most surprised to find.

Uploaded files
A CSV or Parquet file you upload becomes a view over the file on disk. Nothing is imported — the file is the table, and DuckDB reads it where it lies.
Stream windows
The last few minutes of a Kafka topic, one file per topic. See below.

Why not Postgres? Because both of these are columnar, analytical workloads over data you can afford to lose, and Postgres is the one database here you cannot. Pushing fifty thousand events a second through it would make the database holding your users and dashboards also the one under the most write pressure, and a scan of a few million rows would compete with the page you are reading.

Why a file, and not memory? Because the processes that write and the processes that read are different ones. A stream's consumer runs on a worker; your query runs in the web process; the rollup runs on another worker. A file is the only cheap thing all three can see. DuckDB gives a file to one writer at a time, so the consumer takes the lock for the moment it writes and releases it between flushes; readers open read-only and wait out a flush rather than failing on one.

An uploaded file nobody has queried for a few days is unloaded — its view is dropped so no query pays to infer its schema — and the next query that names it brings it back. The file itself is never touched by that.

The notebook interpreter

An optional container, off by default, for notebook cells that are code. It exists so that nobody’s code runs in a worker, the process holding every data source’s decrypted credentials. The workers call it over HTTP with a token. It holds no credentials and calls nothing back.

A Python session
A child process per notebook, with ceilings of its own, which keeps the notebook’s variables between cells. Its data arrives from earlier cells as Parquet, so it needs no route anywhere.
A Scala session
In the Scala image only: a JVM per notebook running the Scala compiler’s own interpreter, with spark a Spark Connect session on the notebook’s cluster. The Scala compiles here. The cluster receives the plans its DataFrames make, and the classes of any lambda or UDF, and runs them.
Which cluster
The notebook’s compute: Local Python, or a Spark Connect data source its groups may use. The server sends that cluster’s address, token, TLS and Spark settings when it starts the session, so the executor holds no cluster of its own, and two notebooks can be on two clusters at once. A session on a cluster, Python or Scala, is the one case where the container needs a route out: to that Connect server, and nowhere else.

Stop is a signal: to a Python child it is an interrupt, and to a Scala session it is a cancel of everything that session is running on the cluster. Either way the notebook’s values survive. A cell that will not stop is ended with its session.

Streams — Kafka, and what a window means

A Kafka topic is not a table and SQLDesk does not pretend otherwise. What it keeps is a window: the last few minutes of a topic, held in DuckDB, queryable with ordinary SQL.

It is explicitly 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.

The cluster is the data source
An administrator registers brokers and credentials once. Topics are its tables.
A consumer runs only while somebody is watching
Nobody watching means nothing consumed and nothing stored. A stream resumes from the end of the topic, never from where it left off — replaying a gap would stamp old events with an arrival time of now, and draw a chart that lies.
The window sizes itself
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 every chart drawn from it says so, because a count from a sampled stream is an estimate and silence about that is the worst outcome.
Rollups outlive the window
Each minute is aggregated into buckets and kept after the raw events have aged out, so "what happened this morning" has an answer when the window has long moved on.

MCP — where the AI pieces sit

The MCP server is part of the web server: JSON-RPC over HTTP, needing nothing heavy. An AI client connects to it the way a browser connects to the API, and runs as the person whose credentials it holds — the same data sources, the same permissions, the same audit.

Three pieces sit behind it, and they are deliberately separate:

The catalog
What the tools know about your warehouse: tables, columns, which ones are actually used together, agreed measures, and queries a person has confirmed as the right answer to a question. Built by a job on the workers — harvesting — which reads each data source's schema and the SQL that recently ran against it. It never overwrites a description somebody wrote.
Its own queue and its own workers
A model exploring a warehouse writes a great many queries. They go on the mcp queue, served by workers that take nothing else, so a model cannot slow down a dashboard somebody is watching.
A cost ceiling and a question, from the engine's own estimate
Optional. Where the engine will say what a query costs before running it — a plan cost from the Postgres family and Vertica, bytes from Trino and BigQuery — run_query can refuse above an install-wide limit, or, above a data source's own line, hand the figure back for the model to put to its person before it runs. No estimate is never a refusal. After a query runs, its answer ends with what the engine says the query used.

No AI component sits between your browser and your data. Nothing is sent to a model by SQLDesk; a model asks SQLDesk, and SQLDesk answers from the data sources that model's user may already read.

The words, and what they mean

Data source
A connection to somewhere data lives, with credentials encrypted at rest. The unit permissions are granted on. A warehouse, a file upload area, or a Kafka cluster.
Query
Saved SQL against one data source. Has an owner, a history of changes, optional parameters and an optional schedule.
Query result
The rows a query returned, stored in Postgres with the hash of the SQL that produced them. What a dashboard shows is a stored result, which is why dashboards are fast and why they have an age.
Visualization
A chart over a query's result. A query can have several.
Widget
A visualization placed on a dashboard.
Live dashboard
One the server refreshes on an interval, once for everyone watching, instead of every open tab re-running the queries on its own timer.
Window
What SQLDesk keeps of a Kafka topic: the last few minutes, in DuckDB. Not a copy of the topic.
Sampling
Keeping a fixed share of a topic's events when it is faster than the ceiling allows. Charts drawn from a sampled stream say so.
Rollup
A per-minute aggregate of a stream, kept after the raw events have gone.
Catalog
What the MCP tools know about your warehouse.
Harvest
The job that builds the catalog from schemas and recently-run SQL.
Unloaded
An uploaded file whose view has been dropped because nothing has queried it lately. The file is untouched and the next query that names it brings it back.

Where everything is kept

StoreHoldsIf you lose it
Postgresusers, data sources, queries, dashboards, alerts, query results, the catalogeverything. Back this up.
Redisjob queues, locks, the schema cache, who is watching whatin-flight jobs, and nothing else
Postgres, againwhether a data source is pausednothing — it used to live only in Redis, so a pause lasted until the next restart and then every scheduled query ran against the warehouse somebody had deliberately taken out of service
DuckDB filesuploaded files' views, stream windowsa window, which refills in minutes; uploads are the files themselves and survive
Your warehouseyour dataSQLDesk never writes to it

Why the same query does not run twice

Five people opening the same dashboard should cost the warehouse one query, not five. The lock that arranges this is a Redis key naming the data source and a hash of the SQL, holding the id of the job that owns it.

Two details decide whether it works. It is held until the result row is written, not until the query returns: between those two moments there was nothing for a second request to join and no stored result to fall back on, so the sibling ran the whole query again. And it is released by compare-and-delete — a job that has finished removes the lock only if the lock is still its own. A plain delete let a finishing job release a lock a newer job had just taken, and the next request started a third run of the same query while the second was still going.