Show HN: Mason – A lightweight Postgres read-replica, built on columnar storage

98 points by tagspace 21 hours ago on hackernews | 21 comments

hum3hum3 | 19 hours ago

I did something sort of similar which is to rewrite postgres so that I could use it against a single file sqlite DB and run in a browser with WASM. https://github.com/drummonds/go-postgres

[OP] tagspace | 19 hours ago

Ah nice. What do you use it for?

ForHackernews | 17 hours ago

richardmeng | 19 hours ago

Very cool.

nylonstrung | 18 hours ago

Outside of the dashboard and team features stuff what does this add over just DuckDB + ADBC connected to postgres?

Is pglite and the node stuff even necessary here?

[OP] tagspace | 18 hours ago

Good question. The majority of the work was two things:

1. the replication logic that keeps duckdb in sync with your postgres (like you'd expect from a read replica)

2. the query rewriter that takes incoming postgres queries and turns them into queries that run fast on duckdb (we've spent a lot of time making sure that most queries are answered in a few 100 milliseconds, even on 10+M rows).

So, I guess the main differences are:

- with ADBC the load still hits your postgres (which is what we wanted to avoid)

- with ADBC you're not guaranteed to get the same answer as postgres (we want confidence that our queries will answer the same, not faster but different)

- you'd have to build your own ETL (if you want to avoid the load on your postgres)

Does that make sense?

aleda145 | 18 hours ago

Cool! DuckDB is awesome

I'm very curious with the use case, why do you need to run analytical queries against the postgres read replica? Why not read the WAL and CDC them elsewhere? Especially if it's adhoc then the (short) delay wouldn't be noticeable.

Also did you tried transpiling SQL if you wanted to match the postgres dialect? I've had great success with duckdb <=> postgres using https://github.com/tobilg/polyglot

NewJazz | 17 hours ago

Sounds like they saw clickhouse as too operationally cumbersome and too much of a shift for their use cases. They seemed to want to reuse existing sql queries or fragments and just get a performance boost, and then also easy spin up these analytical DBs in customer environments on an ad-hoc basis.

[OP] tagspace | 17 hours ago

Yeah, exactly. Our customers have lots of postgres dbs, and we needed something plug and play that we can throw the existing (postgres) queries at, without having to rewrite them. Also saves setting up a warehouse each time.

And yeah, it uses CDC via the WAL if you sync via logical replication.

aleda145 | 16 hours ago

Ah a fleet of customer postgres dbs! Makes sense, thanks for taking the time to explain

alex_hirner | 16 hours ago

Can replicated tables live on s3/parquet only, as in did you try so?

[OP] tagspace | 15 hours ago

Haven't tried it to be honest. Currently very lightweight and just syncs directly to the disk where you run it.

But duckdb supports both S3 and parquet so would likely be easy to support.

What's the usecase, if you don't mind me asking?

I guess the advantage is lower storage costs, but the read latency would take a hit (which would definitely affect query speeds). Would be interesting to try.

neilsimp1 | 16 hours ago

There are too many software projects with this name.

akshay180 | 15 hours ago

I have too many friends with this name

rightisleft | 12 hours ago

There are too many software projects…

pratikgcet1985 | 15 hours ago

This is really good! We are an avid user of ClickHouse and this is awesome work.

aiexplore369 | 7 hours ago

this seems to be promising with clickhouse great work !keep t rolling !
Have you considered other data sources? The idea is solid, I design Enterprise data warehouses for a living and with AI I have been wondering what's going to be next. Redshift/Snowflake, etc., have their pros but they don't come with predefined ingestion and access control.

Another question, how do you scale duckdb to multi user reads? I guess for you it's 1 file behind a node service? A typical data warehouse could have 1,000 concurrent users on a Monday morning.

And any thoughts on temporary access tokens for odbc? A la https://medium.com/@shashwat_singh/hashicorp-vaults-dynamic-.... This is because I would rather not give any real password to AI agents.

[OP] tagspace | 4 hours ago

hey kfk. Yeah, we've definitely been thinking about the potential for other datasources. E.g. we already have use-cases internally where being able to ingest from clickhouse, SQS and S3 would be big wins. Do you have particular sources in mind?

Great question about scalability. Mason right now has really been built for the BI use case, where you have lots of sporadic adhoc queries. It does this really well by dedicating every CPU to every query as it comes in, so it responds as quickly as possible. But, internally we also deal with lots of customer-facing analytics usecases, which is more like the case you describe: 1,000 concurrent users accessing a dashboard concurrently. For that case, the easiest thing to do is to simply give your machine more CPU and RAM (that will get to surprisingly far), but then beyond that we'd need to allow scaling the Mason readers horizontally. Definitely something we're going to look into.

ODBC is an interesting use-case. Not something we come across alot. Can i ask what your use-cases are there?

guy_louzon | an hour ago

Sounds cool. so basically you created a PostgreSQL compatible layer on columnar db so any software on top it is "mostly" indifferent ?

[OP] tagspace | 48 minutes ago

Exactly. Any tool that can talk to postgres can talk to it.