Lovable Realtime architecture showing database change capture, NATS pub sub, and Go WebSocket pods streaming live updates

Lovable Realtime: Inside the New Architecture for Live Data

Lovable announced the rollout of Lovable Realtime, a custom WebSocket infrastructure designed to replace client-side database listeners across its application. The engineering team documented the change in a detailed technical release published on the Lovable blog. The new architecture transitions data streaming away from direct browser connections to Firestore and moves data shaping into a dedicated Go backend running on Google Kubernetes Engine.

According to the engineering team, the core service was built in 40 hands-on working days and rolled out to all users without a single user-facing incident. The production infrastructure currently supports peaks exceeding 2 million concurrent subscriptions while delivering roughly 2.6 billion data and patch frames per month. The update addresses persistent security, authorization, and connection bottlenecks that emerged as workspace collaboration expanded.

The Core Problems with Direct Database Listeners

Historically, portions of the Lovable platform delivered live updates by opening Firestore onSnapshot listeners straight from the client browser. While direct database subscriptions are common in early-stage web development, they introduced three distinct operational hurdles at scale.

First, direct database listeners exposed full documents to the browser. Whenever an engineer added an internal field to a document, that property was sent directly across the network. Security rules had to be mirrored between Firestore Security Rules and the internal Go API permissions model. Keeping these two authorization paths perfectly synchronized across product updates required constant manual oversight and created latent security exposure.

Second, Firestore authorization rules could only query Firebase data stores. Lovable relies on enterprise workspace capabilities like SCIM user provisioning, which syncs corporate groups and permissions into projects. Managing complex relational queries and large transactions across multi-team workspaces required Google Cloud Spanner. Because Firestore Security Rules cannot read external Spanner tables, managing group-level access rules natively within Firestore was not technically viable.

To temporarily bypass this limitation, the team initially proxied onSnapshot subscriptions through their Go API for business and enterprise workspaces. While this reused the centralized API permissions model, each client connection spawned individual upstream listeners for its data dependencies. At millions of concurrent connections, this pattern threatened to exhaust connection pools and created unnecessary read duplication against primary data stores. The proxy opened separate Firestore listeners for each client data dependency, competing with standard database requests in the shared pool.

Key Architectural Components of Lovable Realtime

The newly deployed Lovable Realtime service operates as an independent, database-agnostic streaming pipeline. Instead of binding clients directly to database documents, the platform routes connections through a lightweight WebSocket layer managed entirely in Go.

Under the Lovable Realtime framework, client sessions maintain a single WebSocket connection per browser tab. Every real-time subscription required by components inside that tab is multiplexed over this single channel. The connection terminates on dedicated Go service pods running on Google Kubernetes Engine. Each pod maintains thousands of client WebSocket connections alongside a single upstream connection to a shared message broker.

Multiplexed WebSockets Over Google Kubernetes Engine

Multiplexing connections eliminates redundant transport overhead. In the previous model, multiple interface widgets listening to separate document paths would establish individual network streams. Under the current setup, all active subscriptions in an open tab funnel through one long-lived socket.

Because the Go backend owns the connection state, authorization checks run continuously. If a user loses project membership while their browser tab remains open, the backend can terminate the specific subscription stream mid-session without waiting for an active page refresh.

Event Routing with NATS

For message publication and fan-out, the architecture implements NATS as its central message bus. Database modifications in Firestore and Spanner are captured using change data capture pipelines, translated through an event bridge, and published into NATS subjects. Writers to the database do not need to trigger subscription updates manually.

NATS was selected over alternatives like Redis pub/sub because of its hierarchical wildcard subject matching. In NATS, subjects follow hierarchical patterns such as workspace and project paths matched in a server-side trie. Publishers write to a single specific subject, while subscribing pods declare the exact granularity they require. This prevents the operational overhead of multi-publishing to broad roll-up channels that can overwhelm individual shards under heavy workspace activity. Furthermore, interest-based cluster routing guarantees that messages travel solely to nodes hosting active subscribers.

Backend-Shaped Payloads and Hash Deduplication

