<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Hands-On DevOps Engineering: The Autonomous Platform Architect: 2026 Edition — Building Self-Healing, AI-Native Systems ]]></title><description><![CDATA[The DevOps playbook was quietly rewritten in 2025. Massive Kubernetes 
clusters proved too expensive, too slow, and too operator-heavy for the 
edge-first, cost-conscious world we now live in. The new gold standard is 
Autonomous Platform Engineering — platforms that don't just run code, but 
understand it, watch it at the kernel level, and fix it before your 
on-call engineer even gets the alert.

This 90-day course teaches you to build exactly that: a production-grade 
Internal Developer Platform called NexusCore, running entirely on a 
laptop. You will move below the container to master eBPF, replace Docker 
with WebAssembly for stateless workloads where it makes sense, wire local 
LLMs into your infrastructure control loop with proper guardrails, and 
ship signed, supply-chain-verified artifacts through a GitOps pipeline — 
all inside an 8 GB RAM budget.
]]></description><link>https://clouddc.substack.com/s/the-autonomous-platform-architect</link><image><url>https://substackcdn.com/image/fetch/$s_!_PTe!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a047047-5c9b-4666-a4a8-ecdd00a40b97_1024x1024.png</url><title>Hands-On DevOps Engineering: The Autonomous Platform Architect: 2026 Edition — Building Self-Healing, AI-Native Systems </title><link>https://clouddc.substack.com/s/the-autonomous-platform-architect</link></image><generator>Substack</generator><lastBuildDate>Wed, 27 May 2026 09:44:14 GMT</lastBuildDate><atom:link href="https://clouddc.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[ctoi]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[clouddc@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[clouddc@substack.com]]></itunes:email><itunes:name><![CDATA[devops]]></itunes:name></itunes:owner><itunes:author><![CDATA[devops]]></itunes:author><googleplay:owner><![CDATA[clouddc@substack.com]]></googleplay:owner><googleplay:email><![CDATA[clouddc@substack.com]]></googleplay:email><googleplay:author><![CDATA[devops]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Day 22: Local LLM Runtime — Orchestrating Ollama Services at Hyperscale]]></title><description><![CDATA[The Abstraction Trap: Why Your LLM Gateway Will Collapse]]></description><link>https://clouddc.substack.com/p/day-22-local-llm-runtime-orchestrating</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-22-local-llm-runtime-orchestrating</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Tue, 26 May 2026 08:30:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!iCzN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap: Why Your LLM Gateway Will Collapse</h2><blockquote><p>Every junior engineer I&#8217;ve seen tackle multi-tenant LLM orchestration reaches for the same tools: a Python FastAPI gateway, one subprocess per session calling <code>ollama run</code>, and a Redis queue for &#8220;load balancing.&#8221; It works beautifully &#8212; right up until concurrent sessions hit 50. Then the symptoms appear: P99 latency climbs from 200ms to 4 seconds, CPU steal time spikes, and the kernel&#8217;s CFS scheduler starts making decisions that nobody asked for.</p><p>The reason isn&#8217;t that Python is slow. The reason is that <strong>&#8220;one process per tenant session&#8221;</strong> is a model that scales with RAM and TLB entries, not with your GPU&#8217;s inference throughput. Let me break this into concrete numbers.</p><p>At 1,000 concurrent Ollama sessions using the naive subprocess model:</p><ul><li><p><strong>Process spawn cost:</strong> ~45ms per cold start (execve + dynamic linker + ggml weight mmap initialization)</p></li><li><p><strong>RSS floor:</strong> ~180MB per process (ggml layer allocation even for 7B models in K/V cache sharing mode)</p></li><li><p><strong>TLB invalidation:</strong> Every context switch between processes on x86-64 with PCID off flushes ~1,500 TLB entries. At 1,000 processes doing I/O waits, the scheduler fires ~8,000 context switches/sec. That&#8217;s 12M TLB misses/sec hitting L2 for re-fill &#8212; roughly 18ms of aggregate CPU time wasted per second <em>per core</em>.</p></li><li><p><strong>Futex pressure:</strong> Each streaming session sleeps on a futex waiting for the next token chunk. 1,000 sleeping futexes means the kernel&#8217;s wake path traverses the hash bucket chain 10-80 times/sec per session as tokens arrive.</p></li></ul><p>This isn&#8217;t a language problem. This is a <strong>process model problem</strong>. And WASI 0.3 plus eBPF give us the primitives to fix it from first principles.</p></blockquote><div><hr></div><h2>The Real Bottleneck: Scheduler Thrashing on Token Cadence</h2><blockquote><p>LLM token streaming has a unique I/O profile: <strong>bursty, low-throughput, high-latency-variance</strong>. A 7B model on an RTX 4090 produces tokens at roughly 45-90 tokens/sec. That&#8217;s one token every 11-22ms.</p><p>A sleeping process waiting for the next chunk gets scheduled off-CPU between tokens. When the chunk arrives via Ollama&#8217;s HTTP chunked-transfer response, the kernel must:</p><ol><li><p>Fire the socket&#8217;s receive callback</p></li><li><p>Wake the futex/epoll fd the process is blocked on</p></li><li><p>Re-schedule the process (add to runqueue, wait for next quantum)</p></li><li><p>TLB warm-up on context switch in</p></li></ol><p>Steps 3 and 4 alone cost 15-40&#956;s on a loaded system. For 1,000 sessions, that per-token scheduling overhead is <strong>not parallelized</strong> &#8212; it serializes through the runqueue locks. This is scheduler thrashing: the scheduler spends more cycles managing wake/sleep transitions than the application spends processing tokens.</p><p>The fix: <strong>collapse 1,000 sessions onto a single OS thread using cooperative async I/O</strong>, with session state isolated via Wasm linear memory boundaries instead of process boundaries.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: WASI 0.3 Components + eBPF Socket Tap</h2><p>Here is the 2026 pattern we&#8217;re building:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iCzN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iCzN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png 424w, https://substackcdn.com/image/fetch/$s_!iCzN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png 848w, https://substackcdn.com/image/fetch/$s_!iCzN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png 1272w, https://substackcdn.com/image/fetch/$s_!iCzN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iCzN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png" width="502" height="345.8222222222222" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:775,&quot;width&quot;:1125,&quot;resizeWidth&quot;:502,&quot;bytes&quot;:153145,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/194043142?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iCzN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png 424w, https://substackcdn.com/image/fetch/$s_!iCzN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png 848w, https://substackcdn.com/image/fetch/$s_!iCzN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png 1272w, https://substackcdn.com/image/fetch/$s_!iCzN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda4941a-bcd4-4728-9641-d2d30a1e92fb_1125x775.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="callout-block" data-callout="true"><p><strong>Preparing for a distributed systems interview?</strong><br>&#8594;<strong><a href="https://systemdrd.com/ebooks/sdcourse-distributed-systems-interview">Download the free Interview Pack</a></strong><br><strong>&#8594; <a href="https://clouddc.substack.com/subscribe">Subscribe</a> now to access source code repository - 200 + coding lessons</strong></p></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-22-local-llm-runtime-orchestrating">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 21: The Unified Data API — Routing Queries to the Optimal Store]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-21-the-unified-data-api-routing</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-21-the-unified-data-api-routing</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Sat, 23 May 2026 08:31:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!p_X2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer building a polyglot persistence layer in 2023 would reach for something like GraphQL federation, or a BFF (Backend-for-Frontend) service that speaks HTTP/2 to Redis, Postgres, InfluxDB, and S3. The code is readable. The architecture fits on a whiteboard. It ships in a sprint.</p><p>Three months later, at 40K tenants and 80M requests/day, the on-call rotation becomes a full-time job. The BFF process has a 4&#8211;8ms p99 latency on time-series writes &#8212; because it shares an event loop with graph traversals that scan 200K-edge neighborhoods. The framework is hiding the failure mode: <strong>head-of-line blocking inside a single user-space proxy</strong>.</p><p>The abstraction you chose &#8212; &#8220;one smart router owns all data paths&#8221; &#8212; is the same pattern as a single-threaded accept loop on a socket. It is fine until it isn&#8217;t, and when it breaks, your only tools are horizontal scaling (more cost, more coordination overhead) and profiling a black box you didn&#8217;t write.</p></blockquote><div><hr></div><h2>The Failure Mode: Copy Amplification and TLB Thrashing</h2><blockquote><p>Let&#8217;s be precise about <em>why</em> this pattern fails at hyperscale, not just that it does.</p><p><strong>Copy amplification.</strong> A 4KB query payload travelling through a user-space router crosses the kernel boundary twice per hop: user&#8594;kernel on ingress, kernel&#8594;user on egress to the backend. That is 8KB of memory bandwidth consumed for 4KB of actual data. At 100M RPS with an average payload of 2KB, this wastes ~400GB/s of memory bandwidth &#8212; on hardware that typically delivers 200&#8211;300GB/s total. You are spending more bandwidth <em>moving data to where it will be processed</em> than the backends consume processing it.</p><p><strong>TLB thrashing.</strong> Each tenant process (or each goroutine with its own stack mapped into a large heap) means a distinct virtual address space context. The CPU&#8217;s Translation Lookaside Buffer holds ~1,500 entries on a modern x86 core. At 10K concurrent tenant contexts, any context switch invalidates TLB entries needed by the next tenant. A TLB hit costs ~3 cycles. A miss costs ~200 cycles (page-walk to DRAM). At 100M RPS with a 5% miss rate from scheduler-induced context switching, that is 1 billion wasted cycles per second on a single core &#8212; before you do any actual work.</p><p><strong>Scheduler thrashing.</strong> A Go or Tokio runtime with 10K goroutines/tasks doesn&#8217;t magically parallelize across 10K cores. On a 32-core host, the runtime scheduler itself becomes a contention point. Each scheduling decision is a mutex acquire in the worst case. The symptom is not CPU saturation &#8212; it&#8217;s CPU <em>inefficiency</em>: <code>perf stat</code> shows high <code>sched:sched_switch</code> rates and branch-misprediction counts climbing on the scheduler&#8217;s branch-heavy dispatch loop.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: eBPF-Pinned Socket Routing</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!p_X2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!p_X2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png 424w, https://substackcdn.com/image/fetch/$s_!p_X2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png 848w, https://substackcdn.com/image/fetch/$s_!p_X2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png 1272w, https://substackcdn.com/image/fetch/$s_!p_X2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!p_X2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png" width="498" height="448.2" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1125,&quot;width&quot;:1250,&quot;resizeWidth&quot;:498,&quot;bytes&quot;:217977,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/194036252?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!p_X2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png 424w, https://substackcdn.com/image/fetch/$s_!p_X2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png 848w, https://substackcdn.com/image/fetch/$s_!p_X2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png 1272w, https://substackcdn.com/image/fetch/$s_!p_X2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6209f1fb-153d-4c35-bf7e-d75619721af6_1250x1125.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="callout-block" data-callout="true"><p><strong>Preparing for a distributed systems interview?</strong><br>&#8594;<strong><a href="https://systemdrd.com/ebooks/sdcourse-distributed-systems-interview">Download the free Interview Pack</a></strong><br><strong>&#8594; <a href="https://clouddc.substack.com/subscribe">Subscribe</a> now to access source code repository - 200 + coding lessons</strong></p></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-21-the-unified-data-api-routing">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 20: Cross-Store CDC — Syncing SurrealDB to Qdrant at Hyperscale]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-20-cross-store-cdc-syncing-surrealdb</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-20-cross-store-cdc-syncing-surrealdb</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Wed, 20 May 2026 08:30:14 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!8m9M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>Every senior engineer I&#8217;ve interviewed in the past two years reaches for the same answer when asked &#8220;how do you sync changes from your primary store to a vector database?&#8221;: <em>&#8220;We&#8217;ll use a Kafka connector&#8221;</em> or <em>&#8220;We&#8217;ll poll on a cron.&#8221;</em> Both answers reveal the same mental model &#8212; the store is a black box, and change propagation is a data-plumbing problem you buy off the shelf.</p><p>This is how you end up with a JVM Debezium cluster consuming 6 GB of heap per tenant, a Kafka broker that&#8217;s your new single point of failure, and a latency floor of 400ms before any vector in Qdrant reflects reality. The &#8220;magic&#8221; of the framework hides a brutal truth: <strong>you have surrendered control of your data path</strong>, and every layer you&#8217;ve inserted has a failure mode you cannot observe from userspace.</p><p>In NexusCore we don&#8217;t use Debezium. We don&#8217;t use Kafka. We intercept SurrealDB&#8217;s write path at the kernel boundary using an eBPF <code>uprobe</code> on <code>rocksdb::WriteBatch::Put()</code>, route the raw event through a <code>BPF_MAP_TYPE_RINGBUF</code> into a zero-copy mmap&#8217;d consumer, and process it inside a WASI 0.3 component running in a dedicated wasmtime sandbox. The entire hot path from RocksDB write to Qdrant upsert runs in under 3 microseconds on the critical path, with zero heap allocations in the kernel half.</p></blockquote><div><hr></div><h2>Why &#8220;Process Per Tenant&#8221; Collapses at Scale</h2><blockquote><p>Let&#8217;s do the arithmetic. If you&#8217;re handling 10,000 tenant isolation domains and each CDC pipeline is a Linux process:</p><ul><li><p><strong>Stack overhead:</strong> 2 MB default stack &#215; 10,000 = ~20 GB of virtual address space committed, triggering TLB pressure on every context switch.</p></li><li><p><strong>Scheduler thrashing:</strong> The Linux CFS scheduler on a 32-core machine can execute ~320,000 context switches per second under heavy load. With 10,000 processes each needing a poll tick every 10ms, you&#8217;re demanding 1,000,000 wakeups/second &#8212; 3&#215; the scheduler&#8217;s sustainable throughput before you&#8217;ve processed a single byte of user data.</p></li><li><p><strong>File descriptor overhead:</strong> Each process opens file descriptors for its IPC channel, BPF maps, and network socket &#8212; the kernel&#8217;s <code>fdtable</code> lock contends under concurrent open/close cycles.</p></li><li><p><strong>TLB shootdown cascade:</strong> When a process context-switches on a non-PCID-capable core, the TLB is flushed. A 10k-process churn on 8 NUMA nodes causes cross-node TLB invalidation IPIs that can stall other cores for 50&#8211;200 nanoseconds each. Under sustained write load this becomes measurable in percentile latency charts.</p></li></ul><p>The fix isn&#8217;t &#8220;use more cores&#8221; &#8212; it&#8217;s changing the cardinality of the problem. Instead of N processes for N tenants, we run <strong>one eBPF program per SurrealDB instance</strong> (kernel-resident, no scheduler context) and <strong>M WASI component instances</strong> where M is determined by CPU concurrency budget, not tenant count. Tenant routing happens inside the ring buffer&#8217;s event header, dispatched by the Go orchestrator without forking.</p></blockquote><div><hr></div><h2>The NexusCore CDC Architecture</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8m9M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8m9M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png 424w, https://substackcdn.com/image/fetch/$s_!8m9M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png 848w, https://substackcdn.com/image/fetch/$s_!8m9M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png 1272w, https://substackcdn.com/image/fetch/$s_!8m9M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8m9M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png" width="502" height="451.5768888888889" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1012,&quot;width&quot;:1125,&quot;resizeWidth&quot;:502,&quot;bytes&quot;:147178,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/194031319?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8m9M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png 424w, https://substackcdn.com/image/fetch/$s_!8m9M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png 848w, https://substackcdn.com/image/fetch/$s_!8m9M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png 1272w, https://substackcdn.com/image/fetch/$s_!8m9M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32a7dbc7-6ce0-4e82-9382-e75a022afc15_1125x1012.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="callout-block" data-callout="true"><p><strong>Preparing for a distributed systems interview?</strong><br>&#8594;<strong><a href="https://systemdrd.com/ebooks/sdcourse-distributed-systems-interview">Download the free Interview Pack</a></strong><br><strong>&#8594; <a href="https://clouddc.substack.com/subscribe">Subscribe</a> now to access source code repository - 200 + coding lessons</strong></p></div><p>The critical insight here is the <strong>shared physical frames</strong> between kernel and userspace. <code>BPF_MAP_TYPE_RINGBUF</code> is mapped into userspace via <code>mmap()</code> &#8212; the kernel and Go loader are literally reading from and writing to the same DRAM cells. There is no <code>copy_to_user()</code> call. No syscall on the read path (post-wakeup). This is what makes the latency distribution tight: we&#8217;re only paying for the <code>epoll_wait()</code> wakeup, not for a data copy proportional to payload size.</p><div><hr></div><h2>The eBPF Probe: CO-RE, Not Fragile Symbol Offsets</h2><p>The naive approach to <code>uprobe</code> on a C++ binary is to hardcode the symbol offset found with <code>nm</code>. This breaks the instant SurrealDB is rebuilt with a different optimization level, link-time optimization, or even a different compiler version. In 2026 we use <strong>CO-RE (Compile Once, Run Everywhere)</strong> with BTF type information where available, and for userspace uprobes where BTF doesn&#8217;t apply, we use <code>bpf_probe_read_user()</code> with explicit offset computation verified at load time by a Go binary that <code>dlopen</code>s the target and resolves the symbol dynamically.</p><p>The eBPF program does exactly three things:</p><ol><li><p><code>bpf_probe_read_user()</code> the <code>Slice</code> struct representing the RocksDB key and value.</p></li><li><p>Hash the key (FNV-1a, 4 instructions, no branch) to identify the SurrealDB table.</p></li><li><p><code>bpf_ringbuf_reserve()</code> a 64-byte-aligned slot and <code>bpf_ringbuf_submit()</code> immediately.</p></li></ol><p>The verifier rejects any program exceeding 1 million instructions or accessing out-of-bounds memory. We get a formal memory safety proof from the kernel&#8217;s own verifier on every load &#8212; something you cannot get from userspace code.</p><div><hr></div><h2>WASI 0.3: Async Streams Without the Scheduler</h2><p>WASI Preview 3 ships with native async/await in the component model via <code>wasi:io/poll</code> and the <code>future</code>/<code>stream</code> value types. This is a fundamental shift from Preview 2: components no longer block on I/O. Instead, the wasmtime host drives a non-blocking event loop that services the WASI component&#8217;s <code>future</code> handles using <code>tokio</code>&#8216;s async runtime in the host process.</p><p>Our CDC component exposes one interface:</p><pre><code><code>// cdc-processor.wit
package nexuscore:cdc@0.3.0;

interface processor {
  use wasi:io/streams@0.3.{input-stream, output-stream};

  record cdc-event {
    tenant-id: u64,
    table-hash: list&lt;u8&gt;,
    payload: list&lt;u8&gt;,
    ts-ns: u64,
  }

  record qdrant-upsert {
    collection: string,
    point-id: string,
    vector: list&lt;f32&gt;,
    payload-json: string,
  }

