Serverless WebSockets
Add real-time capabilities to Vercel, Cloudflare Workers, AWS Lambda, and any serverless platform. No infrastructure to manage.
The Serverless WebSocket Problem
Serverless functions are stateless. They spin up, handle a request, and shut down. There's no process running to hold a WebSocket connection open.
WebSockets need persistent connections. The server must stay alive to receive messages from clients and push messages back. This is fundamentally incompatible with serverless.
The solution? Offload the WebSocket connections to a dedicated service. Your serverless functions call an API to send messages, and the service handles delivery.
How PushFlo Solves It
Users Connect to PushFlo
Browser SDK connects to our global WebSocket servers
Your Function Calls Our API
One HTTP POST to publish a message to any channel
We Deliver Instantly
Message delivered to all subscribed clients in <50ms
Works with Your Platform
Same SDK, same API. Just publish messages from your serverless function.
Vercel
Edge Functions & Serverless Functions
// app/api/notify/route.ts
import { PushFloServer } from '@pushflodev/sdk/server';
import { NextResponse } from 'next/server';
const pushflo = new PushFloServer({
secretKey: process.env.PUSHFLO_SECRET_KEY,
});
export async function POST(request: Request) {
const { userId, message } = await request.json();
await pushflo.publish(`user:${userId}`, { message });
return NextResponse.json({ sent: true });
}Cloudflare Workers
Workers & Pages Functions
// worker.ts
import { PushFloServer } from '@pushflodev/sdk/server';
export default {
async fetch(request: Request, env: Env) {
const pushflo = new PushFloServer({
secretKey: env.PUSHFLO_SECRET_KEY,
});
const { userId, message } = await request.json();
await pushflo.publish(`user:${userId}`, { message });
return new Response(JSON.stringify({ sent: true }));
},
};AWS Lambda
Lambda Functions & API Gateway
// handler.ts
import { PushFloServer } from '@pushflodev/sdk/server';
const pushflo = new PushFloServer({
secretKey: process.env.PUSHFLO_SECRET_KEY,
});
export const handler = async (event) => {
const { userId, message } = JSON.parse(event.body);
await pushflo.publish(`user:${userId}`, { message });
return {
statusCode: 200,
body: JSON.stringify({ sent: true }),
};
};Comparing Approaches
How does PushFlo compare to other ways of adding real-time to serverless?
Polling
Client repeatedly requests updates
Pros
- Works everywhere
- Simple to implement
Cons
- High latency (seconds)
- Wastes bandwidth
- Hammers your API
Not real-time
Server-Sent Events
Server pushes to client over HTTP
Pros
- True push
- Browser native
Cons
- One-way only
- Connection limits
- Serverless timeout issues
Limited use
PushFlo
Managed WebSocket infrastructure
Pros
- True real-time (<50ms)
- Bi-directional capable
- Works with serverless
- Global edge network
Cons
- External dependency
- Not free at scale
Best for serverless
Technical Specifications
<50ms
p50 Latency
<300ms
p99 Latency
300+
Edge Locations
99.9%
Uptime SLA
32KB
Max Message Size
JSON
Message Format
Further Reading
Why Serverless Functions Can't Hold WebSocket Connections
A technical deep-dive into the architectural incompatibility and how to fix it.
WebSocket Alternatives for Vercel and Cloudflare Workers
Your options for adding real-time features to serverless apps, from polling to managed services.
The Complete Guide to Real-time Multiplayer Games on Serverless
How to build multiplayer browser games using serverless architecture.
Add real-time to your serverless app
Start with our free tier. 500K messages/month. Works with Vercel, Cloudflare, AWS, and any platform that can make HTTP requests.
On Vercel? See WebSockets for Vercel. Switching providers? Compare Pusher and Ably alternatives.
