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.