<?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: Kulaja Kithsahan</title>
    <description>The latest articles on DEV Community by Kulaja Kithsahan (@kulaja_kithsahan36).</description>
    <link>https://dev.to/kulaja_kithsahan36</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%2F3958718%2Fbb14d8e8-050d-45e7-a6a6-582d87764f38.png</url>
      <title>DEV Community: Kulaja Kithsahan</title>
      <link>https://dev.to/kulaja_kithsahan36</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kulaja_kithsahan36"/>
    <language>en</language>
    <item>
      <title>Stop Streaming Blindly: Architectural Patterns for Cost-Optimized AI Logging</title>
      <dc:creator>Kulaja Kithsahan</dc:creator>
      <pubDate>Sun, 31 May 2026 19:09:40 +0000</pubDate>
      <link>https://dev.to/kulaja_kithsahan36/stop-streaming-blindly-architectural-patterns-for-cost-optimized-ai-logging-ci1</link>
      <guid>https://dev.to/kulaja_kithsahan36/stop-streaming-blindly-architectural-patterns-for-cost-optimized-ai-logging-ci1</guid>
      <description>&lt;p&gt;Hey everyone! 👋&lt;/p&gt;

&lt;p&gt;A lot of modern AI tutorials teach you how to connect an API to a data source and call it a day. But in a production environment—especially in cybersecurity, that approach can break your budget. If a bot script attacks your open server port trying hundreds of passwords a minute, making an individual cloud LLM call for every single log line is a recipe for an astronomical API bill.&lt;/p&gt;

&lt;p&gt;I recently designed an open-source &lt;strong&gt;AI-SOC Command Center&lt;/strong&gt; specifically to solve this problem using a &lt;strong&gt;Micro-Batching Ingestion Buffer&lt;/strong&gt; pattern. Here is the architectural breakdown of how I kept cloud costs low while maintaining real-time intelligence.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Core Architecture
&lt;/h2&gt;

&lt;p&gt;The system is built as a modular pipeline to ensure that local compute handles the noise, leaving the cloud LLM to handle the high-level analysis.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Non-Blocking Stream Pointer
&lt;/h3&gt;

&lt;p&gt;To watch logs continuously without freezing the user interface, the system utilizes a lightweight Python generator stream. It checks for new lines dynamically and immediately releases control back to the system stopwatch if the file is idle.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Volatile State Aggregation
&lt;/h3&gt;

&lt;p&gt;Instead of talking to the internet immediately, incoming logs are captured inside an intermediate state bucket during &lt;strong&gt;15-second&lt;/strong&gt; sliding window. Once the window closes, Pandas compiles the raw rows into a structured format, collapsing thousands of repetitive hits down to a single unique IP signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Aggregating user targets to group metrics locally before API dispatch
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;aggregated_data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;aggregated_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ip_address&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;total_failed_attempts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;targeted_usernames&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# Deduplicates usernames targeted during the burst
&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conditional API Dispatch (The Guardrail)
&lt;/h2&gt;

&lt;p&gt;The system evaluates the aggregated statistics against a customizable threshold controller. If an IP only logs a single casual failure, it is safely dismissed locally. If it breaks the threshold, the entire micro-batch summary is compiled into a single unified payload and sent to the Gemini API.&lt;/p&gt;

&lt;p&gt;Result: 100 automated attacks become exactly 1 API request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a Command Center Web UI
&lt;/h2&gt;

&lt;p&gt;To make this data scannable at a glance, I paired the backend modules with a high-contrast dark theme frontend powered by Streamlit and Plotly Express.&lt;/p&gt;

&lt;p&gt;Instead of basic rendering, the dashboard features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Interactive Donut Charts: Tracking server user account distribution dynamically.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Horizontal Bar Charts: Visualizing active attack vectors and highlighting severe IPs with automated red heat-mapping scale shifts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Asynchronous UI Refreshes: Utilizing st.rerun() loops to fetch log adjustments without interrupting the analytics viewports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Collapsible Security Accordions: Organizing markdown forensic intelligence generated by the AI model cleanly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Clean, Extensible Code
&lt;/h2&gt;

&lt;p&gt;I structured this repository following professional design standards—keeping modules completely isolated, utilizing an &lt;strong&gt;init&lt;/strong&gt;.py packaging structure, and safeguarding local API keys using rigid local configuration rules.&lt;/p&gt;

&lt;p&gt;If you are looking at ways to optimize your data pipelines or integrate LLMs into high-frequency environments without breaking the bank, feel free to dive into the codebase!&lt;/p&gt;

&lt;p&gt;👉 GitHub Repository: &lt;a href="https://github.com/kulajakithsahan36/ai-soc-analyst.git" rel="noopener noreferrer"&gt;https://github.com/kulajakithsahan36/ai-soc-analyst.git&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me know your thoughts on this micro-batching pattern or how you optimize your own AI pipeline thresholds in the comments!&lt;/p&gt;

