A minimal real-time collaborative app where multiple users can see each other's cursors move instantly — built using AWS serverless services.
No servers. No polling. Just real-time.
- 🟢 Real-time cursor updates via WebSocket
- 🎨 Unique color per user
- 👥 Multi-user support
- ⚡ Fully serverless (auto-scaling)
- 🧠 Stateless architecture
- Amazon API Gateway (WebSocket API)
- AWS Lambda (Node.js)
- Amazon DynamoDB
- AWS CDK (TypeScript)
Browser (WebSocket client)
↓
API Gateway (WebSocket)
├── $connect → Lambda → store connection
├── $disconnect → Lambda → delete connection
└── move → Lambda → broadcast message
↓
DynamoDB (connection registry)
.
├── bin/
├── lib/
│ └── realtime-stack.ts # CDK infrastructure
├── lambda/
│ ├── connect.ts # handle new connection
│ ├── disconnect.ts # handle disconnect
│ └── message.ts # broadcast cursor movement
├── frontend/
│ └── index.html # simple client
├── package.json
└── README.md
git clone <your-repo-url>
cd realtime-cursornpm install
cd lambda
npm install
cd ..cdk bootstrapcdk deployAfter deployment, you’ll get:
WebSocketURL = wss://xxxx.execute-api...
Open:
frontend/index.html
Replace:
const ws = new WebSocket("YOUR_WS_URL?boardId=default");with your deployed WebSocket URL.
- Open the page in 2 browser tabs
- Move your mouse
- Watch multiple colored cursors sync in real-time 🎉
$connect→ storeconnectionIdin DynamoDB$disconnect→ remove it
-
Client sends cursor position:
{ "action": "move", "x": 100, "y": 200 } -
Lambda:
- queries all connections
- enriches with
userId+color - broadcasts to everyone
Each update is sent to all connected clients:
1 event → N WebSocket messages
- Lambda holds no state
- DynamoDB is the source of truth
- User color & ID generated in backend
- Prevents spoofing from client
- O(N) fan-out per message (can be costly at scale)
- Potential hot partition (
boardId = default) - Needs cleanup for stale connections (410 Gone)
- ✏️ Draw lines instead of just cursors
- 👥 Multiple rooms / boards
- 🔐 Authentication (JWT / Cognito)
- 🧠 Cursor smoothing
- 📊 Presence indicators (online/offline)
This project demonstrates a core pattern:
Real-time apps can be built using serverless primitives — no dedicated backend servers required.
MIT
Feel free to open issues or submit PRs!
Give it a star ⭐ and share it!