What is the maximum message size for WebSockets?
Answer
The WebSocket protocol does not define a hard maximum message size — frame payload lengths can theoretically be up to 2^63 bytes (64-bit payload length field). However, practical limits are imposed at multiple levels: (1) Server library limits — the Node.js ws library defaults to 100MB (maxPayload option); (2) Browser limits — browsers typically reject messages over 100MB; (3) Proxy/load balancer limits — NGINX has configurable buffer sizes; (4) Memory limits — processing a very large message requires holding it in memory, risking OOM crashes. In practice, WebSocket is designed for many small, frequent messages — it's not the right tool for large file transfers. For files, use HTTP multipart upload. For large data streams, use binary chunking: split large data into fixed-size frames and reassemble on the receiving end using the FIN bit.
Previous
What is STOMP protocol and how is it used with WebSockets?
Next
How do you monitor and debug WebSocket connections?
More WebSockets & Real-time Questions
View all →- Intermediate How do you implement a WebSocket server in Node.js using the `ws` library?
- Intermediate What are Socket.IO rooms and namespaces?
- Intermediate How do you handle WebSocket reconnection logic?
- Intermediate What is the difference between Socket.IO and raw WebSockets?
- Intermediate How do you authenticate WebSocket connections?