What are Real-Time Live Queries?

Last updated: July 2026

A live query is a subscription to a database query — the server pushes create, update, and delete events for matching rows as they happen. It’s the missing tense of database access: normal queries speak in the past (“what matched when I asked”), live queries speak in the continuous present (“what matches, as it changes”). The screen stops asking and starts staying right.

Key takeaways

QuestionAnswer
What it isA standing query — subscribe once, receive every change to its results
The five eventscreate · update · delete · enter · leave
Under the hoodDatabase change stream → predicate matching → WebSocket push
vs. pollingReal-time latency, delta-sized payloads, no per-interval query load
vs. raw socketsThe query layer: matching, typed events, permissions, reconnects

The subscription, in code

The defining move — take the query you already had, and subscribe to it:

// JavaScript / Node.js — Back4app JS SDK
// A live query: subscribe to a QUERY and receive its changes as events
const query = new Parse.Query('Task');
query.equalTo('assignee', currentUser);

const sub = await query.subscribe();
sub.on('create', (t) => addRow(t));       // new match appeared
sub.on('update', (t) => refreshRow(t));   // a match changed
sub.on('enter',  (t) => addRow(t));       // edited INTO the result set
sub.on('leave',  (t) => removeRow(t));    // edited OUT of the result set
sub.on('delete', (t) => removeRow(t));    // a match was deleted

The event vocabulary deserves its table, because enter and leave are what make this query subscription rather than table notification:

EventFires when…Example (subscribed to “tasks assigned to me”)
createA new record matchesA task is created for you
updateA matching record changesYour task’s status flips
enterAn edit makes an existing record matchA task is reassigned to you
leaveAn edit makes a match stop matchingYour task is reassigned away
deleteA matching record is deletedThe task is removed

The pipeline behind the push

How live queries work end to endDatabase writes flow into a change stream; a subscription server matches each change against registered query predicates and pushes typed events over WebSockets to subscribed clients, with permissions checked per subscriber.

WebSocket push

WebSocket push

Writes
(any client, any API)

Database

Change stream
(oplog / WAL / triggers)

Subscription server
predicate matching + ACL check

Subscriber A

Subscriber B

Database writes flow into a change stream; a subscription server matches each change against registered query predicates and pushes typed events over WebSockets to subscribed clients, with permissions checked per subscriber.

Two halves, cleanly separable: the change source — the database’s own write feed (change streams in document stores, replication logs elsewhere) — and the matching layer, which checks each change against every registered predicate and pushes to exactly the subscribers whose results changed, permissions enforced per subscriber. The open LiveQuery protocol is a readable reference implementation of the whole shape.

Live queries vs. polling vs. SSE vs. WebSockets

ApproachLatencyPayloadServer costYou build
PollingPoll intervalFull refetch each timeQueries × clients × frequencyTimers, diffing
Long pollingNear-real-timeFull response per eventHeld connectionsFallback plumbing
SSEReal-timeDeltaStreams, one-wayEvent design
Raw WebSocketsReal-timeWhatever you defineConnections + your fan-outEverything
Live queriesReal-timePer-change eventsMatching + connections (managed)The query

The last column is the argument: with raw sockets you build the message protocol, the routing, the permission checks, and reconnect-catch-up; with live queries the predicate is the protocol and the platform owns the rest.

Common use cases

  • Chat and inboxes — subscribe to the conversation’s messages; arrival is an event, not a refresh.
  • Live dashboards — orders, metrics, fleets: the query defines the view, events keep it true.
  • Collaborative apps — shared task boards and documents where five people’s edits interleave in seconds.
  • Presence and status — who’s online, what’s in progress — enter/leave doing their precise work.
  • Operational screens — support consoles and admin views that must reflect production now, not at last refresh.

Poll, push, or subscribe? A decision matrix

Reach for live queries when…Simpler tools suffice when…
Users watch shared, changing dataData changes rarely — poll gently or refetch on focus
Changes come from many writers and pathsOne writer could just push via SSE
The view is naturally a queryThe message isn’t data-shaped (use sockets directly)
Permissions must gate what each viewer seesEverything is public broadcast
You’d rather not own fan-out infrastructureYou already operate a real-time platform

