⏱️ 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
  1. Mason: a Postgres replica that lives in DuckDB
  2. How it syncs tables and rewrites every query
  3. The Postgres analytical queries benchmark: 81x faster, with exceptions
  4. Built so AI agents can query data without snooping too far
  5. What this means if you run Postgres in production
  6. Mason vs. a standard replica, ClickHouse and Materialize
  7. When Mason isn’t the right fit
  8. Frequently Asked Questions
    1. Does Mason replace Postgres?
    2. Do I need to learn DuckDB to use it?
    3. What if my query looks up a single record by ID?
  9. 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"]
Mason runs as a single Node.js process, with no cluster of its own. Foto de Arnold Francisca en Unsplash

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.

QueryScalePostgresMasonDifference
Count by status10M rows, 10 clients21.721 s0.2595 s84x faster
Count by status100M rows, 1 client216.068 s0.4624 s467x faster
Monthly revenue (with join)10M rows, 10 clients43.909 s2.758 s16x faster
Monthly revenue (with join)100M rows, 1 client335.059 s6.685 s50x faster
Primary key lookup10M rows, 10 clients0.0388 s0.2341 s6.0x slower
Primary key lookup100M rows, 1 client0.0366 s0.1013 s2.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.

Role-based access control limits which tables each AI agent can see. Foto de Emile Perron en Unsplash

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.

OptionQuery engineSQL compatibilityBest for
Standard Postgres replica (streaming or logical)Postgres’s own row-based engineFull, it’s PostgresSpreading read load, not speeding up heavy analytical queries
MasonDuckDB (columnar) behind a Postgres interfaceHigh: rewrites Postgres SQL internallyCounts, sums and group-bys over many rows, without changing the app
ClickHouseIts own columnar engineIts own dialect, different from Postgres’sLarge-scale analytics when you can redesign the data pipeline and queries
MaterializeIncremental materialized views in streamingIts own Postgres-like SQL, geared toward declared viewsAlways 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.

📬 Get new articles by email

We only email about big articles (1-2 a month).

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

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
Categories: ProgrammingTutorials

El Solitario Editorial

Article prepared by the El Solitario editorial team from cited sources, under the editorial responsibility of Luis Navarro. More details in "How we work".

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

You can include code inside <code>…</code> or, for several lines, <pre><code>…</code></pre>.

This site uses Akismet to reduce spam. Learn how your comment data is processed.