<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kaanguler on Medium]]></title>
        <description><![CDATA[Stories by Kaanguler on Medium]]></description>
        <link>https://medium.com/@kaangulergs?source=rss-ccc7ec328f05------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lWTh_L6_6cQ9f-N3</url>
            <title>Stories by Kaanguler on Medium</title>
            <link>https://medium.com/@kaangulergs?source=rss-ccc7ec328f05------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:59:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kaangulergs/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[System Design for AI #5: The Brain of an AI Backend — AI Orchestration]]></title>
            <link>https://medium.com/@kaangulergs/system-design-for-ai-5-the-brain-of-an-ai-backend-ai-orchestration-23eac526815d?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/23eac526815d</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Tue, 29 Sep 2026 12:53:34 GMT</pubDate>
            <atom:updated>2026-09-29T12:53:34.094Z</atom:updated>
            <content:encoded><![CDATA[<p>You give a prompt, and it goes into a magical black box that gives you an answer. Let’s explore what is inside this black box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BTumQTbZru866A9D" /><figcaption>Photo by <a href="https://unsplash.com/@atulr?utm_source=medium&amp;utm_medium=referral">Atul</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><strong>1. What Is AI Orchestration?</strong></h4><p>AI orchestration is the process of directing user input to models, agents, and external tools. Tools can search the internet or external databases that we provide. A main model could call other models that are specialized for specific tasks. For example, we are game designers and we ask the model to make a game. The main model could call other models such as a narrative model, game design model, or art model. Depending on the orchestration architecture, these models can work in parallel. In the final step, the main model aggregates their outputs.</p><h4>2. Why Can’t We Just Call the LLM?</h4><p>We can simply give our input to an LLM, but it may have outdated or insufficient information. So we provide external tools such as internet search or external databases that contain information that is not in the model itself.</p><h4>3. Context Building</h4><p>We take the user input and combine it with information from external sources. We can also provide a system prompt and other contextual information. Then, we aggregate all of them into the context. Depending on the orchestration architecture, the main model can generate an answer or route the task to other agents or models.</p><p><strong>Context = user input + system instructions + relevant retrieved information + conversation state/memory + tool results</strong></p><h4>4. Memory</h4><p>Memory contains information from previous interactions with the model that can be useful in future interactions. Remembering relevant information is important because we don’t want the system to lose useful context between interactions.Recomputing or retrieving the same information repeatedly can also waste time and resources.</p><h4>5. Tool Calling</h4><p>Models are normally trained on data, and we cannot change their internal parameters, so they may not have access to current or external information at runtime. We can provide external things.These are tools. Tools are external sources such as web search.For example, if we want to ask for the current weather, the model cannot directly access real-time weather information from its training data so we give internet access to search on web APIs and when it finds a result it gives this result to model context so model can answer about this question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eGW0NUG2eDPNn0zajt4n6A.png" /><figcaption><a href="https://developers.openai.com/api/docs/guides/function-calling?api-mode=responses">https://developers.openai.com/api/docs/guides/function-calling?api-mode=responses</a></figcaption></figure><h4>6. Guardrails</h4><p>Some users may try to perform unethical actions. These include prompt injection and jailbreak attempts.Attackers might access other people’s sensitive information or force model to do non-ethical or dangerous things.Nature of AI systems is non-deterministic so using prompts hackers might trick models to give these answers or do these dangerous and non-ethical things.So we have to put protection management system for the orchestration. Guardrails can be applied at different points in the workflow, such as input, tool calls, tool results, and output.</p><h4>7. The Orchestrator Loop</h4><p>The orchestrator does not simply call an LLM once and return the response. It can build the context, call the model, decide whether a tool is needed, process the tool result, and send the updated context back to the model.</p><p>This process can continue until the model has enough information to generate the final response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vken3BQViXEUVJkITZvdJg.png" /><figcaption>AI-generated architecture diagram (ChatGPT), reviewed and refined by the author.</figcaption></figure><p>The orchestrator manages this loop between the LLM and external tools until a final response can be generated.</p><h4>8. Types of Orchestration</h4><p><strong><em>Sequential orchestration</em></strong></p><p>Each agent works one after another, with each step using the output from the previous step</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*ZOJ84MKCtHuE6KRyGEiB3A.png" /><figcaption><a href="https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns">https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns</a></figcaption></figure><p><strong><em>Group Chat</em></strong></p><p>Multiple agents collaborate through a shared conversation, with a chat manager coordinating the discussion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*L2MbTEDpuxgTle0Vi6YXcQ.png" /><figcaption><a href="https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns">https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns</a></figcaption></figure><p><strong><em>Concurrent</em></strong></p><p>Multiple agents work on the same task in parallel, and their outputs are combined later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*xvKwn7cLhZQeMo-ItQwkUg.png" /><figcaption><a href="https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns">https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns</a></figcaption></figure><p><strong><em>Handoff orchestration</em></strong></p><p>One agent can transfer the task to another agent when another agent is better suited for the next step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*zDO0H58CH3bDmo3ztWBwsg.png" /><figcaption><a href="https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns">https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns</a></figcaption></figure><p><strong><em>Magentic orchestration</em></strong></p><p>A Magentic manager dynamically coordinates specialized agents, deciding which agent should act next based on the current context, task progress, and evolving plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*aNkEcLRsR6-tUVWgHjDkpg.png" /><figcaption><a href="https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns">https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns</a></figcaption></figure><h4>Conclusion</h4><p>AI orchestration is more than simply calling an LLM. It manages context, memory, tools, guardrails, and the flow between models and agents. Depending on the task, we can use different orchestration patterns such as sequential, concurrent, group chat, handoff, or Magentic orchestration. The important part is choosing the right architecture for the problem instead of adding multiple agents without a clear reason.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>If you found this article useful, consider giving it a clap 👏 and following me for more on AI engineering and system design.</p><p>If you notice anything incorrect or have suggestions for improvement, I’m always open to feedback.</p><h4>References</h4><p><a href="https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns">https://learn.microsoft.com/en-us/azure/architecture/ai-ml/guide/ai-agent-design-patterns</a></p><ul><li><a href="https://www.anthropic.com/engineering/building-effective-agents?utm_source=chatgpt.com">Building Effective AI Agents</a></li><li><a href="https://openai.github.io/openai-agents-python/multi_agent/?utm_source=chatgpt.com">Agent orchestration</a></li><li><a href="https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents?utm_source=chatgpt.com">Effective context engineering for AI agents</a></li><li><a href="https://openai.github.io/openai-agents-python/sessions/?utm_source=chatgpt.com">Overview - OpenAI Agents SDK</a></li><li><a href="https://developers.openai.com/api/docs/guides/function-calling?api-mode=responses">Function calling | OpenAI API</a></li><li><a href="https://openai.github.io/openai-agents-python/guardrails/?utm_source=chatgpt.com">Guardrails</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23eac526815d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Built an Interactive Explorer for SkillCorner Open Data]]></title>
            <link>https://medium.com/@kaangulergs/i-built-an-interactive-explorer-for-skillcorner-open-data-3acf2abca0c5?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/3acf2abca0c5</guid>
            <category><![CDATA[football]]></category>
            <category><![CDATA[sports-analytics]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[soccer]]></category>
            <category><![CDATA[open-data]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Sat, 19 Sep 2026 00:14:37 GMT</pubDate>
            <atom:updated>2026-09-19T00:14:37.538Z</atom:updated>
            <content:encoded><![CDATA[<p>A simpler way to see what’s in the dataset before you start working with the raw files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m0s1x-JJ2OWptE78_acEXA.png" /><figcaption><a href="https://skillcorner-explorer.onrender.com/">https://skillcorner-explorer.onrender.com</a></figcaption></figure><h3><strong>Introduction</strong></h3><p>I started looking at SkillCorner Open Data because of Analytics Cup 2.0.</p><p>In case you have not run into it: SkillCorner and PySport publish 20 complete matches of football tracking data for anyone to download, along with event data, phases of play, season aggregates and a sample of body pose. The competition runs on that dataset. So I downloaded it and started poking around.</p><p>Then I got stuck. Not on anything difficult, just on the ordinary business of working out what I actually had.</p><h4><strong>What I kept needing to know</strong></h4><p>Every session started the same way. I would open a notebook to answer something that was not really an analysis question at all.</p><p>Which matches are in here? What does this particular match contain? What does the tracking data look like if you draw it? Which players turn up often enough to compare? What is in the events file, and what do those columns mean? Is this column filled in, or is it empty for three of the four event types?</p><p>None of that is hard. It is just slow. You download a file, load it, print a few rows, plot something, and an hour later you know something you could have seen in a minute if anyone had shown you.</p><p>The ordering bothered me most. You have to download and open things before you know what you are looking for. I kept wishing I could look first and decide afterwards.</p><h4>The idea</h4><p><strong><em>What if the dataset were just a website?</em></strong></p><p>Not a replacement for the files. You still want the raw data when you build something real. But a place to open, click around and get a feel for what is there, before you commit an evening to it.</p><p>That became the SkillCorner Open Data Explorer.</p><p><a href="https://skillcorner-explorer.onrender.com/"><strong>https://skillcorner-explorer.onrender.com</strong></a></p><p>It is an independent project. It is not an official SkillCorner tool, and it has nothing to do with PySport or the people running the competition. I built it for myself and then tidied it up enough to put online.</p><h4>What you can do with it</h4><p><strong>Matches</strong> : All 20 fixtures, 13 teams, one season of the Australian A-League. Each match page shows what that match actually holds, since not every match carries every layer.</p><p><strong>Tracking</strong>: Press play and watch a real half go past, ten frames a second, the way it sits in the file. You can scrub through it, leave trails behind the players and see the shape each team is holding. You also see something a summary would never tell you: the broadcast camera does not have all 22 players in view at once. Across the 20 matches it averages about nine detected players per frame, and the remaining positions are filled in by extrapolation. Watching that happen changes how you would design an analysis.</p><p><strong>Players</strong> : Rank them on a metric, look at the distribution with the outliers marked, compare percentiles, or open a profile. One thing the page is careful about: the season values are averages per match rather than totals, which is easy to misread and annoying to discover late.</p><p><strong>Events</strong> : There are 94,517 of them across the 20 matches, sitting on a pitch map you can filter. Click any mark and you get the entire row for that event, every column the file holds, rather than a tidied summary of it.</p><p><strong>Body pose</strong> :A sample of skeletons, 29 joints each, drawn next to where those players were standing. It covers one short phase of play rather than whole matches, which is enough to see what the layer is.</p><p><strong>The fields themselves</strong> : A dictionary of all 622 fields with how often each one is actually populated, and a page on what the data misses. A column existing and a column having values in it are two different things here.</p><p>None of it needs downloading. You open a page and look.</p><h4>Why I think it helps for the Analytics Cup</h4><p>If you are considering entering, the question you want answered early is whether the dataset supports the idea in your head.</p><p>That is cheap to answer now and expensive to get wrong later. If your idea leans on a column that turns out to be populated for only one of the four event types, or on seeing all 22 players in a frame, it is better to find out in an afternoon of clicking than in week two of building.</p><p>So there is a page that walks you from a question to the data that answers it, and a page for the competition itself with the dates and a short checklist. I have not repeated the rules there. They are on the official site, and that is where they should be read.</p><h4>A few screenshots</h4><h4>The way in</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m0s1x-JJ2OWptE78_acEXA.png" /></figure><h4>Tracking playback</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_-LuIUgRrE8z5OEpsM7K9A.png" /></figure><p>Dots are players, trails show where they came from, and the shaded areas are each team’s spread. The clock and frame number are the real values from the file.</p><h4>Events on a pitch map</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tm-e4Nj4_ca_jrG4Hboa_A.png" /></figure><p>Every event in the match, coloured by type. Filter it down, then click a mark to read that event’s full row.</p><h4>Player rankings</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q513YzAz2b3-VOr6tMb10g.png" /></figure><h4>Body pose</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fvw6V6DyS_571gKgdqCetA.png" /></figure><p>The skeleton on the left, and on the right the pitch showing which players have pose data and which only have a position.</p><h4>What I would like to add next</h4><p>Two things I keep thinking about.</p><p>The body pose joints are already three dimensional. Every one of the 29 carries a height as well as a position on the pitch, so an ankle sits at ankle height and a wrist rises above the hip. The page draws them flat at the moment, which throws that away. A small scene you could rotate would show what is really in there.</p><p>The other is being able to type a question in plain language and get pointed at the right file and the right columns. A page does that today as a fixed set of branches, which works, but typing the question you actually have would be a nicer way in. Nothing on the site is predicted, every number on it comes from measuring the files, and that would stay true.</p><h4>Try it</h4><p><a href="https://skillcorner-explorer.onrender.com/">https://skillcorner-explorer.onrender.com</a></p><p>If you are opening SkillCorner Open Data for the first time, or working out whether toenter Analytics Cup 2.0, start with Matches, open a fixture, and follow it into the tracking and events for that match.</p><p>The data is SkillCorner Open Data, published by SkillCorner (https://skillcorner.com) with PySport(https://pysport.org/) under the MIT licence, and it stays theirs. The Explorer is just a way to look at it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3acf2abca0c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Is an AI Gateway? Airport Analogy | System Design for AI #4]]></title>
            <link>https://medium.com/@kaangulergs/what-is-an-ai-gateway-airport-analogy-system-design-for-ai-4-4ce75f1fce6b?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ce75f1fce6b</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Sun, 30 Aug 2026 22:07:37 GMT</pubDate>
            <atom:updated>2026-08-30T22:07:37.217Z</atom:updated>
            <content:encoded><![CDATA[<p>It is similar to an airport. Imagine that you have a ticket and want to get on a plane. Airport personnel check your ticket and direct you to the correct gate. An AI gateway applies this logic to AI applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*S2PREyQXyafgdwKJ" /><figcaption>Photo by <a href="https://unsplash.com/@odiin?utm_source=medium&amp;utm_medium=referral">Erik Odiin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What Does An AI Gateway Do</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VwYmc15D3H9p3UK1" /><figcaption><a href="https://konghq.com/blog/enterprise/what-is-an-ai-gateway">https://konghq.com/blog/enterprise/what-is-an-ai-gateway</a></figcaption></figure><p>An AI gateway is middleware between an AI application and foundation models. It is developed to provide security ,monitoring, routing ,authorization, authentication and caching.</p><p><strong>Security</strong></p><p>When a user sends a prompt, first we can check whether the prompt violates our policies or contains a potential prompt injection attack. The AI Gateway can refuse the request and return an appropriate response based on the reason. It also masks sensitive information to protect personal data.</p><p><strong>Routing</strong></p><p>When we work with multiple AI providers, managing all of them increases complexity and cost.For example, some model providers may not be able to serve a model for a while, so the AI Gateway can direct the request to a backup model.</p><p>Another usage option is routing model based on task. For instance , if your task is not heavy , the AI gateway directs it to cheaper models , but when you want to do heavy tasks ,it routes the request to more powerful models.</p><p><strong>Monitoring</strong></p><p>In the agentic AI era, AI systems can make multiple tool calls, access external databases, and call cheaper models for classification tasks. All of this can increase token usage, and if you don’t monitor token usage, your bill can be too high.So you need monitoring to see every action.</p><p><strong>Caching</strong></p><p>Let’s say you type the same prompt. Let’s say you type the same prompt. Isn’t it unnecessary to send the prompt to the model and wait for a similar answer? So we cache previous requests and their responses and return the same response directly.</p><p>We also apply semantic caching. Semantic caching means that we don’t necessiraly need same prompt if we have similar prompts like previous prompts, we can respond according to that previous prompt.However, semantic caching should be used carefully because similar prompts do not always require the same answer.</p><p><strong>API Standardization</strong></p><p>When we use multiple AI providers, every provider can have different APIs. This makes integration harder because developers need to learn and use different API formats.</p><p>AI gateway solves this problem by providing one standard interface for different models and providers. Your application sends the request to the AI gateway in the same format, and the gateway converts it to the format required by the selected AI provider.</p><p>For example, instead of changing your code when you switch from OpenAI to Anthropic, you can send the same request to the AI gateway. The gateway handles the differences between providers.</p><p>This makes it easier to switch models, add new providers, and manage AI services without changing the application itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RVM27lt1GNBSWKjR.png" /><figcaption><a href="https://ngrok.com/blog/ai-gateways-2026">https://ngrok.com/blog/ai-gateways-2026</a></figcaption></figure><h3>AI Gateway VS API Gateway</h3><p>In an API Gateway we set up a middleware layer between an application and backend services for REST APIs and its nature is deterministic.</p><p>AI gateway is for non-deterministic applications. We don’t always know the exact content of the request and response because they depend on the user’s request. In a traditional API Gateway, however, the client usually chooses from predefined API endpoints that we have created. Therefore, we have to control both requests and responses in AI applications. Requests can contain potentially dangerous attacks such as prompt injection, while responses can contain policy-violating or unsafe content. AI Gateway can use AI-based guardrails to analyze the semantic meaning of prompts and responses.</p><p>AI gateway can also choose the best model according to request.For example, an easy task can be directed to cheaper models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eSXvW7bfUzvBL--B2SiSaA.png" /></figure><h3>References</h3><p><a href="https://www.ibm.com/think/topics/ai-gateway">https://www.ibm.com/think/topics/ai-gateway</a></p><ul><li><a href="https://konghq.com/blog/enterprise/what-is-an-ai-gateway">What is an AI Gateway?</a></li><li><a href="https://www.paloaltonetworks.com/cyberpedia/what-is-an-ai-gateway">What Is an AI Gateway?</a></li><li><a href="https://ngrok.com/blog/ai-gateways-2025">AI Gateways in 2025: The Original Guide | ngrok blog</a></li><li><a href="https://ngrok.com/blog/ai-gateways-2026">What Is an AI Gateway, and Do You Need One? | ngrok blog</a></li></ul><p>If you enjoyed this article and want to see more AI System Design content, feel free to clap and follow for the next part of the series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ce75f1fce6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design for AI #3: What Does an API Gateway Actually Do?]]></title>
            <link>https://medium.com/@kaangulergs/system-design-for-ai-3-what-does-an-api-gateway-actually-do-7726b1e715fb?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/7726b1e715fb</guid>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Thu, 13 Aug 2026 09:10:29 GMT</pubDate>
            <atom:updated>2026-08-13T09:10:29.047Z</atom:updated>
            <content:encoded><![CDATA[<p>It is simply a cashier. Let’s make it clearer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tCe4E4nTEOFZdZQQ" /><figcaption>Photo by <a href="https://unsplash.com/@spotonpos?utm_source=medium&amp;utm_medium=referral">SpotOn</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine you want to eat a burger. You go to the cashier to order a burger.You say what burger you want or do you want beverages or potatoes. The cashier takes this order and receives payment from you.An API Gateway does this in a similar manner.</p><p>You don’t have to know the potato fryer or burger maker you just know the cashier , and you can pay once for every service instead of paying for every service.And if there are two fryers, the cashier directs the order to the most available fryer</p><h3>What is API Gateway</h3><p>API Gateway is middleware between clients and services. It provides a unified entry point. Clients don’t have to know the internal backend structure . They know just API gateway and send requests to API Gateway. API Gateway directs requests to the correct services. API Gateway also provides authentication , authorization , rate limiting , monitoring , caching and load balancing.</p><h3>What Does an API Gateway Do?</h3><p>Firstly, API Gateway takes requests from clients , validates parameters and checks allow and deny list. Then, the Gateway checks whether the user is authenticated correctly. After that, it checks the user’s permissions to access the correct services through authorization.Rate limiting is applied if the user sends too many requests from the same IP address. Then, it finally finds the requested service and directs the request to it . While doing these processes it monitors usage , latency etc. When responses are back to the API Gateway, it can aggregate all the responses and structure them and send them to client.</p><h3>API Gateway in an AI System</h3><p>What happens if we put an API Gateway in an AI System.</p><p>Let’s assume a user asks a question: “What is an API Gateway “</p><p>API gateway takes a question over HTTPS .The API gateway can authenticate and authorize the user , check rate limits , validate the request , and then route it to the appropriate AI backend.</p><p>The API Gateway does not generate responses itself. It is basically a bridge to ensure that requests reach the correct service safely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ekyrLR0LUG4lzFGffXnVQ.png" /><figcaption>AI-generated architecture diagram (Gemini), reviewed and refined by the author.</figcaption></figure><p>This is much more important for AI applications because LLM requests might be too expensive and take much more time than requests in traditional backends. So we need to handle traffic load and prevent excessive requests from reaching the AI backend.</p><h3>API Gateway vs Load Balancer vs Reverse Proxy</h3><p>Some people wonder the differences of these.</p><p>Firstly and directly API Gateway has some capabilities of a reverse proxy and can also include load balancing, but it provides additional API-specific features.</p><p>A Load balancer takes requests from client and directs them to the appropriate backend service instance because if we direct requests randomly , clients may have to wait too long in the queue. While doing this, the load balancer usually does not need to understand the actual content or business logic of the request</p><p>A reverse proxy is a server that sits in front of one or more web servers to intercept and forward requests from clients. It acts as an intermediary, ensuring that no client communicates directly with the origin server.</p><p>You can think of an API Gateway as a reverse proxy with additional API-specific capabilities, and in some architectures, it can also handle load balancing.</p><h3>A Simple AI Architecture</h3><p>This is a simplified view of how an API Gateway fits into an AI backend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJ3_IWL10crze1H2FaBFsg.png" /><figcaption>AI-generated architecture diagram (ChatGPT), reviewed and refined by the author.</figcaption></figure><h3>Conclusion</h3><p>As a result, an API gateway is middleware that hides internal services from clients.It also provides some capabilities such as authentication, authorization , rate limiting, routing and caching.Thinking of it as a cashier analogy would make it more understandable.</p><p><em>I hope you enjoyed reading this blog. You are welcome to </em><a href="https://medium.com/@kaangulergs"><em>follow me</em></a><em> because I write more about System Design!</em></p><h3>References</h3><ul><li><a href="https://konghq.com/blog/learning-center/what-is-an-api-gateway">What Is an API Gateway? How It Works, Benefits &amp; Use Cases</a></li><li><a href="https://www.geeksforgeeks.org/system-design/what-is-api-gateway-system-design/">API Gateway - GeeksforGeeks</a></li><li><a href="https://www.cloudflare.com/learning/security/api/what-is-an-api-gateway/">What is an API Gateway?</a></li><li><a href="https://blog.postman.com/what-is-an-api-gateway/">What is an API Gateway?</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F6ULyxuHKxg8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D6ULyxuHKxg8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F6ULyxuHKxg8%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/61161203d53d6ea7c6464b72def4e0ba/href">https://medium.com/media/61161203d53d6ea7c6464b72def4e0ba/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7726b1e715fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design for AI #2 : Inside an AI Backend: It’s More Than Just an API]]></title>
            <link>https://medium.com/@kaangulergs/system-design-for-ai-2-inside-an-ai-backend-its-more-than-just-an-api-899c31559978?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/899c31559978</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Mon, 27 Jul 2026 21:02:15 GMT</pubDate>
            <atom:updated>2026-07-28T11:35:14.112Z</atom:updated>
            <content:encoded><![CDATA[<p>Building an AI application is much more than sending prompts to an LLM. Behind every response, there is a backend responsible for context, memory, tool calling, and reliable inference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MM3pZrNwdnH9QY47UeEBSA.png" /><figcaption>AI-generated architecture diagram (ChatGPT), reviewed and refined by the author.</figcaption></figure><h3>1. Introduction</h3><p>Before AI applications became part of our daily lives, when people talked about a backend, they usually thought of a traditional backend. A client sends a request, the backend executes some business logic, retrieves data if needed, and returns a response. This architecture still powers countless applications today.</p><p>As AI applications become more popular, however, backend systems have to handle much more than traditional business logic. They need to build context, interact with AI models, call external tools, and stream responses back to users. To support these new responsibilities, modern AI backends introduce additional components on top of the traditional architecture.</p><p>Before exploring those components, let’s first take a quick look at how a traditional backend works.</p><h3>2. Traditional Backend</h3><p>In a traditional backend ,user generally sends a request through an API. There is business logic to proccess requests.If necessary , request queries a database or other services and based on the result it returns a deterministic response .This determinism is key charactristic for traditional backend.Every time you will get same return for same input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i2g9uoSuhsdjrcKngS4HKA.png" /><figcaption>AI-generated architecture diagram (ChatGPT), reviewed and refined by the author.</figcaption></figure><h3>3. Why Traditional Backends Are Not Enough for AI</h3><p>The nature of AI is stochastic and requires a lot of computation so we need some components to keep the responses as stable as possible.For example , AI responses may take time longer than usual and load balancer can think that it is an idle connection so it might shut down the connection if infrastructure isn’t designed for streaming or long-lived connections or an API request returns HTTP 200 but we don’t know whether the response is hallucinated or factually correct. So we need different evaluation methodologies.GPU scheduling and policy-violating responses are other problems.</p><p>Because of these issues , AI applications need some additional components to provide scalable , reliable , and safe AI services.</p><h3>4. What Is an AI Backend ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o_jSiWiN4yvJ5uwyZioapg.png" /><figcaption>AI-generated architecture diagram (Claude), reviewed and refined by the author.</figcaption></figure><p>In an AI backend , we need to manage LLM responses, build context and memory and integrate external tools correctly because we need to ensure that answers are in the correct structured format , maintain memory and context and keep latency as low as possible . We also provide tools for LLMs to access external data.</p><p>To provide these services, we start with API Gateway to send requests.The API gateway basically handles rate limiting, authentication , authorization and routing.</p><p>Then we move to the orchestration layer, which is the brain of the backend logic.It provides guardrails , memory and context building, and tool orchestration.This component works very closely with the data layer which provides databases , vector databases to give more information to model .</p><p>The backend then provides this context, memory, guardrails, and tools to the LLM.</p><p>We have two infrastructure options.One is using managed API and the other one is using self-hosted infrastructure .</p><p>These are the essential components to maintain scalable , reliable and safe AI services.</p><h3>5. Traditional Backend vs AI Backend</h3><p>The following table summarizes the main differences between traditional backend and AI backend.</p><p>Traditional Backend | AI Backend<br> — — — — — — — — — — — — — — — — — — — — — — — — — — — — -</p><p>Business Logic → AI Orchestration<br>Deterministic → Probabilistic<br>Database → Database + Vector DB + Tools<br>Mostly CPU → CPU + GPU<br>Immediate Response → Streaming Response<br>HTTP Status Codes → AI Evaluation &amp; Guardrails</p><p>As you can see AI backend is not an entirely new system. It is an extension of a traditional backend.While AI backend focuses on solving the challenges of stochastic LLMs ,traditional backend focuses on solving deterministic , instant requests.</p><h3>6. Conclusion</h3><p>If you understand traditional backends, you already have the basic knowledge. However, AI systems require you to think about scalability, reliability, and safety. LLMs require guardrails, context, memory, and tools to generate correct and safe responses without violating policies. To achieve this, AI backends introduce components such as an orchestrator, model routing, context and memory builders, and tool integrations, which are not part of a traditional deterministic backend.</p><p><em>I hope you enjoyed reading this blog. You are welcome to </em><a href="https://medium.com/@kaangulergs"><em>follow me</em></a><em> because I write more about System Design!</em></p><h3>7. References</h3><ul><li><a href="https://openai.com/business/guides-and-resources/a-practical-guide-to-building-ai-agents/?utm_source=chatgpt.com">A practical guide to building agents</a></li><li><a href="https://medium.com/@unnatisrivastava0603/from-rest-apis-to-ai-powered-apis-a80ad1628475">From REST APIs to AI-Powered APIs</a></li><li><a href="https://tianpan.co/blog/2026-04-18-ai-native-api-design-rest-probabilistic-llm?utm_source=chatgpt.com">AI-Native API Design: Why REST Breaks When Your Backend Thinks Probabilistically - TianPan.co</a></li><li><a href="https://iii.dev/blog/the-harness-is-the-backend/?utm_source=chatgpt.com">The Harness Is the Backend</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=899c31559978" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design for AI #1 : What Happens When You Click “Send” in ChatGPT?]]></title>
            <link>https://medium.com/@kaangulergs/system-design-for-ai-1-what-happens-when-you-click-send-in-chatgpt-03d99bb50294?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/03d99bb50294</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Fri, 17 Jul 2026 23:32:20 GMT</pubDate>
            <atom:updated>2026-07-17T23:43:44.132Z</atom:updated>
            <content:encoded><![CDATA[<p>You probably just give a prompt about what you want to learn then AI model gives an answer but things under the hood are not simple as you think.If you wonder , let’s dive in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FsmLPmU-IIKIp5i_" /><figcaption>Photo by <a href="https://unsplash.com/@emilianovittoriosi?utm_source=medium&amp;utm_medium=referral">Emiliano Vittoriosi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>Route of Prompts</strong></h3><p>Firstly, You simply write a prompt on the browser . Browser takes this prompt through secure , encrypted connection over HTTPS to door of the OpenAI which is API gateway.API Gateway provides monitoring, Rate limiting, logging, routing and authentication, which checks whether the user is authenticated and checks for validity. Some companies separate authentication service.There is also a load balancer which distributes requests across inference servers so that all the task aren’t given one inference server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*phUxGUVSuByf7iDoqKZggA.png" /><figcaption>AI-generated architecture diagram (Gemini), reviewed and refined by the author.</figcaption></figure><h3>Inside AI Infrastructure</h3><p>Congratulations you could pass the door and you are in provider servers. Firstly, System prompt , User prompt and conversation history have to be gathered.This package is given to the tokenizer which separate the text into tokens.But model doesn’t understand raw texts or tokens so we need to convert them into numerical vectors thanks to model’s embedding layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8xcRyr6JhnptQXI2PpYq7w.png" /><figcaption>AI-generated architecture diagram (Gemini), reviewed and refined by the author.</figcaption></figure><h3><strong>Model</strong></h3><p>Model is based on transformer architecture.Instead of reading words one by one , The transformer compares every token with every relevant token using self attention and at every step , the model predicts next token based on all previous tokens.Due to probabilistic nature , models may produce hallucinated responses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2liVe9Edeiw_JNaw.png" /></figure><h3>Streaming Back</h3><p>People are impatient and love feeling real conversation so model doesn’t wait until the last token is generated.It starts sending the answer when tokens are generated.This process is called streaming.So user can see answers like how people talk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6qgGUlk6En74xTXTivxaNw.png" /><figcaption>AI-generated architecture diagram (Gemini), reviewed and refined by the author.</figcaption></figure><h3>Optional Tool Usage</h3><p>Models are trained on data so they don’t know what is going on now.Let’s assume that we ask the model about weather.Model doesn’t know it so we give some APIs to search for weather information and when learn the answer, model put returned weather information into final output .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MIf_LMx3p6JNBh6YeOWYoA.png" /><figcaption>AI-generated architecture diagram (Gemini), reviewed and refined by the author.</figcaption></figure><h3>System Overview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D7pH99384oH_2kN5xOSs-A.png" /><figcaption>AI-generated architecture diagram (ChatGPT), reviewed and refined by the author.</figcaption></figure><h3>References</h3><ul><li><a href="https://blog.bytebytego.com/p/what-actually-happens-when-you-press">What Actually Happens When You Press &#39;Send&#39; to ChatGPT</a></li><li><a href="https://machinelearningmastery.com/the-transformer-model/">The Transformer Model - MachineLearningMastery.com</a></li></ul><p>If you enjoyed this article and want to see more AI System Design content, feel free to clap and follow for the next part of the series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03d99bb50294" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LLM Streaming, Part 2: I Built the Same Stream Three Ways, Then Threw 10,000 Users at It]]></title>
            <link>https://medium.com/@kaangulergs/llm-streaming-part-2-i-built-the-same-stream-three-ways-then-threw-10-000-users-at-it-fd7bddd5f7d0?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd7bddd5f7d0</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Sat, 11 Jul 2026 18:42:36 GMT</pubDate>
            <atom:updated>2026-07-11T18:42:36.777Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rj3EqC9H6bihQNi6hsVF2w.png" /></figure><p><em>A hands-on follow-up to </em><a href="https://medium.com/@kaangulergs/understanding-llm-streaming-polling-sse-and-websockets-7fb14fd3b69b"><strong><em>Understanding LLM Streaming: Polling, SSE, and WebSockets</em></strong></a><em>. Part 1 explained the ideas. This one is me putting them to the test, and being a little surprised.</em></p><p>Part 1 walked through the three ways to stream tokens from an LLM (polling, SSE, and WebSockets), and why SSE tends to be the natural fit for one-way text generation. What it didn’t have was a single number. It was all concepts and diagrams; I never put a stopwatch on any of it.</p><p>This time I did. I built all three transports (polling, SSE, WebSockets), fed them the exact same token stream, and measured everything: first-token time, total time, request count, bytes, even server CPU and memory. Polling shows up in two forms, short and long, and I built both, so there were really four horses in this race. A tiny FastAPI backend, one HTML file, no React, no Docker. First with one user, then, because I got curious, with ten thousand.</p><p>A couple of the results caught me off guard.</p><h3>The setup</h3><p>Everything runs against the same fake “model”: a fixed 10-token stream where <strong>each token takes 300 ms to generate</strong>, simulated with an asyncio.sleep, not a real GPU. That’s the whole point: this benchmark measures <em>transport</em>, not inference. Every protocol is handed the exact same token schedule, so nothing here is a claim about how fast a model runs, only about the pipe you run it through.</p><p>The reason that 300 ms matters so much comes down to how a real model works. It writes its answer one token at a time, in order. Token #5 simply doesn’t exist yet while the model is still busy on token #3. Ask for it early and there’s nothing to hand back; it hasn’t been written. This benchmark enforces exactly that: if a token hasn’t been generated yet, nobody gets it, no matter which transport is asking. That one rule is what makes the comparison meaningful.</p><pre>TOKENS = [&quot;Hello&quot;, &quot;world&quot;, &quot;,&quot;, &quot;this&quot;, &quot;is&quot;, &quot;a&quot;, &quot;streamed&quot;, &quot;LLM&quot;, &quot;response&quot;, &quot;.&quot;]<br>DELAY_MS = 0.3  # simulate 300 ms of &quot;thinking&quot; per token</pre><p>The demo puts four panels side by side, all streaming the same sentence, with a live metrics table running underneath, so every contender races in one view.</p><p><strong>A fair fight.</strong> For the comparison to mean anything, the <em>only</em> thing that changes between the runs is the transport. Everything else is held identical: the same token generator, the same 300 ms delay, the same FastAPI backend, the same machine, the same browser, the same JSON serialization, the same payload. Nobody gets a head start, and nothing is measuring the “model.”</p><p><strong>Test environment.</strong> For the numbers to be reproducible: one uvicorn worker (single process, no --workers), FastAPI 0.104 / Starlette 0.27 on <strong>Python 3.11</strong>, <strong>Windows 10</strong>, a <strong>6-core / 12-thread</strong> CPU with <strong>16 GB RAM</strong>. The load generator is thread-per-client running on the same box. Deliberately modest: the point isn’t the absolute milliseconds, it’s the <em>ratios</em> between transports, and those hold whatever hardware you run this on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I5vX2JnDyPD87JhG5synKA.png" /><figcaption>Short poll, long poll, SSE and WebSocket, all streaming the same sentence side by side</figcaption></figure><p>Now to build them.</p><h3>Polling</h3><p>Polling is beautifully dumb, and I mean that with affection. The client just keeps knocking on the door: <em>got the next token yet? … how about now? … now?</em></p><p>Part 1 split polling in two. <em>Short</em> polling asks again on a fixed timer. <em>Long</em> polling makes the server hold each request open until it has a token to hand back. I built both, and they behave differently enough that they earn separate rows in every table below. Short polling first, since it’s the simpler of the two.</p><p>The tricky part was making it <em>fair</em>. The token you ask for should only become available once it’s been “generated.” So the server withholds it: the client sends back a start time t0, and the server checks whether the token you’re asking for has been produced yet.</p><pre>@app.get(&quot;/poll&quot;)<br>def poll(index: int = 0, t0: float = 0.0):<br>    now = time.time()<br>    if not t0:<br>        t0 = now  # first knock starts the clock</pre><pre>    if index &gt;= len(TOKENS):<br>        return {&quot;done&quot;: True, &quot;ready&quot;: True, &quot;t0&quot;: t0}</pre><pre>    # token `index` doesn&#39;t exist until t0 + (index + 1) * 300ms<br>    if now &lt; t0 + (index + 1) * DELAY_MS:<br>        return {&quot;token&quot;: None, &quot;ready&quot;: False, &quot;t0&quot;: t0}   # nothing yet, a wasted poll</pre><pre>    return {&quot;token&quot;: TOKENS[index], &quot;ready&quot;: True, &quot;index&quot;: index + 1, &quot;t0&quot;: t0}</pre><p>And the client just won’t stop asking:</p><pre>let index = 0, t0 = 0;<br>const poll = async () =&gt; {<br>  const { token, ready, index: next, done, t0: start } = await (<br>    await fetch(`/poll?index=${index}&amp;t0=${t0}`)<br>  ).json();<br>  t0 = start;<br>  if (ready &amp;&amp; token) { appendToken(token); index = next; }<br>  if (!done) setTimeout(poll, 300);<br>};</pre><p>The moment you open the Network tab, one thing jumps out: <strong>a dozen </strong><strong>poll?index=N rows for a ten-word sentence.</strong> Those twelve break down like this: ten of them each land a token; one arrives a hair early and comes back empty (the token just wasn’t ready yet); and a final request asks for token #11 and gets done. Ten useful, two pure overhead. Those empties even have a name: <em>wasted polls</em>. A full round trip, and the server had nothing to give you.</p><h3>Long polling: smarter, but not a cure</h3><p>Part 1 called long polling “smarter than short polling,” and it is. The client stops knocking on a timer. Instead the <em>server</em> holds the request open until the token is actually ready, then answers, and the client asks again the moment it gets a reply.</p><pre>@app.get(&quot;/longpoll&quot;)<br>async def longpoll(request: Request, index: int = 0, t0: float = 0.0):<br>    ready_at = t0 + (index + 1) * DELAY_MS       # when this token finishes generating<br>    while time.time() &lt; ready_at:                # hold the request open until it exists<br>        if await request.is_disconnected():<br>            return {&quot;token&quot;: None, &quot;ready&quot;: False}   # client left -&gt; stop waiting<br>        await asyncio.sleep(ready_at - time.time())<br>    return {&quot;token&quot;: TOKENS[index], &quot;ready&quot;: True, &quot;index&quot;: index + 1, &quot;t0&quot;: t0}</pre><p>The client loop is the short-polling loop with the timer deleted:</p><pre>const longpoll = async () =&gt; {<br>  const { token, index: next, done } = await (<br>    await fetch(`/longpoll?index=${index}&amp;t0=${t0}`)<br>  ).json();<br>  if (token) { appendToken(token); index = next; }<br>  if (!done) longpoll();          // no setTimeout: the server already did the waiting<br>};</pre><p>Two things change immediately. The empty responses vanish, because the server never says “not ready,” it just waits. And first-token latency drops to the generation cadence with no interval to tune. On one user, long polling ties SSE and WebSocket on latency and total time, with zero wasted polls.</p><p>But look at what <em>doesn’t</em> change: it’s still one HTTP request per token. Short polling fired a dozen; long polling fires eleven. Both are a world away from SSE and WebSocket’s single connection. Long polling fixes short polling’s two ugliest symptoms, latency and waste, and leaves the underlying condition untouched: the request count still grows with tokens, not with one stream. Hold that thought for the scaling test, where it turns into the whole story.</p><h3>SSE</h3><p>Server-Sent Events sounds fancier than it is. It’s just one HTTP response that the server keeps writing to instead of closing. That’s the whole idea, and it’s also what OpenAI, Anthropic, and Cohere stream over. You’ve been on the receiving end of SSE every time you watched ChatGPT type.</p><pre>async def sse_generator(request: Request, start: int = 0):<br>    yield &quot;retry: 3000\n\n&quot;                        # how long to wait before reconnecting<br>    for i in range(start, len(TOKENS)):<br>        await asyncio.sleep(DELAY_MS)              # simulate generating this token<br>        if await request.is_disconnected():<br>            return                                # nobody&#39;s home -&gt; stop<br>        yield f&quot;id: {i}\n&quot;<br>        yield f&quot;data: {json.dumps({&#39;token&#39;: TOKENS[i], &#39;index&#39;: i + 1})}\n\n&quot;</pre><p>And the client is almost embarrassingly small:</p><pre>const es = new EventSource(&#39;/sse&#39;);<br>es.onmessage = (e) =&gt; {<br>  const { token } = JSON.parse(e.data);<br>  if (token) appendToken(token);<br>};</pre><p>Two little lines in there are the difference between a demo and something you’d actually ship.</p><p>That id: on every event lets the stream <strong>resume itself</strong>. When the connection drops on flaky train Wi-Fi, the browser reconnects, tells the server the last id it saw, and picks up where it left off. You wrote zero code for that.</p><p>And request.is_disconnected() means the server <strong>stops generating the moment you close the tab</strong>. On a real model, that’s GPU money you just stopped burning on someone who already left.</p><p><strong>One production gotcha worth knowing.</strong> A yield doesn’t guarantee the byte actually leaves the building. Put an nginx (or most reverse proxies) in front, and it may happily <em>buffer</em> your whole response and deliver it in one lump, turning a smooth token trickle into a single late splat. The fix is telling the proxy to stop: the endpoint above already sends X-Accel-Buffering: no, and on the nginx side you’d set proxy_buffering off. If your streaming “works locally but batches in production,” this is almost always why.</p><p>There’s also a quieter ceiling: under HTTP/1.1 a browser allows only ~6 concurrent connections per origin, and an open EventSource holds one of those for its entire life. That’s a non-issue for an LLM chat (one stream per tab), but fan out a dozen SSE streams to the same host and the seventh just sits there waiting. HTTP/2 (connection multiplexing) makes the limit disappear.</p><p>In the Network tab, this whole thing is <em>one row</em>. Type: eventsource. One connection, tokens trickling down it. Compare that to the dozen rows polling left behind.</p><h3>WebSockets</h3><p>For plain token streaming, WebSockets are overkill. But they can do one thing SSE can’t: let the client interrupt mid-stream.</p><p>Think about the <strong>Stop</strong> button in every serious chat UI. You hit it halfway through a rambling answer and generation stops. That button only works because of a WebSocket. SSE can’t do it, because SSE only knows how to talk in one direction.</p><pre>@app.websocket(&quot;/ws&quot;)<br>async def websocket_endpoint(websocket: WebSocket):<br>    await websocket.accept()<br>    cancelled = asyncio.Event()<br><br>    async def listen_for_cancel():<br>        while not cancelled.is_set():<br>            msg = await websocket.receive_text()<br>            if &quot;cancel&quot; in msg.lower() or &quot;stop&quot; in msg.lower():<br>                cancelled.set(); return<br><br>    listener = asyncio.create_task(listen_for_cancel())<br>    try:<br>        for i, token in enumerate(TOKENS):<br>            await asyncio.sleep(DELAY_MS)<br>            if cancelled.is_set():<br>                await websocket.send_json({&quot;cancelled&quot;: True}); break<br>            await websocket.send_json({&quot;token&quot;: token, &quot;index&quot;: i + 1})<br>    finally:<br>        cancelled.set(); listener.cancel()   # skip this and you leak a task per connection</pre><pre>const ws = new WebSocket(`ws://${location.host}/ws`);<br>ws.onmessage = (e) =&gt; {<br>  const { token } = JSON.parse(e.data);<br>  if (token) appendToken(token);<br>};<br>stopBtn.onclick = () =&gt; ws.send(&#39;cancel&#39;);   // the move SSE can&#39;t make</pre><p>But there’s a bill, and it comes due in complexity. Now <em>you</em> own reconnection. You own the connection lifecycle. You own that cleanup in the finally: forget it, and you’re leaking a background task on every connection until your server falls over. So my rule of thumb: reach for WebSockets only when you actually need the client to talk back.</p><h3>The first token is a tie</h3><p>One user, ten tokens, 300 ms each. The numbers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*465uRKlhhiuohiHMAu_C3g.png" /><figcaption>The first token is a tie — single-user metrics for short poll, long poll, SSE, and WebSocket</figcaption></figure><p>Look again at the TTFT row. <strong>All four land in the same ~300 ms ballpark.</strong></p><blockquote><strong><em>The fastest transport wasn’t actually faster.</em></strong></blockquote><p>That was the first result that caught me off guard.</p><p>In this benchmark, your time-to-first-token is set mostly by how long the <em>model</em> takes to produce token one, far more than by the transport carrying it. Every token in my demo costs 300 ms to make, and the transport adds only a few dozen milliseconds on top (a little more for short polling, which has to <em>find</em> the token on a later knock), so the first one shows up in the low 300s of milliseconds whether you’re short-polling or holding a WebSocket open. <strong>Here, transport is a rounding error next to generation time.</strong> The first token lands when the model has written it, not a moment sooner because you reached for a fancier pipe.</p><p>Transport isn’t quite free. In real production, TLS handshakes, reverse-proxy buffering, HTTP framing and CDN hops all pile onto TTFT — but they pile onto <em>every</em> transport. The pecking order doesn’t flip; the absolute numbers just drift upward together.</p><p>What the transport <em>does</em> change is everything that happens <strong>after</strong> that first token, and that’s where polling starts to struggle:</p><p><strong>It wastes work.</strong> Short polling fires twelve requests for ten tokens, one empty-handed. Long polling trims the empties but still spends eleven. SSE and WebSocket: one connection, nothing wasted.</p><p><strong>Short polling is slower overall.</strong> It limps in ~480 ms behind the fast pack, because the client’s 300 ms rhythm and the server’s never quite line up, so every token pays a little phase tax. Long polling skips it by holding the request open and handing over each token the instant it’s ready. That’s the tokens/sec spread: ~2.8 for short polling against ~3.3 for everyone else.</p><p><strong>Both kinds of polling haul more bytes.</strong> Short polling ships roughly double the data even for one user, and long polling barely helps (~1.07 KB against ~1.17 KB), because it still sends a separate response per token. And that number <em>flatters</em> polling: I count only the application payload the client receives, not the HTTP headers each per-token request drags along. (HTTP/2 compresses those headers and reuses the connection, but can’t delete the requests themselves.)</p><p>SSE’s real advantage shows up after the first token. And long polling, clever as it is, is still polling underneath — as the scaling test is about to make painfully clear.</p><h3>Does it scale?</h3><p>One user is a warm-up. The question I really wanted answered was: what happens when everybody shows up at once? So I cranked it: 10, then 100, then 1,000, then 10,000 users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XrqYq44CFS_wY49iwZCORw.png" /><figcaption>Six metrics from 10 to 10,000 users — polling versus SSE and WebSocket</figcaption></figure><p><em>Six metrics from 10 to 10,000 users. Watch the two polling lines climb together, far above SSE and WebSocket.</em></p><p>Two things jump out, and they pull in opposite directions.</p><p><strong>Request count is the whole story, and long polling doesn’t escape it.</strong> At 10,000 users, short polling fired <strong>~103,000 requests</strong> and long polling <strong>~94,000</strong>, the same order of magnitude, because both spend exactly one request per token. SSE and WebSocket did the identical work with <strong>~8,600 connections</strong> each. That’s roughly <strong>11–12×</strong> the traffic, and you can’t tune it away: it’s baked into asking per token instead of holding one stream open. On the log-scaled chart the two polling lines rocket up together while SSE and WS lie flat along the bottom. This is where long polling’s cleverness runs out: it buys SSE-class latency, but it’s still polling underneath.</p><blockquote><strong><em>Polling’s cost is structural.</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UBiajBccEvdzr84-lEKYFQ.png" /><figcaption>Request count as users scale — polling floods the server while SSE and WebSocket stay flat</figcaption></figure><p><strong>On raw speed, though, long polling runs with the leaders.</strong> Total response time splits into a fast pair and a slow pair: WebSocket and long polling up front, SSE and short polling behind. WebSocket and long polling trade the lead the whole way (~6,400 ms at 10,000 users); SSE trails around ~8,000 ms and short polling brings up the rear near ~10,000 ms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UpvsUPpG8CwTiOYE_kKDEw.png" /><figcaption>Total response time as users scale — WebSocket and long poll lead, short poll trails</figcaption></figure><p>Why does SSE, of all things, land in the slow pair? Framing overhead. It isn’t that a WebSocket or a long poll makes the model faster; the tokens are byte-for-byte identical. SSE wraps every event in text/event-stream structure (id:, data:, a blank-line terminator) as UTF-8 text the browser re-parses per event, while a WebSocket frame is a thinner binary envelope and long polling’s replies are compact JSON. Tiny per token, but multiply it across a stampede and it shows up in the totals. So long polling posts great <em>times</em>, while firing an order of magnitude more requests than SSE to get them. Pick your poison.</p><p><strong>And TTFT still doesn’t depend on your transport.</strong> All four first-token lines stay stacked right on top of each other the entire climb. When they rise together past 1,000 users, that’s congestion, which is where this needs a caveat.</p><h3>What this benchmark leaves out</h3><p>A few things it leaves out are worth naming.</p><p><strong>Those “10,000 users” were never 10,000 <em>at the same time</em>.</strong> My load tool spins up one thread per client and eases them in gradually, so real concurrency tops out around 180. Which means a bigger number is mostly a <em>longer</em> test at the same load, not a heavier punch. That’s why latency, throughput, and error rate all go flat after 1,000, while only the cumulative stuff (total requests, traffic, wasted polls) keeps climbing.</p><p><strong>And those ~13% errors past 1,000 users?</strong> That’s my test rig hitting its ceiling, not the transports themselves failing. One uvicorn worker, one process, a thread-based load generator running flat out. Put this on real production infra (multiple workers, async top to bottom) and that ceiling jumps way up.</p><p>None of that saves polling, though. The request explosion and the mountain of wasted polls are <em>baked into how it works</em>. On beefier hardware they don’t shrink. They just get more embarrassing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofDoB-LvDuA4XInL6LwyWQ.png" /><figcaption>Every metric across the load sweep — eight panels including CPU and wall-clock time</figcaption></figure><p><em>Every metric, if you want the full picture.</em></p><h3>What it costs the server</h3><p>Time and throughput are only half the bill. The other half is what each transport does to the box it runs on, and to measure <em>that</em> cleanly I ran a second, quieter experiment: each transport alone, against a freshly-restarted server, sampling the server process’s own CPU and memory the whole time. (Restarted between transports on purpose: memory doesn’t fully hand itself back between runs, and I didn’t want one transport’s leftovers billed to the next.)</p><p>There isn’t one winner here. There’s a <em>trade-off</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*toyVUTh1B_TImqqCVp5Etg.png" /><figcaption>Server cost at 1,000 users — WebSocket cheap on CPU but heavy on memory, polling the opposite</figcaption></figure><p><strong>On CPU, the polling family are the gluttons.</strong> Long polling burned the most, roughly <strong>8× WebSocket’s CPU</strong>, with short polling close behind at ~6×. Every request, empty-handed or not, is a full request the server has to wake up, route, and answer, and long polling’s habit of re-asking the instant it gets a reply keeps the server busiest of all. WebSocket barely registers: once the connection’s open, pushing a token down it is nearly free.</p><p><strong>On memory, the ranking flips.</strong> WebSocket’s open connections cost the most resident memory: each one is a live object with its own buffers and state the server has to keep around. The polling family is the opposite: they hold almost nothing between requests, so their footprint barely lifts off the baseline, and long polling’s is the lightest of all. SSE lands in the middle again.</p><p>So “WebSocket wins” was too glib. WebSocket trades <strong>memory for CPU</strong>; the polling family trades <strong>CPU for memory</strong>, long polling most extremely of all; SSE stays moderate on both. If you’re CPU-bound, the open-connection transports are a gift. If you’re memory-bound and holding a <em>lot</em> of idle connections, that WebSocket number is the one to watch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SQTO0XFPRb5Kb45rLNyy6A.png" /><figcaption>CPU average, CPU peak, and peak memory per transport at the 1,000-user load</figcaption></figure><p><em>CPU vs memory: the two rankings point opposite ways.</em></p><h3>How often should short polling poll?</h3><p>One more thing, and it’s short polling’s problem alone. My client knocks every 300 ms — suspiciously close to the model’s 300 ms per-token rhythm. So I swept it: same 100 users, only the poll interval moving from 50 ms to a full second.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZlHlfQQc7WGITG2JNYyKzQ.png" /><figcaption>Short-polling interval sweep — 300 ms matches the model’s cadence and wins almost everywhere</figcaption></figure><p>Poll <em>fast</em> and you get snappy latency, but look at the price: <strong>3,452 requests, 2,352 of them wasted, triple the bytes, and a matching spike in server CPU.</strong> Poll <em>slow</em> and it all gets cheap, but the stream turns to sludge: at one-second polls the whole response drags out past <strong>11 seconds</strong>, and even the first token limps in over a second late, because you keep discovering ready tokens long after they exist.</p><p>Notice where TTFT bottoms out: right around <strong>300 ms</strong>, where the interval matches the generation cadence. Finer than that just buys wasted polls; coarser and TTFT climbs with the interval. So the tidy default wasn’t a cheat: it’s the sweet spot. But it also makes polling’s whole case <em>worse</em>: to get SSE-like latency you have to poll aggressively, and aggressive polling is exactly what makes the request-and-CPU bill balloon. There’s no interval that gives you low latency <em>and</em> low overhead. SSE just hands you both. Long polling sidesteps the trap too — no interval to pick — though it still can’t shrink the request count.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XFlXfNcoDl_EvVjbR9gGVA.png" /><figcaption>Six panels sweeping the short-polling interval</figcaption></figure><p><em>Faster polling buys latency with requests, CPU and wasted work. TTFT bottoms out at the ~300 ms generation cadence.</em></p><h3>Which one should you use?</h3><p><strong>Default to SSE.</strong> Token streaming, notifications, feeds, tickers: anything flowing server → client. It’s plain HTTP, it reconnects itself, it’s already what the big LLM APIs speak, and it costs you one connection per user. Nine times out of ten, this is the answer, and you can stop reading here.</p><p><strong>Reach for WebSockets when the client needs to talk back.</strong> A live <strong>Stop</strong> button is the smallest example; the real cases are collaborative editing, multiplayer game state, cursor and presence sync, telemetry upload, and voice or other binary streaming: anything where the client is a <em>sender</em>, not just a receiver. You’ll pay for it in connection-management headaches (and in memory, since every open socket is state your server holds), so only pay when you truly need that upstream channel.</p><p><strong>Leave polling in the drawer, both kinds.</strong> If you’re stuck somewhere SSE won’t run, reach for <em>long</em> polling over short: same request cost, but SSE-class latency and no wasted knocks. For actual token streaming, though, both flood your server with one request per token, and now you’ve seen the numbers. Short polling is a fine fallback only for data that barely moves.</p><h3>The takeaways</h3><p>Part 1 pointed at SSE with diagrams. Part 2 backs it with a stopwatch:</p><ul><li><strong>First-token latency is the model’s job, not the transport’s.</strong> Pick your pipe for efficiency and smoothness, not for a first token that was never going to arrive any sooner.</li><li><strong>Polling’s cost is structural, and long polling doesn’t fix it.</strong> Long polling buys SSE-class latency and kills the wasted knocks, but it still fires one request per token: ~94,000 at 10,000 users against SSE and WebSocket’s ~8,600. The request explosion is the whole family’s birthmark.</li><li><strong>Cost isn’t one number.</strong> The polling family is CPU-hungry (all those requests), WebSocket is memory-hungry (all those open connections), SSE is easy on both, one more reason it’s the sensible default.</li><li><strong>SSE is the sweet spot</strong> for one-way streaming. <strong>WebSockets</strong> earn their keep only when the client has something to say back.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd7bddd5f7d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding LLM Streaming: Polling, SSE, and WebSockets]]></title>
            <link>https://medium.com/@kaangulergs/understanding-llm-streaming-polling-sse-and-websockets-7fb14fd3b69b?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fb14fd3b69b</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Wed, 08 Jul 2026 00:42:12 GMT</pubDate>
            <atom:updated>2026-07-08T00:42:12.194Z</atom:updated>
            <content:encoded><![CDATA[<h3>LLM Streaming</h3><p>LLM Streaming is useful when you want to improve user experience by reducing waiting time. Normally, the user has to wait for LLM response but when we use LLM streaming we can give response part by part when generated.</p><p>Let’s imagine that user asks a question that takes 1 minute to generate response. User might not be patient enough to wait or think that there is a problem.When users receive the response as it is generated, they understand that the system is working. And it is a good choice for UX.</p><h3>How does LLM Streaming Work</h3><p>LLMs generate responses token by token, and when we don’t use streaming, the backend waits until the entire response has been generated before sending it to the frontend because LLMs do not have direct access to the frontend. With streaming, tokens are immediately sent to the backend as soon as they become available and then displayed on the frontend. This requires streaming in two stages: from the LLM to the backend, and from the backend to the frontend.</p><h3>How can you stream data to users</h3><p><strong><em>There are several techniques for streaming data to the frontend.</em></strong></p><p><strong>Polling</strong></p><p>In polling, frontend always asks backend to check whether new tokens are available , backend sends them to frontend.There are two types of polling strategy : short polling and long polling.</p><p>In short polling frontend sends a request at certain intervals.This is problematic because we can’t get responses when they are generated.But it is the one of the simplest solutions</p><p>Long polling is smarter than short polling. The frontend sends a request to the backend and waits until new tokens are generated. Once the new tokens are sent, the frontend sends another request.</p><p>Polling is easy to implement but frontend has to send request and this leads to delay to get new data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nug7Bm5LbdtURXaFXkIaPg.jpeg" /></figure><p><strong>Server side events</strong></p><p>It provides real time communication. Initially frontend send an HTTP request once then backend sends response parts when they are generated.Connection remains open until final chunk is sent and it is unidirectional connection except initilazition.Text generation is ideal case because SSE is designed for small chunk of data packages. It reduces network traffic establishing only one connection.Binary data like images and audio is not efficient because it has to convert them to base64 and this process increase the size of files and encoding and decoding operations are also extra costs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8wOt0H1NIOeD5rp6reYciQ.png" /></figure><p><strong>Websockets</strong></p><p>It is very similar to SSE but it supports bidirectional communication which means that frontend and backend can send requests each other if handshake is succesful.Chatbots or audio calls might be a good choice othherwise one sided LLM generation tasks would be overkill.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d3VIFeG-hVeYGsjdtFqY3Q.png" /></figure><p><strong>Advantages of LLM streaming</strong></p><p><em>User Experience : Users can see outputs when they are generated so that (</em>impatient) <em>users can understand that system is working</em></p><p><em>Latency : </em>Users can start reading the response immediately instead of waiting for the entire output.</p><p><em>Earlier Interruption: </em>User can stop generation if they don’t like the generated outputs.</p><p><em>More Interactive apps: </em>Makes applications feel more natural and conversational.</p><p><strong>Disadvantages of LLM streaming</strong></p><p><em>More Complexity : </em>There is a need to think about the pipeline between the LLM, backend, and frontend.</p><p><em>Error Handling : </em>If the connection error occurs during generation, partially generated tokens must be handled correctly</p><p><em>Content Moderation Challenges : </em>Before full response was checked , harmful content may have been sent.</p><p><em>Infrastracture Issues : </em>Long-lived connections consume server resources and require proper timeout and connection management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fb14fd3b69b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Turning a Single Camera Into a Basketball Analytics System]]></title>
            <link>https://medium.com/@kaangulergs/turning-a-single-camera-into-a-basketball-analytics-system-ff6308054288?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff6308054288</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[basketball]]></category>
            <category><![CDATA[sports-analytics]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Mon, 22 Dec 2025 13:16:38 GMT</pubDate>
            <atom:updated>2025-12-22T13:16:38.942Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qR2egke9TfnIP2AKpBE1iw.png" /><figcaption><strong>I used videos from the following YouTube channel as my dataset:</strong><br> <a href="https://www.youtube.com/@whoisai">https://www.youtube.com/@whoisai</a></figcaption></figure><p>Imagine taking 300 shots during a basketball practice.<br> When the workout ends, what you usually walk away with is just a feeling:</p><blockquote>“It was okay today.”</blockquote><p>But was it really?<br> How many shots did you take?<br> How many did you make?<br> Which spots were you better at?<br> And most importantly, is your performance actually improving over time?</p><p>Most of the time, these questions are either never recorded or tracked using pen and paper in a very tedious way.<br>That is exactly where this idea started:</p><blockquote>Can we build a system that automatically counts basketball shots and generates meaningful statistics using only a camera?</blockquote><h4>How Did the Idea Come Up?</h4><p>If you look at existing basketball analytics solutions, most of them rely on:</p><ul><li>smart basketballs,</li><li>sensor-equipped hoops,</li><li>or expensive hardware setups.</li></ul><p>They can be effective, but they’re <strong>not accessible to everyone</strong>.</p><p>My goal was much simpler:</p><blockquote><strong><em>Minimum equipment, maximum insight.</em></strong></blockquote><p>That means:</p><ul><li>a regular camera (even a phone camera),</li><li>a computer running the system,</li><li>and a computer vision pipeline working in the background.</li></ul><p>The system analyzes the live video feed, detects the ball and the hoop, tracks the ball’s motion, and finally answers a very simple question automatically:</p><blockquote><em>“Was this shot made or missed?”</em></blockquote><h4><strong>Not Just Training: Supporting 1v1 Games</strong></h4><p>Although the original motivation was <strong>shot counting</strong>, I realized something important while developing the system:</p><blockquote><em>The same infrastructure naturally supports tracking </em><strong><em>1v1 basketball games</em></strong><em>.</em></blockquote><p>Why? Because the system already:</p><ul><li>tracks the ball,</li><li>detects the hoop,</li><li>determines whether a shot is made.</li></ul><p>Once you also detect <strong>two players on the court</strong>, the following becomes possible:</p><ul><li>separate shot counts for each player,</li><li>basic score tracking,</li><li>automatic post-game summaries.</li></ul><p>So this project is not only a training analytics tool, but also a <strong>camera-based, hardware-free 1v1 game tracking system</strong>.</p><h4>Who Is This System For?</h4><p><strong><em>Individual Players</em></strong></p><p>After a workout, a player can automatically get answers to:</p><ul><li>Total shots taken</li><li>Shots made</li><li>Shooting percentage</li><li>Performance trends over time</li></ul><p><strong><em>Coaches and Teams</em></strong></p><ul><li>Comparing shooting performance across different drills</li><li>Observing how performance changes throughout a practice session</li><li>Identifying strengths and weaknesses with objective data</li></ul><p><strong><em>1v1 Games &amp; Pickup Basketball</em></strong></p><ul><li>Player-based score tracking</li><li>Automatic game summaries</li><li>No need to manually keep score</li></ul><p>All of this works with <strong>no additional hardware</strong>, just a camera.</p><h4><strong>How Does the System Work? (High-Level)</strong></h4><p>At a high level, the system follows these steps:</p><ol><li>Capture live video from a camera</li><li>For each frame, detect:</li></ol><ul><li>the basketball,</li><li>the hoop,</li><li>the players</li></ul><p>3. Track the basketball consistently across frames</p><p>4. Analyze the relationship between the ball and the hoop</p><p>5. Automatically decide whether the shot was made</p><p>6. Store the result and update statistics</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YOYtdkFw6rXroHX1tVLvFA.png" /></figure><p>Technical details will be covered in depth in the next parts of the series.</p><h4>What Does This Enable Long-Term?</h4><p>As data accumulates over time, the system can provide:</p><ul><li>Daily / weekly / monthly performance comparisons</li><li>Zone-based shooting analysis</li><li>Data-driven training planning</li></ul><h4>What Will This Series Cover?</h4><ul><li>How the dataset was created from real basketball footage</li><li>How the basketball and the hoop are detected</li><li>How the ball is tracked across frames</li><li>How players are tracked in 1v1 scenarios</li><li>How the system determines whether a shot is made or missed</li><li>How edge cases such as airballs, rebounds, and blocks are handled</li></ul><h4>Final Thoughts</h4><p>This project is more than just a basketball app for me. It’s a practical demonstration of how <strong>computer vision and object tracking can create real value in a real-world sports problem</strong>.</p><p>If you’re interested in sports analytics, computer vision, or data-driven training systems, the next parts will go much deeper into the technical details.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff6308054288" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RAG 101]]></title>
            <link>https://medium.com/@kaangulergs/rag-101-cf4b00d39955?source=rss-ccc7ec328f05------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf4b00d39955</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[agentic-rag]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[vector-embeddings]]></category>
            <dc:creator><![CDATA[Kaanguler]]></dc:creator>
            <pubDate>Fri, 14 Nov 2025 23:30:16 GMT</pubDate>
            <atom:updated>2025-11-14T23:51:12.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LMtAsIGmRj4_HUuc" /><figcaption>Photo by <a href="https://unsplash.com/@knnslens?utm_source=medium&amp;utm_medium=referral">Kankan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><em>Everyone talks about RAG, and if you don’t know what they are talking about, this writing is for you.</em></blockquote><p>Firstly, I want to explain RAG in simple terms then i will give you a more technical perspective.</p><h3>Simple Explanation</h3><p>We all use LLMs such as ChatGPT, Gemini, and Grok. They are actually pretrained models and they don’t cover new information or your specific queries so we need to find different solutions to figure out this problem. What if we upload an external data source? Can it solve the problem? Absolutely yes! Without training , we can receive new information from this external source and produce new answer based on this source.Actually this is basic idea behind RAG</p><h3>Technical Explanation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*P0PYY39GFht3jgCQmQh_JQ.png" /><figcaption>RAG Pipeline</figcaption></figure><p>Training LLMs is expensive so we rely on LLMs’ prior knowledge and give them new information which can be anything like documents or images. But LLMs can’t understand PDFs or other documents directly so we need to convert them so that LLMs and machines can understand. To do this, we chunk the texts or images, then apply embeddings to convert them into vectors that machines can understand. This is the same thing, as in the example below. We convert sentence to vector.</p><p>“Large language models understand text by converting it into numerical vectors.”<br> ↓<br>[0.15, -0.32, 0.88, 0.04, -0.21, 0.61, 0.03, 0.27, -0.55, 0.09]</p><p>After this embedding process , we send them to a vector database to find closest results. We do this because we don’t want to get every result. It would be very slow. After that ,the user sends a query to the LLM and the LLM searches for relevant chunks and finds closest results with related to prompt .We use <strong>cosine similarity </strong>or <strong>Euclidean distance</strong> to find these closest results. These are actually the top-k chunks and LLM use these chunks to answer.Final step is to respond based on external sources.</p><p>I hope this writing helps you understand the general idea. In the next article, I plan to provide more specific information about each component of the system, such as vector databases, embeddings, chunking, and similarity search.</p><p>See you later. BE HAPPY !</p><p><strong>KAAN GÜLER</strong><br><em>Computer Engineer</em></p><p>Connect with me on <em>LinkedIn </em>(<a href="https://www.linkedin.com/in/g%C3%BClerkaan/">www.linkedin.com/in/gülerkaan</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf4b00d39955" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>