Skip to content

Initial design for a serving layer#34979

Draft
antiguru wants to merge 1 commit intoMaterializeInc:mainfrom
antiguru:serving_layer_design
Draft

Initial design for a serving layer#34979
antiguru wants to merge 1 commit intoMaterializeInc:mainfrom
antiguru:serving_layer_design

Conversation

@antiguru
Copy link
Member

@antiguru antiguru commented Feb 10, 2026

Signed-off-by: Moritz Hoffmann <antiguru@gmail.com>
@antiguru antiguru force-pushed the serving_layer_design branch from 48d241c to a7aa1a5 Compare February 10, 2026 22:28
Copy link

@djahandarie djahandarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw this PR scroll by and wanted to share that we are very excited about this direction! I know it's a draft, but left some random thoughts in case they are useful. (Feel free to ignore them, you don't need to give detailed responses unless it's helpful to your thought process somehow.)


Choices:
* Fast data structure to lookup values by key.
We do not support scans or inequality comparisons.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would be very interested in btree-like access patterns; for example, in a huge amount of our use cases, we have some sort of paginated display of index contents, where we want to SELECT ... WHERE X < ... ORDER BY X LIMIT 100 or similar. Maybe it's not so easy to incrementally maintain a data structure which allows for something like this and that's why you made this choice, but just sharing the thought.


### Proposal 1: Serving layer replicas

We introduce the notion of a serving cluster with serving cluster replicas.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that this would ~fully replace any clusters that currently function as "serving" clusters (like recommended in the docs)? If so this seems great to me, as it keeps the flexibility of the user being able to define their own compute isolation in whatever way is relevant to them, and now it's just more scalable/faster due to the explicit specialization.


Supporting SQL prepared statements (or an equivalent)
* Investigate lateral joins
* If the placeholders are equality lookups, we can convert the query to a materialized view that arranges the data such that the placeholder columns are keys to the prepared statement.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose I'm a bit confused why something special like this would need to be done. Is this to improve the ergonomics of being able to auto-optimize the performance of any arbitrary prepared statement that might come in (compared to users needing to individually define indexes for their access patterns)? I guess I'd be a little afraid of a new query suddenly causing a big rearrangement which starts getting permanently maintained, and manual definition of indexes via dbt or similar feels safer, but maybe I don't see the vision yet or don't fully understand it.

I think the strawman design would be to just extend CREATE INDEX to have USING newdatastructure, and maybe also support something closer to INCLUDE (col1, col2) in Postgres to be able to control what is actually in the index (as opposed to the current pattern of always including everything and requiring users to make views in order to achieve this) to improve ergonomics. Then a prepared statement would simply be responsible for finding a matching index, and from there it could be served very fast, right?


* What's the right data structure?
* How do clients talk to the serving replica?
Is environmentd a bump on the wire, is there a separate service, or do we allow direct connections?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(One vote for as close to a direct connection as possible 😄 We really want to isolate serving between tenants as much as possible, and don't want any cross-tenant DoS situations even if one makes a couple million connections or something crazy. )

@aljoscha
Copy link
Contributor

In that design, is envd still "terminating" network connections or clients go directly to a serving-layer process? I can see either way working, but if clients go directly to a serving-layer process we need a way of syncing catalog changes over to there, and they need to run a check to make sure they're up to date to be strictly serializable.

You'd need roughly https://github.com/MaterializeInc/database-issues/issues/9738, which builds on two other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants