<?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: VozNovel</title>
    <description>The latest articles on DEV Community by VozNovel (@voznovel).</description>
    <link>https://dev.to/voznovel</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%2F4252080%2Fe8c808f0-e577-4dfc-9f21-238c9569e680.jpg</url>
      <title>DEV Community: VozNovel</title>
      <link>https://dev.to/voznovel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/voznovel"/>
    <language>en</language>
    <item>
      <title>Rendering 1,000+ Character Constellation Nodes on HTML5 Canvas &amp; Decoupling AI SSE Streams from Laravel</title>
      <dc:creator>VozNovel</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:28:19 +0000</pubDate>
      <link>https://dev.to/voznovel/rendering-1000-character-constellation-nodes-on-html5-canvas-decoupling-ai-sse-streams-from-2924</link>
      <guid>https://dev.to/voznovel/rendering-1000-character-constellation-nodes-on-html5-canvas-decoupling-ai-sse-streams-from-2924</guid>
      <description>&lt;p&gt;Building an encyclopedia and interactive world-building companion for long-running Eastern fantasy, Xianxia, and Donghua series (often spanning 2,000–4,000+ chapters) introduces a surprisingly fun set of frontend and backend engineering problems.&lt;/p&gt;

&lt;p&gt;While building &lt;strong&gt;&lt;a href="https://voznovel.com" rel="noopener noreferrer"&gt;VozNovel&lt;/a&gt;&lt;/strong&gt;—which now organizes over &lt;strong&gt;37,000 character profiles&lt;/strong&gt;, cultivation realms, factions, and an interactive &lt;strong&gt;AI Storyteller&lt;/strong&gt;—we had to keep everything smooth on mobile browsers and a modest VPS without letting heavy graph views or streaming AI turns lock up web workers.&lt;/p&gt;

&lt;p&gt;Here are the three architectural choices that made the biggest difference.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Moving the Relationship Graph from DOM/SVG to HTML5 &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;For small graphs (&amp;lt;250 entities), SVG or HTML `&lt;/p&gt;` nodes work well. Once we mapped massive cultivation worlds like those in our &lt;strong&gt;&lt;a href="https://voznovel.com/nhan-vat" rel="noopener noreferrer"&gt;VozNovel Character Encyclopedia&lt;/a&gt;&lt;/strong&gt; or dense faction trees such as &lt;strong&gt;&lt;a href="https://voznovel.com/kiem-lai" rel="noopener noreferrer"&gt;Kiếm Lai (Sword of Coming)&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://voznovel.com/co-chan-nhan" rel="noopener noreferrer"&gt;Cổ Chân Nhân (Reverend Insanity)&lt;/a&gt;&lt;/strong&gt;, DOM/SVG hit mobile bottlenecks fast:

&lt;ul&gt;
&lt;li&gt;Recalculating layout and styles across 1,000+ positioned labels during pan/zoom.&lt;/li&gt;
&lt;li&gt;Re-rasterizing hundreds of curved relationship Bézier edges on every touch frame.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Switching to a dedicated &lt;strong&gt;HTML5 &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt;&lt;/strong&gt; renderer solved this with three practical steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Viewport Culling:&lt;/strong&gt; On each &lt;code&gt;requestAnimationFrame&lt;/code&gt;, project viewport bounds into world coordinates and skip drawing any node or edge outside &lt;code&gt;worldBounds + padding&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spatial Hit-Testing:&lt;/strong&gt; Instead of attaching thousands of DOM listeners, transform &lt;code&gt;pointermove&lt;/code&gt; / &lt;code&gt;click&lt;/code&gt; coordinates from screen space back to world space and look up nearby nodes via a lightweight spatial grid in ~O(1) time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clamped DPR &amp;amp; Adaptive Labels:&lt;/strong&gt; Clamp canvas scaling to &lt;code&gt;Math.min(window.devicePixelRatio || 1, 2)&lt;/code&gt; so high-density mobile screens stay crisp without ballooning GPU memory, and suppress secondary labels while &lt;code&gt;isPanning&lt;/code&gt; is active.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  2. Single-Flight Stale Cache &amp;amp; Guest Session Isolation on Laravel + Redis
&lt;/h2&gt;

&lt;p&gt;Directory and character pages receive spiky community traffic. If hundreds of concurrent visitors hit an expired Redis key at the same moment (&lt;strong&gt;cache stampede&lt;/strong&gt;), database queries pile up immediately.&lt;/p&gt;

&lt;p&gt;We added two lightweight safeguards:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single-Flight Lock (&lt;code&gt;Cache::lock&lt;/code&gt;) + &lt;code&gt;stale-while-revalidate&lt;/code&gt;:&lt;/strong&gt; Only &lt;strong&gt;one&lt;/strong&gt; request acquires the lock to rebuild fresh HTML after &lt;code&gt;fresh_until&lt;/code&gt; expires; concurrent visitors receive the cached stale response from Redis in under 2ms while regeneration finishes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anonymous Read Session Skip:&lt;/strong&gt; Read-only public encyclopedia routes switch Laravel's session driver to &lt;code&gt;array&lt;/code&gt; at runtime and strip redundant &lt;code&gt;Set-Cookie&lt;/code&gt; headers for guests, preventing tens of thousands of orphan session keys in Redis every day.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Decoupling Long-Lived AI SSE Streams from PHP Workers
&lt;/h2&gt;

&lt;p&gt;Our &lt;strong&gt;AI Storyteller&lt;/strong&gt; mode keeps a &lt;strong&gt;Server-Sent Events (SSE)&lt;/strong&gt; stream open for 15–60 seconds per interactive story turn while streaming tokens back to the reader. Holding PHP-FPM / LSAPI workers open on slow network sockets quickly exhausts &lt;code&gt;max_children&lt;/code&gt; under concurrency.&lt;/p&gt;

&lt;p&gt;We separated the lifecycle into a two-step &lt;strong&gt;Stream Ticket Handoff&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Laravel handles auth, story memory/canon validation, and quota checks in &amp;lt;30ms, then writes a short-lived signed &lt;strong&gt;HMAC Stream Ticket&lt;/strong&gt; into Redis.&lt;/li&gt;
&lt;li&gt;The browser connects directly to a lightweight &lt;strong&gt;async SSE proxy&lt;/strong&gt; with that ticket so PHP workers immediately return to the pool to serve regular SSR pages under 50ms.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;If you enjoy cultivation/Xianxia worldbuilding, Donghua character lore, or canvas graph performance challenges, feel free to explore &lt;strong&gt;&lt;a href="https://voznovel.com" rel="noopener noreferrer"&gt;VozNovel&lt;/a&gt;&lt;/strong&gt;—and I’d love to hear how you handle large-node canvas rendering or SSE handoffs in your own stack!&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>javascript</category>
      <category>performance</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