  process: func(event: cdc-event) -&gt; result&lt;option&lt;qdrant-upsert&gt;, string&gt;;
}
</code></code></pre><p>The <code>shared-nothing</code> isolation means each tenant&#8217;s component instance has its own linear memory. There are no shared globals, no <code>Arc&lt;Mutex&lt;&gt;&gt;</code> contention across tenants. Memory faults in one component cannot corrupt another. This is the property that Kubernetes namespaces cannot give you &#8212; they share a kernel, a scheduler, and a TCP/IP stack. WASI components share none of these.</p><div><hr></div><h2>The Delta Checker: Why We Don&#8217;t Vectorize Everything</h2><p>Vectorizing on every write is the obvious implementation. It&#8217;s also 100&#215; more expensive than necessary. Most SurrealDB writes are metadata updates &#8212; timestamps, counters, session fields &#8212; that produce a vector indistinguishable from the previous one. We gate every potential upsert through a <strong>cosine similarity check</strong> against the cached previous vector using the <code>ndarray</code> crate&#8217;s SIMD-accelerated dot product. Only when <code>1 - cosine(prev, curr) &gt; &#952;</code> (threshold 0.02 by default) do we proceed to Qdrant.</p><p>In production workloads this cuts Qdrant write amplification by 60&#8211;85% at the cost of ~12 nanoseconds of SIMD computation per event. The cache is a fixed-size <code>BTreeMap&lt;[u8;32], Vec&lt;f32&gt;&gt;</code> keyed on the 32-byte table hash + record ID hash. No external cache, no Redis round-trip.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_KZQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_KZQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png 424w, https://substackcdn.com/image/fetch/$s_!_KZQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png 848w, https://substackcdn.com/image/fetch/$s_!_KZQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png 1272w, https://substackcdn.com/image/fetch/$s_!_KZQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_KZQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png" width="486" height="470.92408163265304" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1187,&quot;width&quot;:1225,&quot;resizeWidth&quot;:486,&quot;bytes&quot;:114979,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/194031319?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_KZQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png 424w, https://substackcdn.com/image/fetch/$s_!_KZQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png 848w, https://substackcdn.com/image/fetch/$s_!_KZQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png 1272w, https://substackcdn.com/image/fetch/$s_!_KZQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F601b2cf2-608c-488c-a4a6-6a85e9159ec3_1225x1187.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>Implementation Deep Dive: </h2><h3>GitHub Link :</h3><p><a href="https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson20/nexuscore-cdc-day20">https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson20/nexuscore-cdc-day20</a></p><h2>Ring Buffer Mechanics</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QSu3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QSu3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png 424w, https://substackcdn.com/image/fetch/$s_!QSu3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png 848w, https://substackcdn.com/image/fetch/$s_!QSu3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png 1272w, https://substackcdn.com/image/fetch/$s_!QSu3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QSu3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png" width="512" height="460.8" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1125,&quot;width&quot;:1250,&quot;resizeWidth&quot;:512,&quot;bytes&quot;:146751,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/194031319?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QSu3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png 424w, https://substackcdn.com/image/fetch/$s_!QSu3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png 848w, https://substackcdn.com/image/fetch/$s_!QSu3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png 1272w, https://substackcdn.com/image/fetch/$s_!QSu3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a69655e-cc0c-441f-bf48-b4dec7a869fe_1250x1125.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The <code>BPF_MAP_TYPE_RINGBUF</code> is a <strong>single-producer, single-consumer</strong> lock-free ring buffer with a twist: it supports <strong>variable-length records</strong> while maintaining 8-byte alignment. The producer (eBPF program) calls <code>bpf_ringbuf_reserve(size)</code> which atomically advances the producer position and returns a pointer to the reserved slot. If the ring is full, <code>bpf_ringbuf_reserve()</code> returns NULL &#8212; <strong>the kernel never blocks, never sleeps, and never signals an error that could surface to userspace</strong>. It is the caller&#8217;s responsibility to detect dropped events via the <code>BPF_RB_NO_WAKEUP</code>/<code>BPF_RB_FORCE_WAKEUP</code> flags and the <code>consumer_pos</code>/<code>producer_pos</code> counters.</p><p>We size our ring at 64 MB per SurrealDB instance. At a peak write rate of 500k records/second with a mean event size of 400 bytes, the ring provides ~320ms of buffering before overflow &#8212; enough time for the consumer to drain under transient backpressure, and enough for the Go loader to alert on a <code>prometheus.Counter</code> tracking <code>ebpf_ringbuf_lost_events_total</code>.</p><div><hr></div><h3>Working Demo Link:</h3><div id="youtube2-6VfpISPs_B4" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;6VfpISPs_B4&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/6VfpISPs_B4?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><h2>Production Readiness: The Metrics That Matter</h2><p>These are the gauges you wire into Grafana before you call this production-ready:</p><p>Metric Alert Threshold What It Means <code>cdc_kernel_probe_ns_p99</code> &gt; 800 ns eBPF tail-call budget exceeded <code>cdc_ringbuf_lost_events_total</code> &gt; 0 for 60s Ring overflow &#8212; increase size or scale consumers <code>cdc_wasm_cold_start_us_p99</code> &gt; 50 &#181;s Component pool exhausted, wasmtime recompiling <code>cdc_delta_skip_ratio</code> &lt; 0.5 Too many writes vectorized &#8212; check &#952; threshold <code>cdc_qdrant_grpc_latency_p99</code> &gt; 5 ms Qdrant backpressure &#8212; check collection shard count <code>cdc_e2e_latency_us_p99</code> &gt; 3000 &#181;s Full pipeline stall &#8212; check all of the above</p><p>The <code>wasm_cold_start_us</code> metric is the one that surprises most engineers. wasmtime compiles Wasm to native code on first instantiation using Cranelift (or Winch for fast startup). Keep a <strong>pool of pre-warmed component instances</strong> &#8212; typically 4&#215; the expected peak concurrency &#8212; to ensure the compilation cost is never on the hot path.</p><div><hr></div><h2>Setup: Tools Required</h2><pre><code><code># Kernel requirements
uname -r  # Must be &gt;= 5.19 for ringbuf + CO-RE stable
cat /proc/sys/kernel/unprivileged_bpf_disabled  # Must be 0 or run as root

# Rust toolchain
rustup install stable  # 1.80+
rustup target add wasm32-wasip2

# WASI component tooling
cargo install cargo-component@0.14  # WASI 0.3 support
cargo install wac-cli               # Component composition

# Go (for eBPF loader)
go version  # 1.23+
go install github.com/cilium/ebpf/cmd/bpf2go@latest

# Qdrant (local dev)
docker run -d -p 6334:6334 qdrant/qdrant:v1.12

# wasmtime
curl -fsSL https://wasmtime.dev/install.sh | bash
</code></code></pre><div><hr></div><h2>Verification Commands</h2><pre><code><code># 1. Verify eBPF probe loaded and ring buffer attached
sudo bpftool prog list | grep cdc_uprobe
sudo bpftool map list | grep cdc_ringbuf

# 2. Confirm ring buffer consumer_pos advancing
watch -n0.5 'sudo bpftool map dump name cdc_ringbuf | grep -E "consumer|producer"'

# 3. Confirm Qdrant collection receiving upserts
curl -s http://localhost:6333/collections/nexuscore_vectors | jq .result.points_count

# 4. End-to-end latency histogram
curl -s http://localhost:9090/metrics | grep cdc_e2e_latency