</description>
      <category>python</category>
      <category>learning</category>
      <category>security</category>
      <category>opensource</category>
    </item>
    <item>
      <title>How I Built a Local AI-Powered Combined Maths Solver for My A/L Preparation</title>
      <dc:creator>Kulaja Kithsahan</dc:creator>
      <pubDate>Fri, 29 May 2026 16:56:26 +0000</pubDate>
      <link>https://dev.to/kulaja_kithsahan36/how-i-built-a-local-ai-powered-combined-maths-solver-for-my-al-preparation-3lo3</link>
      <guid>https://dev.to/kulaja_kithsahan36/how-i-built-a-local-ai-powered-combined-maths-solver-for-my-al-preparation-3lo3</guid>
      <description>&lt;p&gt;Hey everyone! 👋&lt;/p&gt;

&lt;p&gt;I am a student from Sri Lanka currently preparing to step into the highly intense G.C.E. Advanced Level (A/L) Combined Mathematics stream. Balancing school studies with a passion for programming can be tricky, so I decided to bridge the two worlds.&lt;/p&gt;

&lt;p&gt;Instead of just solving math problems on paper, I built a local web-based Combined Mathematics AI Problem Solver tailored to our local syllabus.&lt;/p&gt;

&lt;p&gt;Because this is my very first technical article, I want to pull back the curtain on how I designed the architecture, how the components talk to each other, and why I built it locally on my PC.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Vision : Aligning AI with a Local Syllabus
&lt;/h2&gt;

&lt;p&gt;Standard AI models are great at general math, but local examinations like the Sri Lankan A/Ls require steps to be structured in a very specific way to match local marking schemes.&lt;/p&gt;

&lt;p&gt;My goal was to create a tool where a student could input a problem, and the application would return a step-by-step breakdown that feels familiar to an A/L student. To make it highly responsive and optimized, I didn't want it relying entirely on slow, repetitive cloud API calls every single time.&lt;/p&gt;

&lt;p&gt;Here is the high-level map of how data moves through the system:&lt;/p&gt;

&lt;h2&gt;
  
  
  The Tech Stack Architecture
&lt;/h2&gt;

&lt;p&gt;Instead of writing one massive, tangled file, I broke the project down into three distinct, manageable layers:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Core Backend: FastAPI (Python)
&lt;/h3&gt;

&lt;p&gt;I chose FastAPI to build the engine of this platform. It is lightweight, incredibly fast, and handles asynchronous requests brilliantly. FastAPI acts as the traffic cop it accepts the question from the frontend, packages it securely with specific system instructions, and sends it out.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The Brain: Gemini Pro via Google AI Studio
&lt;/h3&gt;

&lt;p&gt;For the heavy mathematical reasoning, I hooked the backend up to cloud based Large Language Models using the Google GenAI SDK. To ensure the output matches the local syllabus requirements, the backend injects context like syllabus guidelines and past paper structures directly into the prompt before it hits the AI.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. The Memory: SQLite Caching
&lt;/h3&gt;

&lt;p&gt;This is my favorite part of the build. When you are studying, you often re-run or review the exact same math problems. Making an external API call to a cloud model every single time takes seconds and wastes network bandwidth.&lt;/p&gt;

&lt;p&gt;To solve this, I wired up an SQLite database to handle response caching:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When a question comes in, FastAPI checks SQLite first.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cache Hit: If the exact problem has been solved before, it pulls the          answer instantly from the local database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cache Miss: If it's a completely new question, it calls Gemini, saves the                                       fresh solution into SQLite for next time, and returns the answer.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Challenges I Faced (and What I Learned)
&lt;/h2&gt;

&lt;p&gt;As a student developer, building this was a massive learning curve.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Decoupling Logic: At first, trying to make the web framework, the database queries, and the API requests handle asynchronous paths together felt overwhelming.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The "Mysterious Code" Phenomenon: Looking back at my scripts a few weeks later, I realized how quickly code can become complex! Even when your own syntax starts looking a bit like a foreign language to you, understanding the structural design how data goes in and comes out of your modules is what keeps the project alive.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Journey is the Project
&lt;/h2&gt;

&lt;p&gt;Building this tool taught me that you don't need a massive team or a cloud budget to create something highly functional. By combining a fast Python backend like FastAPI with local SQLite caching, a single developer can build responsive, AI-powered applications right on their own local machine.&lt;/p&gt;

&lt;p&gt;This project is just the beginning for me. While my immediate focus is handling my upcoming academic streams, I plan to keep this local platform as my private playground to test new optimization techniques, learn more about database management, and sharpen my Python skills. &lt;/p&gt;

&lt;p&gt;If you are a student developer building tools to solve your own everyday problems, or if you have any tips on backend optimization, I’d love to hear your thoughts in the comments below! 🚀&lt;/p&gt;

</description>
      <category>python</category>
      <category>learning</category>
      <category>ai</category>
      <category>fastapi</category>
    </item>
  </channel>
</rss>
