WebSocket payload size limit exceeded in Reflex state sync
0 reputation · 10 May 2020, 22:29 UTC
Problem: Large dataset in State causes WebSocket timeout
In Reflex, a centralized State class synchronizes variables between the Python backend and the React frontend over a WebSocket connection. When a State variable holds thousands of records, the JSON payload generated for each update can exceed typical browser or server limits, leading to a WebSocket payload size limit exceeded error or silent failure.
Current approach
- Fetch all rows from the database (e.g., 10,000 items).
- Assign the result list to a State variable.
- Trigger pagination by slicing the list in the event handler and updating a page index.
This pattern forces the entire dataset onto the client, inflating the WebSocket traffic and risking memory exhaustion or timeouts.
Unresolved decision
Should pagination and query bounding be handled entirely on the backend before State assignment, or can a hybrid approach (partial state, client‑side caching) mitigate the WebSocket overhead without introducing race conditions?
Questions
- What is the maximum WebSocket payload size that Reflex can reliably transmit, and how does it vary across browsers?
- Can we implement a server‑side
LIMITandOFFSETstrategy that returns only the current page, and what impact does that have on State synchronization latency? - Is there a built‑in mechanism in Reflex to stream large query results incrementally, or must we rely on custom event handlers to push data chunks?