<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shubham Maurya</title>
    <description>The latest articles on DEV Community by Shubham Maurya (@shubham996633).</description>
    <link>https://dev.to/shubham996633</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4262910%2Fabaca1f6-51ef-4754-ba78-bfd2778e2b65.png</url>
      <title>DEV Community: Shubham Maurya</title>
      <link>https://dev.to/shubham996633</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shubham996633"/>
    <language>en</language>
    <item>
      <title>Building a real-time dashboard on Next.js and WebSockets: what breaks and how we handle it</title>
      <dc:creator>Shubham Maurya</dc:creator>
      <pubDate>Tue, 24 Nov 2026 15:00:30 +0000</pubDate>
      <link>https://dev.to/shubham996633/building-a-real-time-dashboard-on-nextjs-and-websockets-what-breaks-and-how-we-handle-it-3doc</link>
      <guid>https://dev.to/shubham996633/building-a-real-time-dashboard-on-nextjs-and-websockets-what-breaks-and-how-we-handle-it-3doc</guid>
      <description>&lt;p&gt;We've built both halves of live dashboards: Go and FastAPI services that stream events over WebSockets to many clients at once, and Next.js and React dashboards. These are the problems worth planning for.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Agree the event contract before building screens
&lt;/h2&gt;

&lt;p&gt;Most real-time bugs are contract bugs: a field that's sometimes missing, a number that's a string, events that arrive out of order, a message type nobody told the frontend about. Before writing UI we pin down every message the backend sends: its type, shape, units, expected rate and ordering guarantees, plus what a snapshot on connect looks like. We keep it as types shared by both sides and validate incoming messages at the edge, so a bad message is logged and dropped instead of breaking a screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Reconnect like the network will fail, because it will
&lt;/h2&gt;

&lt;p&gt;Laptops sleep, phones switch networks, servers deploy. The client needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reconnect with exponential backoff and jitter, so a server restart doesn't get hit by every client at once&lt;/li&gt;
&lt;li&gt;Resubscribe to exactly what the user was watching&lt;/li&gt;
&lt;li&gt;Ask for a fresh snapshot after reconnecting, rather than trusting whatever was on screen&lt;/li&gt;
&lt;li&gt;A visible connection state. A dashboard that silently shows stale data as live is worse than one that says "reconnecting"&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. One store, not state scattered across components
&lt;/h2&gt;

&lt;p&gt;Socket messages go into one normalised store keyed by id, outside React's render cycle. Components subscribe to the slice they need. That's what makes "this row changed" cheap, makes reconnect snapshots easy to apply, and stops two components from disagreeing about the same value.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Batch renders; don't re-render per message
&lt;/h2&gt;

&lt;p&gt;At a few updates a second anything works. At hundreds, calling setState per message freezes the page. Buffer incoming messages and apply them once per animation frame. Virtualise long tables so only visible rows render, and throttle charts to what the eye can follow. The data is still exact; only the painting is batched.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Keep history and filters on REST
&lt;/h2&gt;

&lt;p&gt;The socket is for what's happening now. History, search, filters, muting and exports go through normal REST endpoints with pagination. Mixing the two ("send me the last 10,000 events over the socket") is how connections get slow for everyone.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Put money and permissions on the server
&lt;/h2&gt;

&lt;p&gt;If the dashboard is paid (for example with subscriptions), the server decides what a user may see, ideally when the WebSocket connection is opened. Verify webhooks and process them idempotently, so a retried event is never applied twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Test at peak, not at demo rates
&lt;/h2&gt;

&lt;p&gt;Record a busy period from the real feed or simulate one, replay it at two or three times the expected rate, and watch frame times and memory for an hour. Most real-time problems (leaks, growing arrays, slow re-renders) only show up under sustained load.&lt;/p&gt;




&lt;p&gt;A small working version is open source: &lt;a href="https://github.com/Shubham996633/realtime-dashboard-starter" rel="noopener noreferrer"&gt;https://github.com/Shubham996633/realtime-dashboard-starter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shubham Maurya leads our real-time frontend work. More of our work: &lt;a href="https://buildkodiq.com/work" rel="noopener noreferrer"&gt;https://buildkodiq.com/work&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://buildkodiq.com/blog/real-time-dashboard-nextjs-websockets" rel="noopener noreferrer"&gt;buildkodiq.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance and reviewed by Shubham.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>websockets</category>
      <category>python</category>
    </item>
  </channel>
</rss>
