Six months ago, I shipped the first version of our Solana-based perpetual DEX frontend — a real-time trading dashboard that needed to handle live orderbook updates, position PnL feeds, and funding rate ticks simultaneously. What looked like a clean architecture on paper turned into a series of hard lessons about WebSocket management, React re-rendering, and the subtle ways production traffic breaks your assumptions.
The Architecture We Started With
We initially had a single WebSocket provider wrapping the entire app using Jotai atoms for state synchronization. The logic was clean: one connection, one source of truth, everything subscribed through atoms. It worked beautifully in development — fast, predictable, easy to reason about.
Production told a different story. With 200+ concurrent users on a single market, our message backpressure caused visible lag in the orderbook UI. The root cause? We were processing every tick on the main thread inside...