Introduction
PartyKit is a framework for building real-time, multiplayer, and collaborative applications. It provides serverless WebSocket rooms that run on the edge, making it straightforward to add features like live cursors, collaborative editing, multiplayer games, and real-time dashboards to web applications without managing WebSocket infrastructure.
What PartyKit Does
- Hosts stateful WebSocket rooms that persist for the lifetime of a session
- Runs server-side logic at the edge close to connected users
- Provides built-in integrations with Yjs and other CRDTs for collaborative editing
- Handles room creation, connection management, and message routing automatically
- Supports both WebSocket and HTTP endpoints per room
Architecture Overview
Each PartyKit room is a stateful server that runs in a Cloudflare Durable Object on the edge. When a client connects to a room by ID, PartyKit routes the WebSocket connection to the room's server instance. The server maintains in-memory state, processes messages, and broadcasts updates to connected clients. Rooms are created on demand and can persist state between connections using built-in storage.
Self-Hosting & Configuration
- Create a project with
npm create partykit@latest - Define room behavior by exporting a class with
onConnect,onMessage, andonClosehandlers - Run locally with
npx partykit devfor development with hot reload - Deploy to PartyKit's edge network with
npx partykit deploy - Configure room settings, environment variables, and custom domains in partykit.json
Key Features
- Serverless WebSocket rooms with no infrastructure management
- Edge deployment for low-latency connections worldwide
- Built-in Yjs integration for CRDT-based collaborative editing
- Per-room persistent storage for maintaining state across sessions
- TypeScript-first API with full type safety
Comparison with Similar Tools
- Socket.IO — requires managing your own server; PartyKit is serverless with edge deployment
- Liveblocks — managed collaboration service; PartyKit is open source and self-deployable
- Ably/Pusher — pub/sub messaging services; PartyKit provides stateful rooms with server logic
- Colyseus — game-focused with binary state sync; PartyKit targets general collaboration and real-time apps
FAQ
Q: Can PartyKit be self-hosted? A: The open-source framework can be used locally for development. Production deployment uses PartyKit's edge infrastructure or compatible Cloudflare Workers setups.
Q: What is a room in PartyKit? A: A room is a stateful server instance identified by an ID. All clients connecting to the same room ID share the same server and can communicate in real time.
Q: Does PartyKit support collaborative text editing? A: Yes. It has built-in integration with Yjs, a CRDT library, making it straightforward to add Google Docs-style collaborative editing to any application.
Q: How many concurrent connections can a room handle? A: Each room can handle thousands of concurrent WebSocket connections, with the exact limit depending on message volume and server logic complexity.