Skip to content

Develop a differential JSON-patch stream over tRPC WebSockets to reduce payload sizes for live order books #464

Description

@Damola-Sodiq

Description

Optimize WebSocket data streaming by computing JSON Patches (RFC 6902) on the backend and transmitting only the state deltas to the frontend order book.

Architecture & Context

Broadcasting the entire fractional order book every 3 seconds consumes massive egress bandwidth. Computing a diff against the client's last known state ensures only changing orders are transmitted over the WebSocket.

Technical Requirements

  • Maintain an ephemeral state hash map per connected WebSocket client.
  • Implement an efficient JSON diffing algorithm on the Fastify server.
  • Reconstruct the full object state seamlessly in the Next.js frontend using immer or manual patching.

Acceptance Criteria

  • Payload sizes drop by >80% during active trading sessions.
  • The client state perfectly matches the server state with zero desynchronization.
  • Disconnected clients automatically request a full state snapshot upon reconnecting.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions