DEV Community

Cover image for Design review: Live SQL queries on PostgreSQL
Oxford Harrison
Oxford Harrison

Posted on

Design review: Live SQL queries on PostgreSQL

I’ve been experimenting with something I’ve wanted for a long time:

"live mode" in SQL.

Today, this is now possible on PostgreSQL:

const result = await db.query(
  `SELECT * FROM users`,
  { live: true }
);
Enter fullscreen mode Exit fullscreen mode

With { live: true }, you get back a live result set that reflects the state of the DB in real time.

If rows are inserted, updated, or deleted in the underlying table(s), result.rows reflects those changes automatically — without polling, manually wiring subscriptions, or pushing synchronization logic into application code.

This work is part of a broader "universal query engine" effort for applications and agents – LinkedQL. The implementation is currently in JavaScript, backed by PostgreSQL logical replication.

One obvious thing about this model is how different it feels from the usual CDC/event-pipeline architecture.

With CDC systems, the application often becomes responsible for reconstructing state from streams of low-level events:

  • listening to events
  • interpreting mutations
  • maintaining client-side caches
  • manually reconciling state

Here, however, the query itself is the subscription.

You think in terms of query results and state transitions — not event plumbing and state engineering.

This has been an interesting problem to work on, but it has taken shape really fast. Today, the model has started feeling surprisingly coherent in practice.

But it's still early.

I’d genuinely love engineering feedback on the approach — especially from people who’ve worked deeply with databases, replication systems, query engines, or realtime infrastructure.

Repo:
https://github.com/linked-db/linked-ql

Live query docs:
https://linked-ql.netlify.app/realtime/live-queries

Basic demos you can run against your own PostgreSQL instance:
https://github.com/webqit/node-live-response/tree/main/playground

(Requires logical replication enabled on your PostgreSQL.)

I also wrote a deeper breakdown of the architecture and execution model here:

https://linked-ql.netlify.app/engineering/realtime-engine

...where I discuss the live query engine in detail and a bunch of important engineering questions that underpin the model:

  • What exactly invalidates a query?
  • How do joins behave under mutations?
  • How do you avoid re-running entire queries unnecessarily?
  • What consistency guarantees should consumers expect?
  • How do you fan out updates efficiently across many subscribers?
  • and much more.

Curious where people think this model breaks down — or where it becomes genuinely useful.

Top comments (0)