Native Binary WebSockets in ODAC.JS

July 14, 2026
3 min read
11 reads
Native Binary WebSockets in ODAC.JS

WebSockets were supposed to be the "real-time" protocol, yet most Node.js frameworks treat them like glorified JSON pipes.

You send a Buffer, and behind the scenes, it is stringified into a massive JSON object, wrapped in a text frame, and bloated by 33% or more. This is not just inefficient; it is an architectural failure for high-performance applications like audio streaming, sensor data, or binary protocols.

In the latest release of ODAC.JS, we have overhauled the WebSocket engine to treat binary data with the respect it deserves. No more silent JSON wrapping. No more memory truncation. Just raw, high-performance binary streaming.

The Cost of the "Object" Trap

In Node.js, Buffer and TypedArray are technically objects. For a long time, the standard pattern in framework development was a simple check: "Is it an object? Then JSON.stringify it."

While this is convenient for sending state objects, it is a disaster for binary data. Sending a 1MB buffer as a JSON-encoded array can balloon its size to 4MB or more, crushing your server's CPU and your user's bandwidth.

ODAC.JS now implements a strict Binary Detection Layer that identifies Buffer, ArrayBuffer, and all TypedArray views (like Uint8Array or Float64Array) before they ever hit the serialization engine.

The Binary Detection Flow

Show Me The Code

With ODAC.JS, you do not need to change your API usage to get these performance wins. The framework handles the protocol switching automatically.

// route/websocket.js
Odac.Route.ws('/stream', Odac => {
  // Sending a Node.js Buffer
  const audioChunk = getAudioBuffer();
  Odac.ws.send(audioChunk); // Automatically sent as RFC 6455 BINARY frame

  // Sending a TypedArray with full precision
  const telemetry = new Float64Array([42.0001, -122.345]);
  Odac.ws.send(telemetry); // No precision loss, zero truncation
});

Fixing the "Silent Corruption" Bug

Beyond just performance, we have fixed a critical engineering flaw found in many WebSocket implementations: Byte Truncation.

Previously, passing a Uint16Array or Float32Array to Buffer.from() would often result in data loss because Node.js would attempt to read the view as a list of integers, truncating each element to a single byte.

ODAC.JS now utilizes the backing memory of your views directly. By using Buffer.from(view.buffer, view.byteOffset, view.byteLength), we ensure that every bit of your data is preserved, respecting memory offsets and multi-byte widths.

Before JSON Bloat vs After Native Binary

Why This Matters for the Enterprise

For enterprise-grade applications, efficiency is not just a metric; it is a cost-saving measure. By switching to native BINARY frames, ODAC.JS reduces:

  • CPU Overhead: Skipping JSON.stringify and JSON.parse cycles.
  • Memory Pressure: Using zero-copy memory views instead of creating temporary strings.
  • Bandwidth Usage: Delivering the smallest possible payload over the wire.

Whether you are building a real-time trading dashboard or a collaborative design tool, ODAC.JS provides the foundation for performance that scales without the bloat.

Conclusion

At ODAC.JS, we believe the framework should be invisible. It should just do the right thing by default. With native binary support, your real-time streams are now faster, leaner, and more reliable than ever.