# 5. Stress test
./nexuscore-day20/scripts/stress_test.sh --rate 50000 --duration 30s
</code></code></pre><div><hr></div><h2>Homework: Production-Level Challenge</h2><p><strong>Challenge:</strong> Implement <strong>multi-table routing</strong> inside the eBPF program using a <code>BPF_MAP_TYPE_HASH</code> that maps <code>table_hash &#8594; upsert_strategy</code> (where strategy encodes: which Qdrant collection, which embedding model endpoint, and the &#948; threshold for that table). The routing decision must be made inside the kernel program with zero userspace round-trips. The hash map must be <strong>pinned</strong> to <code>/sys/fs/bpf/nexuscore/routing_table</code> so it survives eBPF program reload without losing configuration. Write a Go CLI tool that updates this map at runtime (hot reload of routing config with zero downtime).</p><p><strong>Acceptance criteria:</strong> Under a 100k writes/second load test, routing table updates must propagate within 1 ring-buffer flush cycle (&lt;5ms), and no events must be dropped during the update window. Prove this with your <code>cdc_ringbuf_lost_events_total</code> counter.</p>]]></content:encoded></item><item><title><![CDATA[Day 19: Vector Quantization — Optimizing Indices for High-Density Storage]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-19-vector-quantization-optimizing</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-19-vector-quantization-optimizing</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Sun, 17 May 2026 08:30:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!uINM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer deploying a vector database for 10,000 tenants will reach for FAISS wrapped in a gRPC service, containerised per tenant. Each container runs OpenBLAS flat-scan over float32 vectors. By the time load hits 1,000 QPS per tenant, you are observing three simultaneous failure cascades:</p><ol><li><p><strong>Memory bandwidth saturation.</strong> At 1536-dimensional float32 embeddings, each vector is 6,144 bytes. A flat scan over 1 million vectors per tenant reads 5.8 GiB from DRAM per query. At 1,000 QPS, that&#8217;s 5.8 TB/s of memory bandwidth demanded &#8212; but DDR5-6400 dual-channel provides roughly 102 GB/s. You are off by a factor of 57 before a single computation begins.</p></li><li><p><strong>TLB thrashing.</strong> The Linux TLB on x86_64 has 1,536 L2 entries. 10,000 FAISS processes means constant TLB shootdowns. Every miss costs 200&#8211;300 ns of page-table walk &#8212; linear in the number of tenants sharing the same NUMA node.</p></li><li><p><strong>Scheduler context-switch overhead.</strong> OpenBLAS queries spawn BLAS threads. At 10K tenants &#215; 8 BLAS threads = 80,000 live threads. The Linux CFS scheduler burns its entire quantum budget shuffling them. Effective CPU utilisation for actual computation drops below 15%.</p></li></ol><p>None of these failure modes are visible in a local Docker test with 2 tenants. They only surface at density &#8212; which is exactly the configuration you cannot test until you&#8217;re in production.</p></blockquote><div><hr></div><h2>The Failure Mode: Cache Line Eviction and TLB Cascade</h2><blockquote><p>The specific bottleneck for naive high-dimensional nearest-neighbour search is <strong>LLC (Last Level Cache) thrashing combined with DTLB miss storms</strong>.</p><p>A modern server CPU (AMD EPYC Genoa, 96 cores) has 384 MB of L3 cache &#8212; impressive until you realise a single tenant&#8217;s 1M-vector float32 index consumes 5.8 GB. The index doesn&#8217;t fit. Every scan evicts the previous tenant&#8217;s warm data. The hardware prefetcher, designed for sequential access patterns with stride &#8804; 2048 bytes, can&#8217;t predict the random access pattern of IVF centroid probing.</p><p>The concrete numbers: each LLC miss costs 70&#8211;120 ns (DDR5 latency). A flat scan over 1M vectors &#215; 6,144 bytes/vector generates roughly 96,000 cache-line loads (at 64 bytes/line). Even with perfect hardware prefetch, that&#8217;s 6.7 ms per query from memory latency alone &#8212; 10&#215; worse than your SLA target.</p><p><strong>Product Quantization breaks this wall.</strong> By encoding each 1536-dim vector into 16 bytes (12:1 compression), a 1M-vector index now fits in 15 MB. That fits in L3. Queries become cache-resident. Distance computation switches from float32 SIMD over 1536 dims to lookup-table operations over 16 bytes. The arithmetic intensity inverts in our favour.</p></blockquote><div><hr></div><h2>The NexusCore 2026 Architecture</h2><p>NexusCore implements <strong>IVF-PQ</strong> (Inverted File Index + Product Quantization) using three cooperating layers:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uINM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uINM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png 424w, https://substackcdn.com/image/fetch/$s_!uINM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png 848w, https://substackcdn.com/image/fetch/$s_!uINM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png 1272w, https://substackcdn.com/image/fetch/$s_!uINM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uINM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png" width="500" height="414.2857142857143" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:725,&quot;width&quot;:875,&quot;resizeWidth&quot;:500,&quot;bytes&quot;:94010,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193877418?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uINM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png 424w, https://substackcdn.com/image/fetch/$s_!uINM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png 848w, https://substackcdn.com/image/fetch/$s_!uINM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png 1272w, https://substackcdn.com/image/fetch/$s_!uINM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48b3a1bf-14f5-4416-aab6-421de75f1af9_875x725.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-19-vector-quantization-optimizing">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 18: Cold Data Lifecycle — Automating Migration to Disk-Based S3]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-18-cold-data-lifecycle-automating</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-18-cold-data-lifecycle-automating</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Thu, 14 May 2026 08:30:54 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!PzfJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer sees &#8220;cold data migration&#8221; and reaches for a framework: Kubernetes CronJob, a Python <code>boto3</code> script, maybe a sidecar container pattern from a blog post dated 2022. They wire up <code>s3cmd</code>, set a 30-day TTL policy in the AWS console, and call it done.</p><p>Here&#8217;s what they missed: <strong>they handed control of their I/O scheduler to a garbage-collected runtime running inside a Linux namespace that itself runs inside a hypervisor</strong>. Every layer adds latency variance. At 100M+ objects per hour &#8212; which is what NexusCore&#8217;s multi-tenant hot-to-cold pipeline actually pushes &#8212; that variance compounds into missed SLAs, runaway memory usage, and thundering-herd S3 <code>TooManyRequests</code> cascades.</p><p>The framework hid the actual problem: <strong>cold data migration is a kernel I/O problem</strong>, not a scheduling problem. The moment you treat it as &#8220;just a cron job,&#8221; you&#8217;ve already lost.</p></blockquote><div><hr></div><h2>The Failure Mode: TLB Thrash and mmap Pressure</h2><blockquote><p>The naive approach spawns one Linux process per tenant for the migration pass. Each process:</p><ol><li><p>Reads a metadata index from disk.</p></li><li><p>Iterates over candidate objects.</p></li><li><p>Calls <code>stat()</code> to get atime/mtime.</p></li><li><p>Calls <code>sendfile()</code> or re-opens for upload.</p></li></ol><p>At scale, this blows up on two fronts:</p><p><strong>TLB Pressure:</strong> Each process gets its own virtual address space. The kernel&#8217;s TLB has to be flushed on every context switch between tenants. With 5,000 active tenants, you&#8217;re context-switching thousands of times per second. On a 48-core Xeon, that&#8217;s ~400 TLB shootdown IPIs (inter-processor interrupts) per second &#8212; each one stalls all cores momentarily. You can observe this directly with <code>perf stat -e dTLB-load-misses</code>.</p><p><strong>Scheduler Thrashing:</strong> The per-process model produces N blocked I/O tasks competing on the same storage device queue. Linux&#8217;s CFS scheduler doesn&#8217;t understand &#8220;these 5,000 tasks are doing identical disk reads.&#8221; It just sees 5,000 runnable processes jockeying for CPU slices, producing constant context-switch overhead measured in microseconds per switch &#8212; which at scale translates to whole milliseconds of aggregate stall per batch cycle.</p><p>The fix is to collapse all tenant migration logic into a <strong>single WASI component</strong> with explicit cooperative scheduling, and do the cold/hot tagging in kernel space via eBPF &#8212; zero process spawns, zero TLB pressure per tenant.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: WASI Component + eBPF File Probe</h2><h3>Core Pattern</h3><p>NexusCore Day 18 implements the following pipeline:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!PzfJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!PzfJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png 424w, https://substackcdn.com/image/fetch/$s_!PzfJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png 848w, https://substackcdn.com/image/fetch/$s_!PzfJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png 1272w, https://substackcdn.com/image/fetch/$s_!PzfJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!PzfJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png" width="512" height="352.7111111111111" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:775,&quot;width&quot;:1125,&quot;resizeWidth&quot;:512,&quot;bytes&quot;:191002,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193777833?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!PzfJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png 424w, https://substackcdn.com/image/fetch/$s_!PzfJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png 848w, https://substackcdn.com/image/fetch/$s_!PzfJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png 1272w, https://substackcdn.com/image/fetch/$s_!PzfJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4eb1b55-c7aa-4094-9637-a84d417705ba_1125x775.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-18-cold-data-lifecycle-automating">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 17: Tiered Storage — Implementing MinIO for Archived Media Blobs]]></title><description><![CDATA[The Problem Nobody Talks About Until Production Burns]]></description><link>https://clouddc.substack.com/p/day-17-tiered-storage-implementing</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-17-tiered-storage-implementing</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Mon, 11 May 2026 08:31:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!KTsa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Problem Nobody Talks About Until Production Burns</h2><blockquote><p>You have 10,000 tenants. Each uploads video blobs ranging from 1MB thumbnails to 4GB raw footage. Your storage layer needs to answer two contradictory demands simultaneously: <strong>sub-millisecond access for hot content</strong> and <strong>pennies-per-GB economics for cold archives</strong>. A junior engineer&#8217;s answer is to throw everything into S3-compatible object storage and call it a day. That answer will cost you at 3 AM when your p99 latency hits 4 seconds and MinIO&#8217;s connection pool is exhausted.</p><p>This lesson is about the <em>real</em> answer: a three-tier storage architecture &#8212; hot (mmap&#8217;d ring buffer), warm (local NVMe staging), cold (MinIO) &#8212; orchestrated by a WASI 0.3 component model and instrumented via eBPF CO-RE probes that give you kernel-level visibility into every byte that moves.</p></blockquote><div><hr></div><h2>The Abstraction Trap</h2><blockquote><p>The junior move is to reach for the official MinIO Rust SDK wrapped in a Tokio async runtime, spawn one task per tenant upload, and let the framework handle connection pooling. Here&#8217;s why this collapses:</p><p><strong>Problem 1 &#8212; Object buffering doubles your memory pressure.</strong> The naive MinIO SDK path does a full-object read into a <code>Vec&lt;u8&gt;</code> before computing the multipart boundary. For a 4GB blob, that&#8217;s 4GB of heap allocation <em>per concurrent upload</em>, per tenant. With 200 concurrent uploads across tenants, you&#8217;ve just allocated 800GB of virtual address space. The OOM killer arrives before your users do.</p><p><strong>Problem 2 &#8212; TLB thrashing at multi-tenant density.</strong> Each per-tenant Tokio runtime has its own heap arena. The kernel&#8217;s TLB (Translation Lookaside Buffer) has ~1,500 entries on a modern x86-64 core. When 500 tenant tasks compete for CPU time, TLB miss rate spikes because each task switch invalidates entries from the previous tenant&#8217;s virtual address space. A single TLB miss costs 100&#8211;300 cycles on a cache-cold DRAM lookup. At 100M req/s, this becomes your dominant CPU consumer &#8212; not your business logic.</p><p><strong>Problem 3 &#8212; Scheduler thrashing from blocking I/O in async context.</strong> MinIO PUT operations over a WAN link take 50&#8211;200ms. If you&#8217;re running <code>tokio::spawn</code> per upload without proper backpressure, you accumulate thousands of futures pinned in memory, each waiting on a TCP ACK. The scheduler bounces between them continuously. Context switch overhead (register save/restore, TLB flush on task switch) dominates.</p><p>The abstraction hid all three of these. The SDK said &#8220;async.&#8221; It lied &#8212; it just moved the blocking into a thread pool.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: Shared-Nothing WASI Components + eBPF I/O Accounting</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KTsa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KTsa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png 424w, https://substackcdn.com/image/fetch/$s_!KTsa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png 848w, https://substackcdn.com/image/fetch/$s_!KTsa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png 1272w, https://substackcdn.com/image/fetch/$s_!KTsa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KTsa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png" width="502" height="323.5111111111111" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c90f715b-82a1-4af2-a444-63421de767c1_1125x725.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:725,&quot;width&quot;:1125,&quot;resizeWidth&quot;:502,&quot;bytes&quot;:194683,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193766474?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KTsa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png 424w, https://substackcdn.com/image/fetch/$s_!KTsa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png 848w, https://substackcdn.com/image/fetch/$s_!KTsa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png 1272w, https://substackcdn.com/image/fetch/$s_!KTsa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc90f715b-82a1-4af2-a444-63421de767c1_1125x725.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-17-tiered-storage-implementing">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 16 — Hybrid Search: Metadata Filters + Vector Similarity at Kernel Speed]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-16-hybrid-search-metadata-filters</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-16-hybrid-search-metadata-filters</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Fri, 08 May 2026 08:30:59 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!XTxt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer building multi-tenant hybrid search in 2026 reaches for Elasticsearch with <code>knn</code> + <code>filter</code> clauses, or Weaviate with its GraphQL API, or LanceDB behind a FastAPI endpoint. Each of these is a black box that hides the single most important question in hybrid search:</p><p><strong>When does the filter execute relative to the ANN traversal?</strong></p><p>Elasticsearch&#8217;s approximate-kNN with pre-filter rewrites your query into an exact brute-force scan over the filtered subset &#8212; destroying the log-N complexity of HNSW entirely. Post-filtering (the default in most frameworks) does ANN first and discards non-matching results afterward, meaning that if 80% of your corpus fails the metadata predicate, you wasted 80% of your floating-point operations. Neither mode is documented prominently. You only discover the failure at load-test time, 48 hours before a launch.</p><p>NexusCore does neither. It executes the filter <strong>inside the kernel</strong>, before a single vector distance computation occurs, using a pinned eBPF hash map that materialises a tenant-scoped candidate bitmap. The HNSW beam search in the Wasm shard never visits a node that isn&#8217;t in the bitmap. Zero wasted FLOPs. Zero cross-tenant data access.</p></blockquote><div><hr></div><h2>The Failure Mode: TLB Thrashing and Scheduler Starvation</h2><blockquote><p>The naive multi-tenant approach &#8212; one Linux process per tenant, each running its own HNSW in-memory &#8212; fails at hyperscale for two compounding reasons.</p><p><strong>TLB thrashing.</strong> Every process switch forces a TLB flush on x86 (without PCID, and most cloud VMs disable PCID). At 10,000 active tenants with a 200 Hz query rate per tenant, you need 2M process-context switches per second. Each switch burns ~1,500 cycles on TLB invalidation alone. At 3 GHz that&#8217;s 1ms of CPU per second per core <strong>just for context switching overhead</strong> &#8212; before you do any actual work.</p><p><strong>Scheduler starvation.</strong> The CFS scheduler&#8217;s O(log N) pick-next becomes meaningful at N=10,000 runnable tasks. Worse: HNSW traversal is memory-latency-bound (pointer chasing through the adjacency list). A single traversal stalls 80&#8211;120 times waiting for cache-line fetches from DRAM (~65ns each). The kernel&#8217;s scheduler has no idea the task is memory-bound; it preempts it at a random stall point, polluting L1/L2 for the next task.</p><p><strong>The Wasm shared-nothing model fixes both.</strong> All tenant shards run on a fixed pool of OS threads (one per physical core). The Wasmtime runtime cooperative-yields between shards at <code>wasi:io/poll</code> call sites &#8212; no kernel scheduler involvement, no TLB flush. Each shard&#8217;s linear memory is isolated by the Wasm sandbox, not by OS page tables. PCID irrelevant. TLB warm.</p></blockquote><div><hr></div><h2>NexusCore Architecture: The 2026 Pattern</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XTxt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XTxt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png 424w, https://substackcdn.com/image/fetch/$s_!XTxt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png 848w, https://substackcdn.com/image/fetch/$s_!XTxt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png 1272w, https://substackcdn.com/image/fetch/$s_!XTxt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XTxt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png" width="504" height="385.19472913616397" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1044,&quot;width&quot;:1366,&quot;resizeWidth&quot;:504,&quot;bytes&quot;:151024,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193757810?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XTxt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png 424w, https://substackcdn.com/image/fetch/$s_!XTxt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png 848w, https://substackcdn.com/image/fetch/$s_!XTxt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png 1272w, https://substackcdn.com/image/fetch/$s_!XTxt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77ff1710-0036-48f4-bf6a-50bdb245930e_1366x1044.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-16-hybrid-search-metadata-filters">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 15: Semantic Indexing — Organizing 100K Tweets by Meaning]]></title><description><![CDATA[The Problem You&#8217;re Actually Solving]]></description><link>https://clouddc.substack.com/p/day-15-semantic-indexing-organizing</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-15-semantic-indexing-organizing</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Tue, 05 May 2026 08:31:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!8wU3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Problem You&#8217;re Actually Solving</h2><blockquote><p>You have 100,000 tweets per tenant. You need to answer queries like: <em>&#8220;Find all tweets semantically similar to &#8216;supply chain disruption in Southeast Asia&#8217;.&#8221;</em> The output isn&#8217;t keyword hits &#8212; it&#8217;s meaning-ranked clusters. This is the foundation of every autonomous content moderation system, real-time trend synthesizer, and multi-tenant analytics platform running at scale in 2026.</p><p>The naive engineer reaches for Python and <code>sentence-transformers</code>. The production engineer asks: <em>what actually happens to my L1 iTLB when I run 50 transformer inference processes side-by-side?</em></p></blockquote><div><hr></div><h2>The Abstraction Trap</h2><blockquote><p>The junior path: wrap <code>sentence-transformers</code> in a FastAPI container, throw it behind a K8s HPA, and call it a day. What you&#8217;ve done is pay for model loading on every pod cold start (500&#8211;800 MB per instance), handed the Linux scheduler a process that makes 30,000+ syscalls per second during batch inference, and ensured that your iTLB &#8212; 64 entries on most Intel Goldmont Plus microarchitectures, 128 on Zen 4 &#8212; misses on <em>every</em> new instruction page when your 50-tenant processes compete for those entries.</p><p>The number that should haunt you: a <code>sentence-transformers</code> model with full PyTorch runtime initializes approximately 2.1M virtual pages. Multiply by 50 tenants and you have 105M page table entries contending for a shared L2 TLB with 1,536 entries (4-way, 384-set). You&#8217;re not bottlenecked on compute. You&#8217;re bottlenecked on virtual memory management.</p><p>The heavy framework hides this. You see &#8220;P99 latency: 800ms&#8221; in your dashboard and you throw more pods at it. The actual diagnosis &#8212; <code>perf stat -e iTLB-load-misses</code> &#8212; would show you 40&#8211;60 million iTLB misses per second per pod. You&#8217;re burning wall-clock time flushing and reloading the instruction TLB, not running transformer math.</p></blockquote><div><hr></div><h2>The Failure Mode: Scheduler Thrashing + iTLB Storms</h2><blockquote><p>When your embedding workload is a standard Linux process:</p><ol><li><p>The OS schedules your inference goroutine/thread on an available core.</p></li><li><p>The model&#8217;s attention layers span hundreds of pages. Each new page the SIMD unit touches that isn&#8217;t in the iTLB = stall waiting for a TLB walker.</p></li><li><p>When the scheduler preempts your thread and migrates it to another core (common at &gt;50% utilization), the other core&#8217;s iTLB is cold &#8212; the entire working set must be re-walked.</p></li><li><p>With 50 concurrent tenants, all polling their own sockets, the scheduler runs at thousands of context switches per second. Every switch = partial iTLB flush on x86 (CR3 reload unless PCID is in play, and under heavy multi-tenant pressure, PCID slots exhaust).</p></li></ol><p>The fix is not &#8220;pin threads to cores&#8221; &#8212; that&#8217;s a band-aid. The fix is to make the <em>model</em> a shared resource loaded once into host memory, referenced by N isolated Wasm linear memory instances that contain only <em>index state and per-request scratch</em>, not the model weights.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: WASI 0.3 + eBPF Ring Buffer</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8wU3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8wU3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png 424w, https://substackcdn.com/image/fetch/$s_!8wU3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png 848w, https://substackcdn.com/image/fetch/$s_!8wU3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png 1272w, https://substackcdn.com/image/fetch/$s_!8wU3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8wU3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png" width="508" height="412.496" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:812,&quot;width&quot;:1000,&quot;resizeWidth&quot;:508,&quot;bytes&quot;:85250,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193661794?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8wU3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png 424w, https://substackcdn.com/image/fetch/$s_!8wU3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png 848w, https://substackcdn.com/image/fetch/$s_!8wU3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png 1272w, https://substackcdn.com/image/fetch/$s_!8wU3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0622f75c-c80b-4dda-b9ac-161e28176190_1000x812.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Layer 1 &#8212; XDP Ingestion (Kernel Space):</strong> An XDP (eXpress Data Path) program runs at the NIC driver hook, before sk_buff allocation. It parses TCP payloads containing newline-delimited tweet JSON, extracts the text field using BPF string helpers, and writes a fixed-width record into a <code>BPF_MAP_TYPE_RINGBUF</code>. This costs ~120ns per packet vs ~1.2&#956;s for the full network stack path &#8212; a 10&#215; reduction in per-tweet ingestion overhead.</p><p>The ring buffer is the zero-copy handoff: the Go consumer calls <code>ring_buffer__poll()</code> with a callback that directly hands a pointer to the mapped kernel buffer region. No <code>copy_to_user</code>. The tweet bytes are read-only by the consumer; the kernel owns the ring.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://clouddc.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands-On DevOps Engineering is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><strong>Layer 2 &#8212; WASI 0.3 Component (User Space):</strong> Each tenant&#8217;s semantic index runs as a Wasm component built against WASI Preview 3. The component exports two interfaces:</p><ul><li><p><code>nexus:index/ingest</code> &#8212; accepts a tweet string, returns a vector ID</p></li><li><p><code>nexus:index/query</code> &#8212; accepts a query string, returns ranked <code>[(id, score)]</code></p></li></ul><p>Internally, the component:</p><ol><li><p>Calls <code>wasi:nn/graph.compute()</code> on the shared host-loaded embedding model (quantized int8 all-MiniLM-L6-v2, 22MB on disk vs 90MB fp32). The host provides this as a pre-initialized <code>Graph</code> resource &#8212; the Wasm component never owns the model weights. All tenants share one model copy in host memory. iTLB footprint: one process worth.</p></li><li><p>Receives a 384-dimensional int8 embedding vector.</p></li><li><p>Inserts the vector into an HNSW graph living in the component&#8217;s Wasm linear memory.</p></li></ol><p><strong>Why Wasm shared-nothing beats processes here:</strong> The component has its own linear memory (heap, HNSW graph, per-request scratch), but it cannot touch any other component&#8217;s memory or the host&#8217;s model weights. Isolation without virtual address space proliferation. The Wasmtime runtime maps all component heaps into the <em>same</em> process, eliminating the CR3-reload-per-switch cost. Your iTLB sees one address space.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!e8aE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!e8aE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png 424w, https://substackcdn.com/image/fetch/$s_!e8aE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png 848w, https://substackcdn.com/image/fetch/$s_!e8aE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png 1272w, https://substackcdn.com/image/fetch/$s_!e8aE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!e8aE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png" width="504" height="428.1984" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1062,&quot;width&quot;:1250,&quot;resizeWidth&quot;:504,&quot;bytes&quot;:135969,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193661794?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!e8aE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png 424w, https://substackcdn.com/image/fetch/$s_!e8aE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png 848w, https://substackcdn.com/image/fetch/$s_!e8aE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png 1272w, https://substackcdn.com/image/fetch/$s_!e8aE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8758eb65-57da-43a1-b721-2be54e2588a9_1250x1062.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>Implementation Deep Dive</h2><h3>GitHub Link :</h3><p><a href="https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson15/nexuscore-semantic">https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson15/nexuscore-semantic</a></p><h3>HNSW in Wasm Linear Memory</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UZHV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UZHV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png 424w, https://substackcdn.com/image/fetch/$s_!UZHV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png 848w, https://substackcdn.com/image/fetch/$s_!UZHV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png 1272w, https://substackcdn.com/image/fetch/$s_!UZHV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UZHV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png" width="494" height="469.1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1187,&quot;width&quot;:1250,&quot;resizeWidth&quot;:494,&quot;bytes&quot;:207214,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193661794?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UZHV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png 424w, https://substackcdn.com/image/fetch/$s_!UZHV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png 848w, https://substackcdn.com/image/fetch/$s_!UZHV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png 1272w, https://substackcdn.com/image/fetch/$s_!UZHV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e18d201-93a8-4053-98c7-0bcf4be92cd6_1250x1187.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The HNSW (Hierarchical Navigable Small World) graph is our ANN index. For 100K 384-dim int8 vectors with M=16 and ef_construction=200:</p><ul><li><p><strong>Layer 0 (base):</strong> 100K nodes &#215; 16 neighbors &#215; 4 bytes per ID = <strong>6.4MB</strong></p></li><li><p><strong>Higher layers:</strong> ~5K nodes total (log distribution) &#215; same width = <strong>~320KB</strong></p></li><li><p><strong>Vector store:</strong> 100K &#215; 384 bytes (int8) = <strong>37.2MB</strong></p></li><li><p><strong>Total heap:</strong> ~44MB per tenant</p></li></ul><p>At 50 tenants that&#8217;s 2.2GB of Wasm linear memory, all within one OS process. No TLB drama. Compare to 50 Python processes with 500MB each = 25GB of virtual address space spread across the page table hierarchy.</p><p>The <code>instant-distance</code> crate compiles cleanly to <code>wasm32-wasip2</code> as of its 0.8 release. We use cosine similarity (inner product on normalized int8 vectors, computed with WASM SIMD via <code>i16x8.mul_saturate</code> sequences).</p><h3>eBPF CO-RE for Tweet Ingestion</h3><p>The XDP program is written in C and compiled with <code>clang -target bpf</code> using BTF-enabled CO-RE (Compile Once, Run Everywhere). It uses <code>bpf_ringbuf_reserve</code> / <code>bpf_ringbuf_submit</code> for lock-free writes to the ring buffer. The critical section is under 50 BPF instructions &#8212; well within the verifier&#8217;s 1M instruction limit and safe for tail call chaining.</p><p>We attach at <code>XDP_FLAGS_SKB_MODE</code> for portability across drivers (generic XDP), promoting to <code>XDP_FLAGS_DRV_MODE</code> when the NIC driver supports native XDP (mlx5, i40e, etc.).</p><h3>Memory-Mapped Model Loading (wasi:blob-store)</h3><p>The embedding model is loaded by the host runtime once at startup via <code>wasi:blobstore</code>. The host deserializes the ONNX model into an <code>ort::Session</code> (ONNX Runtime), then exposes it as a <code>wasi:nn/Graph</code> resource. When a Wasm component calls <code>graph.init-execution-context()</code>, it gets a handle to a shared <code>InferenceSession</code>. The weights stay in host heap memory. The component writes input tensors to a per-context scratch buffer (also host-allocated, but component-scoped) and reads output tensors back.</p><p>This is the critical insight: <strong>the model is a host resource, not a component resource.</strong> The component cannot <code>free()</code> it. It cannot even see it in its linear memory. The Wasm component model enforces this through the capability-based resource system in WASI 0.3.</p><div><hr></div><h3>Working Demo Link :</h3><div id="youtube2-0OoaROahqiw" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;0OoaROahqiw&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/0OoaROahqiw?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><h2>Production Readiness: What to Instrument</h2><p>Metric Tool Threshold Wasm component cold start <code>wasmtime</code> <code>--enable-wasm-metrics</code> &lt; 2ms (AOT compiled) HNSW insert P99 internal histogram &lt; 500&#956;s at ef_construction=200 HNSW query P99 (ef=50) internal histogram &lt; 1ms for 100K index BPF ring buffer drops <code>bpftool map dump</code> 0 (size ring buffer correctly) iTLB-load-misses/op <code>perf stat</code> on wasmtime PID &lt; 0.5% miss rate wasi:nn compute P99 host metrics &lt; 8ms per embedding (int8, CPU) Linear memory RSS per tenant <code>/proc/PID/smaps</code> ~46MB &#177; 5MB</p><p>Run <code>perf stat -e cycles,iTLB-load-misses,dTLB-load-misses -p $(pidof wasmtime_host)</code> during your load test. If iTLB misses exceed 1% of cycles, investigate model-weight sharing &#8212; something is duplicating the model.</p><div><hr></div><h2>Step-by-Step Setup</h2><p><strong>Prerequisites:</strong> Rust 1.80+, <code>cargo-component</code> 0.14+, Go 1.22+, <code>clang</code> with BPF target, <code>bpftool</code>, Linux kernel 6.6+ (for BPF ring buffer v2 APIs), <code>wasmtime</code> CLI 25+.</p><pre><code><code># 1. Bootstrap workspace
bash setup_lesson.sh

# 2. Build WASI component
cd nexuscore-semantic &amp;&amp; cargo component build --release -p semantic-index

# 3. Build eBPF ingester
cd ebpf-ingester &amp;&amp; go generate ./... &amp;&amp; go build -o bin/ingester .

# 4. Run the demo (starts host runtime + eBPF + loads 100K tweet dataset)
./scripts/demo.sh

# 5. Verify correctness
./scripts/verify.sh

# 6. Stress test (10K concurrent queries across 10 simulated tenants)
./scripts/stress.sh

# 7. Observe iTLB behavior
perf stat -e iTLB-load-misses,cycles -p $(cat /tmp/nexuscore.pid) &amp;
./scripts/stress.sh &amp;&amp; fg
</code></code></pre><p>Expected output from <code>verify.sh</code>:</p><pre><code><code>[OK] Wasm component cold start: 1.4ms (AOT)
[OK] 100K tweets indexed in 38.2s (2,618 tweets/sec)
[OK] Semantic query "supply chain disruption" &#8594; top-5 results in 0.6ms P99
[OK] BPF ring buffer drops: 0
[OK] RSS per tenant: 44.8MB
</code></code></pre><div><hr></div><h2>Homework: Production-Level Challenge</h2><p>The current design uses a single HNSW index per tenant in memory. Your challenge:</p><p><strong>Implement HNSW segment compaction over WASI 0.3 streams.</strong></p><p>When a tenant&#8217;s index exceeds 100K entries, split it into two 50K-entry segments (a &#8220;level 0 flush&#8221;). Each segment is serialized to a <code>wasi:filesystem</code> file using the canonical ABI&#8217;s <code>stream&lt;u8&gt;</code> type. Queries must fan-out across segments and merge-sort results by score.</p><p>Constraints:</p><ol><li><p>The flush must happen without pausing ingest. Use a second Wasm component instance for the flush operation (demonstrating concurrent component execution under Wasmtime&#8217;s async WASI support).</p></li><li><p>The serialization format must be byte-compatible between ARM64 and x86-64 (no raw <code>f32</code> dumps &#8212; quantize to int8 before writing).</p></li><li><p>Add a BPF map (<code>BPF_MAP_TYPE_HASH</code>, key=tenant_id, value=segment_count) so the XDP ingester can route incoming tweets to the active write segment without a syscall roundtrip.</p></li></ol><p>When you&#8217;ve done this, you have the core of a distributed vector store. The next step is sharding segments across Wasm components using <code>wasi:sockets</code> &#8212; that&#8217;s Day 16.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://clouddc.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands-On DevOps Engineering is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Day 14 — Text-to-Math: Generating Embeddings with Local Transformers]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-14-text-to-math-generating-embeddings</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-14-text-to-math-generating-embeddings</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Sat, 02 May 2026 08:31:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!H6cR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3>The Abstraction Trap</h3><blockquote><p>A junior engineer reaches for <code>sentence-transformers</code> and spins up a FastAPI server inside a Docker container. Five lines of Python. Works great on the laptop. Then comes Day 1 in production: 800 concurrent tenants, each with their own model process, 400 MB RSS apiece. You&#8217;ve blown 320 GB of memory before the first request completes. The framework hid every decision that mattered: weight loading, thread-pool sizing, GC pressure, and the catastrophic TLB invalidation that happens when 800 separate page tables fight for 512 TLB entries.</p><p>This lesson dismantles that trap. You will implement a MiniLM-style sentence embedding engine as a WASI 0.3 component in Rust, share model weights across all tenant instances via a single read-only <code>mmap</code> region, and use an eBPF CO-RE probe to account every byte of per-tenant memory &#8212; in kernel space, with zero overhead per inference.</p></blockquote><div><hr></div><h3>The Failure Mode: TLB Thrashing at Multi-Tenant Density</h3><blockquote><p>When you run one OS process per tenant, the kernel must maintain a separate page table per process. On x86-64, the TLB (Translation Lookaside Buffer) caches virtual-to-physical address mappings. It has ~1,500 entries on a modern core. With 800 processes, a context switch forces a full TLB flush (<code>CR3</code> reload), destroying every cached mapping.</p><p>The math is brutal. A single 384-dimensional embedding inference touches roughly 350 MB of weight data across 6 transformer layers. With a cold TLB, that&#8217;s ~87,000 page walks at ~100ns each &#8212; <strong>8.7ms of pure TLB miss latency before a single FLOP runs</strong>. At 800 tenants context-switching at 10 kHz, your CPU spends more time handling TLB misses than executing matrix multiplications.</p><p>The fix is not &#8220;use a bigger machine.&#8221; It is architectural: all tenant components share one virtual address range for the model weights, backed by a single <code>MAP_SHARED | MAP_POPULATE</code> huge-page region. The kernel loads those TLB entries once per core, and they stay warm across every component instantiation.</p></blockquote><div><hr></div><h3>The NexusCore Architecture: WASI 0.3 Weight Sharing</h3><p>The key insight: a WASI 0.3 component&#8217;s linear memory is isolated <strong>by design</strong>, but the host can pass a <strong>resource handle</strong> &#8212; a typed, capability-controlled reference &#8212; into any component. We use this to thread a read-only pointer into the weight slab through the WIT interface without violating the shared-nothing guarantee.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!H6cR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!H6cR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png 424w, https://substackcdn.com/image/fetch/$s_!H6cR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png 848w, https://substackcdn.com/image/fetch/$s_!H6cR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png 1272w, https://substackcdn.com/image/fetch/$s_!H6cR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!H6cR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png" width="504" height="453.6" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1125,&quot;width&quot;:1250,&quot;resizeWidth&quot;:504,&quot;bytes&quot;:166353,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193653162?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!H6cR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png 424w, https://substackcdn.com/image/fetch/$s_!H6cR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png 848w, https://substackcdn.com/image/fetch/$s_!H6cR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png 1272w, https://substackcdn.com/image/fetch/$s_!H6cR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42dbca96-6a32-44cc-9ffb-1aa783823b63_1250x1125.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-14-text-to-math-generating-embeddings">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 13: Vector Search — Installing and Tuning Qdrant at Hyperscale]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-13-vector-search-installing-and</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-13-vector-search-installing-and</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Wed, 29 Apr 2026 08:30:24 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!TSMC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer handed a &#8220;vector search sprint&#8221; opens the Qdrant docs, runs <code>docker pull qdrant/qdrant</code>, wraps it in a K8s Deployment with three replicas, and calls it done. The CI pipeline is green. Load tests at 100 RPS look fine.</p><p>Then you hit 50,000 tenants, each making burst queries against their own collection. The scheduler starts thrashing. RSS climbs past the node&#8217;s physical RAM. p99 latency crosses 2 seconds. The on-call engineer stares at Datadog, sees CPU at 40%, and concludes &#8220;we need bigger nodes.&#8221; They are wrong.</p><p>The problem is architectural, not capacity. And it starts with not understanding what Qdrant is actually doing inside the kernel.</p></blockquote><div><hr></div><h2>The Failure Mode: TLB Churn and WAL Contention</h2><blockquote><p>When you deploy one Qdrant instance per tenant (the &#8220;clean isolation&#8221; approach), you are creating one process per tenant. Each process maintains its own HNSW graph in memory. At 50K tenants with a 128-dimensional float32 corpus of 1M vectors per tenant, you are asking the kernel to track 50K independent virtual address spaces, each with multi-gigabyte mmap regions for the HNSW graph.</p><p>The TLB (Translation Lookaside Buffer) on a modern x86-64 CPU holds around 1,536 entries for 4 KiB pages. Each context switch to a different process flushes the TLB (or requires PCID tags, which you&#8217;ve likely not configured). A node handling 50K tenants with short-burst query patterns will see TLB miss rates exceeding 40%, measured by <code>perf stat -e dTLB-load-misses</code>. Every TLB miss is a page-table walk: 4 memory accesses across 4 levels of the page hierarchy. For HNSW traversal, which is pointer-chasing through a graph of ~M/ef_construction average candidates per layer, TLB misses compound directly into search latency.</p><p>The second failure is WAL contention. Qdrant&#8217;s shared WAL uses a ring-buffer model per collection. When hundreds of collections share one Qdrant process under write pressure, WAL segment sealing &#8212; the operation that transforms mutable WAL entries into immutable indexed segments &#8212; competes for the same kernel I/O scheduler queue. <code>iostat -x 1</code> will show <code>await</code> climbing, not because your disk is slow, but because <code>io_depth</code> is saturated with simultaneous fsync calls from tens of collections sealing simultaneously.</p></blockquote><div><hr></div><h2>The NexusCore Architecture</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TSMC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TSMC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png 424w, https://substackcdn.com/image/fetch/$s_!TSMC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png 848w, https://substackcdn.com/image/fetch/$s_!TSMC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png 1272w, https://substackcdn.com/image/fetch/$s_!TSMC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TSMC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png" width="500" height="412.15226939970717" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1126,&quot;width&quot;:1366,&quot;resizeWidth&quot;:500,&quot;bytes&quot;:184181,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193564847?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TSMC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png 424w, https://substackcdn.com/image/fetch/$s_!TSMC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png 848w, https://substackcdn.com/image/fetch/$s_!TSMC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png 1272w, https://substackcdn.com/image/fetch/$s_!TSMC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94dd491f-98b3-4bd9-a77f-3162b793c9bf_1366x1126.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-13-vector-search-installing-and">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 12: Time-Travel Debugging — Reconstructing Historical Feed States]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-12-time-travel-debugging-reconstructing</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-12-time-travel-debugging-reconstructing</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Sun, 26 Apr 2026 08:30:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!f0uR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer tasked with &#8220;replay any feed state at time T&#8221; will reach for event sourcing frameworks &#8212; Apache Kafka + Debezium, or worse, a full EventStoreDB cluster per tenant. The framework <em>works</em>. Until it doesn&#8217;t.</p><p>The hidden failure: every replay request serializes through the broker&#8217;s consumer group protocol. At 10K tenants, a &#8220;time-travel&#8221; query triggers O(N) offset seeks across O(N) partitions. Kafka&#8217;s broker-side offset management wasn&#8217;t designed for concurrent random-access replay &#8212; it was designed for <em>sequential consumption</em>. You&#8217;ve built a time machine that teleports sequentially.</p><p>The deeper trap is what the framework hides: <strong>heap snapshot rehydration</strong>. EventStore&#8217;s &#8220;projection&#8221; model reconstructs state by replaying every event from the beginning of a stream into an in-memory aggregate. That aggregate lives in a JVM heap. Per tenant. Under GC pressure. At hyperscale you&#8217;re not debugging state &#8212; you&#8217;re debugging your garbage collector.</p></blockquote><div><hr></div><h2>The Failure Mode: TLB Thrashing Under Multi-Tenant Replay</h2><blockquote><p>Here&#8217;s what actually kills you at density.</p><p>Each &#8220;standard&#8221; process-per-tenant approach requires its own virtual address space &#8212; its own page table tree. On a Zen 4 core with 64-entry L1 TLB for data and 64-entry L1 iTLB for instructions, running 10K tenants means your TLB is cold <em>by definition</em> on every context switch. Each miss triggers a hardware page table walk: 4 memory accesses (PGD &#8594; PUD &#8594; PMD &#8594; PTE) at ~100 cycles each, assuming L2 cache hits. That&#8217;s 400 cycles <em>per TLB miss</em>, per tenant switch, per replay operation.</p><p>The math: 10K tenants &#215; 50 TLB misses per context switch &#215; 400 cycles = 200M wasted cycles <em>per scheduling epoch</em>. On a 4GHz core that&#8217;s 50ms of pure TLB overhead per second. You&#8217;ve burned 5% of your core doing address translation for the privilege of running &#8220;isolated&#8221; processes.</p><p>Wasm&#8217;s linear memory model solves this structurally. Every tenant&#8217;s Wasm module instance addresses into the <em>same</em> linear memory region managed by the runtime. No per-tenant page tables. No per-tenant TLB entries. The runtime multiplexes N tenants over a single virtual address space, and your TLB stays warm.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: Content-Addressed Replay Engine</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!f0uR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!f0uR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png 424w, https://substackcdn.com/image/fetch/$s_!f0uR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png 848w, https://substackcdn.com/image/fetch/$s_!f0uR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png 1272w, https://substackcdn.com/image/fetch/$s_!f0uR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!f0uR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png" width="508" height="418.5633802816901" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:936,&quot;width&quot;:1136,&quot;resizeWidth&quot;:508,&quot;bytes&quot;:1091570,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193559290?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!f0uR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png 424w, https://substackcdn.com/image/fetch/$s_!f0uR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png 848w, https://substackcdn.com/image/fetch/$s_!f0uR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png 1272w, https://substackcdn.com/image/fetch/$s_!f0uR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd5165d1-70a4-42dd-ad0c-17d338d83201_1136x936.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-12-time-travel-debugging-reconstructing">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 11: CQRS Consistency — Handling Eventual Updates in the UI]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-11-cqrs-consistency-handling</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-11-cqrs-consistency-handling</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Thu, 23 Apr 2026 08:31:10 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!AGFd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer building CQRS in 2024 reaches for Axon Framework, MediatR, or a &#8220;reactive&#8221; BFF layer that auto-subscribes to Kafka topics. The code looks elegant. The demos work at 50 RPS. Then you hit 80,000 tenants doing concurrent writes and the read model starts returning data that is 4&#8211;8 seconds stale. Worse: <em>you don&#8217;t know it&#8217;s happening</em> because the framework swallowed the version metadata.</p><p>The trap is delegation without understanding. Heavy CQRS frameworks abstract three things simultaneously:</p><ol><li><p>The event dispatch mechanism (usually an in-process bus or Kafka consumer)</p></li><li><p>The projection rebuild strategy (usually &#8220;replay all on startup&#8221;)</p></li><li><p>The read-side cache invalidation (usually TTL-based polling)</p></li></ol><p>Each of these abstractions hides a failure mode. When they all fail simultaneously under load, your debugging surface is the framework&#8217;s internals, not your system. The abstraction wasn&#8217;t free &#8212; you just prepaid the cost in operational blindness.</p></blockquote><div><hr></div><h2>The Failure Mode: Scheduler Thrashing and TLB Churn</h2><blockquote><p>Let&#8217;s be precise about what breaks at scale.</p><p>In a na&#239;ve implementation, the read-side query handler is a standard Linux process. After each command write, it re-reads from the projection store (PostgreSQL, Redis, whatever) by forking a new goroutine or spawning a Tokio task. At 100k concurrent tenants each issuing 1 write/second, you have 100k concurrent readers.</p><p>The kernel scheduler must context-switch between these 100k tasks. Each context switch requires saving and restoring approximately 200 bytes of register state. More critically: <strong>each switch invalidates the TLB (Translation Lookaside Buffer) for user-space virtual addresses</strong>. On modern x86-64, a TLB miss costs 50&#8211;150 ns of memory walk latency. At 100k switches/second, that&#8217;s 5&#8211;15 ms of pure TLB miss overhead <em>per second, per core</em>. Multiply by your thread fan-out and you&#8217;re burning 20&#8211;30% of your CPU on virtual-address translation bookkeeping.</p><p>The secondary failure: the projection store connection pool. At 100k readers, each holding a connection for ~2ms, you need 200 simultaneous DB connections at steady state. PostgreSQL&#8217;s shared memory overhead per connection is ~5MB. That&#8217;s 1GB of postgres RAM purely for connection state. Under burst, this becomes the first saturation point.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: eBPF Invalidation + WASI Component Isolation</h2><p>The 2026 pattern flips the model. Instead of readers polling the write side, we push <em>invalidation signals</em> from the kernel using an eBPF ring buffer probe attached to the write path. No polling. No timers. No framework magic.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AGFd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AGFd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png 424w, https://substackcdn.com/image/fetch/$s_!AGFd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png 848w, https://substackcdn.com/image/fetch/$s_!AGFd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png 1272w, https://substackcdn.com/image/fetch/$s_!AGFd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AGFd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png" width="500" height="455.88235294117646" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:775,&quot;width&quot;:850,&quot;resizeWidth&quot;:500,&quot;bytes&quot;:140874,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193554380?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AGFd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png 424w, https://substackcdn.com/image/fetch/$s_!AGFd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png 848w, https://substackcdn.com/image/fetch/$s_!AGFd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png 1272w, https://substackcdn.com/image/fetch/$s_!AGFd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20e5eef8-0039-49fe-b2e7-6064a56c8a67_850x775.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-11-cqrs-consistency-handling">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 10: Query Path — Building Pre-Computed Read Projections]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-10-query-path-building-pre-computed</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-10-query-path-building-pre-computed</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Mon, 20 Apr 2026 08:31:04 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!v-3K!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>Every junior engineer I&#8217;ve watched build a read-heavy multi-tenant API reaches for the same hammer: an ORM, a query builder, maybe a Redis cache slapped in front of a Postgres replica. The framework hides the crime. What you don&#8217;t see:</p><ul><li><p>The ORM emits <code>SELECT *</code> with ten JOINs when you need three columns.</p></li><li><p>The Redis <code>GET</code> is a synchronous round-trip blocking an async task.</p></li><li><p>The Postgres replica has a shared <code>shared_buffers</code> pool that hot tenants evict from cold tenants.</p></li><li><p>When your tenant count hits 50,000, the Redis hot-key distribution means your top 1% of tenants destroy the other 99%.</p></li></ul><p>These are not bugs you can <code>grep</code> for. They are <strong>structural failure modes</strong> that only surface at scale&#8212;specifically, when your QPS crosses the point where per-request computation exceeds the cost of the hardware it runs on.</p><p>The pattern we&#8217;re killing today: <strong>on-demand aggregation</strong>. The replacement: <strong>pre-computed read projections served from kernel-pinned eBPF maps, rebuilt asynchronously by a WASI 0.3 projection engine</strong>.</p></blockquote><div><hr></div><h2>The Failure Mode: TLB Thrashing at Tenant Density</h2><blockquote><p>The naive architecture is a Linux process (or goroutine pool) per tenant that computes projections on demand. Let&#8217;s be precise about why this collapses.</p><p>On a 64-core machine running 10,000 tenant contexts, you have two problems:</p><p><strong>Problem 1: TLB pressure.</strong> Each tenant&#8217;s WASM linear memory lives in a distinct virtual address range. When the scheduler preempts tenant A and runs tenant B, the CPU must flush TLB entries for tenant A&#8217;s pages (or rely on PCIDs if ASID space isn&#8217;t exhausted). On an Intel Sapphire Rapids, a full TLB flush costs ~1,400 cycles. At 100,000 tenant switches/second, that&#8217;s <strong>140M wasted cycles per core per second</strong>&#8212;before you&#8217;ve done a single byte of useful work.</p><p><strong>Problem 2: Scheduler thrashing.</strong> The Linux CFS scheduler&#8217;s <code>vruntime</code> accounting works well at O(log n) for low tenant counts. At 50,000 runnable tasks, the rbtree walk itself becomes measurable. Worse: NUMA effects mean tenant memory may be on the wrong socket, adding 80&#8211;120ns latency per cache miss. At L3-miss rates of 5% on a projection computation touching 4KB of event data, you&#8217;re burning <strong>96ns &#215; 0.05 &#215; (events per projection)</strong> in NUMA penalties alone.</p><p>The fix: <strong>stop computing projections on the read path entirely.</strong> The read path should only <em>read</em>.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: XDP-Pinned Projection Cache</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!v-3K!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!v-3K!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png 424w, https://substackcdn.com/image/fetch/$s_!v-3K!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png 848w, https://substackcdn.com/image/fetch/$s_!v-3K!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png 1272w, https://substackcdn.com/image/fetch/$s_!v-3K!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!v-3K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png" width="502" height="376.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:750,&quot;width&quot;:1000,&quot;resizeWidth&quot;:502,&quot;bytes&quot;:106946,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193437199?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!v-3K!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png 424w, https://substackcdn.com/image/fetch/$s_!v-3K!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png 848w, https://substackcdn.com/image/fetch/$s_!v-3K!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png 1272w, https://substackcdn.com/image/fetch/$s_!v-3K!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0573d43c-bba8-4e46-b198-170b33c3417b_1000x750.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Three invariants that make this work at scale:</p><ol><li><p><strong>The XDP program is the entire read path for cache hits.</strong> It never crosses the kernel/userspace boundary. A cache hit costs ~200ns including DMA and packet transmission&#8212;no context switch, no scheduler, no allocator.</p></li><li><p><strong>Projections are rebuilt in WASI 0.3 components</strong> using async event streams. The component holds no mutable state between events; it is a pure function of accumulated events. This is the shared-nothing property that lets us run 50,000 tenant projection engines in a single wasmtime process without TLB pressure.</p></li><li><p><strong>The eBPF map is the interface contract.</strong> The WASI engine writes Flatbuffer-encoded projections into the pinned map. The XDP program reads them. Neither knows about the other except through the map schema. This is <strong>explicit kernel/userspace data coupling</strong>&#8212;you own the ABI.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TqyA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TqyA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png 424w, https://substackcdn.com/image/fetch/$s_!TqyA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png 848w, https://substackcdn.com/image/fetch/$s_!TqyA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png 1272w, https://substackcdn.com/image/fetch/$s_!TqyA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TqyA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png" width="506" height="429.8976" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1062,&quot;width&quot;:1250,&quot;resizeWidth&quot;:506,&quot;bytes&quot;:164968,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193437199?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TqyA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png 424w, https://substackcdn.com/image/fetch/$s_!TqyA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png 848w, https://substackcdn.com/image/fetch/$s_!TqyA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png 1272w, https://substackcdn.com/image/fetch/$s_!TqyA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F694e5e52-94bb-4dd3-a691-57da99d6c4bb_1250x1062.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div></li></ol><div><hr></div><h2>Implementation Deep Dive</h2><h3>GitHub Link :</h3><p><a href="https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson10/nexuscore-day10">https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson10/nexuscore-day10</a></p><h3>eBPF CO-RE: The XDP Projection Cache</h3><p>The eBPF program uses CO-RE (Compile Once, Run Everywhere) via BTF type information, so it attaches correctly across kernel versions from 5.15 through 6.10+ without recompilation.</p><p>The map definition:</p><pre><code><code>// projection_xdp.bpf.c
struct proj_key {
    __u32 tenant_id;
    __u32 projection_id;
};

struct proj_value {
    __u64 version;
    __u32 data_len;
    __u8  data[MAX_PROJ_SIZE]; // Flatbuffer payload, 4096B max
};

struct {
    __uint(type, BPF_MAP_TYPE_LRU_HASH);
    __uint(max_entries, 1 &lt;&lt; 20);  // 1M entries ~= 4GB resident
    __type(key, struct proj_key);
    __type(value, struct proj_value);
    __uint(pinning, LIBBPF_PIN_BY_NAME); // &#8594; /sys/fs/bpf/nexuscore/proj_cache
} proj_cache SEC(".maps");
</code></code></pre><p>The XDP handler classifies the packet (custom binary framing over UDP), does the map lookup, and either DMA-copies the Flatbuffer directly into the packet&#8217;s data region or calls <code>XDP_PASS</code> on a miss:</p><pre><code><code>SEC("xdp")
int xdp_proj_handler(struct xdp_md *ctx) {
    void *data     = (void *)(long)ctx-&gt;data;
    void *data_end = (void *)(long)ctx-&gt;data_end;

    // Parse our binary framing: [u32 tenant_id][u32 proj_id][...payload...]
    struct nexus_hdr *hdr = data;
    if ((void *)(hdr + 1) &gt; data_end)
        return XDP_PASS;

    struct proj_key key = {
        .tenant_id     = bpf_ntohl(hdr-&gt;tenant_id),
        .projection_id = bpf_ntohl(hdr-&gt;projection_id),
    };

    struct proj_value *val = bpf_map_lookup_elem(&amp;proj_cache, &amp;key);
    if (!val)
        return XDP_PASS; // miss &#8594; userspace handles rebuild

    // Bounds-check then copy projection into response region
    __u32 copy_len = val-&gt;data_len;
    if (copy_len &gt; MAX_PROJ_SIZE)
        return XDP_ABORTED;

    // bpf_xdp_store_bytes: zero-copy if same NIC, copy otherwise
    if (bpf_xdp_store_bytes(ctx, sizeof(struct nexus_hdr),
                            val-&gt;data, copy_len) &lt; 0)
        return XDP_PASS;

    return XDP_TX; // reflect packet back with projection payload
}
</code></code></pre><p>The critical detail: <code>BPF_MAP_TYPE_LRU_HASH</code> uses per-CPU LRU lists internally. There is no global lock. At 100 million lookups/second distributed across 64 cores, you get ~1.5M lookups per core per second&#8212;well within the lock-free per-CPU LRU budget.</p><h3>WASI 0.3 Projection Engine</h3><p>The projection engine is a WASI component compiled to <code>wasm32-wasip2</code>. It uses the component model&#8217;s new async ABI (<code>canon lift/lower</code> with <code>async</code> flavor in WIT) for non-blocking event consumption.</p><p>The WIT world definition:</p><pre><code><code>// wit/world.wit
package nexuscore:projection@0.3.0;

interface projection-engine {
    use wasi:io/poll@0.3.0.{pollable};
    use wasi:keyvalue/store@0.3.0.{bucket};

    record event {
        tenant-id: u32,
        seq: u64,
        payload: list&lt;u8&gt;,
    }

    record projection {
        version: u64,
        data: list&lt;u8&gt;,  // Flatbuffer encoded
    }

    // Async: returns a pollable; caller polls until ready
    async rebuild-projection: func(
        events: list&lt;event&gt;,
        store: borrow&lt;bucket&gt;,
    ) -&gt; result&lt;projection, string&gt;;
}

world nexuscore-projection {
    export projection-engine;
    import wasi:keyvalue/store@0.3.0;
    import wasi:io/poll@0.3.0;
    import wasi:logging/logging@0.1.0;
}
</code></code></pre><p>The Rust implementation uses <code>wit-bindgen</code> 0.36 generated bindings. The key pattern is <strong>shared-nothing isolation</strong>: each tenant&#8217;s projection rebuild gets its own component instance with its own linear memory. The wasmtime host reuses compiled modules (<code>.cwasm</code> AOT cache) but allocates fresh linear memory per instance&#8212;avoiding cross-tenant heap state.</p><pre><code><code>// src/lib.rs (WASI component)
#[async_trait::async_trait]
impl Guest for ProjectionEngine {
    async fn rebuild_projection(
        events: Vec&lt;Event&gt;,
        store: BorrowedBucket&lt;'_&gt;,
    ) -&gt; Result&lt;Projection, String&gt; {
        // Fold events into projection state - pure function, no external calls
        let mut state = ProjectionState::default();
        for evt in &amp;events {
            state.apply(evt).map_err(|e| e.to_string())?;
        }

        // Serialize to Flatbuffer (zero-copy layout)
        let mut builder = flatbuffers::FlatBufferBuilder::with_capacity(4096);
        let data = state.to_flatbuffer(&amp;mut builder);

        // Persist to wasi:keyvalue for durability
        let key = format!("proj:{}:{}", state.tenant_id, state.projection_id);
        store.set(&amp;key, data).await.map_err(|e| e.to_string())?;

        Ok(Projection {
            version: state.version,
            data: data.to_vec(),
        })
    }
}
</code></code></pre><p>The async <code>store.set()</code> call uses <code>wasi:keyvalue</code>&#8216;s async ABI&#8212;it yields a pollable back to the wasmtime async executor without blocking the OS thread. This is the WASI 0.3 improvement over Preview 2: true component-model-level async, not thread-per-connection blocking.</p><h3>Map Pinning: The Kernel/Userspace Contract</h3><p>The loader pins the eBPF map to <code>/sys/fs/bpf/nexuscore/proj_cache</code>. The WASI engine&#8217;s host (the wasmtime embedder, written in Rust) opens this pinned map fd and writes updated projections after every successful rebuild:</p><pre><code><code>// loader/src/main.rs
let map_fd = libbpf_rs::Map::from_pinned_path(
    "/sys/fs/bpf/nexuscore/proj_cache"
)?;

// After WASI projection rebuild completes:
map_fd.update(
    &amp;proj_key_bytes,
    &amp;proj_value_bytes,
    libbpf_rs::MapFlags::ANY,
)?;
</code></code></pre><p>This is the <strong>explicit ABI boundary</strong>. The WASI component never touches kernel state directly&#8212;it returns bytes to the host embedder, which holds the map fd with appropriate CAP_BPF privileges. The component runs with zero kernel privileges; it cannot escalate.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JREQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JREQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png 424w, https://substackcdn.com/image/fetch/$s_!JREQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png 848w, https://substackcdn.com/image/fetch/$s_!JREQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png 1272w, https://substackcdn.com/image/fetch/$s_!JREQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JREQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png" width="500" height="375" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:750,&quot;width&quot;:1000,&quot;resizeWidth&quot;:500,&quot;bytes&quot;:74441,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193437199?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JREQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png 424w, https://substackcdn.com/image/fetch/$s_!JREQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png 848w, https://substackcdn.com/image/fetch/$s_!JREQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png 1272w, https://substackcdn.com/image/fetch/$s_!JREQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa16f2437-8387-432e-8dc1-e01a4d2ccbff_1000x750.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h3>Working Demo Link :</h3><div id="youtube2-nIvSJxpm9iA" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;nIvSJxpm9iA&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/nIvSJxpm9iA?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><h2>Production Readiness: Metrics That Matter</h2><p>Metric Target Why It Matters XDP cache hit rate &gt; 97% Sub-2% miss rate means projection TTL is calibrated Projection rebuild latency (p99) &lt; 2ms Determines your worst-case write-to-read lag eBPF map lookup ns (p50) &lt; 180ns LRU lock contention visible here first WASI instance cold start &lt; 400&#181;s AOT <code>.cwasm</code> cache; &gt; 1ms means JIT fallback Flatbuffer encode per tenant &lt; 80&#181;s CPU cost of projection serialization Ring buffer drop rate 0 If &gt; 0, projection engine is starving; add worker goroutines</p><p>Watch <code>bpftool map show pinned /sys/fs/bpf/nexuscore/proj_cache</code>&#8212;the <code>max_entries</code> vs <code>entries</code> ratio tells you LRU eviction pressure. If you&#8217;re evicting &gt; 5% per minute, your working set doesn&#8217;t fit. Either shard the map or increase <code>max_entries</code> (memory permitting).</p><div><hr></div><h2>Step-by-Step Setup</h2><p><strong>Prerequisites:</strong></p><pre><code><code># Kernel &#8805; 5.15, BTF enabled
uname -r &amp;&amp; ls /sys/kernel/btf/vmlinux

# Toolchain
rustup target add wasm32-wasip2
cargo install wit-component wasm-tools
apt-get install clang-17 libbpf-dev linux-headers-$(uname -r)
</code></code></pre><p><strong>Build and run:</strong></p><pre><code><code>chmod +x setup_lesson.sh &amp;&amp; ./setup_lesson.sh
cd nexuscore-day10
make build          # Compiles eBPF .bpf.o + WASI .wasm + Rust loader
sudo make load      # Pins eBPF map, attaches XDP to lo interface
make demo           # Streams live projection cache hits to terminal
make stress         # 500k req/s load test, 10k tenants
make verify         # Checks hit rate, map health, rebuild latency
make cleanup        # Detaches XDP, unpins maps
</code></code></pre><p><strong>Verification:</strong></p><pre><code><code># Confirm XDP attached
ip link show lo | grep xdp

# Live map stats
sudo bpftool map show pinned /sys/fs/bpf/nexuscore/proj_cache

