⏱️ Reading time: 7 min
Postgres is excellent at handling orders, users or inventory, but when a query scans millions of rows to sum, count or group data, the same engine that protects those transactions turns slow. Mason tackles that problem without asking you to change a single line of your analytical queries in Postgres: it syncs the tables you choose to an internal columnar engine and rewrites every query on the fly. In the benchmark the project publishes, a count query over 10 million rows took 15.7 seconds on the primary Postgres instance and 0.193 seconds on the Mason replica, with the same result: 81 times faster (source).
📑 En este artículo
- Mason: a Postgres replica that lives in DuckDB
- How it syncs tables and rewrites every query
- The Postgres analytical queries benchmark: 81x faster, with exceptions
- Built so AI agents can query data without snooping too far
- What this means if you run Postgres in production
- Mason vs. a standard replica, ClickHouse and Materialize
- When Mason isn’t the right fit
- Frequently Asked Questions
- References
Mason: a Postgres replica that lives in DuckDB
Mason is a single Node.js process you can run on any server: it stores its configuration and the synced data in the folder where it runs, with no extra infrastructure to depend on. The project is open source under the Apache 2.0 license, so you can self-host it or use the managed option offered as Mason Cloud (Mason: a drop-in Postgres read replica for analytics).
Internally, Mason doesn’t replace Postgres syntax: it deliberately mimics it. The team built it from scratch to match Postgres syntax and behavior, not DuckDB’s, so an application’s existing queries can point at Mason without rewriting the SQL that already works against the primary database.
How it syncs tables and rewrites every query
You choose which tables and columns to sync and how they stay up to date: on demand, through periodic polling or via direct logical replication from Postgres. Mason stores that copy in DuckDB’s columnar engine, built to read many rows across a few columns at once, exactly the pattern an analytical query follows.
When a query arrives, Mason doesn’t just pass it to DuckDB as is: it rewrites it into the form that engine executes fastest and returns a response identical to what Postgres would give. The diagram below summarizes the flow:
flowchart LR
A["Postgres (source of truth)"] -->|"syncs chosen tables"| B[("Mason's internal DuckDB")]
C["Client or app"] -->|"same Postgres SQL query"| D["Mason rewrites the query"]
D --> B
B --> E["Same result, much faster"]
The Postgres analytical queries benchmark: 81x faster, with exceptions
Mason’s main benchmark ran on an AWS m7g.xlarge instance (4 vCPUs, 16 GiB of RAM, EBS gp3 storage) with count, sum and group-by queries, the kind of workload dashboards and reports use (methodology published by Mason). In the sample query, which groups 10 million HTTP requests by response code (74.1% with code 200, 15.0% with 304, 8.5% with 404 and 2.4% with 500), Postgres took 15.7 seconds and Mason returned the same result in 0.193 seconds.
| Query | Scale | Postgres | Mason | Difference |
|---|---|---|---|---|
| Count by status | 10M rows, 10 clients | 21.721 s | 0.2595 s | 84x faster |
| Count by status | 100M rows, 1 client | 216.068 s | 0.4624 s | 467x faster |
| Monthly revenue (with join) | 10M rows, 10 clients | 43.909 s | 2.758 s | 16x faster |
| Monthly revenue (with join) | 100M rows, 1 client | 335.059 s | 6.685 s | 50x faster |
| Primary key lookup | 10M rows, 10 clients | 0.0388 s | 0.2341 s | 6.0x slower |
| Primary key lookup | 100M rows, 1 client | 0.0366 s | 0.1013 s | 2.8x slower |
The measurements were taken from a cold start: each engine was restarted and the page cache was cleared before every run, with 1 or 10 clients sending the query at the same time, taking the median of 3 runs (methodology details). The project itself warns that real-world results will vary depending on the size and distribution of your data, so these numbers are a reference, not a guarantee.
📌 Note: in both primary key lookup tests, Postgres was faster than Mason: Mason’s advantage shows up in queries that read many rows, not in looking up a single record by its identifier.
Built so AI agents can query data without snooping too far
Mason adds role-based access control: every tool, AI agent or client gets its own user, and that role decides which tables and columns it can read. It also supports row-level security, limiting each user to their own records and following foreign keys into related tables (Mason documentation).
Every query gets logged: who ran it, what SQL it sent, how long it took and, if it was rejected, why. Mason also ships its own MCP server, so agents like Claude Code or ChatGPT can look at the tables and run queries within the limits their role sets, without direct access to the full database. For teams already running dashboards with Grafana or Prometheus, Mason exposes its own metrics and a health check so those same tools can monitor it without extra configuration.
What this means if you run Postgres in production
If you work as a backend or data engineer and have dashboards, reports or an AI agent hitting your production Postgres directly, first check what kind of query is generating that load. Run an EXPLAIN on the slow queries: if they’re scans that group, count or sum many rows, they’re direct candidates to move to a replica like Mason without touching the application’s SQL. If instead they’re point lookups by index or primary key, Mason’s own benchmark shows you’re better off staying on Postgres.
The practical decision isn’t to migrate everything, but to sync only the tables that feed reports and leave transactional paths where they are. That avoids the risk of moving a workload Mason handles worse and reduces how much you need to keep in sync.
Mason vs. a standard replica, ClickHouse and Materialize
Mason isn’t the only way to take analytical pressure off Postgres. The best-known alternatives in the same space offer a useful comparison, though each carries a different adoption cost.
| Option | Query engine | SQL compatibility | Best for |
|---|---|---|---|
| Standard Postgres replica (streaming or logical) | Postgres’s own row-based engine | Full, it’s Postgres | Spreading read load, not speeding up heavy analytical queries |
| Mason | DuckDB (columnar) behind a Postgres interface | High: rewrites Postgres SQL internally | Counts, sums and group-bys over many rows, without changing the app |
| ClickHouse | Its own columnar engine | Its own dialect, different from Postgres’s | Large-scale analytics when you can redesign the data pipeline and queries |
| Materialize | Incremental materialized views in streaming | Its own Postgres-like SQL, geared toward declared views | Always up-to-date results for queries known ahead of time |
The key difference is adoption cost. ClickHouse and Materialize perform very well, but they require designing a data pipeline or declaring views in advance. Mason bets that the query you already have, the same one running against Postgres today, is enough.
When Mason isn’t the right fit
The benchmark itself marks the clearest limit: on primary key lookups, Mason was between 2.8 and 6.0 times slower than Postgres (Mason’s benchmark). If your workload is mostly that, adding Mason doesn’t help and adds one more process to keep in sync.
Mason is still a young project: it launched on Hacker News as a Show HN, the channel where brand-new infrastructure tools get posted, without the production track record of a project with years of third-party use. Before trusting it with a critical path, it’s safer to try it on internal reports first, not on the path the end user sees.
There’s also the cost of keeping a second copy of the data on disk and the work of keeping the sync current, even if that’s smaller compared to setting up a pipeline to ClickHouse.
Frequently Asked Questions
Does Mason replace Postgres?
No. It’s a read-only replica: writes still go to Postgres, and Mason only mirrors the tables you chose to sync.
Do I need to learn DuckDB to use it?
No. You keep writing Postgres SQL; Mason translates that query into the plan DuckDB executes internally and returns the same result.
What if my query looks up a single record by ID?
According to the published benchmark, Postgres is still faster in that case: Mason’s advantage shows up in queries that read many rows, not in a single lookup.
References
- Mason: a drop-in Postgres read replica for analytics: official announcement, architecture and main benchmark.
- Mason documentation: syncing, role-based access control and MCP support.
- Show HN: Mason, a lightweight Postgres read-replica built on columnar storage: community discussion about the launch.
Featured image: Foto de Florian Olivo en Unsplash
How each article is made (sources, testing and editorial criteria): How we work.
Did it work for you? Got a different error? Say so below: questions get answered and help the next reader.
Leave a comment
0 Comments