The client-side discipline that keeps subscriptions healthy, whatever you choose: subscribe narrowly (selective predicates on indexed fields), and unsubscribe when the screen closes — standing queries are server state, and screens that leak them accumulate cost invisibly.

Limitations and trade-offs

  • Matching is a real workload. Every write is checked against registered predicates; thousands of broad subscriptions on hot classes multiply it — selectivity is the lever.
  • Connections are state. The socket fleet needs affinity, heartbeats, and fan-out backplanes — managed platforms exist precisely because this is undifferentiated heavy lifting.
  • Reconnects need catch-up. A client that was offline missed events; robust flows re-run the base query on resubscribe rather than trusting the gap was quiet.
  • Ordering and delivery are at-least-once shaped. Idempotent event handlers (apply by object ID, not by append) absorb the occasional duplicate gracefully.
  • Not everything wants a subscription. Rarely-viewed, rarely-changed data is polling territory; live queries earn their cost where eyes and writes are both frequent.

Live queries on Back4app

Back4app is an open-source Backend-as-a-Service (BaaS) platform that combines a managed database, auto-generated REST and GraphQL APIs, authentication, file storage, and Cloud Code serverless functions. Live Query is its real-time layer, and the code tabs above are the entire client story: the same query builder you already use, one subscribe call, five typed events — with ACLs checked per subscriber so real-time never bypasses the permission model, and the WebSocket fleet, change streams, and fan-out running as managed infrastructure. Enable Live Query on a class in the dashboard, subscribe from any SDK, and the continuous present tense is a feature, not a project.

Frequently asked questions

What is a live query?

A standing subscription to a database query: instead of asking once and getting a snapshot, you subscribe to the query and the server pushes an event every time its result set changes — a matching record created, updated, deleted, or edited into or out of the results. Your screen stops polling and starts listening.

How is a live query different from a normal query?

Lifetime. A normal query runs, returns, and is done — its answer starts aging immediately. A live query stays registered on the server: the initial results arrive the same way, and then targeted change events keep them current until you unsubscribe. Same predicate language, opposite relationship with time.

How do live queries work under the hood?

Two halves joined: a change source and a transport. The database emits its stream of writes — via change streams, replication logs, or triggers — and a subscription server matches each change against registered query predicates, pushing relevant events to subscribers over WebSockets. The client SDK wraps the socket lifecycle so your code only sees typed events.

What are the enter and leave events?

The subtle pair that makes query subscriptions precise. Enter fires when an existing record is edited so it starts matching your predicate; leave fires when an edit makes it stop matching. A task reassigned to you enters your assigned-to-me subscription without being created; reassigned away, it leaves without being deleted. Create, update, and delete cover the rest.

Why are live queries better than polling?

Three ways at once: latency — changes arrive in real time instead of at the next poll; bandwidth — events carry only what changed instead of refetching everything; and load — the server does per-change matching instead of running full queries per client per interval. Polling every few seconds is simulation; subscriptions are the real thing.

What do live queries add over raw WebSockets?

The query brain. A raw socket moves messages; everything else — which clients care about which changes, what the events mean, who is allowed to see what, catching up after reconnects — is code you write. A live query layer does predicate matching server-side, types the events, enforces permissions per subscriber, and manages the socket lifecycle. It is the difference between a transport and a feature.

Are GraphQL subscriptions the same as live queries?

Same family, different trigger. GraphQL subscriptions fire on named events you define — a mutation publishes, subscribers receive. Live queries fire on result-set changes to a query — no event wiring, the predicate is the subscription. Both ride WebSockets; live queries trade explicit event design for automatic coverage of every write path.

How do live queries scale?

On two axes: connections — thousands of open sockets spread across subscription servers behind a pub/sub backplane — and matching — every write checked against registered predicates, which is why selective subscriptions on indexed fields matter. Managed platforms run both axes for you; the client-side discipline is subscribing narrowly and unsubscribing when screens close.

Related terms

Compare with

Further reading

Ready to build your backend?

Start your project on Back4app in minutes — database, auth, APIs, and Cloud Code included. No credit card required.

Written and reviewed by Back4app Engineering, Back4app Engineering · Published 2026-07-27