Real-time Data Processing with Supabase: Complete Guide

Complete guide to implementing real-time data streaming and analytics with Supabase. From WebSocket connections to advanced streaming analytics with PostgreSQL.
Key Metrics
- <50ms latency
- 10K ops/s throughput
- 100K+ concurrent users
- 99.9% uptime
Overview
Supabase revolutionizes real-time data processing by combining PostgreSQL's powerful features with modern WebSocket technology. For Norwegian businesses, this means the ability to build responsive, real-time applications without complex infrastructure.
Three Core Benefits
- Sub-50ms Latency — Lightning-fast data transfer from database to client
- PostgreSQL Power — Full SQL support with ACID transactions
- 100K+ Connections — Scales automatically with traffic
2025 Supabase Realtime Updates
- New Realtime Components (March 2025): Cursor Sharing, Avatar Stack and Chat components for faster development
- Publishable Keys: New key format (sb_publishable_xxx) for improved security and independent rotation
- RLS on realtime.messages: Row Level Security now supported on private channels
- Realtime Settings UI: New dashboard for configuring realtime settings directly in Supabase
- Standardized Error Codes: Consistent error handling across all realtime operations
Typical Use Cases
- Live Dashboards: Real-time KPI tracking and business intelligence
- Chat & Messaging: Instant message exchange
- Live Collaboration: Simultaneous document editing
- IoT Data Streaming: Sensor and device data in real-time
- Financial Trading: Stock data and price updates
Architecture and Components
Supabase Real-time builds on PostgreSQL's LISTEN/NOTIFY functionality combined with Elixir-based WebSocket servers to deliver scalable, real-time communication.
Database Layer
- PostgreSQL with WAL replication
- Row Level Security (RLS)
- Triggers and stored procedures
- LISTEN/NOTIFY mechanisms
Realtime Server
- Elixir/Phoenix WebSocket server
- Automatic connection management
- Message broadcasting
- Client authentication
Client Libraries
- JavaScript/TypeScript SDK
- React hooks integration
- Auto-reconnection logic
- Type-safe subscriptions
Management
- Dashboard monitoring
- Connection metrics
- Rate limiting
- Error tracking
Data Flow
The data flow in Supabase Real-time works as follows:
Client App → (WebSocket) → Realtime Server → (LISTEN/NOTIFY) → PostgreSQL
Bidirectional communication with automatic reconnection and error handling.
Basic Setup
1. Project Initialization
Start by creating a new Supabase project and installing the required dependencies:
# Install Supabase CLI
npm install -g @supabase/cli
# Create new Next.js project
npx create-next-app@latest realtime-analytics --typescript --tailwind --app
# Navigate to project
cd realtime-analytics
# Install Supabase JavaScript client
npm install @supabase/supabase-js
# Install additional dependencies for real-time
npm install @supabase/realtime-js recharts date-fns lucide-react
# Initialize Supabase locally (optional)
supabase init
2. Supabase Configuration
Create environment variables and initialize the Supabase client with real-time support:
# Supabase configuration
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
# Real-time configuration
NEXT_PUBLIC_REALTIME_ENDPOINT=wss://your-project.supabase.co/realtime/v1
NEXT_PUBLIC_REALTIME_API_KEY=your-anon-key
# Analytics configuration (optional)
ANALYTICS_RETENTION_DAYS=30
MAX_CONCURRENT_SUBSCRIPTIONS=100
3. Supabase Client Setup
import { createClient } from '@supabase/supabase-js'
import { RealtimeClient } from '@supabase/realtime-js'
// TypeScript types
export interface Database {
public: {
Tables: {
events: {
Row: {
id: string
event_type: string
data: Json
user_id?: string
created_at: string
metadata?: Json
}
Insert: {
event_type: string
data: Json
user_id?: string
metadata?: Json
}
Update: {
event_type?: string
data?: Json
metadata?: Json
}
}
analytics_summary: {
Row: {
id: string
metric_name: string
value: number
timestamp: string
dimensions: Json
}
Insert: {
metric_name: string
value: number
dimensions?: Json
}
Update: {
value?: number
dimensions?: Json
}
}
}
}
}
export type Json =
| string
| number
| boolean
| null
| { [key: string]: Json | undefined }
| Json[]
// Create standard Supabase client
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
export const supabase = createClient<Database>(
supabaseUrl,
supabaseAnonKey,
{
realtime: {
params: {
eventsPerSecond: 10 // Limit events to avoid rate limiting
}
}
}
)
// Create dedicated realtime client for advanced use cases
export const realtimeClient = new RealtimeClient(
process.env.NEXT_PUBLIC_REALTIME_ENDPOINT!,
{
params: {
apikey: process.env.NEXT_PUBLIC_REALTIME_API_KEY!
}
}
)
RealtimeManager Class
export class RealtimeManager {
private subscriptions: Map<string, any> = new Map()
// Subscribe to table changes
subscribe(
table: string,
filter: string | null,
callback: (payload: any) => void
) {
const channel = supabase
.channel(`public:${table}${filter ? `:${filter}` : ''}`)
.on(
'postgres_changes',
{
event: '*',
schema: 'public',
table: table,
...(filter && { filter })
},
callback
)
.subscribe()
const subscriptionKey = `${table}-${filter || 'all'}`
this.subscriptions.set(subscriptionKey, channel)
return subscriptionKey
}
// Unsubscribe
unsubscribe(subscriptionKey: string) {
const channel = this.subscriptions.get(subscriptionKey)
if (channel) {
supabase.removeChannel(channel)
this.subscriptions.delete(subscriptionKey)
}
}
// Unsubscribe all
unsubscribeAll() {
this.subscriptions.forEach((channel) => {
supabase.removeChannel(channel)
})
this.subscriptions.clear()
}
// Send real-time event
async sendEvent(channel: string, event: string, payload: any) {
const channelInstance = supabase.channel(channel)
await channelInstance.send({
type: 'broadcast',
event: event,
payload: payload
})
}
// Batch insert with real-time notification
async batchInsert(
table: string,
data: any[],
chunkSize: number = 1000
) {
const chunks = []
for (let i = 0; i < data.length; i += chunkSize) {
chunks.push(data.slice(i, i + chunkSize))
}
const results = []
for (const chunk of chunks) {
const { data: result, error } = await supabase
.from(table)
.insert(chunk)
.select()
if (error) throw error
results.push(...(result || []))
}
return results
}
}
Cost Analysis
Real-time data processing costs can vary significantly. Here is a detailed comparison based on a typical Norwegian business with 10,000 active users and 1TB data processing per month:
| Solution | Setup | Monthly | Per Request | Total/mo |
|---|---|---|---|---|
| Supabase | Free | 25 NOK/GB | 0.002 NOK/req | 2,500 NOK/mo |
| AWS + Kinesis | 5,000 NOK | 45 NOK/GB | 0.004 NOK/req | 4,800 NOK/mo |
| Custom WebSocket | 15,000 NOK | 35 NOK/GB | 0.003 NOK/req | 8,200 NOK/mo |
Supabase Features Included
- Real-time subscriptions
- Automatic scaling
- Built-in auth
- Edge functions
Supabase Advantages
- 69% lower total cost compared to AWS
- Zero startup costs — start for free
- Authentication and authorization included
- Automatic scaling at no extra cost
- GDPR-compliant hosting in Europe
Useful Resources
Frequently Asked Questions
What is the typical latency for Supabase Real-time?
Supabase Real-time delivers sub-50ms latency for most use cases. This includes the time from a database change to the client receiving the update via WebSocket. For Norwegian users with European hosting, latency is typically 20-40ms.
Do I need to set up my own WebSocket server?
No. Supabase includes a fully managed Elixir/Phoenix WebSocket server that handles connection management, message broadcasting, and client authentication automatically. You simply subscribe to changes via the JavaScript SDK.
How does Supabase Real-time handle scaling?
Supabase scales automatically based on the number of concurrent connections. The platform supports 100K+ concurrent users without manual configuration. For extremely high traffic, you can adjust the eventsPerSecond parameter to control throughput.
Is Supabase Real-time GDPR-compliant for Norwegian businesses?
Yes. Supabase offers EU-based hosting, and with Row Level Security (RLS) you can control exactly which data is accessible to which users. Publishable Keys (launched 2025) provide improved security with independent rotation.
What does it cost to get started with Supabase Real-time?
You can start for free with the Supabase Free tier. For production use, the typical cost is around 2,500 NOK/month for a Norwegian business with 10,000 active users — 69% cheaper than an equivalent AWS setup.
Related Reading
Stay Updated
Subscribe to our newsletter for the latest AI insights and industry updates.
Get in touch