# Projection hit rate counter
sudo bpftool map lookup pinned /sys/fs/bpf/nexuscore/stats key hex 00 00 00 00
</code></code></pre><div><hr></div><h2>Homework: Production-Level Challenge</h2><p>The current projection engine rebuilds from <strong>all events</strong> on every cache miss. This is correct but expensive for tenants with deep event history (millions of events).</p><p><strong>Your task:</strong> Implement <strong>incremental projection snapshots</strong> with delta-event replay.</p><ol><li><p>After a projection reaches 10,000 events, write a snapshot checkpoint to <code>wasi:blobstore</code> (not <code>wasi:keyvalue</code>&#8212;blobs are cheaper for large payloads).</p></li><li><p>On rebuild, load the latest snapshot and replay only events with <code>seq &gt; snapshot.seq</code>.</p></li><li><p>Modify the eBPF XDP program to embed a <code>snapshot_version</code> field in the projection key so stale snapshots are never served after a version rollback.</p></li><li><p><strong>Prove it works:</strong> Your stress test should show &lt; 5ms p99 rebuild latency even for tenants with 1M historical events.</p></li></ol><p>The constraint: your WASI component must remain <code>async</code>-safe. No blocking reads on the blobstore. Use <code>wasi:io/poll</code> pollables throughout.</p><p>This is the pattern Netflix uses for Titus task-state projections. A tenant with 10M historical task events should rebuild in under 10ms. Anything slower means your snapshot interval is too coarse.</p>]]></content:encoded></item><item><title><![CDATA[Day 9: Command Path — Designing High-Throughput Write Models]]></title><description><![CDATA[The Problem Nobody Talks About Until Production Burns]]></description><link>https://clouddc.substack.com/p/day-9-command-path-designing-high</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-9-command-path-designing-high</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Fri, 17 Apr 2026 08:30:43 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!cQ8n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Problem Nobody Talks About Until Production Burns</h2><blockquote><p>You&#8217;ve read the papers. You know about WAL-based write paths, LSM trees, and &#8220;append-only is fast.&#8221; You&#8217;ve benchmarked a Tokio-based Rust service doing 800K writes/sec on your laptop and called it done.</p><p>Then you deploy to a 200-tenant production cluster and watch p99 latency crater to 40ms on tenant writes while your dashboards show CPU at 12%. The bottleneck isn&#8217;t compute. It&#8217;s the <strong>kernel scheduler and your TLB</strong>.</p><p>This lesson is about the write path at the <em>system</em> level &#8212; the path a write takes from the network card through kernel space into your application&#8217;s memory, and why everything you learned from &#8220;async Rust is fast&#8221; collapses under real multi-tenant density.</p></blockquote><div><hr></div><h2>The Abstraction Trap</h2><blockquote><p>A junior engineer given &#8220;build a high-throughput write service&#8221; reaches for Axum or Actix, slaps on a <code>tokio::spawn</code> per tenant, and ships. This isn&#8217;t wrong for a single-tenant service. It&#8217;s catastrophically wrong for multi-tenant at scale.</p><p>Here&#8217;s what&#8217;s hidden inside that <code>tokio::spawn</code>:</p><ol><li><p><strong>Thread-pool sharing.</strong> Tokio&#8217;s default runtime uses <code>num_cpus</code> worker threads. At 500 concurrent tenants each doing bursty writes, the scheduler&#8217;s work-stealing dequeue operates on a shared structure &#8212; that&#8217;s spinlock contention proportional to burst concurrency.</p></li><li><p><strong>Context-switch TLB churn.</strong> Every time the kernel preempts your thread to run another, if the new thread touches different virtual addresses (different tenant buffers), the TLB entries for the previous tenant are either evicted or you take a shootdown IPI to other cores. On a 32-core machine with 1000 active tenants, TLB miss rates climb from ~0.1% to ~8%. Each L1 TLB miss costs 8&#8211;12 cycles; an L2 miss costs 40&#8211;60. At 100M writes/sec this becomes your entire budget.</p></li><li><p><strong>Wasm runtime hidden state.</strong> If you run per-tenant Wasm modules inside a shared <code>wasmtime::Engine</code> with shared compilation caches, you&#8217;ve coupled tenants at the JIT layer. A recompile triggered by one tenant&#8217;s code flush evicts instruction cache lines used by others.</p></li><li><p><strong>The correct mental model:</strong> each tenant write path is a <em>separate state machine</em> that must share <em>zero runtime state</em> with other tenants, and the kernel must see <em>zero per-tenant system calls</em> during the write hot path.</p></li></ol></blockquote><div><hr></div><h2>The Failure Mode: Scheduler Thrashing and TLB Storms</h2><p>Let&#8217;s be precise. The failure cascade looks like this:</p><pre><code><code>t=0ms   | 500 tenants submit write bursts simultaneously
t=0.1ms | Kernel runqueue depth spikes: O(500) wake events
t=0.2ms | Work-stealing dequeues on 32 cores create false-sharing on
         | cache line containing queue tail pointer (~64 bytes, 32 cores
         | reading/writing = ~15% of cycles on cache coherency traffic)
t=0.4ms | First tenant writes touch page tables not in TLB &#8594;
         | page walker invoked, 4-level PT traversal = ~200 cycles each
t=1.2ms | Accumulated TLB shootdown IPIs begin saturating the
         | inter-processor interrupt bus on NUMA node 0
t=8ms   | p50 write latency has tripled. You have not moved a single
         | byte of actual payload data.
</code></code></pre><p>The fix is not &#8220;use more cores.&#8221; The fix is to <strong>eliminate per-write syscalls</strong> and <strong>isolate tenant state from the kernel scheduler entirely</strong> during the write hot path.</p><div><hr></div><h2>The NexusCore 2026 Architecture: eBPF-Gated WASI Write Actors</h2><p>We implement the <strong>Command Path</strong> as three cooperating layers:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cQ8n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cQ8n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png 424w, https://substackcdn.com/image/fetch/$s_!cQ8n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png 848w, https://substackcdn.com/image/fetch/$s_!cQ8n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png 1272w, https://substackcdn.com/image/fetch/$s_!cQ8n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cQ8n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png" width="506" height="455.260989010989" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1310,&quot;width&quot;:1456,&quot;resizeWidth&quot;:506,&quot;bytes&quot;:1004800,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193322806?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cQ8n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png 424w, https://substackcdn.com/image/fetch/$s_!cQ8n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png 848w, https://substackcdn.com/image/fetch/$s_!cQ8n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png 1272w, https://substackcdn.com/image/fetch/$s_!cQ8n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5662414d-4bd3-4fc1-a785-e146186da1ea_5000x4500.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-9-command-path-designing-high">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 8: Event Replay — Engineering a System-Wide “Undo” Button]]></title><description><![CDATA[The Real Problem Nobody Tells You About]]></description><link>https://clouddc.substack.com/p/day-8-event-replay-engineering-a</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-8-event-replay-engineering-a</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Wed, 15 Apr 2026 08:31:09 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!-P4F!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Real Problem Nobody Tells You About</h2><blockquote><p>When a junior engineer hears &#8220;event replay,&#8221; they reach for Kafka. When a mid-level engineer hears it, they reach for Event Sourcing frameworks built on top of Postgres. Both are wrong for the same reason: <strong>they are solving the data persistence problem, not the causal consistency problem at the kernel boundary.</strong></p><p>At hyperscale &#8212; 100M+ requests per second across 50,000 active tenants &#8212; &#8220;replay&#8221; isn&#8217;t about replaying application logs. It&#8217;s about replaying the <em>exact causal sequence of syscall-observable state mutations</em> that produced a given tenant&#8217;s world-state, and doing so without disturbing adjacent tenants who share the same physical memory bus.</p><p>This is what Day 8 is about. We&#8217;re building NexusCore&#8217;s <strong>Temporal Event Journal (TEJ)</strong>: a zero-copy, kernel-assisted, per-tenant append-only log that enables causal replay of any tenant&#8217;s state to any prior checkpoint, in under 200 microseconds of end-to-end latency.</p></blockquote><div><hr></div><h2>The Abstraction Trap</h2><blockquote><p>A framework engineer will tell you to use Axon Framework, EventStoreDB, or &#8220;just Kafka with compaction.&#8221; Here&#8217;s what those choices cost you at the instruction level:</p><p><strong>EventStoreDB on JVM:</strong></p><ul><li><p>Every event append triggers JVM safepoint polling (~200ns overhead per thread)</p></li><li><p>Garbage collector stop-the-world pauses: 10&#8211;80ms per GC cycle</p></li><li><p>Object header overhead: 16 bytes per Java object, even for a 4-byte event payload</p></li><li><p>At 100M events/sec, GC is running continuously &#8212; you are not in control of your latency SLA</p></li></ul><p><strong>Kafka with replication:</strong></p><ul><li><p>A <code>produce()</code> call with <code>acks=all</code> requires two network round-trips and an <code>fsync</code> per batch</p></li><li><p>The page cache absorbs writes, but <code>fsync</code> drains it &#8212; a 50&#181;s blocking syscall minimum</p></li><li><p>Partitioning by tenant ID introduces hot partitions the moment one tenant goes viral</p></li><li><p>You cannot do sub-millisecond replay because Kafka&#8217;s consumer protocol has ~5ms minimum fetch latency</p></li></ul><p><strong>What both hide from you:</strong> They give you durability theater. You believe your event was &#8220;stored&#8221; the moment <code>produce()</code> returns, but you cannot control whether that byte has crossed the PCI-E bus to the NVMe controller. You&#8217;ve traded control for convenience, and at hyperscale, you pay for that trade in P99 latency cliffs.</p></blockquote><div><hr></div><h2>The Failure Mode: TLB Thrashing and Scheduler Starvation</h2><blockquote><p>The naive implementation &#8212; one thread per tenant event log, each with its own heap-allocated event queue &#8212; fails at scale for two compounding reasons:</p><p><strong>TLB Pressure:</strong> The x86-64 TLB has 1,536 L1 entries (4KB pages) and 16 L2 entries (1GB pages). If each tenant&#8217;s event buffer is independently <code>malloc</code>&#8216;d, the allocator will scatter buffers across the virtual address space. At 50,000 tenants, even accessing 3 tenants&#8217; buffers in sequence will miss the L1 TLB 100% of the time. A TLB miss costs 50&#8211;300 cycles to walk the page table. At 100M events/sec across 50K tenants, you&#8217;re spending more CPU time on page table walks than on actual event processing.</p><p><strong>Scheduler Thrashing (CFS Starvation):</strong> Linux&#8217;s Completely Fair Scheduler uses a red-black tree ordered by virtual runtime. With 50,000 threads all wanting to append events, the scheduler&#8217;s <code>task_struct</code> red-black tree becomes a 50K-node lookup on every context switch. Each switch costs ~2,000&#8211;5,000 cycles for TLB flush + register save. At high concurrency, the scheduler itself becomes a serialization bottleneck &#8212; threads spend more time <em>waiting to run</em> than <em>actually running</em>.</p><p>The solution eliminates both: a single-producer ring buffer per tenant, processed by a <strong>fixed thread pool</strong> (sized to physical core count), using <strong>mmap&#8217;d contiguous memory</strong> for all tenant buffers to minimize TLB pressure.</p></blockquote><div><hr></div><h2>The NexusCore TEJ Architecture</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-P4F!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-P4F!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png 424w, https://substackcdn.com/image/fetch/$s_!-P4F!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png 848w, https://substackcdn.com/image/fetch/$s_!-P4F!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png 1272w, https://substackcdn.com/image/fetch/$s_!-P4F!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-P4F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png" width="500" height="422.7335164835165" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1231,&quot;width&quot;:1456,&quot;resizeWidth&quot;:500,&quot;bytes&quot;:952741,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193155783?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-P4F!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png 424w, https://substackcdn.com/image/fetch/$s_!-P4F!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png 848w, https://substackcdn.com/image/fetch/$s_!-P4F!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png 1272w, https://substackcdn.com/image/fetch/$s_!-P4F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7859de5-8f65-4816-b768-0300487ce28b_4850x4100.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-8-event-replay-engineering-a">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 7: The Append-Only Log — Achieving 100% Data Durability]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-7-the-append-only-log-achieving</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-7-the-append-only-log-achieving</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Mon, 13 Apr 2026 08:31:01 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3S-n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer tasked with &#8220;durable multi-tenant logging&#8221; reaches for Kafka, or Loki, or at best <code>tokio::fs::File</code> with <code>write_all</code>. That instinct is lethal at scale.</p><p>Kafka wraps your writes in a ZooKeeper (or KRaft) consensus round-trip. Loki pushes your log lines through a Prometheus-compatible ingestion pipeline with label indexing. Both are correct solutions for <em>their design envelope</em>. Neither was designed for 100K concurrent tenant writers sharing a single host, each demanding sub-millisecond write acknowledgment and crash-consistent durability. The framework hides the syscall. The syscall is where your latency lives.</p><p>The specific failure: when you use a library that calls <code>fsync(2)</code> per write, you are serializing every tenant through the kernel&#8217;s journal commit queue. On ext4 with <code>data=ordered</code>, a single <code>fsync</code> flushes the entire journal. At 10K tenants each writing 100 msg/sec, you are requesting 1M journal flushes per second. The drive&#8217;s NCQ depth is 32. The math ends there.</p></blockquote><div><hr></div><h2>The Failure Mode: Journal Convoy + TLB Thrash</h2><blockquote><p>Two pathologies destroy naive implementations:</p><ol><li><p><strong>inode mutex convoy.</strong> <code>O_APPEND</code> writes on Linux acquire <code>i_rwsem</code> (inode read-write semaphore) for each write. It is a fair mutex &#8212; FIFO. Thread 1 holds it, threads 2&#8211;99,999 queue behind it. Your p99 latency grows linearly with tenant count. This is not hyperbole; this is the specific call chain: <code>sys_write &#8594; vfs_write &#8594; ext4_file_write_iter &#8594; inode_lock</code>. Profile it with <code>bpftrace -e 'kprobe:inode_lock { @[comm] = count(); }'</code> and watch your writer threads stack up.</p></li><li><p><strong>Scheduler thrash + TLB shootdowns.</strong> One process per tenant means one set of page tables per tenant. Every context switch between tenant-N and tenant-N+1 requires a TLB flush on x86_64 (unless PCID is active and the kernel recycles the ASID &#8212; it won&#8217;t at 100K unique address spaces). You burn ~200&#8211;400 cycles per context switch just on TLB invalidation. At 100K tenants, each scheduled once per millisecond, that is 100K &#215; 400 cycles &#215; 1000 = 40 billion wasted cycles per second. That is your entire CPU budget on a 3 GHz 4-core machine, four times over.</p></li></ol></blockquote><div><hr></div><h2>The NexusCore Architecture: Segment-Log with Group Commit</h2><p>NexusCore Day 7 implements a <strong>shared-nothing Wasm append-only log</strong> with <strong>io_uring group commit</strong> and <strong>eBPF CO-RE durability telemetry</strong>.</p><p>The design pillars:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3S-n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3S-n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png 424w, https://substackcdn.com/image/fetch/$s_!3S-n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png 848w, https://substackcdn.com/image/fetch/$s_!3S-n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png 1272w, https://substackcdn.com/image/fetch/$s_!3S-n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3S-n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png" width="548" height="377.50274725274727" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1003,&quot;width&quot;:1456,&quot;resizeWidth&quot;:548,&quot;bytes&quot;:1037525,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193155639?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3S-n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png 424w, https://substackcdn.com/image/fetch/$s_!3S-n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png 848w, https://substackcdn.com/image/fetch/$s_!3S-n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png 1272w, https://substackcdn.com/image/fetch/$s_!3S-n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d983c22-5641-4625-9575-8dca6375e225_4500x3100.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-7-the-append-only-log-achieving">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 6: Rust-Powered Events — Zero-Copy Redpanda Ingestion at Hyperscale]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-6-rust-powered-events-zero-copy</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-6-rust-powered-events-zero-copy</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Sat, 11 Apr 2026 08:30:30 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3VYM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer handed this problem will reach for <code>rdkafka-rs</code>, wrap it in Tokio, spin one <code>async</code> task per tenant partition, and ship it. It works. It works until you&#8217;re at 4,000 concurrent tenant log streams, and your on-call pager detonates at 3am because the kernel scheduler is burning 38% of your CPU doing nothing but choosing which thread to run next.</p><p>Here is what that engineer missed: <code>rdkafka</code> binds <code>librdkafka</code> &#8212; a C library with its own internal thread pool, its own buffer management, and its own epoll loop. You&#8217;re now running <em>two</em> async runtimes (Tokio + librdkafka&#8217;s internal poller), two heap allocators (jemalloc inside librdkafka, the Rust global allocator), and the OS thread model underneath Tokio&#8217;s work-stealing scheduler. Each abstraction layer has its own backpressure model. None of them are coherent with each other. At scale, they fight.</p><p>The specific failure mode is <strong>TLB thrashing</strong>. Every OS thread has a virtual address space segment in the CPU&#8217;s Translation Lookaside Buffer. When the scheduler context-switches between 8,000 active Tokio worker threads (each pinned to a partition consumer), the TLB is continuously invalidated. A TLB miss costs 40-100 CPU cycles to resolve via a hardware page-table walk. At 100M req/s, those misses accumulate to hundreds of milliseconds of aggregate latency per second cluster-wide. This is not a bottleneck you can profile with <code>flamegraph</code>. It&#8217;s invisible until it kills you.</p></blockquote><div><hr></div><h2>The NexusCore 2026 Pattern</h2><p>We replace the entire model with two components:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3VYM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3VYM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png 424w, https://substackcdn.com/image/fetch/$s_!3VYM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png 848w, https://substackcdn.com/image/fetch/$s_!3VYM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png 1272w, https://substackcdn.com/image/fetch/$s_!3VYM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3VYM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png" width="516" height="464.25824175824175" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1310,&quot;width&quot;:1456,&quot;resizeWidth&quot;:516,&quot;bytes&quot;:1004551,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193134359?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3VYM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png 424w, https://substackcdn.com/image/fetch/$s_!3VYM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png 848w, https://substackcdn.com/image/fetch/$s_!3VYM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png 1272w, https://substackcdn.com/image/fetch/$s_!3VYM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe91a9fec-a0ce-42ed-9d47-836238f31b0d_5000x4500.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://clouddc.substack.com/p/day-6-rust-powered-events-zero-copy">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 5: Benchmarking SurrealDB vs. Traditional Polyglot Stacks]]></title><description><![CDATA[The Abstraction Trap: Why Your ORM Is Lying to You]]></description><link>https://clouddc.substack.com/p/day-5-benchmarking-surrealdb-vs-traditional</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-5-benchmarking-surrealdb-vs-traditional</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Thu, 09 Apr 2026 08:31:06 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!7hFz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap: Why Your ORM Is Lying to You</h2><blockquote><p>A junior engineer handed this problem would reach immediately for <code>wrk</code>, <code>k6</code>, or <code>Artillery</code>. They&#8217;d spin up Docker Compose with Postgres + Redis + Elasticsearch, point the tool at both stacks, and report p99 latencies. <strong>That benchmark is worthless.</strong> It measures your network stack, your serialization layer, your container runtime&#8217;s veth overhead &#8212; everything <em>except</em> the thing you care about: where does the kernel actually spend time serving each query?</p><p>Here&#8217;s what they miss: a traditional polyglot stack for a multi-tenant SaaS typically touches <strong>three separate processes</strong> per logical operation. A document write might hit:</p><p><strong>    PostgreSQL</strong> (relational store, MVCC row versioning, shared buffer pool)</p><p><strong>    Redis</strong> (cache invalidation, ephemeral session state, pub/sub fan-out)</p><p><strong>    Elasticsearch</strong> (async index update via Logstash/Kafka bridge)</p><p>SurrealDB collapses this into a single process with a multi-model engine &#8212; relational, document, graph &#8212; backed by RocksDB. Sounds like a win. But the failure mode is <strong>not obvious</strong> from application-level metrics.</p></blockquote><div><hr></div><h2>The Failure Mode: TLB Pressure and Scheduler Thrashing</h2><blockquote><p>At 100M+ req/s density, the polyglot stack fails from <strong>inter-process context switch cost</strong> and <strong>TLB shootdowns</strong>. Every <code>sendmsg</code> crossing a process boundary flushes the TLB on the recipient core. At hyperscale multi-tenancy, each tenant namespace compounds this: if you&#8217;re running 500 tenant shards across 64 cores, the L2 TLB (typically 1536 entries on Zen 4, 2048 on Golden Cove) is permanently cold for connection-heavy workloads.</p><p>SurrealDB&#8217;s failure mode is subtler: <strong>RocksDB compaction storms</strong>. RocksDB uses LSM trees. At write-heavy density, L0 compaction triggers pause the foreground writer thread. The SurrealQL parser also operates on a per-query heap allocation &#8212; there is no arena-per-connection optimization in current builds. Under concurrent tenant load, this produces <strong>allocator lock contention</strong> in jemalloc&#8217;s thread cache.</p><p>Neither failure mode is visible in application-level p99 latency &#8212; until it is, catastrophically. <strong>The only ground truth is kernel-space measurement.</strong></p></blockquote><div><hr></div><h2>The NexusCore Architecture: eBPF-Native Benchmarking</h2><p>The NexusCore Day 5 pattern uses three components:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7hFz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7hFz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png 424w, https://substackcdn.com/image/fetch/$s_!7hFz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png 848w, https://substackcdn.com/image/fetch/$s_!7hFz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png 1272w, https://substackcdn.com/image/fetch/$s_!7hFz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7hFz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png" width="502" height="564.75" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1638,&quot;width&quot;:1456,&quot;resizeWidth&quot;:502,&quot;bytes&quot;:702785,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193035376?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7hFz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png 424w, https://substackcdn.com/image/fetch/$s_!7hFz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png 848w, https://substackcdn.com/image/fetch/$s_!7hFz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png 1272w, https://substackcdn.com/image/fetch/$s_!7hFz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6c26785-9f2b-4758-8cbc-3e1a56379dc3_4000x4500.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The key insight: <strong>we never trust the database&#8217;s own metrics</strong>. We trust what the kernel records &#8212; syscall entry/exit timestamps using <code>bpf_ktime_get_ns()</code>, aggregated into log2 histograms in per-CPU BPF maps. This gives us:</p><ul><li><p><strong>True I/O latency</strong> (not application-perceived latency, which includes scheduler jitter)</p></li><li><p><strong>Syscall count per query</strong> (reveals hidden chattiness in polyglot stacks)</p></li><li><p><strong>Context switch rate per tenant</strong> (exposes scheduler thrashing)</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fkYK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fkYK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png 424w, https://substackcdn.com/image/fetch/$s_!fkYK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png 848w, https://substackcdn.com/image/fetch/$s_!fkYK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png 1272w, https://substackcdn.com/image/fetch/$s_!fkYK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fkYK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png" width="500" height="472.1840659340659" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1375,&quot;width&quot;:1456,&quot;resizeWidth&quot;:500,&quot;bytes&quot;:954862,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193035376?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fkYK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png 424w, https://substackcdn.com/image/fetch/$s_!fkYK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png 848w, https://substackcdn.com/image/fetch/$s_!fkYK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png 1272w, https://substackcdn.com/image/fetch/$s_!fkYK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c5e740f-74ee-41b7-a82b-c04746a8e9dc_4500x4250.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div></li></ul><div><hr></div><h2>Implementation Deep Dive</h2><h3>GitHub Link :</h3><p><a href="https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson5/nexuscore-day5">https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson5/nexuscore-day5</a></p><h3>eBPF Probe: Histogram Aggregation Without Heap</h3><pre><code><code>// Slot = log2(latency_ns), capped at 64 buckets
// PERCPU_ARRAY: each CPU writes its own slot, no atomic contention
struct {
    __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
    __uint(max_entries, 64);
    __type(key, u32);
    __type(value, u64);
} latency_hist SEC(".maps");
</code></code></pre><p><code>BPF_MAP_TYPE_PERCPU_ARRAY</code> is the critical choice here. A naive <code>BPF_MAP_TYPE_HASH</code> requires a lock on every update &#8212; at 100M events/s, that lock becomes the bottleneck. PERCPU_ARRAY gives each CPU its own array slot. The userspace aggregator sums them at read time &#8212; a <code>O(ncpu * nbuckets)</code> operation done once per reporting interval, not once per event.</p><h3>WASI 0.3 Orchestrator Component</h3><p>WASI Preview 3 introduces <strong>async-native components</strong> with <code>wasi:io/poll</code>. The orchestrator is compiled to <code>wasm32-wasip2</code> and runs inside Wasmtime 25+ with the component model enabled:</p><pre><code><code>// wit/world.wit
package nexuscore:benchmark@0.1.0;

world orchestrator {
    import wasi:io/poll@0.2.0;
    import wasi:clocks/monotonic-clock@0.2.0;
    export run: func(scenario: scenario-config) -&gt; bench-result;
}
</code></code></pre><p>The WASI component issues benchmark scenarios as pure data &#8212; it has <strong>no network access itself</strong>. It&#8217;s a sandboxed computation engine. The host runtime (our Rust binary) interprets the scenario and issues actual syscalls. This is the shared-nothing model: the WASI component cannot accidentally bypass the measurement layer.</p><h3>io_uring Load Generator: Zero-Copy Fixed Buffers</h3><pre><code><code>// Register fixed buffers once &#8212; kernel maps them into its address space
// Subsequent SQEs reference by buffer index, not pointer
// Eliminates one copy per send on the hot path
uring.register_buffers(&amp;[IoSlice::new(&amp;send_buf)])?;
</code></code></pre><p>Standard <code>sendmsg</code> requires a copy from userspace buffer to kernel socket buffer. <code>io_uring</code> with fixed buffers (<code>IORING_OP_SEND_ZC</code> on 6.0+) eliminates this copy. At 100k connections, this saves <code>~64 bytes &#215; 100k = 6.4 MB</code> of per-event copy overhead per second &#8212; enough to meaningfully impact L3 cache residency.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XSz9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XSz9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png 424w, https://substackcdn.com/image/fetch/$s_!XSz9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png 848w, https://substackcdn.com/image/fetch/$s_!XSz9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png 1272w, https://substackcdn.com/image/fetch/$s_!XSz9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XSz9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png" width="508" height="508" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1456,&quot;width&quot;:1456,&quot;resizeWidth&quot;:508,&quot;bytes&quot;:1113216,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/193035376?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XSz9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png 424w, https://substackcdn.com/image/fetch/$s_!XSz9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png 848w, https://substackcdn.com/image/fetch/$s_!XSz9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png 1272w, https://substackcdn.com/image/fetch/$s_!XSz9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd50d9ab1-9a27-4b98-9d61-23c3c2db4de9_5000x5000.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h3>Working Demo Link :</h3><div id="youtube2-jPbaTxiN52U" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;jPbaTxiN52U&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/jPbaTxiN52U?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><h2>Production Readiness: What to Watch</h2><p>Metric Healthy Range Alarm Threshold Collection Method <code>vfs_read</code> p99 latency (SurrealDB) &lt; 80&#181;s &gt; 500&#181;s eBPF histogram <code>tcp_sendmsg</code> p99 (polyglot) &lt; 120&#181;s &gt; 800&#181;s eBPF kprobe Context switches / sec / tenant &lt; 2000 &gt; 15000 <code>perf stat</code> RocksDB compaction stall (SurrealDB) &lt; 5ms/min &gt; 50ms/min <code>/metrics</code> endpoint TLB miss rate (polyglot) &lt; 0.5% &gt; 5% <code>perf stat -e dTLB-load-misses</code> WASI cold start &lt; 800&#181;s &gt; 3ms Wasmtime telemetry BPF ring buffer drop rate 0 &gt; 0 <code>/sys/kernel/debug/tracing/</code></p><p><strong>Cold start</strong> matters in multi-tenant density because tenants are evicted from memory under pressure. A 3ms cold start at 500 tenants/s throughput means 1.5s of dead capacity &#8212; unacceptable.</p><div><hr></div><h2>Step-by-Step Setup</h2><h3>Prerequisites</h3><pre><code><code># Kernel &gt;= 6.1 (CO-RE BTF required)
uname -r

# Rust toolchain with WASI target
rustup target add wasm32-wasip2
cargo install wasmtime-cli --version "^25"

# bpftool + clang 16+ for CO-RE compilation
sudo apt install -y clang-16 libbpf-dev linux-headers-$(uname -r) bpftool

# Go 1.22+ for userspace BPF loader
go version
</code></code></pre><h3>Run the Full Benchmark</h3><pre><code><code># Generate the workspace
chmod +x setup_lesson.sh &amp;&amp; ./setup_lesson.sh

# Start both database stacks
./scripts/start.sh

# Run the WASI orchestrator under Wasmtime
./scripts/demo.sh

# Apply load: 10k req/s, 500 concurrent tenants, 60 seconds
./scripts/load_test.sh --rps 10000 --tenants 500 --duration 60s

# Verify eBPF histograms are collecting
./scripts/verify.sh

# Render the live terminal dashboard
./scripts/dashboard.sh

# Teardown
./scripts/cleanup.sh
</code></code></pre><h3>Verification Commands</h3><pre><code><code># Confirm BPF programs are loaded and attached
sudo bpftool prog list | grep nexuscore

# Dump raw histogram for SurrealDB vfs_read
sudo bpftool map dump name latency_hist_surreal

# Check ring buffer event rate (should not drop)
cat /sys/kernel/debug/tracing/trace_pipe | grep nexuscore | head -20

# Verify WASI component loaded correctly
wasmtime run --wasi preview2 target/wasm32-wasip2/release/orchestrator.wasm -- --dry-run
</code></code></pre><div><hr></div><h2>Homework: Production-Level Challenge</h2><p><strong>Challenge: Implement per-tenant eBPF isolation using cgroup-aware BPF maps.</strong></p><p>Current implementation aggregates all tenant latencies into a single histogram. Your task:</p><ol><li><p><strong>Extend the eBPF probe</strong> to read the cgroup ID from <code>task_struct</code> using CO-RE (<code>BPF_CORE_READ</code>). Use this as the outer key of a <code>BPF_MAP_TYPE_HASH_OF_MAPS</code> &#8212; an inner map per tenant cgroup.</p></li><li><p><strong>Modify the WASI orchestrator</strong> to emit tenant-tagged scenarios, and extend the WIT interface with a <code>tenant-id</code> field in <code>bench-result</code>.</p></li><li><p><strong>Prove isolation</strong>: run two tenants simultaneously &#8212; one doing bulk writes (compaction pressure), one doing point reads. Show that the compaction storm&#8217;s latency spike is <strong>visible in the writer&#8217;s histogram but not the reader&#8217;s</strong>, and that your eBPF probe correctly attributes it.</p></li><li><p><strong>Bonus</strong>: implement a <code>bpf_spin_lock</code>-free mechanism using <code>BPF_MAP_TYPE_RINGBUF</code> with per-CPU reservation to stream per-tenant events to userspace without ever dropping an event under 50k events/s.</p></li></ol><p>This challenge directly mirrors the isolation work done on Google&#8217;s Borg network accounting layer &#8212; where per-container eBPF maps replaced <code>/proc/net</code> polling and reduced monitoring overhead from 3% CPU to 0.1%.</p><div><hr></div><p><em>Next: Day 6 &#8212; WASI Component Composition: Building a Multi-Tenant Query Router with Zero Shared State</em></p>]]></content:encoded></item><item><title><![CDATA[Day 4 — Live Mode: Implementing Real-Time Schema-less Updates]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-4-live-mode-implementing-real</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-4-live-mode-implementing-real</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Tue, 07 Apr 2026 08:31:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!4koI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer approaching real-time schema-less updates reaches for Avro, Protobuf with <code>Any</code>, or a JSON schema registry backed by Redis. The pattern is familiar: serialize the schema descriptor alongside the payload, deserialize at the consumer, validate, process. At 10K RPS, this is invisible. At 10M RPS across 50K tenants, it becomes a catastrophe &#8212; not because the <em>logic</em> is wrong, but because the <em>physics</em> is.</p><p>Here is what the framework hides from you: every schema deserialization is a heap allocation. Every heap allocation under multi-tenant density is a potential TLB miss. At 50K active tenants, each with their own schema version in flight, your L3 cache line eviction rate exceeds 40% under sustained load. The CPU spends more cycles walking page tables than executing your business logic. Your p99 latency doesn&#8217;t &#8220;creep up&#8221; &#8212; it falls off a cliff.</p><p>The Kafka-Connect style magic makes this worse. It wraps each schema lookup in a gRPC call to a schema registry sidecar, adding 3&#8211;5 syscalls per message: <code>socket()</code>, <code>connect()</code>, <code>send()</code>, <code>recv()</code>, <code>close()</code> &#8212; or their keep-alive equivalents via epoll. At hyperscale, the scheduler thrashing from thousands of concurrent epoll waiters causes involuntary context switches that burn 5&#8211;15&#181;s of CPU time <em>per switch</em>. You cannot batch your way out of this.</p></blockquote><div><hr></div><h2>The Failure Mode: TLB Thrashing Under Schema Diversity</h2><blockquote><p>The TLB (Translation Lookaside Buffer) holds virtual-to-physical page mappings. On a modern x86-64 chip, you have ~1,500 L1 TLB entries. With 50K tenants each holding even a 4KB schema descriptor in heap memory, you are referencing memory scattered across thousands of pages. Every schema lookup that misses TLB costs 100&#8211;300 CPU cycles for a page table walk. At 100M RPS, a 5% TLB miss rate on schema lookups alone translates to <strong>150M wasted cycles per second per core</strong> &#8212; that is dead throughput you will never recover.</p><p>The root cause: heap-allocated schema objects have no spatial locality. <code>malloc</code> has no awareness of your access patterns. It places schema objects wherever it finds free memory, and under high churn (tenants updating schemas), fragmentation ensures sequential schema lookups jump across gigabytes of virtual address space.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: Kernel-Pinned Schema Descriptors + WASI Shared-Nothing Components</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4koI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4koI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png 424w, https://substackcdn.com/image/fetch/$s_!4koI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png 848w, https://substackcdn.com/image/fetch/$s_!4koI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png 1272w, https://substackcdn.com/image/fetch/$s_!4koI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4koI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png" width="538" height="376.5260989010989" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1019,&quot;width&quot;:1456,&quot;resizeWidth&quot;:538,&quot;bytes&quot;:891205,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/192928289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4koI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png 424w, https://substackcdn.com/image/fetch/$s_!4koI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png 848w, https://substackcdn.com/image/fetch/$s_!4koI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png 1272w, https://substackcdn.com/image/fetch/$s_!4koI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff509ccd5-2652-4b32-a908-f09437363eb4_5000x3500.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The 2026 NexusCore pattern eliminates the user-space schema lookup entirely. We push the schema registry into the <strong>kernel via eBPF</strong>, pin it in a BPF LRU hash map, and have the XDP layer pre-classify and tag every incoming packet <em>before</em> it reaches user-space. The WASI component never performs a schema lookup &#8212; it receives a pre-typed memory view.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!waG7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!waG7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png 424w, https://substackcdn.com/image/fetch/$s_!waG7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png 848w, https://substackcdn.com/image/fetch/$s_!waG7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png 1272w, https://substackcdn.com/image/fetch/$s_!waG7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!waG7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png" width="526" height="447.2445054945055" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1238,&quot;width&quot;:1456,&quot;resizeWidth&quot;:526,&quot;bytes&quot;:927549,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/192928289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!waG7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png 424w, https://substackcdn.com/image/fetch/$s_!waG7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png 848w, https://substackcdn.com/image/fetch/$s_!waG7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png 1272w, https://substackcdn.com/image/fetch/$s_!waG7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dc17873-718e-4272-b0f4-a6d08fa3513a_5000x4250.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><pre><code><code>[ NIC ] &#8594; [ XDP Hook ] &#8594; [ BPF LRU Map: tenant_id &#8594; SchemaDescriptor ]
              &#8595;
        [ Tag packet with schema_version + field_offsets ]
              &#8595;
        [ perf ring buffer ] &#8594; [ WASI Component Instance (per tenant) ]
              &#8595;
        [ wasi:io/streams ] &#8594; [ Zero-copy linear memory write ]
</code></code></pre><p>Three properties make this work at scale:</p><p><strong>1. BPF LRU Hash maps have O(1) kernel-space lookup with no syscall.</strong> The XDP program runs at IRQ context &#8212; it never enters the scheduler. Schema lookup is a single <code>bpf_map_lookup_elem</code> call against a map whose hot entries fit in L2 cache.</p><p><strong>2. WASI shared-nothing isolation is free at this layer.</strong> Each tenant component has its own 64KB linear memory. The eBPF layer writes the pre-classified payload directly into an <code>mmap</code>-backed ring buffer segment that the component reads via <code>wasi:io/streams</code>. No cross-tenant memory aliasing, no mutex contention, no GC pressure.</p><p><strong>3. Live schema updates are atomic map swaps.</strong> BPF <code>BPF_MAP_TYPE_LRU_HASH</code> updates are atomic per-entry. The control plane (written in Go) calls <code>bpf_map_update_elem()</code> with <code>BPF_ANY</code> &#8212; the kernel&#8217;s RCU mechanism ensures in-flight lookups see either the old or new descriptor, never a torn write. We drain in-flight requests via a sequence counter before re-instantiating the component.</p><div><hr></div><h2>Implementation Deep Dive</h2><h3>GitHub Link :</h3><p><a href="https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson4/nexuscore-day4">https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson4/nexuscore-day4</a></p><h3>eBPF Schema Map (C, CO-RE)</h3><pre><code><code>// SPDX-License-Identifier: GPL-2.0
#include &lt;linux/bpf.h&gt;
#include &lt;bpf/bpf_helpers.h&gt;
#include "nexuscore_schema.h"  // generated struct definitions

struct schema_descriptor {
    __u64 version;
    __u16 field_count;
    __u16 field_offsets[64];  // byte offsets within payload
    __u8  field_types[64];    // 0=u64, 1=f64, 2=bytes, 3=str
} __attribute__((packed));

struct {
    __uint(type, BPF_MAP_TYPE_LRU_HASH);
    __uint(max_entries, 65536);   // 64K tenants
    __type(key, __u32);           // tenant_id
    __type(value, struct schema_descriptor);
    __uint(pinning, LIBBPF_PIN_BY_NAME);  // pinned: /sys/fs/bpf/nexuscore/schemas
} schema_map SEC(".maps");

// XDP program reads tenant_id from first 4 bytes of UDP payload,
// looks up schema, tags packet metadata, passes to AF_XDP socket
SEC("xdp")
int nexuscore_classify(struct xdp_md *ctx) {
    void *data = (void *)(long)ctx-&gt;data;
    void *data_end = (void *)(long)ctx-&gt;data_end;

    // Bounds check: compiler verifier requires this
    struct nexuscore_hdr *hdr = data + sizeof(struct ethhdr)
                                     + sizeof(struct iphdr)
                                     + sizeof(struct udphdr);
    if ((void *)(hdr + 1) &gt; data_end)
        return XDP_DROP;

    __u32 tenant_id = hdr-&gt;tenant_id;  // network byte order, big-endian
    struct schema_descriptor *sd = bpf_map_lookup_elem(&amp;schema_map, &amp;tenant_id);
    if (!sd)
        return XDP_PASS;  // unknown tenant: fallback to slow path

    // Write schema version into XDP metadata for AF_XDP consumer
    // Uses bpf_xdp_adjust_meta to prepend 8 bytes of metadata
    if (bpf_xdp_adjust_meta(ctx, -8) != 0)
        return XDP_PASS;

    struct nexuscore_meta *meta = (void *)(long)ctx-&gt;data_meta;
    if ((void *)(meta + 1) &gt; (void *)(long)ctx-&gt;data)
        return XDP_PASS;

    meta-&gt;schema_version = sd-&gt;version;
    meta-&gt;tenant_id      = tenant_id;

    return XDP_PASS;
}
char _license[] SEC("license") = "GPL";
</code></code></pre><p>The critical insight: <code>bpf_xdp_adjust_meta</code> prepends metadata to the packet <em>without copying</em>. The AF_XDP consumer in user-space reads <code>data_meta</code> directly from the UMEM frame. Zero extra allocations.</p><h3>WASI 0.3 Component (Rust)</h3><pre><code><code>// wit-bindgen 0.28, wasi:io/streams@0.3.0
use wasi::io::streams::{InputStream, StreamError};
use wasi::io::poll::poll;

// WIT-generated schema descriptor mirrors the eBPF struct
#[repr(C, packed)]
struct SchemaDescriptor {
    version: u64,
    field_count: u16,
    field_offsets: [u16; 64],
    field_types: [u8; 64],
}

struct TenantComponent {
    schema: SchemaDescriptor,
    sequence: u64,
}

impl TenantComponent {
    // Called by WASI host when a new schema version is pushed
    // This is a *component import*, not an RPC call &#8212; no syscall overhead
    fn apply_schema_update(&amp;mut self, raw: &amp;[u8]) -&gt; Result&lt;(), SchemaError&gt; {
        if raw.len() &lt; core::mem::size_of::&lt;SchemaDescriptor&gt;() {
            return Err(SchemaError::InvalidDescriptor);
        }
        // Safety: we verified length, struct is #[repr(C, packed)]
        let new_schema = unsafe {
            core::ptr::read_unaligned(raw.as_ptr() as *const SchemaDescriptor)
        };
        if new_schema.version &lt;= self.schema.version {
            return Err(SchemaError::StaleUpdate);
        }
        // Drain: spin until sequence counter aligns
        // In production this is a futex wait, not a spin
        self.schema = new_schema;
        self.sequence = self.sequence.wrapping_add(1);
        Ok(())
    }

    fn process_frame(&amp;self, stream: &amp;InputStream) -&gt; Result&lt;Vec&lt;FieldValue&gt;, StreamError&gt; {
        // Non-blocking read via wasi:io/streams
        // Returns Ready(bytes) or Closed &#8212; no blocking poll
        let bytes = stream.read(65536)?;
        let mut fields = Vec::with_capacity(self.schema.field_count as usize);

        for i in 0..self.schema.field_count as usize {
            let offset = self.schema.field_offsets[i] as usize;
            let field_type = self.schema.field_types[i];
            let value = match field_type {
                0 =&gt; FieldValue::U64(u64::from_be_bytes(
                    bytes[offset..offset+8].try_into().unwrap()
                )),
                1 =&gt; FieldValue::F64(f64::from_be_bytes(
                    bytes[offset..offset+8].try_into().unwrap()
                )),
                2 =&gt; FieldValue::Bytes(bytes[offset..].to_vec()),
                _ =&gt; FieldValue::Unknown,
            };
            fields.push(value);
        }
        Ok(fields)
    }
}
</code></code></pre><p>No <code>serde</code>, no <code>derive(Deserialize)</code>, no reflection. The schema descriptor <em>is</em> the deserialization logic &#8212; a 128-byte struct that encodes field positions and types. Parsing a 10-field record takes exactly 10 array lookups and 10 <code>from_be_bytes</code> calls. The compiler inlines all of it.</p><h3>Control Plane: Atomic Schema Push (Go + libbpf-go)</h3><pre><code><code>// control_plane/schema_pusher.go
package main

import (
    "github.com/cilium/ebpf"
    "unsafe"
)

type SchemaDescriptor struct {
    Version      uint64
    FieldCount   uint16
    _            [6]byte // padding
    FieldOffsets [64]uint16
    FieldTypes   [64]uint8
}

func pushSchema(m *ebpf.Map, tenantID uint32, sd SchemaDescriptor) error {
    // BPF_ANY: create or update, never fails on existing key
    // Kernel RCU ensures atomic visibility to XDP readers
    return m.Put(tenantID, unsafe.Pointer(&amp;sd))
}
</code></code></pre><p>The Go control plane opens the pinned map at <code>/sys/fs/bpf/nexuscore/schemas</code> and pushes updates. The XDP program running in kernel-space sees the new descriptor on the <em>very next packet</em> for that tenant &#8212; no restart, no drain signal, no rolling deploy. </p><div><hr></div><h3>Working Demo Link :</h3><div id="youtube2-0D-_GiH21OM" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;0D-_GiH21OM&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/0D-_GiH21OM?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!M2Cw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!M2Cw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png 424w, https://substackcdn.com/image/fetch/$s_!M2Cw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png 848w, https://substackcdn.com/image/fetch/$s_!M2Cw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!M2Cw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!M2Cw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png" width="524" height="419.27197802197804" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1165,&quot;width&quot;:1456,&quot;resizeWidth&quot;:524,&quot;bytes&quot;:940648,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/192928289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!M2Cw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png 424w, https://substackcdn.com/image/fetch/$s_!M2Cw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png 848w, https://substackcdn.com/image/fetch/$s_!M2Cw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!M2Cw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe18dff98-e2e9-4c1c-83ec-4184009dcc05_5000x4000.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Production Readiness: What to Measure</h3><p>Metric Tool Threshold XDP schema lookup latency <code>bpftool prog profile</code> &lt; 200ns p99 WASI component cold start <code>wasmtime --invoke</code> + <code>perf stat</code> &lt; 800&#181;s Schema update propagation lag Custom eBPF ring buffer timestamp &lt; 1 packet cycle (&lt; 100&#181;s) TLB miss rate <code>perf stat -e dTLB-load-misses</code> &lt; 0.5% AF_XDP UMEM frame starvation <code>/sys/class/net/&lt;iface&gt;/statistics</code> 0 rx_dropped Wasm linear memory pressure Custom WASI host metric &lt; 80% of 64KB page budget</p><p>Run <code>perf stat -e dTLB-load-misses,dTLB-loads ./load_test</code> before and after enabling kernel-pinned schemas. The miss rate should drop by 60&#8211;80% because all schema data now lives in BPF map memory, which the kernel keeps cache-resident for hot entries.</p><div><hr></div><h2>Setup: Tools Required</h2><pre><code><code># Kernel headers + libbpf (5.15+ for BPF_MAP_TYPE_LRU_HASH with pinning)
apt install linux-headers-$(uname -r) libbpf-dev clang llvm

# Rust toolchain with WASI target
rustup target add wasm32-wasip2   # WASI 0.3 / Preview 2+
cargo install wit-bindgen-cli@0.28 wasm-tools

# Wasmtime 24+ (WASI 0.3 support)
curl -sSf https://wasmtime.dev/install.sh | bash

# Go 1.22+ for control plane
go install github.com/cilium/ebpf/cmd/bpf2go@latest

# Verify eBPF program loading
bpftool prog list
bpftool map list
</code></code></pre><p>Verify your BPF map is pinned after loading:</p><pre><code><code>ls -la /sys/fs/bpf/nexuscore/
# Expected: schemas (LRU_HASH, 65536 entries)
bpftool map dump pinned /sys/fs/bpf/nexuscore/schemas
</code></code></pre><p>Verify XDP program is attached:</p><pre><code><code>ip link show dev lo | grep xdp
# Expected: xdp/id:&lt;N&gt; (native mode, not generic)
</code></code></pre><div><hr></div><h2>Homework: Production-Level Challenge</h2><p>The current implementation applies schema updates on the <em>next packet</em>. This is fine for additive changes (new fields), but <strong>destructive schema changes</strong> (removed or retyped fields) can corrupt in-flight frames that were classified under the old schema but processed under the new one.</p><p><strong>Your challenge:</strong> Implement a two-phase schema commit protocol:</p><ol><li><p>Add a <code>pending_version</code> field to the BPF map value alongside <code>active_version</code>.</p></li><li><p>The XDP program tags packets with the version active <em>at classification time</em>.</p></li><li><p>The WASI component buffers frames tagged with <code>pending_version</code> until it receives a <code>commit</code> signal from the control plane.</p></li><li><p>On commit, the component atomically swaps <code>active_version = pending_version</code> and flushes the buffer.</p></li></ol><p>Measure the maximum buffering latency under 1M RPS load. The target: &lt; 5ms p99 commit latency with zero dropped frames. Use <code>bpftool map update</code> and a custom BPF ring buffer to trace the version transition events.</p>]]></content:encoded></item><item><title><![CDATA[Day 3: Document-Graph Hybrid Queries — Fetching Posts via Relationships]]></title><description><![CDATA[The Abstraction Trap]]></description><link>https://clouddc.substack.com/p/day-3-document-graph-hybrid-queries</link><guid isPermaLink="false">https://clouddc.substack.com/p/day-3-document-graph-hybrid-queries</guid><dc:creator><![CDATA[devops]]></dc:creator><pubDate>Sun, 05 Apr 2026 08:30:52 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!pnCP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The Abstraction Trap</h2><blockquote><p>A junior engineer reaches for Neo4j, spins up a Node.js API wrapped in Docker, deploys a K8s Deployment with three replicas, and calls it done. The graph query works in staging. At 50,000 concurrent tenants and 100M requests/second it implodes.</p><p>Why? Because Neo4j&#8217;s Bolt driver maintains a per-connection TCP socket. Each tenant query requires a round-trip through the Java heap allocator, a Netty event loop context switch, and a Cypher plan cache lookup. At 50K tenants that&#8217;s 50K file descriptors, 50K kernel socket buffers, and a thundering herd of context switches every time a GC pause stalls the JVM. The framework hides all of this from you &#8212; until it doesn&#8217;t.</p><p>The real failure is epistemic. You outsourced your understanding of <em>how the data moves</em> to a framework that assumed you&#8217;d have tens of tenants, not tens of thousands.</p></blockquote><div><hr></div><h2>The Failure Mode: TLB Pressure + Scheduler Thrashing</h2><blockquote><p>When you store a graph as <code>HashMap&lt;NodeId, Vec&lt;EdgeId&gt;&gt;</code> and scatter adjacency lists across the heap, every edge hop is a pointer dereference into a random address. At 50K tenants with separate heaps, you consume the L3 TLB (Translation Lookaside Buffer) in milliseconds. On a Zen 4 core, the L1 DTLB has 64 entries. Miss rate climbs to 30&#8211;40%, and each TLB miss costs 50&#8211;100 cycles for a page table walk.</p><p>Combine that with Linux&#8217;s CFS scheduler: one OS thread per tenant request means 50K runnable threads. The scheduler&#8217;s <code>rb_tree</code> pick_next_task call alone burns ~3&#181;s per context switch. At 100M req/s, you&#8217;re spending more time on scheduling overhead than on actual graph traversal.</p><p>The solution is: <strong>eliminate per-tenant OS threads</strong> and <strong>eliminate heap-scattered pointer chasing</strong> simultaneously.</p></blockquote><div><hr></div><h2>The NexusCore Architecture: CSR in Wasm Linear Memory + eBPF XDP Routing</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pnCP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pnCP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png 424w, https://substackcdn.com/image/fetch/$s_!pnCP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png 848w, https://substackcdn.com/image/fetch/$s_!pnCP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!pnCP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pnCP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png" width="526" height="420.87225274725273" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1165,&quot;width&quot;:1456,&quot;resizeWidth&quot;:526,&quot;bytes&quot;:906910,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/192925230?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pnCP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png 424w, https://substackcdn.com/image/fetch/$s_!pnCP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png 848w, https://substackcdn.com/image/fetch/$s_!pnCP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png 1272w, https://substackcdn.com/image/fetch/$s_!pnCP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb811b8d4-ab6e-4574-9b3b-8fe37faab100_5000x4000.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>NexusCore Day 3 implements <strong>Compressed Sparse Row (CSR)</strong> graph layout inside each tenant&#8217;s Wasm linear memory, with eBPF XDP handling tenant routing at the NIC ring buffer &#8212; before the Linux network stack even sees the packet.</p><h3>Why CSR</h3><p>CSR stores a graph as three flat arrays:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OyRq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OyRq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png 424w, https://substackcdn.com/image/fetch/$s_!OyRq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png 848w, https://substackcdn.com/image/fetch/$s_!OyRq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png 1272w, https://substackcdn.com/image/fetch/$s_!OyRq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OyRq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png" width="502" height="391.6703296703297" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1f047460-3d78-4c61-822d-34701429df82_5000x3900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1136,&quot;width&quot;:1456,&quot;resizeWidth&quot;:502,&quot;bytes&quot;:868422,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/192925230?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OyRq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png 424w, https://substackcdn.com/image/fetch/$s_!OyRq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png 848w, https://substackcdn.com/image/fetch/$s_!OyRq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png 1272w, https://substackcdn.com/image/fetch/$s_!OyRq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f047460-3d78-4c61-822d-34701429df82_5000x3900.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><pre><code><code>row_ptr:    [u32; n_nodes + 1]   &#8212; prefix sums of out-degree
col_idx:    [u32; n_edges]       &#8212; neighbor node IDs, packed contiguously
edge_weight:[f32; n_edges]       &#8212; edge weights or relationship metadata
</code></code></pre><p>To walk all neighbors of node <code>k</code>, you read <code>row_ptr[k]</code> and <code>row_ptr[k+1]</code>, then iterate <code>col_idx[row_ptr[k]..row_ptr[k+1]]</code>. This is a single sequential memory region. Modern CPUs prefetch sequential reads. You go from ~50 random TLB misses per graph hop to near-zero.</p><p>At the document side, posts live in an <strong>arena slab allocator</strong> &#8212; a single contiguous <code>[u8]</code> in Wasm linear memory. A <code>col_idx</code> entry is not just a node ID; it also encodes a document arena offset. Fetching a post is one 64-bit integer decode and a slice range &#8212; no allocator call, no heap fragmentation.</p><h3>Why WASI 0.3 Shared-Nothing Components</h3><p>WASI 0.3 (Preview 3) introduces the Component Model with first-class async support. Each tenant is a <em>component instance</em> &#8212; a completely isolated Wasm linear memory with no shared mutable state between tenants. The WIT interface for our query looks like:</p><pre><code><code>package nexuscore:graph@0.3.0;