When an event reaches a pod through NATS, the matching subscription function executes server-side. The Go function retrieves required parameters, enforces centralized access rules, and serializes only the permitted fields into a data transfer object.

Before transmitting data across the WebSocket, the service computes an xxh3-128 hash of the output against the previously sent payload. If the data has not materially changed, the frame is dropped. If changes occurred, only the computed deltas travel to the client, reducing bandwidth consumption across millions of active streams.

Developer Experience on Frontend and Backend

The new streaming model unifies how engineers build reactive features across the platform stack. Developers interact with the service through a structured TypeScript SDK on the client and Go functions on the server.

  • Typed Frontend SDK: Browser components request data using a typed hook that specifies the subscription name and parameters. Parameters and response payloads are generated directly from Go structs, ensuring end-to-end type safety.
  • Automatic Component Sharing: When multiple visual components on a page subscribe to the same project or entity, the SDK shares a single underlying server subscription rather than duplicating network overhead.
  • Resilient Connections: The client SDK handles reconnection with randomized jitter and backoff while managing authentication token refresh frames over the established socket.
  • Server Subscription Handlers: Backend handlers read like standard API endpoints. Developers retrieve parameters, validate permissions against the main application model, and project raw database rows into clean client-facing shapes.

Evaluating Alternatives to Lovable Realtime

Before writing custom infrastructure, the team evaluated existing commercial and open-source realtime products against three strict criteria: compatibility with both Firestore and Spanner without a database migration, reactive mid-session authorization re-evaluation, and full server control over payload shapes.

Transport services including Pusher, Ably, PubNub, and Centrifugo addressed connection transport and message revocation, but they required external implementation of change data capture, subscription dependency tracking, and server projections. Replicache offered client-side synchronization with custom backend computation, yet still left notification routing and permissions-driven payload tracking to be built in-house.

Database-bundled solutions like Supabase Realtime, Firebase Realtime Database, Hasura, PowerSync, and Zero provided tight database reactivity within their supported engines. However, they did not offer a unified abstraction across heterogeneous Firestore and Spanner data stores without extensive glue code. Specialized platforms like Electric required replicating data into Postgres, while systems like Convex required hosting core application data within their proprietary database engine. Creating Lovable Realtime allowed the engineering team to keep its existing storage layer intact while enforcing centralized security in Go.

Where This Fits in Production Systems

Engineering teams building collaborative dashboards and SaaS platforms frequently face similar real-time scaling limits. As applications transition from simple CRUD prototypes to multi-tenant business platforms, exposing database structures directly to the client browser quickly becomes unsustainable.

When Wasif designs custom software development systems and automated data workflows, separating transport logic from data authorization is a core architectural priority. Relying on raw database rules for client subscriptions limits your ability to integrate external identity providers, audit changes, or integrate secondary databases. The architecture chosen for Lovable Realtime highlights the durability of combining change data capture with event-driven message brokers for high-concurrency environments.

Frequently Asked Questions

What are the primary performance figures achieved by this implementation?

In production, the deployment handles peaks of over 2 million concurrent subscriptions and delivers around 2.6 billion data and patch frames each month. The core engine was completed in 40 working days without user-facing incidents during migration.

How does Lovable Realtime handle mid-session access revocation?

Because Lovable Realtime processes authorization inside Go subscription handlers rather than static client-side database rules, access rights are continuously re-evaluated. If an enterprise administrator updates team memberships or revokes a user credential, the reactive pipeline detects the permission change and can terminate the client stream immediately during an open connection.

Why was NATS chosen instead of Redis pub/sub?

NATS supports server-side trie matching for hierarchical wildcard subjects. This allows publishers to write to specific subjects while subscribers define their own granularity without overloading roll-up channels. In addition, NATS routes messages only to cluster nodes that hold active subscriptions.

Conclusion

The rollout of Lovable Realtime shows that scaling live collaboration requires moving data shaping and access control back into server code. By decoupling real-time synchronization from database-specific security rules, companies can protect private records, support hybrid database engines, and maintain stable network usage even past millions of simultaneous connections. If you are planning high-performance data architectures or bespoke business systems, feel free to reach out to discuss your project.

Leave a Comment

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

Scroll to Top
Secret Link