<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kunal Kaushik</title>
    <description>The latest articles on DEV Community by Kunal Kaushik (@selixes).</description>
    <link>https://dev.to/selixes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4023541%2F7eff8e79-1944-41cc-ac21-11ced5009d8f.webp</url>
      <title>DEV Community: Kunal Kaushik</title>
      <link>https://dev.to/selixes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/selixes"/>
    <language>en</language>
    <item>
      <title>Selixes - I Engineered a Sub-15ms Failover Proxy to Stop AI Agent Crashes</title>
      <dc:creator>Kunal Kaushik</dc:creator>
      <pubDate>Fri, 10 Jul 2026 07:40:02 +0000</pubDate>
      <link>https://dev.to/selixes/my-engineering-passion-why-i-built-a-sub-15ms-proxy-to-stop-llm-agent-crashes-5hjg</link>
      <guid>https://dev.to/selixes/my-engineering-passion-why-i-built-a-sub-15ms-proxy-to-stop-llm-agent-crashes-5hjg</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for &lt;a href="https://dev.to/challenges/weekend-2026-07-09"&gt;Weekend Challenge: Passion Edition&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;The modern AI ecosystem relies entirely on upstream API stability. Yet, building autonomous agents right now feels like building on quicksand. OpenAI, Anthropic, and other major providers routinely suffer from latency spikes, unexpected &lt;code&gt;502 Bad Gateway&lt;/code&gt; errors, and aggressive &lt;code&gt;429 Too Many Requests&lt;/code&gt; rate limits. &lt;/p&gt;

&lt;p&gt;For consumer apps, a dropped connection is an annoyance. For enterprise autonomous agents executing multi-step workflows, a single dropped request mid-stream can crash an entire loop—often resulting in runaway retry logic that burns hundreds of dollars in API credits before you even receive a PagerDuty alert.&lt;/p&gt;

&lt;p&gt;I am obsessed with system architecture and high availability. I became so passionate about solving this specific edge case that I spent the last few months engineering &lt;strong&gt;Selixes&lt;/strong&gt; — a high-throughput edge proxy gateway designed to sit between your application and your LLM providers.&lt;/p&gt;

&lt;p&gt;Selixes intercepts the data stream in real-time. If the primary provider's latency spikes beyond an acceptable threshold or drops the connection mid-generation, Selixes instantly fails over to a backup model in &lt;strong&gt;under 15ms&lt;/strong&gt;, completely invisibly to the end-user. It also utilizes atomic Redis operations to enforce hard session spend caps, acting as an absolute circuit breaker against runaway agent spend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;You can explore the live architecture, documentation, and the developer platform here: &lt;a href="https://selixes.com" rel="noopener noreferrer"&gt;https://selixes.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(Note: Because Selixes operates entirely at the infrastructure routing layer, the magic happens invisibly on the backend. However, you can experience the failover mechanism by swapping out your base URL using the SDK integration below.)&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;The core philosophy behind Selixes was zero-friction adoption. Because the gateway exposes a fully standard, OpenAI-compatible endpoint, engineering teams do not need to rewrite their agent logic or learn a new SDK. &lt;/p&gt;

&lt;p&gt;You can view the full source code for the proxy and deployment instructions on our GitHub repository:&lt;br&gt;
&lt;strong&gt;🔗 &lt;a href="https://github.com/selixes/selixes-gateway" rel="noopener noreferrer"&gt;GitHub Repository: selixes/selixes-gateway&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You simply point your existing client to the gateway:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;OpenAI&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;openai&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Before: Direct connection (Highly vulnerable to outages and rate limits)&lt;/span&gt;
&lt;span class="c1"&gt;// const client = new OpenAI({ apiKey: 'sk-...' });&lt;/span&gt;

&lt;span class="c1"&gt;// After: Proxied through Selixes with Google AI as the failover engine&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://gateway.selixes.com/v1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;slx_...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; 
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How I Built It
&lt;/h2&gt;

&lt;p&gt;The fundamental engineering challenge was achieving mid-stream failover without introducing massive latency. If an upstream provider accepts a connection but drops it mid-generation, catching that error and spinning up a brand-new TLS handshake to a backup model typically causes a massive lag spike that breaks the UX.&lt;/p&gt;

&lt;p&gt;Here is a technical teardown of the architecture I built to solve this:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Atomic Spend Caps via Redis
&lt;/h3&gt;

&lt;p&gt;Every incoming request performs a lightning-fast lookup using a Redis &lt;code&gt;INCRBYFLOAT&lt;/code&gt; operation. It calculates the exact token cost and checks if the session has exceeded its pre-defined budget cap in under &lt;code&gt;1ms&lt;/code&gt;. If the budget is blown, the proxy intercepts the request and returns a standard 429 error instantly, killing the runaway loop at the edge.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Optimistic TCP Pre-warming
&lt;/h3&gt;

&lt;p&gt;To solve the failover latency problem, I implemented a rolling health window for providers using a Redis sliding window algorithm. When the primary provider's latency telemetry spikes above the 95th percentile, the Selixes gateway preemptively initiates a parallel, background TCP connection to the fallback provider. If the primary request ultimately fails, the fallback connection is already TLS-handshaked and ready to pipe the stream.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. The Google AI Integration (Gemini 3.1 Pro)
&lt;/h3&gt;

&lt;p&gt;The failover architecture is only as good as the fallback engine. I integrated &lt;strong&gt;Google Gemini 3.1 Pro&lt;/strong&gt; via the Google AI ecosystem as the default safety net. To achieve true sub-15ms failover, the fallback model must be globally distributed, incredibly fast, and highly available. &lt;/p&gt;

&lt;p&gt;Because Google's infrastructure is arguably the most robust in the world, it serves as the perfect enterprise failover. When OpenAI drops the ball, my gateway pipes the conversational context straight to Gemini 3.1 Pro. The autonomous loop stays alive, the user experience remains uninterrupted, and the engineering team doesn't get woken up at 3 AM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prize Categories
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Best Use of Google AI&lt;/strong&gt;&lt;br&gt;
I am submitting this project for the Google AI category. Instead of building a standard chatbot wrapper, I utilized Google AI (specifically Gemini 3.1 Pro) as the backbone for an enterprise-grade failover infrastructure. This project demonstrates how Google's speed and reliability can be leveraged to keep competing systems online.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next &amp;amp; Closing Thoughts
&lt;/h2&gt;

&lt;p&gt;Building Selixes started out of pure frustration with upstream API instability, but it's evolved into a robust piece of infrastructure that I rely on daily. My next goal is to implement predictive latency routing—where the gateway dynamically routes traffic &lt;em&gt;before&lt;/em&gt; a primary provider fully spikes, based on global telemetry trends.&lt;/p&gt;

&lt;p&gt;If you are an engineer dealing with autonomous agent crashes, rate limits, or spiraling LLM costs, I'd love for you to try out the gateway. &lt;/p&gt;

&lt;p&gt;Any feedback, code reviews, or pull requests on the &lt;a href="https://github.com/selixes/selixes-gateway" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; are highly appreciated. Let's make AI infrastructure bulletproof! 🚀&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>weekendchallenge</category>
    </item>
  </channel>
</rss>