interface query {
  use wasi:io/streams@0.3.0.{output-stream};

  record query-params {
    root-node-id: u32,
    max-depth:    u8,
    tenant-id:    u32,
  }

  /// Returns a streaming iterator of serialized post documents.
  query-posts-by-relationship: func(params: query-params)
      -&gt; result&lt;output-stream, string&gt;;
}

world nexuscore-graph {
  export query;
}
</code></code></pre><p>This is not async/await bolted onto a sync runtime. WASI 0.3&#8217;s <code>output-stream</code> is a proper guest-driven async primitive &#8212; the component yields byte chunks as it walks the CSR graph, and the host runtime (Wasmtime) polls the stream without blocking a thread. No thread pool, no blocking executor, no Tokio reactor.</p><h3>Why eBPF XDP (Not iptables, Not tc)</h3><p>XDP (eXpress Data Path) runs your eBPF program at the NIC driver level, before <code>sk_buff</code> allocation. At 100M pps, skipping <code>sk_buff</code> allocation saves ~80 cycles per packet. Our eBPF program does exactly one thing: look up the tenant ID from the packet&#8217;s first 8 bytes, perform a <code>bpf_map_lookup_elem</code> on a <code>BPF_MAP_TYPE_HASH</code> (tenant_id &#8594; wasm_instance_slot), then emit a <code>perf_event</code> into the per-CPU ring buffer. The Wasmtime host polls that ring buffer using <code>io_uring</code> &#8212; one system call for a full batch, not one system call per packet.</p><div><hr></div><h2>Implementation Deep Dive</h2><h3>GitHub Link :</h3><p><a href="https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson3/nexuscore-day3">https://github.com/sysdr/nexus-core-devops-engineering-p/tree/main/lesson3/nexuscore-day3</a></p><h3>eBPF CO-RE Probe (C)</h3><pre><code><code>// src/ebpf/xdp_tenant_router.bpf.c
#include &lt;vmlinux.h&gt;
#include &lt;bpf/bpf_helpers.h&gt;
#include &lt;bpf/bpf_endian.h&gt;

