How did we design the architecture for a real‑time analytics dashboard?
We started by mapping the data flow: raw events from the client’s SaaS platform landed in a Kafka‑like ingest service, were transformed into aggregate metrics, and then written into Supabase tables. Supabase’s built‑in replication slot emitted PostgreSQL LOGICAL changes, which we captured via its realtime API. On the frontend, a Next.js page subscribed to these channels using the Supabase JavaScript client, opening a WebSocket socket that pushed new rows directly into React state via React Query’s useSubscription hook.

Key architectural decisions:
- Database schema – We denormalized frequently queried aggregates (e.g., hourly active users, revenue per plan) into materialized views refreshed via
pg_cron. This kept the real‑time tables lightweight. - API layer – Next.js API routes handled authentication and role‑based filtering, then proxied the Supabase
realtimechannel token to the client, ensuring WebSocket connections were scoped to each tenant. - Connection management – To avoid opening a socket per user, we implemented a lightweight Node.js WebSocket gateway that multiplexed Supabase broadcasts to many frontend clients, reducing simultaneous connections from 500 to ~50 on the Supabase side.
- Fallback mechanism – In environments where WebSockets were blocked (corporate firewalls), the client fell back to Supabase’s polling‑based
subscribewith a 5‑second interval, preserving usability without sacrificing core functionality.
The result was a system where a metric update triggered in the database appeared on the dashboard within 150‑250 ms, well under the 500 ms threshold users perceive as “instant.”
What challenges emerged when scaling WebSocket connections with Supabase?
Our first load test revealed a surprising bottleneck: each new dashboard tab opened a separate WebSocket to Supabase, quickly exhausting the free tier’s 100‑connection limit. We solved this by introducing the multiplexing gateway mentioned above, but the journey taught us three nuanced lessons:
- Heartbeat tuning – Supabase expects a ping every 30 seconds; our gateway’s idle timeout was set to 60 seconds, causing sporadic disconnects. Aligning the interval to 25 seconds eliminated false‑positive drops.
- Message ordering – Because we batched multiple inserts into a single WebSocket payload, occasional race conditions caused the UI to display stale aggregates. Adding a monotonic
event_idcolumn and sorting client‑side resolved the inconsistency. - Error propagation – When the gateway crashed, clients silently stopped receiving updates. We integrated a reconnect exponential backoff and exposed a subtle toast notification, keeping users aware of connectivity issues.
Addressing these points increased our stable concurrent user count from 300 to a steady 800 during peak hours, with 99.9 % message delivery success.
Which real‑world metrics proved the dashboard’s impact?
After two months in production, the client reported measurable improvements:
- Decision latency – Time from event occurrence to actionable insight dropped from an average of 4 minutes to 22 seconds, a 91 % reduction.
- User engagement – Dashboard daily active users rose 38 % as teams began checking metrics multiple times per shift instead of once per day.
- Operational cost – By leveraging Supabase’s managed Postgres and avoiding custom WebSocket servers, infrastructure expenses fell 27 % compared to the prior self‑hosted Node + Redis solution.
- Development velocity – The team shipped three new widget types (funnel conversion, cohort retention, predictive trend) in under two weeks each, thanks to the real‑time API’s consistency.
These numbers aren’t just abstract; they translate to faster marketing campaign adjustments, quicker churn intervention, and more confident product road‑mapping.
How can other teams replicate this approach?
If you’re considering a similar stack, follow these five steps to get a real‑time dashboard off the ground quickly:
- Provision Supabase – Create a project, enable the Realtime addon, and set up row‑level security (RLS) policies for tenant isolation.
- Model aggregates – Design tables that store pre‑computed metrics; use
pg_cronor Supabase Functions to refresh them on a suitable interval (e.g., every minute for near‑real‑time). - Set up a WebSocket gateway – A lightweight Node.js server using
wscan subscribe to Supabase’srealtimebroadcast and rebroadcast to multiple clients; deploy it behind a reverse proxy for SSL termination. - Integrate with Next.js – In your pages or
appdirectory, initialize the Supabase client, fetch the channel token via an API route, and useuseSubscription(or a custom hook) to update React state. - Add fallback & monitoring – Implement a polling fallback, expose Prometheus metrics on the gateway, and set up alerts for disconnect rates above 1 %.
By adhering to this checklist, you can avoid the most common pitfalls—connection exhaustion, message ordering gaps, and opaque failure modes—while retaining the speed and simplicity that make Supabase + Next.js a compelling combo.
FAQ
Q: Do I need a separate WebSocket server if I use Supabase Realtime?
A: Not necessarily. Supabase’s Realtime service already provides WebSocket endpoints. However, for high fan‑out scenarios (many clients per channel) a lightweight multiplexing gateway helps stay within connection limits and adds observability.
Q: How does row‑level security affect real‑time updates?
A: RLS is evaluated on each change broadcast. If a user lacks permission for a row, Supabase simply doesn’t send that update over the WebSocket, keeping data leakage impossible without extra code.
Q: Can I use Supabase Realtime with server‑side rendering in Next.js?
A: Yes. During SSR you can fetch the initial state via Supabase’s REST API; once the client hydrates, you open the WebSocket subscription to receive live deltas.
Q: What is the maximum message size Supabase Realtime can handle?
A: The payload limit is 1 MB per message. For larger events, store the bulk data in a separate table or object storage and send only a reference ID via Realtime.
Q: How do I handle schema changes without dropping connections?
A: Supabase allows additive schema changes (new columns, tables) without disrupting existing replication slots. For breaking changes, create a new slot, update the gateway to subscribe to it, and perform a blue‑green deploy of the frontend.
HowTo Steps: Launching Your Own Real‑Time Analytics Dashboard
- Set up Supabase – Create a project, enable Realtime, and define tables for raw events and aggregated metrics. Turn on row‑level security to enforce tenant isolation.
- Build the aggregation pipeline – Use a scheduled Supabase Function or
pg_cronto roll up raw events into summary tables every minute; index the timestamp and tenant‑id columns for fast lookups. - Create a Next.js app – Initialize with
create-next-app@latest, install@supabase/supabase-js, and add an API route that returns a Realtime channel token based on the current user’s JWT. - Implement the WebSocket subscription – In a React component, call
supabase.channel('public:metrics'), subscribe topostgres_changesevents, and update state with React Query or SWR for caching and deduplication. - Add resilience – Implement a heartbeat check (send a ping every 25 seconds), reconnect with exponential backoff on failure, and display a subtle UI indicator when the connection is degraded.
Takeaway: Combining Supabase’s managed real‑time Postgres, Next.js’s hybrid rendering, and a thin WebSocket gateway yields a dashboard that feels instantaneous, scales to hundreds of concurrent users, and saves weeks of custom backend work.
Let's Work Together
Ready to turn your data into instant insights? I’ve helped remote teams ship production‑grade real‑time analytics dashboards that cut latency, boost engagement, and keep costs low. Let’s discuss how we can build yours.



