<?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 Ganesh Kumar on Medium]]></title>
        <description><![CDATA[Stories by Ganesh Kumar on Medium]]></description>
        <link>https://medium.com/@ganeshkumarprofession?source=rss-17c2bb50062c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SksPE2DmySVpDN2x0t7bSA.jpeg</url>
            <title>Stories by Ganesh Kumar on Medium</title>
            <link>https://medium.com/@ganeshkumarprofession?source=rss-17c2bb50062c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 05:40:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ganeshkumarprofession/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[How I Reduced AI Coding Agent Token Waste by 70%]]></title>
            <link>https://medium.com/@ganeshkumarprofession/how-i-reduced-ai-coding-agent-token-waste-by-70-f0e7d4a8d215?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0e7d4a8d215</guid>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 30 Aug 2026 16:22:51 GMT</pubDate>
            <atom:updated>2026-08-30T17:08:41.073Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://journal.hexmos.com/tag/mcp/">mcp</a></p><p>- 6 min read</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amisKIjyCSWh5NjP3zuVMg.png" /></figure><p>AI coding agents often read more code than necessary.</p><p>When a developer asks a simple question about a function, the agent searches multiple files, opens entire source files, and fills the context window with irrelevant tokens.</p><p>Usually, with a bigger codebase, it takes a lot of time to execute, consumes more tokens, and costs more. After seeing this, we may feel that we could have just searched and found the answer in seconds.</p><p>Let’s understand why it happens, how we can optimize it, and how we can use the agent effectively.</p><p>Before we explore how to solve this, we should understand how AI agents do their work.</p><h3>How Does an AI Agent Work in a Codebase?</h3><p>Whenever an instruction is given to the agent, it reconstructs code relationships at runtime.</p><p>Suppose the repository contains 500 files of 100,000 lines.</p><p>It does not send all 100,000 lines to the model at once.</p><p>Instead, it builds context step by step.</p><p>The agent runs grep, rg, and other search commands.</p><p>Even if it uses LSP support, this can cause full file reads, which waste tokens, compute, cost, and time.</p><p>Suppose you ask an AI coding agent:</p><blockquote><em>“Trace the call chain of </em><em>GetUser()&quot;</em></blockquote><p>A standard coding agent starts with a text search.</p><p><strong>Step 1</strong> — The agent searches for GetUser across all files using grep or ripgrep.</p><p><strong>Step 2</strong> — The search returns user_service.go as a match. The agent reads the file.</p><p><strong>Step 3</strong> — Inside user_service.go, the agent sees a call to UserService.Get(). The agent searches for that next.</p><p><strong>Step 4</strong> — The search returns service.go. The agent reads the file.</p><p><strong>Step 5</strong> — Inside service.go, the agent sees a call to repository.Find(). The agent searches for that next.</p><p><strong>Step 6</strong> — The search returns repository.go. The agent reads the file.</p><p><strong>Step 7</strong> — Inside repository.go, the agent sees the database query. The exploration ends.</p><p>If the codebase is huge, then it will do even more searching and reading, basically consuming a lot of unwanted code.</p><pre>Searches 2,000 tokens File reads 15,000 tokens Search results 5,000 tokens Reasoning 3,000 tokens ---------------------------- Total 25,000 tokens</pre><p><strong>What Actually Goes Into the LLM Context?</strong></p><p>The LLM receives the intermediate information produced during exploration.</p><p>Search result, file content, new symbol, another search, and it goes on.</p><p>The final relationship is small, but the agent consumes a much larger amount of context to discover it.</p><p>This is where codebase-memory-mcp helps.</p><h3>How Using Codebase Memory MCP Helps Reduce Tokens</h3><p>codebase-memory-mcp is not an AI model that understands your codebase.</p><p>It is a local code parser, a static-analysis layer, a graph database, and an MCP server.</p><p>Basically, it is a mixture of all findings in a single place.</p><p>For example:</p><p>and:</p><p>Instead of sending all the source code to the LLM, Tree-sitter parses the code and extracts structural information:</p><pre>Function: GetUser Function: FindUser Call: GetUser → repository.FindUser</pre><p>Tree-sitter provides the syntactic AST and identifies definitions, calls, imports, and other structural facts.</p><p><strong>Program Fact Extraction</strong></p><p>The important idea is to compute deterministic facts once rather than asking the LLM to rediscover them repeatedly.</p><p>For example:</p><pre>A CALLS B B DEFINES C D IMPORTS E route X → handler Y</pre><p>The tool stores these facts and reuses them.</p><p>The expensive work runs once, and queries then become cheap.</p><p>The fundamental principle:</p><blockquote><em>Do not repeatedly make the AI rediscover deterministic information. Compute it once, store it structurally, and let the AI query the result.</em></blockquote><p><strong>Hybrid LSP Semantic Resolution</strong></p><p>Tree-sitter alone provides a syntactic AST.</p><p>It handles naming, structure, and call sites well.</p><p>However, it cannot always determine the exact semantic target.</p><p>For example:</p><p>Tree-sitter identifies:</p><p>But it does not know which display_name() this refers to.</p><p>The semantic layer resolves the actual target.</p><p>The architecture works on two layers. Both LSP and Tree-sitter combine.</p><p>This produces more meaningful relationships than text matching alone.</p><p><strong>MCP-Based Code Intelligence</strong></p><p>The graph is stored locally, and the tool exposes it through MCP tools.</p><p>The database performs the traversal.</p><p>The LLM does not perform the traversal.</p><p>The MCP server exposes tools for:</p><ul><li>Search</li><li>Tracing</li><li>Architecture</li><li>Impact analysis</li><li>Graph queries</li><li>Dead-code detection</li><li>Cross-service relationships</li></ul><p><strong>Reduction of 70% Of Tokens</strong></p><p>The text search discovery step consumed approximately 1,500 tokens.</p><p>The graph lookup consumed approximately 50 tokens.</p><p>This represents a 97% token reduction for the discovery step.</p><p>The knowledge graph does not compress source code.</p><p>It reduces the data required to locate code.</p><p>After the tool located the function, the agent must read the function code.</p><p>The codebase-memory-mcp tool does not remove the 2,300 tokens of Go code.</p><p>It prevents the agent from reading the remaining 5,200 tokens in service.go.</p><p>The table shows token usage for the entire task:</p><p>ApproachTokens</p><p>Text search and full-file read</p><p>~9,000</p><p>Knowledge graph search and function snippet</p><p>~2,500</p><p><strong>Token Savings~70%</strong></p><p>In thier officaial doc they mention with bigger codebase it will reduce more token exponencially.</p><p><strong>How to Set Up MCP in Claude Code</strong></p><p>Run the installer:</p><p>Restart Claude Code.</p><p>Inside Claude Code, run:</p><p>The output should show:</p><pre>codebase-memory-mcp 15 tools</pre><p>Tell Claude:</p><p>To enable the graph UI, run:</p><pre>codebase-memory-mcp --ui=true --port= 9749</pre><p>We can actually view the graph of the application to see what my LiveReview application graph looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RbDEtrvrmR98dPKZ.gif" /></figure><p>By the way, I am building <a href="https://github.com/HexmosTech/liveReview/?ref=journal.hexmos.com">LiveReview</a> — a blast-radius aware AI code review built for your business-critical systems. Star us to help devs discover the project, give it a try, and share your feedback to help improve the product.</p><h3>Compress Terminal Output with rtk</h3><p>Even after using MCP, the agent still executes shell commands such as:</p><pre>git status git diff git log rg &quot;foo&quot; go test ./... docker ps</pre><p>A large part of the output from these commands is unnecessary for the LLM.</p><p>For example, git status can contain:</p><p>The useful information is only the list of changed files.</p><p>Similarly, go test ./... can return:</p><p>The successful packages are not useful for diagnosing the failure.</p><p>This is where rtk helps.</p><h3>How rtk Trims Shell Output</h3><p>rtk is a different optimization from codebase-memory-mcp.</p><p>codebase-memory-mcp reduces code exploration.</p><p>rtk reduces command output.</p><p>rtk does not understand the codebase.</p><p>It reduces the amount of command output that reaches the LLM context.</p><p>For example:</p><p>The agent does not need to know that rtk is active.</p><p>Run the installer:</p><p>For supported agents, a hook intercepts Bash tool calls.</p><p>When Claude runs:</p><p>the hook changes the execution path.</p><p>rtk is not an LLM.</p><p>It is a Rust processor that transforms command output.</p><p>The CPU overhead is very small.</p><p>The expensive part is the model context, not the filtering.</p><p>I tested rtk on a grep search:</p><pre>grep -C 2 &quot;ProcessReview&quot; .</pre><p>The raw command output measured 6,065 bytes.</p><p>The rtk output measured 2,972 bytes.</p><p>This result demonstrates a 51% output size reduction.</p><p>The output retained all required search information.</p><p>rtk does not parse code structure.</p><p>It filters output text that the agent does not require.</p><p>One important limitation: rtk does not intercept Claude Code&#39;s native tools.</p><p>Those tools bypass the Bash hook.</p><p>However, shell commands such as cat, ls, git, and test runners all work with rtk.</p><h3>Final Takeaway</h3><p>codebase-memory-mcp and rtk attack different parts of the token problem.</p><p>codebase-memory-mcp reduces token usage by giving the agent precomputed structural relationships.</p><p>rtk reduces huge command output to small, useful output.</p><p>Together, these tools target two different sources of unnecessary context and reduce total token usage.</p><p>Your team’s attention is limited, and the deluge of AI-generated code is making it harder to keep production stable while also shipping at high velocity.</p><p>I’m building <strong>LiveReview</strong>, a blast-radius aware AI code review built for your business-critical systems.</p><p>Instead of presenting every diff with equal emphasis, <strong>LiveReview scores each change by blast radius — how far its impact reaches through your call graph — so you can focus attention where it actually matters.</strong></p><p>Spend code review effort where business risk is highest — not spread evenly across every diff.</p><p><strong>Try LiveReview on your codebase:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kPtxSFZ0-i249yYy.png" /></figure><p><em>Originally published at </em><a href="https://journal.hexmos.com/token-reduction-tools/"><em>https://journal.hexmos.com</em></a><em> on August 30, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0e7d4a8d215" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Do Smart Devices Perform Multiple Tasks?]]></title>
            <link>https://medium.com/@ganeshkumarprofession/how-do-smart-devices-perform-multiple-tasks-0c9e15da7e6e?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c9e15da7e6e</guid>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 12 Apr 2026 16:46:57 GMT</pubDate>
            <atom:updated>2026-04-12T19:12:36.071Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://journal.hexmos.com/tag/mcu/">mcu</a></p><p>- 6 min read</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bJINjMbx-9OL7bYX.png" /></figure><p>Ever wonder how your Alexa, robot vacuum cleaner, and smartwatch seamlessly perform multiple tasks without getting stuck in the middle? How exactly are these devices programmed to handle it all?</p><p>You came to the right place to understand how it happens under the hood.</p><p>In this article, we will understand how these tasks are performed and how they work.</p><p>As all these devices use a microcontroller. I will be explaining using the simple microcontroller ESP8266.</p><h3>How will the task be performed?</h3><p>Every smart device consists of a microcontroller. These microcontrollers are programmed to perform specific tasks.</p><p>These tasks are performed using a single loop function.</p><pre>// Perform Task }</pre><p>This loop function will run continuously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J-DSywhphdu6gCpV.png" /></figure><p>In this loop, we can do multiple things.</p><p>Let’s take the example of a weather monitoring device.<br>These operations are done using a single loop function. As there is nothing else to do.</p><ol><li>Start Device</li><li>Start Loop</li><li>Read sensor data</li><li>Display data / Store data</li><li>Repeat the process</li></ol><p>But this comes with a problem.</p><p>This loop will be running with a microsecond delay.<br>If we run this loop function, it will run continuously. Means there will be no delay between the operations.</p><h3>How will a normal loop cause a problem?</h3><p>Let’s assume the above operation takes 1 ms (which is not true in real-world use, as it depends on which microcontroller you use).</p><p>The DHT11 sensor should have a 1-second delay between readings.</p><p>That means the above loop will run 1000 times in 1 second to just see if the sensor data has changed.</p><p>Can you see the problem?</p><p>1000 times operation means 1000 times power consumption.</p><p>1000 times the power consumption means the battery will drain fast, or the embedded system will heat up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*IRVCZ377Ue-yZxTY.png" /></figure><p>To avoid this, we can use a delay function.</p><p>By adding a delay, we are making sure that the loop function is not running continuously.</p><p>This is a good implementation if we have only one task to perform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*wHz5Fr2BU2AmZtFe.png" /></figure><p>But if we want to do multiple operations to be performed in specific intervals.</p><h3>Adding Other Operations in a loop</h3><p>Like this, if we want to read the DHT11 sensor every 1 second and read the MQ2 sensor every 5 seconds. We can’t use the delay function.</p><p>It will be like this.</p><p>This will cause a 5-second no-data reading from the DHT11 sensor.</p><p>Hence, there will be data loss for 5 seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*gVQ41lMOO3RVgF_4.png" /></figure><p>Here is where the task scheduler comes into the picture.</p><h3>What is Task Scheduler?</h3><p>A task scheduler is a lightweight system that allows a processor to juggle multiple activities seemingly at the same time, a concept known as multitasking.</p><p>A task scheduler solves this problem using a “to-do list” approach.</p><p>Instead of freezing, the program loops continuously at top speed.</p><p>Every time it loops, the scheduler checks the clock and looks at its list of tasks to see if any are due to run right now.</p><p>If a task’s time is up, the scheduler runs it and then immediately goes back to checking the clock.</p><p>To understand the internal clock, imagine the microcontroller holding a stopwatch that starts counting milliseconds the moment it powers on.</p><p>In the Arduino framework, this stopwatch is read using a function called millis().</p><p>Instead of pausing the whole system to wait, the scheduler constantly checks this stopwatch against a simple formula for each task:</p><p>Current Time - Last Time Executed &gt;= Interval</p><p>Here is a simple example of how the task scheduler works in ESP8266.</p><p>Ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*keQ8o9_eylz5qWJE.png" /></figure><p>This way, we can perform multiple operations in specific intervals without blocking the loop function.</p><h3>Core Logic of Task Scheduler</h3><p>I want to perform two operations in ESP8266.</p><ol><li>Blink the LED every 2.5 seconds 1 time.</li><li>Blink the LED every 5 seconds 2 times.</li></ol><p>Let’s see how to do this without using the built-in task scheduler.</p><ol><li>Set up serial communication and the LED pin.</li><li>Start Loop.</li><li>Check if 2.5 seconds have passed since the last task activation.</li><li>If yes, perform the blink.</li><li>Check if 5 seconds have passed since the last task activation.</li><li>If yes, perform the blink</li></ol><p>Output:</p><p>See, as we defined, to use a 2.5 sec interval for the first task and a 5 sec interval for the second task.</p><p>This also means the 2nd time, a 2.5 sec blink will happen after 5 sec from the 1st blink.</p><p>This will create a 2-second blink in 5 sec.</p><h3>Using Task Scheduler</h3><p>We are going to use the task scheduler library to perform multiple operations in specific intervals.</p><p>Let’s see how to do this using the task scheduler library.</p><ol><li>Include the task scheduler library.</li><li>Create a scheduler object.</li><li>Define tasks.</li><li>Add tasks to the scheduler.</li><li>Enable tasks.</li><li>Run the scheduler.</li></ol><p>In this way, we can perform multiple operations in specific intervals without blocking the loop function.</p><p>Output:</p><p>You can also see that the 5.0s blink is happening first, and sometimes the 2.5s blink is happening first.</p><p>This is because of the task scheduler library. It has its own algorithm to perform the tasks.</p><h3>How real-world devices use task scheduler</h3><p>In real-world devices, task scheduling depends on the complexity of the system.</p><p>For simple devices (like basic IoT systems using ESP8266), developers use the same approach we discussed earlier — non-blocking scheduling using millis() or lightweight task schedulers.</p><p>For more advanced devices, a <strong>Real-Time Operating System (RTOS)</strong> such as FreeRTOS is commonly used.</p><p>An RTOS allows:</p><ul><li>Running multiple tasks with priorities</li><li>Executing time-critical tasks without delay</li><li>Managing communication between tasks</li></ul><p>For example, a smart device can:</p><ul><li>Read sensors periodically</li><li>Handle WiFi communication</li><li>Update display</li><li>Respond to user input</li></ul><p>All these tasks run efficiently using a scheduler without blocking each other.</p><p>In short, real-world systems use more advanced schedulers, but the core idea remains the same as the simple loop-based scheduler explained earlier.</p><h3>Conclusion</h3><p>We understood how smart devices perform multiple tasks using the task scheduler and how to use it to perform multiple operations in specific intervals without blocking the loop function.</p><p><em>Originally published at </em><a href="https://journal.hexmos.com/how-task-scheduler-works/"><em>https://journal.hexmos.com</em></a><em> on April 12, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c9e15da7e6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Go Slices Work Under the Hood: What Makes Them Stand Out from Other Languages]]></title>
            <link>https://medium.com/@ganeshkumarprofession/how-go-slices-work-under-the-hood-what-makes-them-stand-out-from-other-languages-8f3a652fdf1c?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f3a652fdf1c</guid>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 08 Mar 2026 17:06:33 GMT</pubDate>
            <atom:updated>2026-03-17T03:53:35.588Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://journal.hexmos.com/tag/golang/">golang</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gH27cpFeGgPFNyUX.png" /></figure><p>Slices are one of the most commonly used data structures in Go.</p><p>They appear simple on the surface, but their design is carefully engineered to provide flexibility without sacrificing performance.</p><p>In this article, we will examine how Go slices work internally and analyze the algorithm that enables them to grow dynamically while remaining efficient.</p><h3>What are slices?</h3><p>Slices are dynamic arrays. It uses pointers to refer to the underlying array. Further below, we will understand more in detail.</p><h3>How to create slices?</h3><p>Initialize the array and create a slice from it.</p><p>For creating a slice from an array, we use [start:end] notation.</p><p>start is the starting index of the slice.</p><p>end is the ending index of the slice.</p><pre>import &quot;fmt&quot;<br><br>func main() {<br>    s := [5]int{10, 20, 30, 40,50}<br>    fmt.Println(s)<br>    var s1 []int = s[1:3]<br>    fmt.Println(s1)<br>}</pre><p><strong>Output:</strong></p><pre>[10 20 30 40 50]<br>[20 30]</pre><h3>Using Structs with Slices</h3><p>We can store any data type in a slice.</p><p>For example, we can store a struct in a slice.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>type Person struct {<br>    Name string<br>    Age  int<br>}<br><br>func main() {<br>    people := []Person{<br> {Name: &quot;John&quot;, Age: 30},<br> {Name: &quot;Jane&quot;, Age: 25},<br> }<br>    fmt.Println(people)<br>}</pre><p>The output of the code will have JSON-like output inside square brackets.</p><p><strong>Output:</strong></p><pre>{John 30} {Jane 25}]</pre><p>So, we understood how to create slices. But to understand how Go creates and how it handles slices, we have to understand the algorithm behind it. Let’s see the source code of Go. <a href="https://github.com/golang/go/blob/master/src/runtime/slice.go?ref=journal.hexmos.com">link</a></p><h3>How do slices work internally?</h3><p>Slices will have 3 components.</p><ol><li>Pointer to the underlying array.</li><li>Length of the slice.</li><li>Capacity of the slice.</li></ol><p>It is a little bit confusing; let’s understand with the example below.</p><pre>[10, 20, 30, 40, 50]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*x9YaLGQ6GqQsy8gx.png" /></figure><p>Now, from the above image, we can understand how slices are created internally.</p><h3>Modifying Slices</h3><p>When we do slicing from a new slice with a different start point, it will create a new slice with a different pointer.</p><p>If we change the pointer, then the data from the previous pointer will be lost.</p><p>To identify how it works, let’s see the example below.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    s := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}<br>    printSlice(s)<br><br>    s = s[1:5]<br>    printSlice(s)<br><br>    s = s[2:]<br>    printSlice(s)<br><br>    s = s[:1]<br>    printSlice(s)<br>}<br>func printSlice(s []int) {<br>    fmt.Printf(&quot;len=%d cap=%d %v\n&quot;, len(s), cap(s), s)<br>}</pre><p>Here is the visual representation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CAg4vniTiX16nTW8.png" /></figure><p><strong>Output:</strong><br>This is the actual output of the code.</p><pre>gk@jarvis:~/exp/code/rd/go-exmaple$ go run main.go<br>len=10 cap=10 [1 2 3 4 5 6 7 8 9 10]<br>len=4 cap=9 [2 3 4 5]<br>len=2 cap=7 [4 5]<br>len=1 cap=7 [4]</pre><p>I explained how empty data is represented in slices.</p><h3>How is an empty slice represented?</h3><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    var s []int<br>    fmt.Println(s, len(s), cap(s))<br>    if s == nil {<br>        fmt.Println(&quot;s is nil&quot;)<br> }<br>}</pre><p><strong>Output:</strong></p><pre>[] 0 0<br>s is nil</pre><p>len and cap are 0 because the slice is not initialized.</p><p>When we initialize a slice, it will have a defined length and capacity.</p><p>The underlying pointer will point to the first element of the backing array, and both the length and capacity will be set to the number of elements in that array.</p><h3>Initializing a Slice</h3><p>We can initialise slices with different data types.</p><h3>Initializing a Slice with make</h3><p>make is a predefined function in Go used to create and initialize slices, maps, and channels.</p><p>Reference variables like slices are typically initialized using the make command from Go&#39;s built-in functions.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    a := make([]int, 5)<br>    fmt.Println(a, len(a), cap(a))<br><br>    b := make([]int, 5, 10)<br>    fmt.Println(b, len(b), cap(b))<br>}</pre><p><strong>Output:</strong></p><pre>[0 0 0 0 0] 5 5<br>[0 0 0 0 0] 5 10</pre><p>This allows you to create a slice with a specific length and capacity.</p><p>make([]T, len, cap)</p><ul><li>For a := make([]int, 5), it creates a slice of length 5 and capacity 5.</li><li>For b := make([]int, 5, 10), it creates a slice of length 5 and capacity 10.</li></ul><h3>Variable Declaration</h3><p>You can also initialize a slice directly using a slice literal:</p><pre><br>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    a := []int{1, 2, 3, 4, 5}<br>    fmt.Println(a, len(a), cap(a))<br>}</pre><p><strong>Output:</strong></p><pre>[1 2 3 4 5] 5 5</pre><p>For this slice, the pointer points to the first element of the underlying array, and the length and capacity are set to the number of elements provided.<br>Now, we will see how to initialize 2D slices and how to append to a slice.</p><h3>Initializing 2D Slices</h3><pre>package main<br><br>import (<br>    &quot;fmt&quot;<br>    &quot;strings&quot;<br>)<br><br>func main() {<br><br>    ticTacToeBoard := [][]string{<br> {&quot;_&quot;, &quot;_&quot;, &quot;_&quot;},<br> {&quot;_&quot;, &quot;_&quot;, &quot;_&quot;},<br> {&quot;_&quot;, &quot;_&quot;, &quot;_&quot;},<br> }<br><br>    ticTacToeBoard[0][0] = &quot;X&quot;<br>    ticTacToeBoard[2][2] = &quot;O&quot;<br>    fmt.Println(ticTacToeBoard)<br>    for i := 0; i &lt; len(ticTacToeBoard); i++ {<br>        fmt.Println(strings.Join(ticTacToeBoard[i], &quot; &quot;))<br> }<br>}</pre><p>We are initializing a 2D slice of strings with 3 rows and 3 columns.</p><p>We can modify the values of the slice using the index variable[x][y].</p><p>Finally, we are printing the slice using a loop.</p><p>Each loop iteration prints a row of the slice.</p><p><strong>Output:</strong></p><pre>gk@jarvis:~/exp/code/rd/go-exmaple$ go run main.go <br>[[X _ _] [_ _ _] [_ _ O]] <br>X _ _ <br>_ _ _<br>_ _ O</pre><h3>Appending to a Slice</h3><p>Slices are dynamic arrays. We can append to a slice using the append function.</p><p>We can append any data type to a slice.</p><p>Simple example:</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    a := []int{1, 2, 3, 4, 5}<br>    fmt.Println(a)<br><br>    a = append(a, 6)<br>    fmt.Println(a)<br>}</pre><p><strong>Output:</strong></p><pre>gk@jarvis:~/exp/code/rd/go-exmaple$ go run main.go <br>[1 2 3 4 5] <br>[1 2 3 4 5 6]</pre><p>Before we start going further, let’s understand how the append function works.</p><p>As we know, slices are dynamic arrays.</p><p>When we append to a slice, the slice is resized.</p><p>Let’s check how appending will resize the slice.</p><p>So, with that context, the result should be len=6 cap=6 [1 2 3 4 5 6] after appending 6 to the slice.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    a := []int{1, 2, 3, 4, 5}<br>    printSlice(a)<br><br>    a = append(a, 6)<br>    printSlice(a)<br>}<br>func printSlice(s []int) {<br>    fmt.Printf(&quot;len=%d cap=%d %v\n&quot;, len(s), cap(s), s)<br>}</pre><p><strong>Actual Output:</strong></p><pre>gk@jarvis:~/exp/code/rd/go-exmaple$ go run main.go <br>len=5 cap=5 [1 2 3 4 5] <br>len=6 cap=10 [1 2 3 4 5 6]</pre><p>Why cap is 10?</p><p>To understand this, let’s see how the append function works.</p><p>Now let’s see why this happens and what the reason is behind it.</p><h3>The Slice Append Algorithm</h3><p>In the official source code of append function, you can see here <a href="https://github.com/golang/go/blob/master/src/runtime/slice.go?ref=journal.hexmos.com">link</a></p><p>There are two cases for appending to a slice.</p><ol><li>Appending a single element to a slice.</li><li>Appending multiple elements to a slice.</li></ol><p>Append a single element to a slice:</p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    a := []int{}<br>    printSlice(a)<br>    a = append(a, 0)<br>    printSlice(a)<br><br>    a = append(a, 1)<br>    printSlice(a)<br>    a = append(a, 2)<br>    printSlice(a)<br>    a = append(a, 3)<br>    printSlice(a)<br>    a = append(a, 4)<br>    printSlice(a)<br>    a = append(a, 5)<br>    printSlice(a)<br>    a = append(a, 6)<br>    printSlice(a)<br>}<br>func printSlice(s []int) {<br>    fmt.Printf(&quot;len=%d cap=%d %v\n&quot;, len(s), cap(s), s)<br>}</pre><p>This will output:</p><pre>gk@jarvis:~/exp/code/rd/go-exmaple$ go run main.go<br>len=0 cap=0 []<br>len=1 cap=1 [0]<br>len=2 cap=2 [0 1]<br>len=3 cap=4 [0 1 2]<br>len=4 cap=4 [0 1 2 3]<br>len=5 cap=8 [0 1 2 3 4]<br>len=6 cap=8 [0 1 2 3 4 5]<br>len=7 cap=8 [0 1 2 3 4 5 6]</pre><p>We can see clearly how the capacity is growing.</p><p>Whenever there is a match with len and cap, the next element will be appended with cap and double the previous cap.</p><p>We didn’t expect that, but let’s understand the algorithm behind the append function.</p><h3>How Append Works Internally</h3><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    a := []int{1, 2,}<br>    printSlice(a)<br><br>    a = append(a, 3)<br>    printSlice(a)<br><br>    a = append(a, 4,5,6,7,8,9)<br>    printSlice(a)<br><br>    a =  append(a, 10,11,12)<br>    printSlice(a) <br>}   <br>func printSlice(s []int) {<br>    fmt.Printf(&quot;len=%d cap=%d %v\n&quot;, len(s), cap(s), s)<br>}</pre><p>Output:</p><pre>gk@jarvis:~/exp/code/rd/go-exmaple$ go run main.go <br>len=2 cap=2 [1 2]<br>len=3 cap=4 [1 2 3]<br>len=9 cap=10 [1 2 3 4 5 6 7 8 9]<br>len=12 cap=20 [1 2 3 4 5 6 7 8 9 10 11 12]</pre><p>Append 1: Bulk append of 1,2<br> Inserted length is 2<br> Capacity is 2</p><p>Append 2: Single append of 3<br> Inserted length is 1<br> Capacity is 4<br> Which is double the previous capacity</p><p>Append 3: Bulk append of 4,5,6,7,8,9<br> Inserted length is 6<br> Capacity is 10<br> Which is double the previous capacity, but increased by 2 to round off to the bucket size</p><p>Append 4: Bulk append of 10,11,12<br> Inserted length is 3<br> Capacity is 20<br> Which is double the previous capacity</p><p>The underlying reasons for this behavior are:</p><ol><li><strong>Safety Checks</strong></li><li><strong>Zero-Size Shortcut</strong>: If the slice is empty, it skips allocation if possible.</li><li><strong>Calculating the Target Capacity</strong>:</li><li>If the current capacity is <strong>small</strong> (less than 256 elements), it will <strong>double</strong> the capacity.</li><li>If the current capacity is <strong>large</strong> (256 elements or more), it grows by a formula that smooths the transition from <strong>2.0x to 1.25x</strong>. <em>(Note: Before Go 1.18, this threshold was 1024 and grew strictly by 1.25x).</em></li><li>If there is a <strong>bulk append</strong> and the required capacity is strictly greater than double the current capacity, it jumps straight to the exact required capacity, and even rounds up to the next size class.</li><li><strong>Byte Math and Memory Rounding (Size Classes)</strong>:<br> Single-element append: will double the capacity.<br> Bulk append: will calculate the required capacity and round it up to the next size class.</li></ol><p>This is a capacity growth algorithm of append function is specifically designed to minimize the number of reallocations.</p><p>Reallocations are expensive operations.</p><p>Now let’s see how the loop works with the append function</p><h3>Common Slices Operations</h3><h3>Looping with a Standard for Loop</h3><p>Let’s assign the power of 2 to a slice and print it.</p><p>With normal loop we can print the slice.</p><p>We basicaly loop over the length of the slice using the index.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br><br><br>var power = []int{1,2,4,8,16,32}<br><br>func main() {<br>    for i:=0; i&lt;len(power); i++ {<br>        fmt.Printf(&quot;2^%d = %d\n&quot;, i, power[i])<br> }<br>}</pre><p>This will output:</p><pre>2^0 = 1<br>2^1 = 2<br>2^2 = 4<br>2^3 = 8<br>2^4 = 16<br>2^5 = 32</pre><h3>Using Go’s Built-in range Function</h3><p>Go provides a very simple way to loop over a slice.</p><p>Where i is the index and v is the value of the element.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br><br><br>var power = []int{1,2,4,8,16,32}<br><br>func main() {<br>    for i,v := range power {<br>        fmt.Printf(&quot;2^%d = %d\n&quot;, i, v)<br> }<br>}</pre><p>Output:</p><pre>2^0 = 1<br>2^1 = 2<br>2^2 = 4<br>2^3 = 8<br>2^4 = 16<br>2^5 = 32</pre><p>we can also define the index as if we don’t want to use it.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br><br><br>var power = []int{1,2,4,8,16,32}<br><br>func main() {<br>    for _,v := range power {<br>        fmt.Printf(&quot;%d\n&quot;, v)<br> }<br>}</pre><p>Output:</p><pre>1<br>2<br>4<br>8<br>16<br>32</pre><h3>Conclusion</h3><p>Go slices offer the perfect balance of developer convenience and system performance.</p><p>By understanding the relationship between the underlying array, length, and capacity—along with the clever growth algorithm Go uses to minimize expensive memory reallocations—you can write much more efficient code.</p><p>Instead of blindly appending data, you can now anticipate how your slices will grow and strategically use make to pre-allocate memory when you know your target size in advance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ErxlYOfLw05dpBCk.png" /></figure><p>Any feedback or contributors are welcome! It’s online, source-available, and ready for anyone to use.<br> ⭐ Star it on GitHub: <a href="https://github.com/HexmosTech/git-lrc?ref=journal.hexmos.com">https://github.com/HexmosTech/git-lrc</a></p><p><em>Originally published at </em><a href="https://journal.hexmos.com/understanding-go-slices-algorithm/"><em>https://journal.hexmos.com</em></a><em> on March 8, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f3a652fdf1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a In-Memory Cache in Go Using Generics With TTL]]></title>
            <link>https://medium.com/@ganeshkumarprofession/how-to-build-a-in-memory-cache-in-go-using-generics-with-ttl-5903237aa75f?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5903237aa75f</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 01 Feb 2026 16:12:08 GMT</pubDate>
            <atom:updated>2026-03-17T03:35:39.003Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://journal.hexmos.com/tag/go/">Go</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p4mEVfpdhMNMbwkz.png" /></figure><p>There is a famous saying in computer science:</p><p><em>“There are only two hard things in Computer Science: cache invalidation and naming things.”</em> — Phil Karlton</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Knx5xHUGPjT7y-0S.png" /></figure><p>It is challenging to balance <strong>performance</strong> (caching aggressively) with <strong>accuracy</strong> (ensuring users see the latest data immediately).<br> If you cache too much, users see old data. If you invalidate too often, your databases get hammered with traffic.</p><p>This is where <strong>performance optimization</strong> becomes critical. Whether you’re building a web application or a microservice, reducing API latency is key to a good user experience.</p><h3>Why In-Memory Caching?</h3><p>In-memory caching solves this by storing frequently accessed data in RAM, avoiding slow database queries. This significantly improves system performance.</p><p>Go is particularly well-suited for this task. Its lightweight concurrency model (goroutines and sync primitives) allows us to build highly efficient, thread-safe caches that handle high read/write throughput with ease.</p><blockquote><em>Note: There are some popular packages like </em><a href="https://github.com/patrickmn/go-cache?ref=journal.hexmos.com"><em>go-cache</em></a><em> that can be used directly.</em></blockquote><h3>Basic In-Memory Cache</h3><p>Now, let’s explore how to implement a basic in-memory cache in Go.</p><p>Since generics were introduced in Go 1.18, you might prefer a generic implementation. However, for simplicity, we’ll start with map[string]interface{}.</p><p>For a basic cache, we need 4 main operations:</p><ol><li><strong>Set(key, value)</strong>: Adds or updates a value for a given key. It uses a write lock ( Lock) to ensure thread safety during the update.</li><li><strong>Get(key)</strong>: Retrieves the value associated with a key. It uses a read lock ( RLock), allowing multiple concurrent readers.</li><li><strong>Delete(key)</strong>: Removes a specific key-value pair from the cache using a write lock.</li><li><strong>Clear()</strong>: Resets the cache by replacing the map with a new one using a write lock.</li></ol><p>We use map[string]interface{} to store values of any type against string keys. While flexible, this requires runtime type assertions and isn&#39;t type-safe.</p><h3>The Structure</h3><p>We define a Cache struct containing the map and a sync.RWMutex for thread safety.</p><h3>Implementation</h3><p>We get the folowing output</p><pre>gk@jarvis:~/exp/code/cache/basic$ go run main.go Value for key1: value1</pre><p>We can’t see key2 as it has been deleted.</p><h3>Key Findings</h3><p>We have a working cache.</p><p>We used a mutex for locking to avoid concurrent access. If you are new to Mutexes, I recommend exploring <a href="https://www.geeksforgeeks.org/go-language/mutex-in-golang-with-examples/?ref=journal.hexmos.com">Mutex in Golang</a>.</p><p>We understood the importance of caching and how it helps improve performance and efficiency.</p><p>However, if you notice, the current cache doesn’t support the concept of expiry of keys (TTL — Time To Live).<br> Items stay in the cache forever unless manually deleted.</p><p>Let’s add expiry support to our cache, which means after a defined TTL, the item expires and is removed from the cache.</p><h3>Adding TTL Support</h3><p>Since each cache entry can have a defined TTL, we create a CacheItem struct that contains interface{} for storing value and an expiry time field.</p><h3>How it Works</h3><ul><li>Adding Data<br> When you add data, you must specify how long it should live.<br> Expiry Time = Current Time + TTL</li><li>Retrieving Data<br> This is the smartest part.<br> In this <strong>lazy expiration</strong> approach, the cache does not run a background timer to delete old keys (which consumes CPU). Instead, it checks at the moment you ask for the data.</li></ul><p><strong>Lookup</strong>: It finds the item in the map.<br><strong>Check</strong>: Is Current Time &gt; Expiry Time?<br><strong>If Yes (Expired)</strong>: It explicitly deletes the item right now and tells you it wasn’t found (false).<br><strong>If No (Valid)</strong>: It returns the value.</p><h3>Thread-Safe Cache with TTL</h3><p>We just need to update the cache structure, set function, and get function.</p><ol><li><strong>The Structure</strong>: We define CacheItem to hold the value and its expiration time. The Cache struct now uses a map of CacheItem.</li><li><strong>Set(…, ttl)</strong>: Sets the value with an expiration time calculated as time.Now().Add(ttl).</li><li><strong>Get(key)</strong>: Checks if the item exists and hasn’t expired. If expired, it upgrades to a write lock to delete the item (lazy expiration).</li></ol><h3>Implementation</h3><p>With this expiry support, our cache implementation becomes more versatile and suitable for a wider range of caching scenarios.</p><blockquote><strong><em>Note</em></strong><em>: This is a basic implementation. In real world apps often use </em><em>sync.Map, eviction policies (LRU), or libraries like </em><a href="https://github.com/patrickmn/go-cache?ref=journal.hexmos.com"><em>go-cache</em></a><em> or </em><a href="https://github.com/jellydator/ttlcache?ref=journal.hexmos.com"><em>ttlcache</em></a><em>.</em></blockquote><p>When you run the code:</p><pre>gk@jarvis:~/exp/code/cache$ go run main.go Value for name: mohit Name key has expired Weight key has expired</pre><p>By this we can verify it correctly storing and handling TTL.</p><h3>Key Findings</h3><p>We successfully implemented TTL support using a lazy expiration strategy.</p><p>This approach is efficient as it avoids background CPU usage when the cache is idle.</p><p>However, there is a major drawback: <strong>Memory Leak</strong>.<br> Keys that expire but are never accessed again will remain in the map forever.</p><p>To resolve this, we need a background cleanup process.</p><h3>Using Go Generics</h3><p>In this improved version, we will address the <strong>memory leak</strong> by introducing a background “janitor” process that periodically removes expired items.</p><p>Additionally, we’ll leverage <strong>Go Generics</strong> (available since Go 1.18) to enforce type safety, eliminating the need for interface{} and runtime type assertions.</p><h3>Structure</h3><ol><li><strong>StartCleanup(interval)</strong>: Launches a background goroutine that runs periodically (every interval) to scan and remove expired items.</li><li><strong>StopCleanup()</strong>: Signals the background goroutine to stop, preventing goroutine leaks when the cache is no longer needed.</li></ol><h3>Implementation</h3><p>We get this following output</p><p>We can see cache size is 0 after the cleanup.</p><h3>Testing</h3><p>To help identify race conditions, it is recommended to run your code with the race detector enabled:</p><pre>go run -race main.go</pre><p><strong>Note</strong>: The race detector is a powerful tool, but it does not <strong>guarantee</strong> that all concurrency bugs are caught. It only detects race conditions that strictly occur during the execution.</p><h3>Key Improvements</h3><ol><li><strong>Type Safety</strong>: No more interface{}. The compiler ensures you only store/retrieve the correct types.</li><li><strong>Concurrency Optimization</strong>: Get() uses RLock (Read Lock) for better performance under load.</li><li><strong>Automatic Cleanup</strong>: The StartCleanup method runs a background loop to delete expired keys, preventing memory leaks from stale data.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*His47AvnO8HjgP9u.png" /></figure><h3>Conclusion</h3><p>Now we have designed an In-Memory Cache that handles expiry.</p><p>With TTL-based lazy expiration, we strike a practical balance: fresh data when needed, reduced database load most of the time, and simple code.</p><h3>Sources</h3><ol><li><a href="https://medium.com/on-building-software/why-cache-invalidation-is-actually-hard-e8b5e9a83e45?ref=journal.hexmos.com">https://medium.com/on-building-software/why-cache-invalidation-is-actually-hard-e8b5e9a83e45</a></li><li><a href="https://www.mohitkhare.com/blog/go-in-memory-cache/?ref=journal.hexmos.com">https://www.mohitkhare.com/blog/go-in-memory-cache/</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*JgMqI7CmP-AwDjgy.png" /></figure><p>I’ve been building FreeDevTools for developers.</p><p>It is a curated collection of cheatsheets, Manual Pages, MCPs, SVGs, PNGs, and various frequently used tools crafted to simplify workflows and reduce friction.</p><p>My goal is to save you time by providing the materials you need for your daily work in one place, so you don’t have to hunt across multiple websites.</p><p>It’s online, open-source, and ready for anyone to use. Any feedback or contributions are welcome!</p><p>👉 Check it out: <a href="https://hexmos.com/freedevtools?ref=journal.hexmos.com">FreeDevTools</a><br> ⭐ Star it on GitHub: <a href="https://github.com/HexmosTech/FreeDevTools?ref=journal.hexmos.com">freedevtools</a></p><p><em>Originally published at </em><a href="https://journal.hexmos.com/go-in-memory-cache/"><em>https://journal.hexmos.com</em></a><em> on February 1, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5903237aa75f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Commits to DAGs: How Git Uses a DAG to Track Your Code History]]></title>
            <link>https://medium.com/@ganeshkumarprofession/from-commits-to-dags-how-git-uses-a-dag-to-track-your-code-history-ac2a961448de?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac2a961448de</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 28 Dec 2025 16:07:15 GMT</pubDate>
            <atom:updated>2025-12-28T17:19:10.199Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://journal.hexmos.com/tag/git/">git</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ekO9ah3E8WYCUOJV.png" /></figure><p>Most developers use <a href="https://git-scm.com/?ref=journal.hexmos.com">Git</a> daily, often memorizing commands without fully understanding what happens under the hood. We know <em>how</em> to use git add and git commit, but do we really know <em>how it works</em>?</p><p>At its core, Git is a simple key-value data store. It is a database, and understanding its fundamental unit-the <strong>commit</strong> -is crucial to mastering it.</p><p>In this blog, we will demystify Git by exploring its internal structure, starting with the most important building block.</p><h3>What Is a Commit?</h3><p>A commit is not just a diff; it represents the state of your project at a specific moment in time.<br> Internally, a commit points to a <strong>tree object</strong>, which in turn points to <strong>blob objects</strong> (the actual file contents). Git uses content-addressable storage, so unchanged files are not duplicated-they are simply referenced again.</p><p>Each commit has 3 things.</p><ol><li><strong>Snapshot:</strong> Pointer to the project’s directory tree.</li><li><strong>Metadata:</strong> Author, timestamp, and message.</li><li><strong>Parent:</strong> Pointer to the previous commit.</li></ol><p>This creates a chain where each commit points to its parent, tracing back to the initial commit.</p><p>The first commit has no parent and is called the root commit.</p><p>A merge commit typically has 2 parents.</p><p>We will explore more about Git below.</p><h3>Why Git Uses a DAG</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/0*Yr7clVwXw4oprdSO.png" /></figure><p>Each commit contains a Snapshot, Metadata, and the parent commit ID.<br> Each commit points to its parent.</p><p>Hence, there is no way for the commit history to form a cycle or loop.</p><p>This structure is known as a Directed Acyclic Graph (DAG).</p><p>The resulting graph contains the history of every commit, capturing every decision made by the developer.</p><p>This makes Git powerful, as we can return to the state of any past commit.</p><h3>How Branching Works</h3><p>A common misconception is that a branch contains a full copy of the project files. This is not how Git works.</p><p>A branch is simply a lightweight movable pointer to a commit. It doesn’t contain files; the commit it points to references a tree object, which in turn points to the files (blobs).</p><p>Let’s understand with an example.<br> Master Branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pInkyK9OdKiDs6Oi.png" /></figure><p>Create New Branch</p><pre>git checkout -b iss53 # Switched to a new branch &quot;iss53&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*78dG899EHJurhpDv.png" /></figure><p>Commit changes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k8wCnys4mx7Yytaw.png" /></figure><p>If you want to change anything in the master branch</p><p>Checkout to the branch</p><pre>git checkout master Switched to branch &#39;master&#39;</pre><p>And commit changes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tvAx007C-VkbyQsc.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rriDGIk0kem0V8B-.gif" /></figure><p>We will understand how Git knows in which commit we are working and the structure of git.</p><h3>HEAD: The Pointer for Git Commits</h3><p>Git uses a special pointer called HEAD to track the current location. HEAD usually points to the current branch name, which in turn points to the latest commit.</p><p>Let’s assume we are in the main branch.</p><p>HEAD points to main, and main points to the latest commit.</p><p>Commit will be your current location.</p><p>If we want to create a branch “feature”</p><pre>git checkout feature</pre><p>Suppose we want to check a specific commit. We will use git to point to the specific commit. This will be known as detached HEAD. There will be no branch pointing between head and commit.</p><p>Actually, we can commit a few more changes. But when we switch to a different commit, it will be orphaned, and no branch will be pointing to it; this will be known as an orphaned commit.</p><p>Git’s garbage collector will eventually delete these unreachable commits (usually after 30 days by default).</p><blockquote><em>Actual Reality: We usually try to see in old commits in detached mode. We fix and commit changes. When we move back to the main branch, all commits will be lost.<br> That is why git warns that the head is in detached mode.</em></blockquote><h3>The Structure of Git</h3><p>Git has 3 stages:</p><ol><li><strong>Working Directory:</strong> This consists of the actual files on your disk that you are currently modifying.</li><li><strong>Staging Area (Index):</strong> A file that stores information about what will go into your next commit. (Uses git add .)</li><li><strong>Repository:</strong> Database of commits, also called permanent history. (Uses git commit -m &quot;update&quot;)</li></ol><h3>Git Undo Commands</h3><p>In this section, we will look at git checkout, git reset, and git revert.</p><p>These three commands are all used to undo changes, but they function differently, which can often be confusing.</p><h3>Git Checkout</h3><p>This command will move only the head.</p><p>Git head is now pointing to c3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/0*816UWURND_LO6DvI.png" /></figure><p>Now, when we check out to c1</p><pre>git checkout c1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/0*YEpgCg_Ff0qUra1K.png" /></figure><p>Now, the head is detached, and it is pointing to c1.</p><blockquote><em>Note: No commits are changed, no history is changed, and no branch is moved.</em></blockquote><p>This means we are just seeing changes made in a particular commit.</p><h3>Git Reset</h3><p>Git reset is more powerful than checkout because it moves the branch pointer itself, not just the HEAD.</p><p>Here we have 4 commits</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/0*V0ddXtmxy0ffIVUZ.png" /></figure><p>When we use git reset c1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/0*aST1uCfgowl7HabW.png" /></figure><p>Head moves, and remaining commits will be orphaned.</p><ol><li>--soft<br> Moves HEAD to the target commit. Staged changes and working directory are preserved (changes appear as staged).</li><li>--mixed (Default)<br> Moves HEAD to the target commit. Staging area is reset to match the commit, but working directory is preserved (changes appear as modified but unstaged).</li><li>--hard<br> Moves HEAD to the target commit. Staging area and working directory are reset to match the commit (all uncommitted changes are lost).</li></ol><h3>Git Revert</h3><p>This command creates a new commit that undoes the changes made in a previous commit. It does not remove the old commit from history.</p><p>For example:</p><p>I want to remove c1 from the main branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/0*GcdvQDHS_Qf7CUUp.png" /></figure><p>Git creates a new commit that is the exact opposite of c1, effectively canceling out the changes while keeping the history intact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/0*D0T-bdvuFNVbQ2kq.png" /></figure><h3>Git Rebase</h3><p>When you create a new branch and start committing changes, you create a divergent history (DAG) for that branch.</p><pre># 1. Create and switch to a new branch <br>git checkout -b new-feature # 2. Make some commits <br>git add . git commit -m &quot;D&quot;</pre><p>Meanwhile, other contributors may have pushed new commits to the main branch, meaning your branch is now behind.</p><pre># Switch to main and pull latest changes <br><br>git checkout main <br>sgit pull origin main</pre><p>When you perform a rebase, Git takes the commits from your new branch and “replays” them on top of the latest commit of the main branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*93svpt0KeliD_L_a.png" /></figure><p>Once the rebase is done, the original commits from your new branch are orphaned (no longer used), and your branch now has a clean, linear history extending from the latest main.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TVJx64s4Gt0Lqp_v.png" /></figure><blockquote><em>Note: If you run into conflicts during the rebase, fix the files, add them, and run: </em><em>git rebase --continue</em></blockquote><p>Here are commands to work with it.</p><p>CommandDescription</p><p>git checkout -b &lt;branch&gt;</p><p>Creates and switches to a new branch.</p><p>git rebase main</p><p>Moves your current branch’s commits to the tip of main.</p><p>git rebase --continue</p><p>Continues the rebase process after resolving conflicts.</p><p>git rebase --abort</p><p>Stops the rebase and returns the branch to its original state.</p><h3>Conclusion</h3><p>This blog post provides a detailed introduction to Git, version control, and related concepts.</p><p>However, it is obvious that I have missed out on some important topics like merge conflicts and pull requests. I tried to explain the importance of version control in software development and then explain what Git is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*azzx98TYYbYTLOaR.png" /></figure><p>I’ve been building for <strong>FreeDevTools</strong>.</p><p>A collection of UI/UX-focused tools crafted to simplify workflows, save time, and reduce friction when searching for tools and materials.</p><p>Any feedback or contributions are welcome!</p><p>It’s online, open-source, and ready for anyone to use.</p><p>👉 Check it out: <a href="https://hexmos.com/freedevtools?ref=journal.hexmos.com">FreeDevTools</a><br> ⭐ Star it on GitHub: <a href="https://github.com/HexmosTech/FreeDevTools?ref=journal.hexmos.com">freedevtools</a></p><p><em>Originally published at </em><a href="https://journal.hexmos.com/git-uses-dag/"><em>https://journal.hexmos.com</em></a><em> on December 28, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac2a961448de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CAVLite: Lightweight, Memory-Efficient Security Audit for Low-RAM Servers.]]></title>
            <link>https://medium.com/@ganeshkumarprofession/cavlite-lightweight-memory-efficient-security-audit-for-low-ram-servers-bd032a4341a8?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd032a4341a8</guid>
            <category><![CDATA[clamav]]></category>
            <category><![CDATA[clamscan]]></category>
            <category><![CDATA[clamd]]></category>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 30 Nov 2025 17:01:27 GMT</pubDate>
            <atom:updated>2025-11-30T18:15:41.152Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*taQG1sTUZzjaq_D3.png" /></figure><p>If you run a server with limited resources—specifically, standard 4GB RAM and 2 vCPU setup- you are likely familiar with the constant, stressful balancing act between performance and security.</p><p>You know you need antivirus protection and system audits. You know the risks of leaving a server vulnerable to intruders, malware, and data theft.</p><p>But you also know that running a standard security scan on a lean VPS can be a death sentence for your uptime.</p><p>Ultimately, you are forced into a terrible choice: leave the server vulnerable, or risk crashing the entire machine by running a heavy security scan.</p><p>Standard security tools assume you have hardware to spare.</p><p>But when you are running a production environment on 4GB of RAM, a sudden memory spike doesn’t just slow things down.</p><p>It pins your CPU at 100%, triggers Out of Memory (OOM) kills, takes down your web services, and leaves you scrambling to reboot while your users face downtime.</p><p>We faced this exact problem. After months of continuous trial and error, witnessing servers choke on default configurations, we realized we needed a better way.</p><p>After some continuous trial and error with configurations, we found a way to run ClamAV and Lynis without crashing the system.</p><p>This is why we built <a href="https://github.com/HexmosTech/CAVLite?ref=journal.hexmos.com"><strong>CAVLite</strong></a>.</p><h3>Why clamscan Is a Problem on Low-RAM Servers?</h3><p>The industry standard for open-source Linux security is <a href="https://www.clamav.net/?ref=journal.hexmos.com"><strong>ClamAV</strong></a>.</p><p>It is powerful, effective, and free. However, it is also notoriously resource-intensive.</p><p>clamscan is the standalone command-line scanner.<br> Every time you run it:</p><ul><li>It loads the ENTIRE virus database (600MB-900MB) into RAM</li><li>It unloads it after the scan</li><li>It does this again for each run</li><li>This creates high CPU + heavy RAM spikes → a 4GB server suffers.</li></ul><h3>Why Using Clamd and ClamdScan Is a Better Option</h3><p>Clamd is the ClamAV daemon.</p><ul><li>Loads the virus database once</li><li>Stays in memory</li><li>clamdscan sends scan requests to the daemon</li><li>Fast scanning</li><li>Lower peak RAM usage</li><li>No repeated DB loading</li></ul><h3>Install ClamAV Daemon</h3><pre>sudo apt update sudo apt install clamav-daemon -y</pre><ul><li>This will add clamav-daemon to your system.</li><li>Clamd config file will be created at /etc/clamav/clamd.conf</li></ul><h3>Configure clamd for Low-RAM Usage</h3><p>Edit the config file to limit the memory usage.</p><pre>sudo vim /etc/clamav/clamd.conf</pre><p>You can copy the config file from here : <a href="https://github.com/HexmosTech/CAVLite/blob/main/config/clamav/clamd.conf?ref=journal.hexmos.com">Link</a></p><pre>sudo vim /etc/clamav/freshclam.conf</pre><p>You can copy the config file from here : <a href="https://github.com/HexmosTech/CAVLite/blob/main/config/clamav/freshclam.conf?ref=journal.hexmos.com">Link</a></p><p>By the above configuration, you can run the ClamAV daemon with low RAM usage.</p><p>But there are a lot of manual steps to run a scan.</p><p>So, we created <a href="https://github.com/HexmosTech/CAVLite?ref=journal.hexmos.com"><strong>CAVLite</strong></a> to run scans with ease.</p><h3>Introducing CAVLite</h3><p>CAVLite is a wrapper script that automates the process of running ClamAV scans on your server.</p><p>This will help you configure configs while installing.</p><pre>curl -fsSL https://raw.githubusercontent.com/HexmosTech/CAVLite/main/install.sh | sudo bash</pre><p><strong>Start Security Scan</strong></p><pre>sudo cavlite --start</pre><ul><li>It starts clamav-daemon <em>only</em> when you ask for a scan.</li><li>It waits for the virus definitions to load safely in the background.</li><li>It uses clamdscan (the lightweight client) to talk to the daemon. This is significantly faster and lighter than the standalone clamscan.</li><li>Infected files are immediately moved to a quarantine directory (/var/quarantine).</li><li>It simultaneously triggers <strong>Lynis</strong> to perform a system-wide security audit to check for hardening issues.</li><li>The moment the scan is done, CAVLite stops the daemon. This immediately releases that 1GB of RAM back to your web server or database.</li><li>You get a summary log and a notification (via Discord or other webhooks).</li></ul><p><strong>Stop Security Scan</strong></p><pre>sudo cavlite --stop</pre><ul><li>In case you want to stop the scan, you can use this command.</li><li>It will stop the daemon and release the memory.</li></ul><h3>Conclusion</h3><p>With CAVLite, you can automatically configure and start a scan and get a simple summary discord notification.</p><p>It is open source, and we would love for you to try it out and let us know what you think.</p><p><strong>Check out the repository here:</strong><br><a href="https://github.com/HexmosTech/CAVLite?ref=journal.hexmos.com">https://github.com/HexmosTech/CAVLite</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*3ravC3pFu8ynExmO.png" /></figure><p>We’ve been building for <strong>FreeDevTools</strong>.</p><p>A collection of UI/UX-focused tools crafted to simplify workflows, save time, and reduce friction when searching for tools and materials.</p><p>Any feedback or contributions are welcome!</p><p>It’s online, open-source, and ready for anyone to use.</p><p>👉 Check it out: <a href="https://hexmos.com/freedevtools?ref=journal.hexmos.com">FreeDevTools</a><br> ⭐ Star it on GitHub: <a href="https://github.com/HexmosTech/FreeDevTools?ref=journal.hexmos.com">freedevtools</a></p><p><em>Originally published at </em><a href="https://journal.hexmos.com/cavlite/"><em>https://journal.hexmos.com</em></a><em> on November 30, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd032a4341a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Announcing udwall: A New Tool for Making UFW and Docker Play Nice With Each Other]]></title>
            <link>https://medium.com/@ganeshkumarprofession/announcing-udwall-a-new-tool-for-making-ufw-and-docker-play-nice-with-each-other-87e4aeace91f?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/87e4aeace91f</guid>
            <category><![CDATA[ufw]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[firewall]]></category>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 23 Nov 2025 17:26:17 GMT</pubDate>
            <atom:updated>2025-11-23T18:25:43.167Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://journal.hexmos.com/tag/ufw/">ufw</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7szhOwD_YbX6vArp.png" /></figure><p>Many of us believe that the combination of <a href="https://en.wikipedia.org/wiki/Uncomplicated_Firewall?ref=journal.hexmos.com"><strong>UFW</strong></a> and <a href="https://en.wikipedia.org/wiki/Docker_(software)?ref=journal.hexmos.com"><strong>Docker</strong></a> is the standard stack for deploying applications securely without exposing docker container ports.</p><p>Configuring UFW via provisioning tools like <a href="https://en.wikipedia.org/wiki/Ansible_(software)?ref=journal.hexmos.com">Ansible</a> is usually seamless, giving us confidence that our servers are secure.</p><p>However, there is a massive, often overlooked security gap in this setup that meanse using UFW with Docker can be dangerous.</p><p>Basically, even though your UFW status says “Active” and is set to block all incoming traffic, <strong>Docker container ports often remain wide open to the public internet.</strong></p><p>At <strong>Hexmos</strong>, we are dedicated to enhancing the developer experience, having built tools like <a href="https://hexmos.com/livereview/?ref=journal.hexmos.com"><strong>Livereview</strong></a> and <a href="https://hexmos.com/freedevtools/?ref=journal.hexmos.com"><strong>FreeDevtools</strong></a>.</p><p>We investigated this critical security flaw and built <a href="https://github.com/HexmosTech/udwall?ref=journal.hexmos.com"><strong>udwall</strong></a> to finally make UFW and Docker compatible by default.</p><h3>Understanding Docker Security Flaw</h3><p>The problem is straightforward but alarming. You set up a server, enable UFW, and set a default deny policy. You feel secure.</p><p>Then, you spin up a Docker container and publish a port:</p><p>You might assume that because you haven’t explicitly allowed port 8080 in UFW, it is blocked from the outside world. But it is totaly wrong in actual scenario.</p><p>Curl the port 8080 with ip address of your server.</p><p>You will get response from nginx server.</p><p>Docker interacts directly with iptables. When it starts a container, it inserts rules into the PREROUTING chain of the nat table. These rules take precedence over UFW&#39;s standard rules.</p><p>Essentially, Docker punches a hole right through your firewall, exposing your internal services to the public internet regardless of your UFW configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/0*y8xANH2nFA3ejbW3.png" /></figure><h3>A Decade of Unsolved Docker Security Flaw</h3><p>We are not the only ones facing this. This behavior isn’t a bug in the traditional sense; it’s an architectural conflict that has plagued the DevOps community for years.</p><p>It has been almost <strong>10 years</strong> since this issue was reported, and it remains a major pain point. A quick look at the community discussions reveals the scale of the confusion:</p><ul><li><strong>GitHub Issues:</strong> The original thread <a href="https://github.com/moby/moby/issues/4737?ref=journal.hexmos.com">moby/moby#4737</a> is legendary in the Docker community for its longevity.</li><li><strong>Docker Forums:</strong> Users frequently ask why <a href="https://forums.docker.com/t/running-multiple-docker-containers-with-ufw-and-iptables-false/8953?ref=journal.hexmos.com">UFW is seemingly ignored</a>.</li><li><strong>Stack Overflow:</strong> Countless threads, like <a href="https://askubuntu.com/questions/652556/uncomplicated-firewall-ufw-is-not-blocking-anything-when-using-docker?ref=journal.hexmos.com">this one</a>, show developers scrambling to figure out why their ports are exposed.</li></ul><p>While there are many suggested workarounds, most involve fragile manual scripts that break the moment a container restarts or Docker updates its iptables rules.</p><h3>The Existing Solution (and its Drawbacks)</h3><p>When we first encountered issues, we looked for established solutions. The “gold standard” for years has been a project called ufw-docker by <strong>chaifeng</strong>.</p><p>It is a fantastic utility that solves the underlying routing issue by modifying the iptables configuration to add a custom DOCKER-USER chain. This ensures traffic destined for Docker containers is actually checked by UFW before being allowed through.</p><p>However, as we adopted it in production, we ran into significant friction that made automation difficult:</p><ol><li><strong>Manual Rule Management:</strong> It requires manual steps to manage rules for specific containers. If you are automating infrastructure, these manual interventions are a bottleneck.</li><li><strong>Persistence &amp; State Issues:</strong> We found that if UFW was disabled or reloaded, the protection for Docker ports could become inconsistent.</li><li><strong>Complex Uninstall:</strong> Historically, removing the tool was risky. It required manually stripping iptables rules, and doing it wrong could lock you out of your server.</li></ol><blockquote><em>Note: </em><em>ufw-docker recently added an </em><a href="https://github.com/chaifeng/ufw-docker/commit/c45eff693f87a8a7f7a002c8b337abbf22480ca9?ref=journal.hexmos.com"><em>uninstall command</em></a><em>.</em></blockquote><h3>Why We Built udwall?</h3><p>At Hexmos, our internal infrastructure relies heavily on Docker. We needed a solution that was:</p><ol><li><strong>Secure by default</strong> (fixing the Docker hole).</li><li><strong>Native to UFW</strong> (no weird hacks).</li><li><strong>Easy to automate</strong> (for tools like Ansible).</li></ol><p>We realized that the existing solutions, while brilliant, were too manual for a modern, fast-paced CI/CD environment.</p><p>We started building udwall originally as an internal tool to secure our own servers without the headache of manual rule management.</p><p>However, seeing that thousands of developers have been struggling with this exact issue for a decade, we decided to open source it.</p><p>udwall is our attempt to make UFW and Docker play nicely together, automatically, so you can trust your firewall again.</p><p>udwall builds upon the solid logic of ufw-docker but wraps it in a declarative management system. It is designed to make UFW Docker-compatible with a single command.</p><h3>What makes udwall different?</h3><ol><li><strong>Declarative:</strong> You define your rules in a Python-based config file (udwall.conf).</li><li><strong>Atomic Updates:</strong> When you apply changes, udwall handles the logic. It removes old rules that are no longer in your config and applies the new ones.</li><li><strong>Safety:</strong> It automatically backs up your /etc/ufw and iptables rules before every change, so you can always revert if something goes wrong.</li><li><strong>Simplicity:</strong> It handles both standard host rules (like SSH) and Docker routing rules in one place.</li></ol><h3>Getting Started with udwall</h3><p>The goal of this tool is to minimize friction. Here is how you can secure your Docker host in just a few minutes.</p><p>Continue Reading: <a href="https://journal.hexmos.com/udwall/#installation">Link</a></p><p><strong>Check out the repository here:</strong><br><a href="https://github.com/HexmosTech/udwall?ref=journal.hexmos.com">https://github.com/HexmosTech/udwall</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Irok6nTUN3refZ0E.png" /></figure><p>We’ve been building for <strong>FreeDevTools</strong>.</p><p>A collection of UI/UX-focused tools crafted to simplify workflows, save time, and reduce friction when searching for tools and materials.</p><p>Any feedback or contributions are welcome!</p><p>It’s online, open-source, and ready for anyone to use.</p><p>👉 Check it out: <a href="https://hexmos.com/freedevtools?ref=journal.hexmos.com">FreeDevTools</a><br> ⭐ Star it on GitHub: <a href="https://github.com/HexmosTech/FreeDevTools?ref=journal.hexmos.com">freedevtools</a></p><p><em>Originally published at </em><a href="https://journal.hexmos.com/udwall/"><em>https://journal.hexmos.com</em></a><em> on November 23, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87e4aeace91f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How TCP and UDP Protocols Work: Understanding Their Critical Role in Internet Communication]]></title>
            <link>https://medium.com/@ganeshkumarprofession/how-tcp-and-udp-protocols-work-understanding-their-critical-role-in-internet-communication-c53d0b119180?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c53d0b119180</guid>
            <category><![CDATA[udp]]></category>
            <category><![CDATA[tcp]]></category>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 19 Oct 2025 14:41:33 GMT</pubDate>
            <atom:updated>2025-10-19T15:44:30.689Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://journal.hexmos.com/tag/tcp/">tcp</a></p><p>How does data travel from a server to your screen in a split second? What is the logic behind it? What rules and protocols does it use that make it all work?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Hut2Bi7qfDuNcdXj.png" /></figure><p><em>Hello, I’m Ganesh. I’m working on</em> <a href="https://hexmos.com/freedevtools"><em>FreeDevTools online</em></a><em>,</em> <a href="https://hexmos.com/freedevtools"><em>currently building</em></a> <em>one place for all dev tools, cheat codes, and TLDRs</em> — a free, open-source hub where developers can quickly find and use tools without any hassle of searching all over the internet.</p><p>Two of the most important players in this process are <a href="https://en.wikipedia.org/wiki/Transmission_Control_Protocol?ref=journal.hexmos.com"><strong>TCP</strong></a> and <a href="https://en.wikipedia.org/wiki/User_Datagram_Protocol?ref=journal.hexmos.com"><strong>UDP</strong></a>.</p><p>Think of them as two different types of postal services.</p><p>One is like sending a tracked, registered letter that requires a signature, while the other is like dropping a quick postcard in the mailbox.</p><p>Both get the message across, but they are designed for very different jobs. Let’s break down what they are, how they work, and when you’d use one over the other.</p><h3>Logic Behind Each Protocol</h3><p>The biggest difference between TCP and UDP comes down to a simple trade-off: do you need every single piece of data to arrive perfectly, or do you need the data to arrive as fast as possible?</p><p><strong>TCP (Transmission Control Protocol)</strong> is the reliable option. It’s built to guarantee that every packet of data sent from a source arrives at the destination, and in the correct order. It achieves this using two key mechanisms:</p><ul><li><strong>Sequence Numbers</strong>: TCP labels every data packet with a number. This allows the receiving computer to reassemble the packets in the right order, even if they arrive jumbled.</li><li><strong>Acknowledgments (ACKs)</strong>: When the receiver gets a packet, it sends back an acknowledgment, or an “ACK,” telling the sender, “I got packet #5!” If the sender doesn’t receive an ACK for a specific packet, it assumes it was lost and sends it again.</li></ul><p>This back-and-forth checking makes TCP incredibly robust, but all this coordination adds extra work, which we call <strong>overhead</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*Jw3vISEZ0Q486Crr.png" /></figure><p><strong>UDP (User Datagram Protocol)</strong> is the speedy, “best-effort” option. It’s designed for low overhead and high speed. UDP sends packets out but offers no guarantees. It doesn’t know if the data arrived, if it arrived in order, or if it was corrupted along the way. It’s like dropping that postcard in the mail-it’s fast and simple, but you’re not entirely sure it will get there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/0*jsIKRatD56eUf9bR.png" /></figure><h3>Difference Between TCP and UDP</h3><p>This difference in reliability stems from how each protocol starts a conversation.</p><h3>TCP is connection-oriented.</h3><p>Before it sends any actual data, it performs a process called a <strong>three-way handshake</strong>. It’s the digital equivalent of a phone call:</p><ol><li><strong>Computer A to Server B</strong>: “Hi, are you there? I’d like to connect.” (This is a SYN packet)</li><li><strong>Server B to Computer A</strong>: “Yes, I’m here and ready to connect.” (A SYN-ACK packet)</li><li><strong>Computer A to Server B</strong>: “Great, here comes the data!” (An ACK packet)</li></ol><p>Only after this formal connection is established does the data transfer begin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5hLhowcMrVa6QV6G.png" /></figure><p>Continue Reading: <a href="https://journal.hexmos.com/understanding-tcp-udp/#udp-is-connectionless">Link</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*loqa36fZRWOfVoZK.png" /></figure><p>I’ve been building for <strong>FreeDevTools</strong>.</p><p>A collection of UI/UX-focused tools crafted to simplify workflows, save time, and reduce friction in searching tools/materials.</p><p>Any feedback or contributions are welcome!</p><p>It’s online, open-source, and ready for anyone to use.</p><p>👉 Check it out: <a href="https://hexmos.com/freedevtools">FreeDevTools</a><br>⭐ Star it on GitHub: <a href="https://github.com/HexmosTech/FreeDevTools">freedevtools</a></p><p><em>Originally published at </em><a href="https://journal.hexmos.com/understanding-tcp-udp"><em>https://journal.hexmos.com</em></a><em> on October 19, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c53d0b119180" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[These Key Features of GraphQL make it Unique among Other API Technologies]]></title>
            <link>https://medium.com/@ganeshkumarprofession/these-key-features-of-graphql-make-it-unique-among-other-api-technologies-46f31e3a7baf?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/46f31e3a7baf</guid>
            <category><![CDATA[graphql-vs-rest]]></category>
            <category><![CDATA[graphql-schema]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 07 Sep 2025 15:26:14 GMT</pubDate>
            <atom:updated>2025-09-07T16:03:12.916Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://journal.hexmos.com/tag/graphql/">graphql</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PugK6OYcakuZ3b8R.png" /></figure><p><em>Hello, I’m Ganesh. I’m building </em><a href="https://hexmos.com/livereview/"><em>LiveReview</em></a><em>, a private AI code review tool that runs on your LLM key (OpenAI, Gemini, etc.) with highly competitive pricing — built for small teams. Do check it out and give it a try!</em></p><p>When building modern applications, especially for mobile devices, how you get data from the server to the client is everything. For years, REST has been the standard for API design, but it often comes with frustrations. Let’s look at the problems that led to a new way of thinking and the birth of a powerful alternative: GraphQL.</p><h3>Why was <a href="https://graphql.org/?ref=journal.hexmos.com">GraphQL</a> introduced in the first place?</h3><p>Before we dive into <a href="https://graphql.org/?ref=journal.hexmos.com">GraphQL</a>, it’s crucial to understand the challenges it was designed to solve. Traditional API architectures like REST often struggle with two pervasive and inefficient patterns:</p><ul><li><a href="https://www.geeksforgeeks.org/graphql/what-are-over-fetching-and-under-fetching/?ref=journal.hexmos.com"><strong>Over-fetching</strong></a><strong>:</strong> This happens when an endpoint returns more data than the client application actually needs. Imagine needing just a user’s name but receiving an object with 20 fields of user information. This wastes bandwidth and adds unnecessary processing overhead for the client.</li><li><a href="https://www.geeksforgeeks.org/graphql/what-are-over-fetching-and-under-fetching/?ref=journal.hexmos.com"><strong>Under-fetching</strong></a><strong>:</strong><br> This is the opposite problem, where a single endpoint doesn’t provide all the required data, forcing the client to make multiple API calls. To get a blog post, its author, and its comments, an application might have to make three sequential requests. This “request waterfall” significantly increases load times, especially on slow mobile networks.</li></ul><p>These inefficiencies were particularly painful in an increasingly mobile-centric world, setting the stage for a new solution.</p><h3>The Birth of GraphQL</h3><p>The story of GraphQL begins at <a href="https://developers.facebook.com/?ref=journal.hexmos.com">Facebook</a> around 2011–2012. The company was making a critical pivot from HTML5-based mobile apps to fully native experiences. They quickly realized their existing REST-like APIs were deeply inefficient for this new mobile environment. The multiple round-trips and bloated data payloads resulted in slow load times and a poor user experience on unreliable mobile networks.</p><p>In response, an internal team was tasked with creating a more efficient data-fetching API specifically for their native iOS application. This project evolved into GraphQL, and its first version was deployed in 2012 to power the News Feed in the redesigned Facebook for iOS app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9H-oacRhPJZpCWmM.png" /></figure><p>This origin story is key: GraphQL wasn’t an academic exercise. It was <strong>forged as a practical solution to a pressing business problem</strong>, with the performance needs of the client application as its primary driver.</p><h3>Mastering the Operations: Queries, Mutations, and Subscriptions</h3><p>At its core, GraphQL allows clients to interact with the API through three distinct types of operations.</p><h3><a href="https://graphql.org/learn/queries/?ref=journal.hexmos.com">Queries</a>: For Reading Data</h3><p>A GraphQL <a href="https://graphql.org/learn/queries/?ref=journal.hexmos.com"><strong>Query</strong></a> is a read-only operation used to request data from the server. The client declaratively specifies the exact data fields it needs, and the server responds with a JSON object where the structure precisely mirrors the query. This solves over-fetching and under-fetching in a single request.</p><p>For example, to fetch a specific user’s name and email, the query would look like this:</p><pre>query {<br>  user(id: 123) {<br>    name<br>    email<br>  }<br>}</pre><h3>Mutations: For Writing Data</h3><p>While queries are for reading data, <a href="https://graphql.org/learn/mutations/?ref=journal.hexmos.com"><strong>Mutations</strong></a> are used for all write operations, such as creating, updating, or deleting data.</p><p>A critical feature is that mutations in a single request are <strong>guaranteed to execute serially</strong>, which prevents race conditions and makes side effects predictable.</p><p>Here, the mutation creates a new user and asks for the id, name, and email of the newly created user to be returned in the response.</p><pre>mutation {<br>  createUser(input: { name: &quot;John Doe&quot;, email: &quot;johndoe@example.com&quot; }) {<br>    id<br>    name<br>    email<br>  }<br>}</pre><p>This mutation finds a user by their id and updates their information. The response will contain the updated data.</p><pre>mutation {<br>  updateUser(id: 123, input: { name: &quot;Jane Smith&quot;, email: &quot;janesmith@example.com&quot; }) {<br>    id<br>    name<br>    email<br>  }<br>}</pre><p>This mutation deletes a user and returns the data of the user that was just removed.</p><pre>mutation {<br>  deleteUser(id: 123) {<br>    id<br>    name<br>    email<br>  }<br>}</pre><p><a href="https://graphql.org/learn/subscriptions/?ref=journal.hexmos.com"><strong>Subscriptions</strong></a> are the third operation type, designed to handle real-time data updates. A client can subscribe to specific events on the server. When that event occurs, the server pushes the updated data to the client over a long-lived connection, typically using WebSockets.</p><p>For example, a client could subscribe to receive updates whenever a new comment is added to a specific blog post:</p><pre>subscription {<br>  newComment(postId: &quot;123&quot;) {<br>    id<br>    content<br>    author {<br>      name<br>    }<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IceGibwmY-Wn2lnm.png" /></figure><p>After sending this subscription, the client will maintain a connection to the server and automatically receive the new comment’s details every time a comment is added to post “123”.</p><p>Continue Reading: <a href="https://journal.hexmos.com/graphql-features/#key-features-of-graphql">Link</a></p><p><a href="https://hexmos.com/livereview/?utm_source=https://journal.hexmos.com/graphql-features&amp;utm_medium=bannerad&amp;utm_campaign=liveapi">LiveReview</a> helps you get great feedback on your PR/MR in a few minutes. Saves hours on every PR by giving fast, automated first-pass reviews. If you’re tired of waiting for your peer to review your code or are not confident that they’ll provide valid feedback, here’s LiveReview for you.</p><p><em>Originally published at </em><a href="https://journal.hexmos.com/graphql-features/"><em>https://journal.hexmos.com</em></a><em> on September 7, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46f31e3a7baf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Graphs in Golang Without Starting from Scratch]]></title>
            <link>https://medium.com/@ganeshkumarprofession/implementing-graphs-in-golang-without-starting-from-scratch-43e701c9ff9e?source=rss-17c2bb50062c------2</link>
            <guid isPermaLink="false">https://medium.com/p/43e701c9ff9e</guid>
            <category><![CDATA[graph]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ganesh Kumar]]></dc:creator>
            <pubDate>Sun, 27 Jul 2025 16:10:08 GMT</pubDate>
            <atom:updated>2025-07-27T16:30:05.393Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JiRot2QQaDI52E1M.png" /></figure><p>Have you ever imagined a world without connections? Think about your social media full of random unknown people in your follow recommendations, maps not showing the shortest direction between two destinations, or file imports turning into a mess of unrelated modules after compiling. This would be hard even to imagine, right?</p><p>This type of core data is managed by creating connections between it, thereby forming a network of relationships. In programming terms, we call this a <a href="https://en.wikipedia.org/wiki/Graph_(abstract_data_type)?ref=journal.hexmos.com">graph data structure</a>.</p><p>In this article, you’ll see how to use this structure to solve any problems related to relations.</p><h3>What is a Graph?</h3><p>A graph is a nonlinear data structure that contains nodes and edges. A node (or vertex) is just a single unique value, while an edge represents a connection or relationship between two of these nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4G2hnWaDOmRu0nxj.png" /></figure><p>Think of something like Instagram: every user is a node, and every time you follow a user, you create a new edge connecting two nodes together.</p><p>This is known as a directed graph because the relationship flows one way-the follower follows the followed, and not vice‑versa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*S-qXT699TIV5dIMJ.png" /></figure><p>Now consider Facebook: your edges in the graph are friendships, and this relationship goes both ways, which is known as an undirected graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Llw2du_xwRpOJh92.png" /></figure><p>Graphs can also be <strong>weighted</strong>, which means the edge has some additional data about the relationship, like the distance between two airports.</p><p>A node might also point to itself, like an airplane that takes off and comes back to land at the same airport-this is known as a cycle.</p><p>When a directed graph has no cycles-that is, you can’t start at one node and eventually loop back-it’s called a <a href="https://en.wikipedia.org/wiki/Directed_acyclic_graph?ref=journal.hexmos.com"><strong>Directed Acyclic Graph (DAG)</strong></a>. DAGs are perfect for modeling hierarchical structures, where each link has a clear one‑way flow (for example, parent → child in a family tree).</p><p>One way to represent a graph in memory is with an <strong>adjacency matrix</strong> (a 2D array). You create one row and one column per node; if there’s an edge from node <em>i</em> to node <em>j</em>, you place a 1 at cell <em>(i, j)</em>, otherwise a 0. This makes lookups for a specific edge extremely fast, but costs <strong>O(n²)</strong> space and even <strong>O(n²)</strong> time to insert a new node.</p><p>An alternative approach is an adjacency list: in this representation, we start with a collection of nodes, then each node has its array of its neighbours. This makes it faster to iterate over a node’s edges and is more efficient with memory, especially when you have many nodes and few edges.</p><p>This format is much more space-efficient when most people follow only a few others. It’s like everyone keeping a short list of their connections instead of filling out a big full table.</p><h3>Applying Graph Concepts to a Family Tree</h3><p>Let us now consider a <strong>DAG</strong> and apply it to something like <strong>family relationships</strong>:</p><p>No loops are possible because a child can’t point back to an ancestor. This makes DAGs ideal for modeling things like <strong>family trees</strong>, where a person can have one or more children, but no backward links to parents or ancestors.</p><p>Let’s work with a concrete example. Imagine you have a scattered list of family members:</p><p>This flat slice hides a clear family structure. We can model this with a DAG where each person is a <strong>node</strong> and each parent-child link is a directed <strong>edge</strong>.</p><p>First, we’ll define a struct for our nodes using the <a href="https://github.com/dominikbraun/graph?ref=journal.hexmos.com">github.com/dominikbraun/graph</a> library.</p><p>Continue Reading: <a href="https://journal.hexmos.com/graph-implementation-in-go/#building-and-visualizing-the-graph">Link</a></p><p><em>Originally published at </em><a href="https://journal.hexmos.com/graph-implementation-in-go/"><em>https://journal.hexmos.com</em></a><em> on July 27, 2025.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43e701c9ff9e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>