struct tenant_event {
    __u32 tenant_id;
    __u32 slot;
    __u64 timestamp_ns;
};

struct {
    __uint(type, BPF_MAP_TYPE_HASH);
    __uint(max_entries, 65536);
    __type(key,   __u32);   // tenant_id
    __type(value, __u32);   // wasm_instance_slot
} tenant_map SEC(".maps");

struct {
    __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
    __uint(key_size,   sizeof(__u32));
    __uint(value_size, sizeof(__u32));
} events SEC(".maps");

SEC("xdp")
int xdp_tenant_router(struct xdp_md *ctx) {
    void *data     = (void *)(long)ctx-&gt;data;
    void *data_end = (void *)(long)ctx-&gt;data_end;

    // NexusCore wire format: first 4 bytes = tenant_id
    if (data + sizeof(__u32) &gt; data_end)
        return XDP_PASS;

    __u32 tenant_id = *(__u32 *)data;
    __u32 *slot = bpf_map_lookup_elem(&amp;tenant_map, &amp;tenant_id);
    if (!slot)
        return XDP_PASS;

    struct tenant_event ev = {
        .tenant_id    = tenant_id,
        .slot         = *slot,
        .timestamp_ns = bpf_ktime_get_ns(),
    };
    bpf_perf_event_output(ctx, &amp;events, BPF_F_CURRENT_CPU,
                          &amp;ev, sizeof(ev));
    return XDP_REDIRECT;
}

char LICENSE[] SEC("license") = "GPL";
</code></code></pre><p>This is CO-RE (Compile Once, Run Everywhere). <code>vmlinux.h</code> is generated from the target kernel&#8217;s BTF data, meaning the binary runs on any 5.15+ kernel without recompilation.</p><h3>Rust: CSR Graph Engine (WASI 0.3 Component)</h3><pre><code><code>// src/wasm/nexuscore_graph/src/lib.rs
#![no_std]
extern crate alloc;

use alloc::vec::Vec;
use wit_bindgen::generate;

generate!({
    world: "nexuscore-graph",
    path: "../../wit",
});

use exports::nexuscore::graph::query::{Guest, QueryParams};
use wasi::io::streams::OutputStream;

/// CSR graph backed by Wasm linear memory arenas.
pub struct GraphEngine {
    row_ptr:     Vec&lt;u32&gt;,   // n_nodes + 1 prefix-sum offsets
    col_idx:     Vec&lt;u32&gt;,   // packed neighbor IDs
    doc_offsets: Vec&lt;u64&gt;,   // col_idx &#8594; arena byte offset + length
    arena:       Vec&lt;u8&gt;,    // slab of raw document bytes
}

impl GraphEngine {
    pub fn bfs_posts(&amp;self, root: u32, max_depth: u8) -&gt; impl Iterator&lt;Item = &amp;[u8]&gt; {
        let mut visited = alloc::collections::BTreeSet::new();
        let mut queue: Vec&lt;(u32, u8)&gt; = alloc::vec![(root, 0)];
        let mut result: Vec&lt;&amp;[u8]&gt; = Vec::new();

        while let Some((node, depth)) = queue.pop() {
            if depth &gt;= max_depth || !visited.insert(node) {
                continue;
            }
            let start = self.row_ptr[node as usize] as usize;
            let end   = self.row_ptr[node as usize + 1] as usize;

            // Sequential read &#8212; hardware prefetcher friendly
            for &amp;neighbor in &amp;self.col_idx[start..end] {
                let packed = self.doc_offsets[neighbor as usize];
                let offset = (packed &gt;&gt; 20) as usize;
                let len    = (packed &amp; 0xFFFFF) as usize;
                result.push(&amp;self.arena[offset..offset + len]);
                queue.push((neighbor, depth + 1));
            }
        }
        result.into_iter()
    }
}

pub struct Component;

impl Guest for Component {
    fn query_posts_by_relationship(
        params: QueryParams,
    ) -&gt; Result&lt;OutputStream, alloc::string::String&gt; {
        let engine = unsafe { ENGINE.as_ref().ok_or("engine not initialized")? };
        let stream = OutputStream::new();

        for doc_bytes in engine.bfs_posts(params.root_node_id, params.max_depth) {
            stream.write(doc_bytes).map_err(|e| alloc::format!("{e:?}"))?;
        }
        Ok(stream)
    }
}

static mut ENGINE: Option&lt;GraphEngine&gt; = None;
</code></code></pre><p>Key observation: <code>#![no_std]</code> with <code>extern crate alloc</code>. The component has no OS syscalls inside the graph traversal hot path &#8212; pure Wasm instructions operating on linear memory. The <code>BTreeSet</code> for visited nodes uses the arena allocator, not a system allocator call.</p><h3>Rust: Wasmtime Host (io_uring + perf ring polling)</h3><pre><code><code>// src/host/src/main.rs
use io_uring::{opcode, types, IoUring};
use wasmtime::{Engine, Store, Component, Linker};
use wasmtime_wasi::preview2::WasiCtxBuilder;

const RING_DEPTH: u32 = 256;

#[tokio::main]
async fn main() -&gt; anyhow::Result&lt;()&gt; {
    let mut ring = IoUring::new(RING_DEPTH)?;

    // Pre-load Wasm components into a pool indexed by tenant slot
    let engine  = Engine::default();
    let wasm    = std::fs::read("nexuscore_graph.wasm")?;
    let component = Component::from_binary(&amp;engine, &amp;wasm)?;

    // io_uring: submit perf ring buffer read ops in batch
    loop {
        let (submitter, sq, cq) = ring.split();
        // ... poll eBPF perf ring, dispatch to component per event
        // Each CQE maps to one tenant_event; we batch into groups of 64
        // before yielding to Tokio, keeping CPU-to-cache ratio optimal.
        for cqe in cq {
            let event = unsafe { &amp;*(cqe.user_data() as *const TenantEvent) };
            dispatch_to_component(&amp;component, &amp;engine, event).await?;
        }
    }
}
</code></code></pre><p>The <code>io_uring</code> submission queue batches 256 perf ring reads into one <code>io_uring_enter</code> syscall. That&#8217;s the entire syscall budget for 256 tenant requests. Traditional epoll would require 256 <code>epoll_wait</code> calls.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lmJ0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lmJ0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png 424w, https://substackcdn.com/image/fetch/$s_!lmJ0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png 848w, https://substackcdn.com/image/fetch/$s_!lmJ0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png 1272w, https://substackcdn.com/image/fetch/$s_!lmJ0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lmJ0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png" width="500" height="439.90384615384613" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/de6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1281,&quot;width&quot;:1456,&quot;resizeWidth&quot;:500,&quot;bytes&quot;:836410,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://clouddc.substack.com/i/192925230?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lmJ0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png 424w, https://substackcdn.com/image/fetch/$s_!lmJ0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png 848w, https://substackcdn.com/image/fetch/$s_!lmJ0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png 1272w, https://substackcdn.com/image/fetch/$s_!lmJ0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde6fbcd1-14e9-48ac-baa6-f5d62f700c64_5000x4400.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h3>Working Demo Link :</h3><div id="youtube2-cM7jza5ex2s" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;cM7jza5ex2s&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/cM7jza5ex2s?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><h2>Production Readiness: Metrics to Watch</h2><p>Metric Healthy Threshold Alert XDP redirect rate (pps) &gt; 10M/s &lt; 5M/s Wasm cold start (&#181;s) &lt; 80&#181;s &gt; 200&#181;s CSR BFS p99 latency (&#181;s) &lt; 40&#181;s &gt; 150&#181;s TLB miss rate (perf stat) &lt; 2% &gt; 10% io_uring CQE batch size avg &gt; 64 avg &lt; 8 Arena fragmentation % &lt; 5% &gt; 20%</p><p>Instrument with <code>perf stat -e dTLB-load-misses,cache-misses</code> on the Wasmtime host process. A rising TLB miss rate with constant request rate means tenants&#8217; graph data is growing beyond L3 reach &#8212; trigger a CSR repack.</p><div><hr></div><h2>Step-by-Step Setup</h2><h3>Prerequisites</h3><pre><code><code># Rust toolchain with Wasm target
rustup target add wasm32-wasip2
cargo install wit-bindgen-cli cargo-component

# eBPF toolchain
sudo apt install clang-16 libbpf-dev linux-headers-$(uname -r)
cargo install bpf-linker

# Wasmtime CLI (for verification)
curl -fsSL https://wasmtime.dev/install.sh | bash

# Go (for eBPF loader)
wget https://go.dev/dl/go1.22.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.22.linux-amd64.tar.gz
go install github.com/cilium/ebpf/cmd/bpf2go@latest
</code></code></pre><h3>Build and Verify</h3><pre><code><code># Run the setup script to scaffold the full workspace
chmod +x setup_lesson.sh &amp;&amp; ./setup_lesson.sh

# Build eBPF probe
cd src/ebpf &amp;&amp; make

# Build Wasm component
cd src/wasm/nexuscore_graph
cargo component build --release
# Expected output: nexuscore_graph.wasm (~180 KiB, pre-stripped)

# Verify WIT interface compliance
wasmtime component inspect nexuscore_graph.wasm

# Run host with synthetic load
cd src/host &amp;&amp; cargo run --release -- --tenants 1000 --rps 50000

# Stress test (requires root for XDP)
sudo ./scripts/stress.sh --duration 60 --tenants 50000 --pps 10000000

# Check TLB miss rate during stress
perf stat -e dTLB-load-misses,L1-dcache-loads \
  -p $(pgrep nexuscore-host) sleep 10
</code></code></pre><h3>Verify Correctness</h3><pre><code><code># Unit test: CSR graph traversal produces correct post IDs
cargo test -p nexuscore_graph -- --nocapture

# Integration test: end-to-end tenant query returns expected document bytes
cargo test -p nexuscore_host -- integration --nocapture

# Observe eBPF map state
sudo bpftool map dump name tenant_map | head -40
</code></code></pre><div><hr></div><h2>Homework: Production-Level Challenge</h2><p>The current BFS allocates a <code>BTreeSet</code> for visited-node tracking on every query. At hyperscale, this is one allocation per request. Your task:</p><ol><li><p><strong>Implement a bitmap visited-set</strong> inside the Wasm linear memory arena. For a graph of <code>n</code> nodes, allocate <code>ceil(n/8)</code> bytes at a fixed arena offset and use bitwise operations for membership testing. This eliminates the <code>BTreeSet</code> allocation entirely.</p></li><li><p><strong>Extend the WIT interface</strong> to support <strong>depth-limited DFS with a result limit</strong> &#8212; return at most <code>k</code> posts, stopping early. Add a <code>max-results: u32</code> field to <code>QueryParams</code> and implement short-circuit traversal in the component.</p></li><li><p><strong>Measure the delta</strong>: use <code>hyperfine</code> to benchmark <code>bfs_posts</code> before and after the bitmap change at 1K, 10K, and 100K node graphs. Report the instruction count difference using <code>perf stat -e instructions</code>.</p></li><li><p><strong>Hard mode</strong>: Implement <strong>tenant graph partitioning</strong> &#8212; when a single tenant&#8217;s graph exceeds 4 MiB of Wasm linear memory pages, split it into two component instances with a cross-component WIT <code>import</code> call that bridges the shard boundary. Measure the cross-shard hop latency overhead vs. same-shard traversal.</p></li></ol><p>This is the difference between a working system and a production system. An allocation on every request is a latency cliff waiting to happen under GC pressure &#8212; even in Rust&#8217;s bump allocator.</p>]]></content:encoded></item></channel></rss>