<?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 Harsh Kumar on Medium]]></title>
        <description><![CDATA[Stories by Harsh Kumar on Medium]]></description>
        <link>https://medium.com/@harshkumar.h?source=rss-9e58d4660450------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*m3TxzIobPKzp1W0rTKfxUQ.jpeg</url>
            <title>Stories by Harsh Kumar on Medium</title>
            <link>https://medium.com/@harshkumar.h?source=rss-9e58d4660450------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 21:53:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harshkumar.h/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[gRPC and Protocol Buffers: A Simple Explanation]]></title>
            <link>https://medium.com/@harshkumar.h/grpc-and-protocol-buffers-a-simple-explanation-726b81c5fb05?source=rss-9e58d4660450------2</link>
            <guid isPermaLink="false">https://medium.com/p/726b81c5fb05</guid>
            <dc:creator><![CDATA[Harsh Kumar]]></dc:creator>
            <pubDate>Sun, 07 Sep 2025 16:04:27 GMT</pubDate>
            <atom:updated>2025-09-07T16:04:27.409Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever worked with distributed systems, you’ve probably heard the terms <strong>gRPC</strong> and <strong>Protocol Buffers (Protobuf)</strong>. They might sound intimidating, but they solve very common problems in a smart and efficient way.</p><p>In this blog, I’ll explain <strong>what gRPC and Protobuf are, why they exist, and how they work</strong>, all in simple words. My focus will be on concepts rather than implementation details, so you’ll get a solid understanding of the core architecture.</p><h4><strong>Key Terms to Know Beforehand</strong></h4><p><strong>. IDL (Interface Definition Language):</strong>An IDL is a language that enables programs written in different programming languages to communicate. It defines the structure of messages and the methods that can be called. In simple terms, it acts as a contract between two services.</p><figure><img alt="Fig 1" src="https://cdn-images-1.medium.com/max/1024/1*GuHpBLwsAmP6WXMnK2Th7w.png" /></figure><ul><li><strong>HTTP/2:</strong> A major revision of the HTTP protocol, offering features like <strong>multiplexing</strong> (sending multiple requests/responses over a single connection) and <strong>streaming</strong>, which make communication faster and more efficient.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4oRQ1QkymdMs6IwA7MUdgQ.png" /></figure><h4><strong>What is gRPC?</strong></h4><p><strong>gRPC</strong> is a modern, high-performance framework for <strong>Remote Procedure Calls (RPCs)</strong>.</p><p>In simple terms:</p><ul><li>It allows a client to <strong>invoke a function on a remote server as if it were local</strong>.</li><li>Unlike <strong>REST</strong>, which revolves around <strong>resources and HTTP methods (GET, POST, PUT, DELETE)</strong>, gRPC revolves around <strong>functions and their input/output messages</strong>.</li></ul><p>gRPC was <strong>open-sourced by Google in 2015</strong>. Interestingly, the <strong>“g” in gRPC doesn’t officially stand for Google</strong> — Google has given it different playful meanings across versions.</p><p>From an implementation perspective:</p><ul><li>On the <strong>server side</strong>, you define and implement the service methods.</li><li>On the <strong>client side</strong>, gRPC generates a <strong>stub</strong> that exposes those methods as if they were local functions.</li><li>Under the hood, gRPC handles all the <strong>network communication, serialization (via Protobuf), and transport (via HTTP/2)</strong>.(more on this below)</li></ul><h4><strong>Why gRPC is useful:</strong></h4><ul><li>Microservices often involve multiple services written in different languages. gRPC makes <strong>service-to-service communication simpler and consistent</strong>.</li><li>gRPC functions are easier to reason about. The code itself is almost self-documenting.</li><li>It supports multiple programming languages with official libraries.</li><li>It leverages <strong>HTTP/2</strong> for better performance</li></ul><p><strong>Analogy:</strong> Think of your home internet cable: it’s a single wire, yet it carries Zoom calls, YouTube streams, WhatsApp messages, and file downloads all at the same time. That’s how HTTP/2 works — it multiplexes multiple streams over a single TCP connection.</p><h4><strong>What is Protocol Buffers (Protobuf)?</strong></h4><p><strong>Protobuf</strong> is the most common IDL used with gRPC. It lets you define <strong>data structures and service contracts</strong> in <strong>.proto</strong> files.As this is in the form of a contract, both the client and server need to have the same proto file. The proto file acts as the intermediary contract for client to call any available functions from the server.</p><p>The encoding method Protobuf uses is pretty complicated. If you want to take a deep dive into how it works, check out this <a href="https://protobuf.dev/programming-guides/encoding/">comprehensive documentation.</a></p><pre><br>syntax = “proto3”;<br><br>service Greeter {<br>  rpc SayHello (HelloRequest) returns (HelloResponse);<br>}<br><br>message HelloRequest {<br>  string name = 1;<br>}<br><br>message HelloResponse {<br>  string message = 1;<br>}</pre><h4><strong>Why use Protobuf instead of JSON:</strong></h4><ul><li><strong>Compact binary format:</strong> Smaller and faster than JSON.</li><li><strong>Language-agnostic code generation:</strong> Define your service once, and gRPC can generate client and server code in Go, Java, Python, Node.js, and more.</li><li><strong>Strong contracts:</strong> Both client and server must use the same proto file, ensuring compatibility.</li></ul><p><strong>Analogy:</strong> Using Protobuf is like sending a <strong>zipped file</strong> instead of a huge raw file — it’s faster and saves space.</p><h4><strong>Let’s clear common confusion:</strong></h4><ul><li>gRPC manages <strong>how the client and server communicate</strong>.</li><li>Protobuf handles <strong>how data is encoded/decoded</strong>.</li></ul><p>They are separate, but they complement each other perfectly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-rEW31cdBfwAw6gJ8hpAw.png" /></figure><h4><strong>Why Not Just Use REST?</strong></h4><p>REST APIs have been the backbone of the web for years, but they have limitations:</p><ul><li>Less efficient for microservices with high inter-service communication.</li><li>Not ideal for real-time streaming or performance-critical systems.</li></ul><p>gRPC solves these issues and brings additional advantages.</p><h4><strong>Advantages of gRPC</strong></h4><ol><li><strong>HTTP/2 → Faster communication with multiplexing</strong></li></ol><ul><li>Multiple requests and responses can flow simultaneously over a single connection without blocking.</li><li>Supports streaming for client, server, and bidirectional communication.</li></ul><p><strong>2. Streaming Types in gRPC:</strong></p><ul><li><strong>Unary:</strong> Single request, single response.</li><li><strong>Server streaming:</strong> Single request, multiple responses.</li><li><strong>Client streaming:</strong> Multiple requests, single response.</li><li><strong>Bidirectional streaming:</strong> Both client and server stream data simultaneously.</li></ul><p><strong>3. Cross-language support</strong></p><ul><li>gRPC can generate code for multiple programming languages from a single .proto file.</li></ul><p><strong>4. Strong contracts</strong></p><ul><li>Both client and server adhere to the same interface, reducing miscommunication and runtime errors.</li></ul><h4><strong>Conclusion :</strong></h4><ul><li><strong>gRPC</strong> allows you to call functions on a remote server as if they were local, making service-to-service communication efficient and structured.</li><li><strong>Protocol Buffers (Protobuf)</strong> define the data and service contracts in a compact, language-agnostic format, ensuring consistent communication between clients and servers.</li></ul><p>In this post, we’ve only touched the tip of the iceberg — there’s much more to explore in gRPC and Protobuf.</p><p>You can check out <strong>practical examples of gRPC streaming and other features</strong> in my <a href="https://github.com/harshsharma2112/Go-Grpc-Project">Go gRPC project on GitHub.</a></p><p>I’d love to hear your thoughts! Share your <strong>experiences, questions, or corrections</strong> in the comments. Continuous learning and discussion make these technologies easier to master.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=726b81c5fb05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Memory Chaos to Control: Mastering GOMEMLIMIT in Go]]></title>
            <link>https://medium.com/@harshkumar.h/from-memory-chaos-to-control-mastering-gomemlimit-in-go-3265397bde2c?source=rss-9e58d4660450------2</link>
            <guid isPermaLink="false">https://medium.com/p/3265397bde2c</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[artificalintelligence]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Harsh Kumar]]></dc:creator>
            <pubDate>Sat, 07 Jun 2025 12:12:02 GMT</pubDate>
            <atom:updated>2025-06-07T12:12:02.950Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*VXFRljx7Z-fqr9ycCdrL4A.png" /></figure><p>Recently, while working at my organization, I faced a frustrating issue — one of my microservices started <strong>slowing down significantly</strong>. After digging in, I discovered the culprit: <strong>CPU throttling</strong>. This happens when the system restricts how much CPU a process can use.</p><p>CPU throttling often relates to <strong>memory management</strong>, as the system may throttle CPU usage to cope with <strong>memory pressure</strong>. The most common reasons include:</p><ul><li><strong>High memory pressure</strong> causing the OS to restrict resources.</li><li><strong>Garbage Collection (GC) overhead</strong>, where Go’s runtime spends too much CPU time cleaning up unused memory instead of letting the app do its real work.</li><li><strong>Burst allocation spikes</strong> that cause resource contention.</li></ul><p>In this blog, I’ll focus on CPU throttling caused by frequent <strong>garbage collection</strong> in Go applications. This often happens when your app <strong>doesn’t have enough memory</strong> to run smoothly, causing the <strong>GC to compete</strong> with your program for CPU time.</p><h3>Why Understanding Go Matters</h3><p>Before diving into <strong>GOMEMLIMIT</strong>, it’s helpful to know some basics about Go itself.</p><p>Go is a <strong>compiled language</strong> — your code is converted into a <strong>standalone executable</strong> before running. This makes Go programs <strong>faster and more predictable</strong> compared to interpreted languages like Python or JavaScript.</p><p>But Go also comes with a <strong>garbage collector (GC)</strong>, like other languages such as <strong>C# or Java</strong>. This means you <strong>don’t have to manually free memory</strong> — the GC runs in the background and <strong>cleans up memory</strong> that’s no longer needed.</p><p>While convenient, the <strong>GC does consume CPU time</strong> — and if it runs too often, it can <strong>impact your application’s performance</strong>.</p><h3>Stack vs Heap: How Go Allocates Memory</h3><p>Go uses <strong>two main areas</strong> to allocate memory: the <strong>stack</strong> and the <strong>heap</strong>.</p><ul><li><strong>Stack allocation</strong> is <strong>fast and cheap</strong>. It’s for <strong>short-lived, local variables</strong> inside functions. These are automatically <strong>cleaned up</strong> when the function ends, so the <strong>GC doesn’t need to touch them</strong>.</li><li><strong>Example:</strong></li></ul><pre>func countToTen() {<br>    for i := 0; i &lt; 10; i++ {<br>        fmt.Println(i)  // &#39;i&#39; is allocated on the stack<br>    }<br>}</pre><p><strong>. Heap allocation</strong> is <strong>slower and more expensive</strong>. It’s for variables that <strong>live longer</strong>, like those <strong>shared between goroutines</strong> or <strong>returned from functions</strong>. The <strong>GC manages heap memory</strong> by freeing unused objects.</p><p><strong>Example:</strong></p><pre>type User struct {<br>    Name string<br>}<br><br>func newUser(name string) *User {<br>    return &amp;User{Name: name}  // allocated on the heap<br>}<br><br>func main() {<br>    u := newUser(&quot;Alice&quot;)<br>    fmt.Println(u.Name)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*I0n3A3yBWniGtizisrSxZQ.jpeg" /></figure><h4><strong>Even with Enough Memory, OOM Can Still Happen</strong></h4><p>Sometimes, even when your system has <strong>enough free memory</strong>, your app can get <strong>killed by Out-Of-Memory (OOM) errors</strong>. This usually happens because <strong>container limits (cgroups)</strong> or OS heuristics <strong>see sudden memory spikes as too risky</strong>. If the <strong>garbage collector can’t free memory fast enough</strong>, your app’s <strong>memory usage may burst past limits</strong>, causing termination.</p><p>🔹 <strong>Example</strong>: Imagine your <strong>server has 4 GB free</strong>, and your <strong>app is using 1 GB</strong>. You might think you’re <strong>safe</strong> — but if the <strong>GC can’t reclaim memory fast enough</strong> due to <strong>allocation patterns</strong> or <strong>CPU throttling</strong>, or if the <strong>OS enforces strict container memory limits</strong>, your app might still <strong>get killed unexpectedly</strong>.</p><p><strong>GOMEMLIMIT helps</strong> by setting a <strong>clear memory usage target</strong> for Go, smoothing out these spikes and <strong>avoiding unexpected kills</strong>.</p><h4><strong>What Is a Soft Limit?</strong></h4><p>Think of a <strong>soft limit</strong> as a guideline rather than a <strong>hard cap</strong>. The Go runtime <strong>tries to keep memory usage below this limit</strong>, but if your application needs <strong>more than the allocated limit</strong>, the <strong>garbage collector (GC) will compete</strong> with your program for resources. This can lead to unexpected crashes.</p><p>🔹 <strong>Example</strong>: Imagine your <strong>app typically requires 1 GB</strong> of memory to run smoothly. You set <strong>GOMEMLIMIT to 1.2 GB</strong> to keep memory usage under control. However, at some point, your app suddenly tries to <strong>allocate 1.3 GB</strong> due to increased workload or spikes in heap usage. Since the runtime is already managing memory <strong>to stay within the soft limit</strong>, the <strong>GC may attempt to reclaim memory</strong> at the same time your code is trying to allocate more. This <strong>resource contention</strong> can cause your app to <strong>slow down, stall, or even crash</strong>, because the GC isn’t able to free memory fast enough to accommodate the demand.</p><h4><strong>Balancing Memory Usage and CPU Efficiency: Setting GOMEMLIMIT Effectively</strong></h4><p>The <strong>GOMEMLIMIT</strong> variable allows you to <strong>set a soft heap memory limit</strong> for your Go program, keeping memory allocation under control. When heap usage <strong>approaches this limit</strong>, Go <strong>triggers garbage collection more aggressively</strong> to free unused memory <strong>before hitting a critical failure</strong>.</p><p>🔹 <strong>For example:</strong> If your <strong>app typically requires 1 GB</strong>, then setting <strong>GOMEMLIMIT to 1.5 GB</strong> provides a <strong>safe buffer</strong> for normal operations. Meanwhile, defining a <strong>strict memory cap at 1.8 GB</strong> ensures your app doesn’t exceed safe memory limits while preventing excessive GC cycles.</p><p>🔹 <strong>Optimal GOMEMLIMIT values</strong> can vary based on <strong>available resources, workload spikes, and container constraints</strong>, so monitoring <strong>memory trends and adjusting accordingly</strong> is crucial for <strong>long-term performance stability</strong>.</p><h4>Simple Tips for Effective GOMEMLIMIT Configuration</h4><p>✅ <strong>Monitor</strong> your app’s <strong>typical heap memory usage</strong> over time.</p><p>✅ Choose a <strong>GOMEMLIMIT value</strong> slightly <strong>above this typical usage</strong>.</p><p>✅ Ensure the limit <strong>gives enough room</strong> for <strong>occasional memory spikes</strong>.</p><p>✅ Avoid <strong>setting the limit too low</strong> to prevent <strong>frequent garbage collection</strong>.</p><p>✅ Adjust the <strong>limit based on observed app behavior</strong> and performance in production.</p><p><strong>Final Thoughts</strong></p><p>GOMEMLIMIT is a <strong>powerful tool</strong> for managing your <strong>Go app’s memory and performance</strong> — but it requires <strong>careful tuning</strong>. Understanding how <strong>Go allocates memory</strong> and how <strong>garbage collection works</strong> will help you <strong>choose the right limits</strong> and <strong>keep your services running smoothly</strong>.</p><p>What are your experiences with GOMEMLIMIT or memory optimization in Go? Share your insights in the comments below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3265397bde2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>