<?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 Siddhartha Varma on Medium]]></title>
        <description><![CDATA[Stories by Siddhartha Varma on Medium]]></description>
        <link>https://medium.com/@siddharthav?source=rss-d4f96f432560------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZcffwXudELSnuRMcyF0lwQ.jpeg</url>
            <title>Stories by Siddhartha Varma on Medium</title>
            <link>https://medium.com/@siddharthav?source=rss-d4f96f432560------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:02:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@siddharthav/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[Your Claude is only as smart as you are.]]></title>
            <link>https://siddharthav.medium.com/your-claude-is-only-as-smart-as-you-are-309448b67ce0?source=rss-d4f96f432560------2</link>
            <guid isPermaLink="false">https://medium.com/p/309448b67ce0</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Siddhartha Varma]]></dc:creator>
            <pubDate>Sat, 20 Sep 2025 06:01:46 GMT</pubDate>
            <atom:updated>2025-09-22T05:39:40.271Z</atom:updated>
            <content:encoded><![CDATA[<h3>Software Engineering in the Agentic Era</h3><h3>When Prompting Becomes Programming</h3><p>Prompt in, app out. The code fails, but too many <em>builders</em> cannot tell you why.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5fBA3FcR5AiK_Q_wFZ-rGw.png" /><figcaption>created with nano 🍌</figcaption></figure><p>My feed is full of “vibe coders” shipping apps with prompts, accepting whatever the AI generates without understanding it. People who once struggled with basic CSS now call themselves “AI engineers”.</p><p>In two years, we’ve jumped from awkward tab completions from Copilot to it raising PRs directly on GitHub. This feels like developer’s Excel moment: coding agents remove the tedium of typing, but fundamentals still matter, just like we still teach math without calculators.</p><p>We’ve had many shifts — from punch cards to high-level languages — but this one changes the relationship, not just the medium. More and more, prompting is treated as programming. That’s the difference, and it’s why I’m concerned about where we’re headed.</p><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//x.com/karpathy/status/1617979122625712128&amp;image=" width="500" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/0801f8c9b7b8002b309825e8ea50b9b2/href">https://medium.com/media/0801f8c9b7b8002b309825e8ea50b9b2/href</a></iframe><h3>Tesla vs Mumbai Traffic</h3><p>A good chunk of people believe AI agents like Claude Code, Codex, and Copilot are nearly fully autonomous like Tesla Autopilot — smooth and predictable, hands-off coding. You just prompt and magic happens.</p><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//x.com/slow_developer/status/1899430284350616025&amp;image=" width="500" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/d508014e7bc193c130513e7545447550/href">https://medium.com/media/d508014e7bc193c130513e7545447550/href</a></iframe><p>On the other hand, my experience has been more like navigating rush hour traffic in Mumbai. It’s so chaotic. A Tesla would just give up, and you, a driver well-versed with Mumbai traffic, would want to grab the wheel to avoid crashing into someone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hIDZzbLVIU9XaEdTiUshFA.png" /><figcaption>a chaotic congestion, modified with nano 🍌</figcaption></figure><p>Vibe coders, on the other hand, just prompt their way through their problems, riding on AI confidence and ✨vibes ✨. They feel fast, they look productive, they feel productive.</p><p>But I have seen their code, it is unmaintainable garbage.</p><h3>Garbage In, Garbage Stays</h3><p>I’ve been writing code for a while now, and I have seen good code countless times. Human written code isn’t perfect. Sometimes the variable names are cryptic, sometimes there are bugs. <strong>But there is surgical precision there.</strong> Every line has a reason. When humans write code, less is more. Less code means fewer bugs. Less code is more performant.</p><p>LLMs, on the other hand are like the friend who never shuts up. Claude gives you 50 lines when 5 would do. It over-engineers solutions and adds backward compatibility for features you have not even released. It will create 5 utility functions doing the same thing in different files. It creates abstractions that sometimes make no sense at all. I recently worked on a codebase where the AI had imported two different google libraries just to fetch some calendar data.</p><p>The thing that worries me most is garbage code has a persistence problem. Unlike regular refactoring where you gradually improve a system, AI-generated bloat tends to compound. Before you know it, the codebase has become a nested mess of dependencies and abstractions that nobody fully understands.</p><p>Sure you can rewrite garbage code, but it requires <strong>recognizing</strong> it as garbage first. If you do not understand a domain/library/framework well enough to spot the BS, you are stuck maintaining an increasingly complex system that becomes increasingly harder to debug with each iteration.</p><h3>The Fake Dopamine of Speed</h3><p>The other thing that has been a bother is a fake dopamine rush from vibe coding. You start to feel like speed is your friend. You prompt something and it works. Instant gratification.</p><p>I don’t think this speed is real. Yes, speed matters when you’re building software in a highly competitive and ever-changing landscape, but at what cost?</p><p>When you’re moving fast, prompting your way through the problems, you’re not actually understanding what you’re building. You’re not learning the patterns. You don’t form mental models. You’re not developing the intuition to understand where things might break, and they will, and when they do, you’re stuck — <strong>because you can’t debug what you don’t understand.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BnVDWmT__L4zudQ90_MdaA.png" /><figcaption>bob the “builder” trying to make sense of things under the hood, generated with nano 🍌</figcaption></figure><p>That fake speed you get from vibe coding? It disappears the moment something goes wrong. Suddenly you’re slower than everyone else because you have to reverse-engineer your own code just to figure out what’s happening. I’ve faced this too. I spent a day debugging Claude generated cross-timezone slot booking flow with google calendar conflict mitigation, finally gave up and started handrolling the implementation.</p><p>Teams move lightning fast in the beginning, then hit a wall when they need to maintain or extend what they built. The technical debt compounds. The bugs multiply. And all that speed you thought you had? It vanishes.</p><p>This speed trap is particularly <em>seductive</em> because it feels so different from traditional development bottlenecks. But recognizing it is crucial for using AI tools effectively.</p><h3>Where AI Actually Shines</h3><p>Don’t get me wrong: I’m not anti-AI. These tools are genuinely powerful when used properly. I’ve found AI incredibly helpful for specific tasks: generating test cases, writing boilerplate code, explaining unfamiliar APIs, and handling tedious migrations. Claude is excellent at walking through complex codebases and explaining implementation. Claude code is delightful to use. I recently used it to handle a complex merge conflict as well!</p><p>The difference is in how you use them. For example, instead of asking it to “create X”, I spend time with it understanding the existing codebase, often creating markdown documents for things that are important. In this process, I build a mental model, <strong>I understand the context</strong>. Then I ask Claude to implement the task specifically how I want. I use the documents to steer it, I ask it to write code like I want. I control the architecture. I know what good output looks like. I can spot when something’s wrong. The AI is amplifying my existing knowledge, not replacing it.</p><p>This is the crucial distinction that vibe coders miss. They’re trying to use AI as a replacement for understanding rather than as an accelerator for understanding. That’s where the problems start.</p><p>So what does responsible AI-assisted development actually look like in practice?</p><h3>What I Think We Should Be Doing</h3><p>I’ve been using AI as a learning accelerator rather than a replacement for thinking. As I suggested with the last example, the key is maintaining agency over the process while leveraging AI’s strengths. I keep drilling down until I understand the fundamentals. The AI can follow my curiosity as far as the context window allows, and it’ll find creative ways to explain concepts that would take me hours to research manually.</p><p>When I’m using Claude Code for development, I’ve developed a process that keeps me in control:</p><ol><li>Plan what you want first — don’t just throw problems at the AI</li><li>Read Claude’s plan before accepting anything — prompt it to tell what exactly it is going to change and where</li><li>Question every decision — just because it sounds smart doesn’t mean it is</li><li>Research the concepts I don’t understand</li><li>Rarely auto-accept changes</li></ol><p>I’ve also been trying to solve problems from first principles more often. When I land on something I don’t know how to implement, I use Claude as a brainstorming partner, not the author.</p><h3>Why I Think This Moment Is Actually Exciting</h3><p>Here’s what I’ve noticed: everyone’s struggling with this transition. Senior engineers who spent decades building mental models are watching them get disrupted. Junior developers are questioning whether they should even learn fundamentals. Mid-level engineers are wondering if their experience still matters.</p><p>But I think this disruption creates opportunity for anyone willing to adapt. We can learn to see AI tools for what they really are — powerful but (currently) dumb assistants that need supervision. We can develop the skills to prompt effectively while understanding the fundamentals deeply enough to know when the AI is leading us astray. I’ve seen this work out very well for engineers with experience and early adoption of AI tools.</p><p>The companies that figure this out first are going to dominate. They need engineers who can move fast with AI without sacrificing quality, engineers who can debug AI-generated code and engineers who can make have enough context to make correct architectural decisions.</p><p>While everyone’s panicking about AI replacing jobs, I think they’re missing the biggest opportunity in first principles thinking. This agentic era actually creates more room for this approach because you’re not constrained by “this is how it has always been done”.</p><h3>Bottom Line</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kCFTvioWzVtlcyFN5jI0yw.png" /><figcaption>Humans set the blueprint. AI follows it. Created with nano 🍌</figcaption></figure><p>I don’t think developer jobs are disappearing. I think they’re evolving into something more important. We’re not just writing code anymore. We’re steering intelligent systems, maintaining quality, and making sure the software that gets built is actually worth building.</p><p>The <em>vibe coders</em> will flame out when their lack of fundamentals catches up to them. The booking flows with race conditions? The bloated abstractions? The security vulnerabilities hidden in AI-generated code? They’ll all surface eventually, and someone will have to clean up the mess.</p><p>The engineers who take this opportunity to deeply understand both AI capabilities and software fundamentals are going to be unstoppable. They’ll be the ones who can move fast without breaking things. Who can debug the un-debuggable. Who can make the hard architectural decisions that determine whether a system scales or not.</p><p>This isn’t about replacing developers. It’s about separating the engineers who understand what they’re building from the ones who were just going through the motions. The agentic era doesn’t scare me. It excites me. Because I think it’s going to make the difference between good and great engineers more obvious than ever.</p><p>The question isn’t whether AI will change how we build software — it already has. The question is whether you’ll use it as a crutch or as a catalyst for becoming a better engineer.</p><p>*You can replace “Claude” with any AI agent you use a lot, Anthropic please do not sue me for this.</p><p>This article is also AI-assisted, but as always, the thoughts, ideas and examples are original.</p><p>If you resonated with this and want to chat? <a href="https://calendar.notion.so/meet/siddverma1999/connect">Book a meeting</a></p><p>X: <a href="https://x.com/sidposting">@sidposting</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=309448b67ce0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Green Tea Garbage Collector]]></title>
            <link>https://siddharthav.medium.com/green-tea-garbage-collector-63233aa5a9b5?source=rss-d4f96f432560------2</link>
            <guid isPermaLink="false">https://medium.com/p/63233aa5a9b5</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[memory-management]]></category>
            <dc:creator><![CDATA[Siddhartha Varma]]></dc:creator>
            <pubDate>Sun, 13 Jul 2025 11:27:54 GMT</pubDate>
            <atom:updated>2025-07-13T12:15:25.402Z</atom:updated>
            <content:encoded><![CDATA[<h3>Green Tea GC: How Go Stopped Wasting 35% of Your CPU Cycles</h3><p>Go 1.25’s experimental garbage collector stops CPU stalls by organizing memory into neighborhoods instead of random object jumping</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hWwQY7ndA6zZAkANtUEonw.png" /></figure><h3>Introduction</h3><p>Your Go application is performing well, handling requests efficiently. But there’s a performance issue you might not be aware of- the garbage collector <strong>is wasting 35% of CPU cycles waiting for memory access</strong>. Every time the GC jumps between objects scattered across RAM, your CPU sits idle while data is retrieved from memory</p><p>Green Tea GC, Go’s experimental new garbage collector reduces this waste by upto 50%. The garbage collector is available as an experiment in the upcoming Go 1.25, expected to be released in <a href="https://tip.golang.org/doc/go1.25">August 2025</a>.</p><h3>Revisiting Garbage Collection</h3><p>Before we dive into how Green Tea works, here’s a quick refresher on Garbage Collectors -</p><p>Any program typically allocates objects on two types of memories, Stack and Heap. Stack memory is generally easy to manage and clean (references are dropped along with frames after the work is done), while some other objects like constants live on the Heap.</p><p>In the early days of programming, programmers used to manage memory on their own (remember malloc from C?). This meant that if the memory wasn’t freed after use, it lead to memory leaks and if you freed twice, a crash.</p><p>Then came Garbage Collectors, popularized by languages like Java, JS (V8). The idea was novel, instead of allocating and deallocating by hand, the runtime would manage the memory instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nBx_JcO-hYb7XvccR8L-rg.png" /><figcaption>Garbage Collection</figcaption></figure><blockquote>The compiler can also figure out which objects go to the heap, which objects stay on the stack. This is called <a href="https://en.wikipedia.org/wiki/Escape_analysis">Escape Analysis</a>.</blockquote><h4>Stop The World</h4><p>Early Garbage Collection algorithms were quite naive like “Stop The World”. STW completely halts the execution of the program to run a collection cycle. This guarantees that new objects are not allocated or the references are not changed when the collector is running.</p><p>But this meant that the program pauses for long duration, sometimes even for seconds(!) when the GC is running. This was a cause for concern in high availability applications like web servers.</p><h4>Concurrent Garbage Collection</h4><p>Concurrent Garbage Collectors allow for garbage collection to occur at the same time when the application is running, minimizing pauses and improving performance, especially in real-time systems. They are designed to reduce “stop-the-world” pauses, where the application is halted entirely for garbage collection.</p><p>But these have a higher CPU overhead and implementation complexity — if this runs for a longer duration one cannot guarantee prohibition of new object allocations or reference changes.</p><h3>Go’s Garbage Collector</h3><p>Go’s Garbage Collector has gone through various transitions, starting from a simple STW mark-sweep to what we have now: <strong>A concurrent, Tri-Colour Mark and Sweep Garbage Collector</strong>.</p><h4>How does the current GC work</h4><p>The current GC runs in two phases — Mark and Sweep. In the Mark phase, we assume all objects to be <em>white</em> (unreachable). We start at the root objects (constants etc), mark them as <em>grey. </em>All grey objects are are added to a queue to be processed. We pick a grey object from the queue and start processing it’s children. As soon as a child is marked grey, it’s added to the queue and the parent is marked <em>black.</em> At the end, we have a mix of black and grey <em>accessible </em>objects. In the Sweep phase, we find all the <em>inaccessible</em> white objects (garbage) and clean it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*nwcUZ_FckHclO2VxJRk8Kg.png" /></figure><p>This algorithm is brilliant because it can run while your program continues executing. Go adopted this approach and refined it into one of the best garbage collectors in the industry, with pause times under a few milliseconds. But there is still a problem lurking beneath the surface.</p><h4>Performance Bottlenecks in current GC</h4><p>Modern CPUs process instructions at gigahertz speeds, but accessing main memory (DRAM) requires 200–400 CPU cycles compared to just 1 cycle for L1 cache access. To bridge this performance gap, CPUs use a hierarchy of caches (L1, L2, L3) — each level larger but slower than the previous.</p><p>The current garbage collector creates poor <strong>spatial locality</strong> by following object references randomly across memory. When the GC jumps from object A (at memory address 0x1000) to object B (at 0x5000), it likely causes a cache miss. The CPU must then wait hundreds of cycles to fetch the new data from DRAM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0RutL4_ZWf8N_-jlt1czxA.png" /><figcaption>Cache misses causes wastage of CPU cycles</figcaption></figure><p>This memory access pattern is where Go’s current GC becomes a performance bottleneck. Studies show that <strong>approximately 35% of GC CPU cycles are spent stalled on memory accesses</strong>, excluding knock-on effects.</p><h3>Green Tea Garbage Collector</h3><p>Enter Green Tea. Instead of frantically jumping between objects and causing cache misses left and right, Green Tea groups memory into blocks called <strong>spans</strong>. It processes entire spans together. By this method, on a cache miss, you load the entire span into the cache. This reduces the CPU cycle wastage and improves the GC performance.</p><p>But that’s not all. What if the span has only one marked object? Processing the entire span would be inefficient. The algorithm takes this into account and behaves in an adaptive manner. Green Tea solves this with <strong>representative object</strong> optimization.</p><p>It tracks the object which caused the span to be queued and uses a <em>hit flag</em> to detect if more objects get marked while the span is waiting. If more objects get marked, the hit flag is true and we processes the entire span for <em>maximum locality.</em> If the hit flag is false, just process the representative object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0NAD4UwZq5pUVznBOorcw.png" /><figcaption>Existing GC vs Green Tea</figcaption></figure><h3>Results</h3><p>The results speak for themselves. In GC-heavy benchmarks, Green Tea shows 10 to 50% reduction in garbage collection CPU cost. On multi-core systems, the benefits are even greater. Green Tea includes work-stealing mechanisms similar to Go’s scheduler, and there are even prototype SIMD-accelerated scanning kernels showing additional improvements.</p><p>Green Tea is available as an experimental feature in Go 1.25. Enable it with the following flag when building, after downloading Go 1.25.</p><pre>$ GOEXPERIMENT=greenteagc go build</pre><h3>References</h3><ul><li>Green Tea Discussion — <a href="https://github.com/golang/go/issues/73581">https://github.com/golang/go/issues/73581</a></li><li>Tracing GC — <a href="https://en.wikipedia.org/wiki/Tracing_garbage_collection">https://en.wikipedia.org/wiki/Tracing_garbage_collection</a></li><li>Getting to Go: The Journey of Go’s Garbage Collector — <a href="https://go.dev/blog/ismmkeynote">https://go.dev/blog/ismmkeynote</a></li><li>Go GC: Prioritizing low latency and simplicity — <a href="https://go.dev/blog/go15gc">https://go.dev/blog/go15gc</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63233aa5a9b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A deep dive into Dynamo’s architecture and scale]]></title>
            <link>https://towardsaws.com/a-deep-dive-into-dynamos-architecture-and-scale-88d6a28cd511?source=rss-d4f96f432560------2</link>
            <guid isPermaLink="false">https://medium.com/p/88d6a28cd511</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[dynamodb]]></category>
            <dc:creator><![CDATA[Siddhartha Varma]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 12:19:23 GMT</pubDate>
            <atom:updated>2025-02-18T12:18:39.158Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="image generated by grok" src="https://cdn-images-1.medium.com/max/1024/1*DrDLm3X9GMJvjxs-TvNeTw.png" /></figure><p>Understanding DynamoDB’s core principles — from architecture decisions to real-world patterns</p><h3>Intro</h3><p>On Prime Day 2021, Amazon’s systems made trillions of API calls to DynamoDB, peaking at 89.2M requests per second (RPS), all while maintaining single digit millisecond latency. Yet, many developers struggle with database scaling issues that DynamoDB was created to solve.</p><p>Having worked extensively with DynamoDB at <a href="https://blog.zomato.com/category/technology">Zomato</a> , I have also hit the same roadblocks, like hot partitions throttling applications, costs spiraling due to over-provisioning and data models that worked perfectly in other databases suddenly becoming performance bottlenecks. These challenges often stem from approaching DynamoDB with a traditional database mindset.</p><p>In this article, I’ll dive into DynamoDB’s architecture through a system design perspective. We’ll explore the fundamentals of dynamo, how it’s scaling and performance management differs from traditional databases, and more importantly — how to architect your applications to harness the full power of dynamo. Whether you’re debugging performance issues, optimizing costs, or just starting with DynamoDB, understanding these internals will help you make better design decisions.</p><h3>Understanding DynamoDB’s core principles</h3><p>At the heart of DynamoDB’s robustness and scalability lie six core principles around which it was architected. These principles prioritize simplicity, predictability, and reliability. Let’s explore each, starting with perhaps the most counterintuitive</p><h4>1. Predictability over peak performance</h4><p>This sounds very counterintuitive from a software perspective. Shouldn’t one chase maximum throughput? While other databases also follow this approach, DynamoDB takes a contrarian stance — predictable performance matters more than peak performance.</p><p>If you marinate on this, it does make a lot of sense from a database perspective. What good is a lightning fast database which occasionally hangs for several seconds — even milliseconds? The latency spikes will ultimately affect application performance. DynamoDB’s architects recognized this early on and set an ambitious goal — complete all requests with sub 10ms latencies.</p><p>How does it achieve this? Through some clever architectural decisions:</p><ul><li><strong>Global Admission Control</strong> to manage capacity across entire tables, preventing any single partitioning from becoming a bottleneck</li><li>Automatic partitioning to distribute I/O load evenly, even as access patterns change</li><li>Proactive monitoring and rebalancing to prevent resource exhaustion before it impacts performance</li><li><strong>Multi-tenant architecture</strong> with strict resource isolation ensures consistent performance even under varied workloads</li></ul><p>The result — Once <em>properly</em> configured, applications can rely on consistent performance whether they’re handling normal traffic or sudden spikes. No more over-provisioning “just in case” or late-night panic when traffic patterns change.</p><h3>2. Multi-tenant Architecture with Isolation</h3><p>Unlike traditional databases where you might have dedicated instances, DynamoDB takes a different approach — it runs multiple customer’s workloads on the same physical machines.</p><p>Now, you might be thinking, does it not introduce the <a href="https://docs.aws.amazon.com/wellarchitected/latest/saas-lens/noisy-neighbor.html">noisy neighbour problem?</a> This is where DynamoDB’s clever resource management comes in:</p><ul><li><strong>Resource Reservation</strong> — Each table gets guaranteed capacity through token bucket allocation. When you provision throughput or use on-demand tables, DynamoDB reserves corresponding resources, ensuring your workload gets its fair share regardless of other tenants</li><li><strong>Strict Workload Isolation</strong> — Storage nodes host replicas from different tables and customers, but use partition-level token buckets to enforce throughput limits. Even if one tenant’s workload spikes, it can’t consume more than its allocated capacity, protecting other tenants’ performance.</li><li><strong>Dynamic Load Balancing</strong> — DynamoDB’s autoadmin service continuously monitors storage node utilization. If a node’s throughput exceeds a threshold percentage of its maximum capacity, DynamoDB automatically redistributes partitions to maintain balanced load across the fleet.</li><li><strong>Proactive Capacity Management</strong> — Rather than waiting for resource exhaustion, DynamoDB tracks consumed capacity trends and automatically rebalances partitions before performance is impacted. Storage nodes independently report when they’re approaching capacity limits.</li></ul><p>These mechanisms ensure workload isolation between co-resident tables while maintaining high resource utilization. The benefit of this is cost savings, which gets passed down to customers while giving performance guarantees.</p><figure><img alt="A database architecture diagram showing three customer environments (A, B, and C) and their data distribution across storage nodes. Customer A has two tables (A1 and A2), Customer B has one table (B1), and Customer C has three tables (C1, C2, and C3). The tables are connected to three storage nodes below, with each node containing multiple partitions. Storage Node 1 contains partitions A1-P1, B1-P1, and C1-P1. Storage Node 2 contains partitions A2-P1, A1-P2, and C2-P1. Storage Node 3 contains pa" src="https://cdn-images-1.medium.com/max/800/0*lNStLOr10TNv69N8.png" /><figcaption><em>Multi-tenancy in DynamoDB</em></figcaption></figure><blockquote>Autoadmin service is responsible for fleet health, partition health, scaling of tables, and execution of all control plane requests.</blockquote><h3>3. Boundless Scale for Tables</h3><p>DynamoDB takes another contrarian approach with this principle. In traditional databases, we often have to carefully plan capacity and manage storage thresholds. Unlike these databases — for DynamoDB there are no predefined limits for the amount of data each table can store. Tables grow elastically to meet the demand of the customers’ applications.</p><p>DynamoDB is designed to scale the resources dedicated to a table from several servers to many thousands as needed. How does DynamoDB achieve this seemingly infinite scalability? The secret lies in its partitioning strategy</p><p>When you create a table, DynamoDB splits it into multiple partitions. Each partition being a dedicated slice of storage and compute that’s responsible for a specific range of keys. These ranges are organized so that no two partitions overlap (disjoint ranges), and each partition handles all keys within its assigned range (continuous ranges).</p><p>For example, if your table uses numeric keys from 1–100, you might have:</p><ul><li>Partition A: Keys 1–35</li><li>Partition B: Keys 36–70</li><li>Partition C: Keys 71–100</li></ul><p>Each key range is handled by exactly one partition, with no gaps or overlaps between partitions. As your table grows in size or throughput demands increase, DynamoDB automatically splits these partitions when:</p><ol><li><strong>Data Size:</strong> When a partition’s stored data exceeds its size threshold. This ensures no single partition grows too large to manage.</li><li><strong>Throughput:</strong> When a partition’s consumed capacity consistently exceeds partition limits. DynamoDB monitors actual usage patterns and splits partitions based on observed traffic, not just size.</li></ol><p>This automatic splitting enables tables to scale horizontally as they grow. Each new partition adds more dedicated storage and compute capacity to your table, all managed transparently by DynamoDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*bc9E9usA5PUlhL2E.png" /><figcaption><em>Automatic splitting</em></figcaption></figure><h3>4. High Availability</h3><p>In today’s world, even a few minutes of database downtime can severely impact businesses. DynamoDB is architected for high availability, offering a 99.99% SLA for regular tables and an even higher 99.999% SLA for global tables.</p><p>At its core, DynamoDB achieves this through a sophisticated replication strategy. Every partition of your table is replicated across multiple Availability Zones (AZs) — physically separate data centers in the same region. But replication alone isn’t enough — it’s how DynamoDB manages these replicas that makes the difference.</p><p>Each partition has multiple replicas distributed across different AZs, forming what’s called a <strong>replication group</strong>. Within each group, one replica acts as the leader, coordinating writes and strongly consistent reads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*LoTNC9z5dYwmmo-2.png" /><figcaption><em>Interaction Between Core Components</em></figcaption></figure><p>Here’s how it works:</p><p><strong>For writes</strong></p><ul><li>When a write request arrives, the leader generates a WAL (write ahead log) record</li><li>This record must be persisted by a quorum of replicas before acknowledging the write</li><li>Even if one replica fails, as long as the quorum exists, writes continue uninterrupted</li></ul><p><strong>For reads</strong></p><ul><li>Strongly consistent reads are served by the leader</li><li>Eventually consistent reads can be served by any replica</li><li>This flexibility allows it to balance load and maintain availability even during failures</li></ul><p>In case when things go wrong, DynamoDB has multiple layers of failure protection:</p><ul><li><strong>Fast recovery</strong> — If a replica becomes unhealthy, DynamoDB quickly adds a “log replica”, which is a lightweight replica that only stores recent write logs. This ensures durability while a full replica is being rebuilt.</li><li><strong>Smart failure detection</strong> — Before triggering failovers, replicas check with their peers to confirm if a leader is truly unavailable, preventing disruptions from temporary network issues</li><li><strong>Automatic healing</strong> — DynamoDB’s autoadmin service continuously monitors partition health and automatically replaces unhealthy replicas, ensuring your data remains triple-replicated</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*qBTZN_E25SBI8OF4.png" /><figcaption><em>Interaction inside a Replication Group</em></figcaption></figure><p>DynamoDB maintains this level of availability without requiring any operational overhead from developers. You don’t need to configure replication, manage failovers, or worry about cross-AZ communication — it’s all handled automatically.</p><h3>5. Fully Managed Cloud Service</h3><p>DynamoDB takes another fundamentally different approach to database management compared to traditional databases — it’s fully managed, meaning developers never have to worry about the underlying infrastructure. This principle goes beyond simple automation; it’s baked into DynamoDB’s core design:</p><p><strong>Resource Management</strong></p><ul><li>Developers interact purely through the DynamoDB API to create tables and perform operations</li><li>No need to think about server provisioning, storage allocation, or cluster configuration</li><li>The service automatically handles resource scaling based on your needs</li></ul><p><strong>Operational Tasks</strong></p><ul><li>All software patching and upgrades happen transparently</li><li>Hardware failures are automatically detected and remediated</li><li>Backups are managed systematically without impacting performance</li><li>Data encryption is handled automatically at rest and in transit</li></ul><p><strong>Infrastructure Management</strong></p><ul><li>No need to configure distributed database clusters</li><li>Automatic recovery from failures without manual intervention</li><li>Built-in security features like encryption and access control</li><li>Continuous monitoring and maintenance without downtime</li></ul><p>The beauty of this approach is that developers can focus entirely on their application logic rather than database administration. Whether you’re running a small application or handling millions of requests per second, the operational complexity remains zero.</p><h3>6. Flexible Use Cases</h3><p>While DynamoDB is often categorized as a NoSQL database, it’s designed with flexibility in mind, accommodating various data models and consistency requirements. This flexibility manifests in several key ways:</p><p><strong>Data Model Flexibility</strong> — DynamoDB doesn’t force developers into a particular data model or consistency model. DynamoDB tables don’t have a fixed schema but instead allow each data item to contain any number of attributes with varying types, including multi-valued attributes. Tables use a key-value or document data model.</p><p><strong>Consistency Options</strong> — Developers can choose between eventual or strong consistency for reads, which allows applications to balance performance and consistency reads. You could choose to have strong consistency for critical operations and eventual consistency for better performance when absolute consistency isn’t required.</p><p><strong>Query Patterns</strong> — DynamoDB supports both single item operations and range queries, with secondary indexes for flexible access patterns and global tables for low latency multi region access. It also supports ACID transactions across items without compromising the scalability, availability, and performance characteristics of DynamoDB tables.</p><h3>Common Pitfalls</h3><p>While DynamoDB’s architecture solves many scaling challenges, teams often hit roadblocks when approaching it with a traditional database mindset. Here are common pitfalls to avoid:</p><h4>Poor Partition Key Design</h4><ul><li>Using sequential IDs as partition keys, causing write hotspots</li><li>Using too few unique partition keys, leading to throttling</li><li>Using highly correlated values (like dates) that create temporal hotspots</li><li><strong>Better Approach:</strong> Choose partition keys with high cardinality and good distribution. Consider composite keys or adding random suffixes for better distribution</li></ul><h4>Inefficient Access Patterns</h4><ul><li>Creating too many indexes, increasing write costs and complexity</li><li>Not aligning schema with query patterns</li><li><strong>Better Approach:</strong> Design your schema around your access patterns. Start with your queries and work backwards to your data model.</li></ul><h4>Over-Relying on Secondary Indexes</h4><ul><li>Creating an index for every possible query pattern</li><li>Not considering the write amplification cost</li><li><strong>Better Approach:</strong> Use sparse indexes and carefully evaluate the cost-benefit of each index</li></ul><h4>Inappropriate Item Size</h4><ul><li>Storing items that approach the 400KB limit, not considering item size growth over time</li><li><strong>Better Approach:</strong> Consider chunking strategies for large items, and plan for data growth.</li></ul><blockquote><em>Having faced these challenges at scale, I’ll share our journey of overcoming them in an upcoming article</em></blockquote><h3>Cost Optimization Strategies</h3><p>One of the most painful lessons teams learn with DynamoDB is how quickly costs can spiral without proper planning. Let’s dive into strategies that can help you optimize costs while maintaining performance.</p><h4>Choosing Your Capacity Mode</h4><p>DynamoDB offers two capacity modes, each with its own trade-offs.</p><p><strong>Provisioned capacity</strong></p><p>Provisioned Capacity is best for predictable workloads and lowers cost when properly sized. But it requires careful capacity planning and one should also consider using auto scaling to handle traffic variations</p><p><strong>On-demand capacity</strong></p><p>On-demand capacity is perfect for unpredictable workloads or development environments where traffic patterns are still unclear. While it might cost more than steady-state workloads, the operational simplicity and peace of mind can be worth the premium.</p><h4>Smart Capacity Planning</h4><p>Success with DynamoDB requires a data-driven approach to capacity planning. Start by monitoring your CloudWatch metrics to understand your usage patterns. Look for daily and weekly trends, seasonal spikes, and any anomalies. If you’re just starting out, consider using on-demand capacity during development — the usage data you gather will be invaluable for optimizing costs later.</p><h4>Lifecycle Management</h4><p>Just like cleaning out your closet, regularly reviewing and managing your data can lead to significant savings. Use TTL (Time To Live) for temporary data like session information or logs. For historical data that you need to keep but don’t access frequently, consider archiving to S3. Another often-overlooked strategy is using sparse indexes — they not only improve query performance but can significantly reduce storage costs.</p><h4>Stay Alert: Monitor Your Costs</h4><p>The best way to avoid cost surprises is to stay vigilant. Set up CloudWatch alarms for throttling events — they’re often a sign that your capacity planning needs adjustment. Monitor your consumed capacity against what you’ve provisioned to identify opportunities for optimization. Track costs at a granular level — by table and index — to understand where your money is going. Most importantly, set up budget alerts to catch any unexpected increases before they become painful surprises.</p><h3>Conclusion</h3><p>DynamoDB’s architecture represents a fundamental shift in how we think about databases. Its design principles — from predictable performance to global admission control — weren’t chosen arbitrarily, but evolved from real-world challenges of running databases at scale.</p><p>As I’ve experienced firsthand at Zomato, success with DynamoDB requires embracing these principles rather than fighting them. Whether it’s rethinking our partition keys for better distribution, chunking large items for efficient storage, or carefully planning our capacity needs — each decision needs to align with DynamoDB’s architectural foundations.</p><p>DynamoDB isn’t just another database with a different query language. By understanding it’s principles and avoiding common pitfalls, you can harness this same power for your applications, regardless of scale. The effort you invest in understanding its architecture and aligning your design decisions with its principles will pay dividends in scalability, reliability, and operational simplicity.</p><p>References:</p><p><a href="https://www.usenix.org/system/files/atc22-elhemali.pdf">https://www.usenix.org/system/files/atc22-elhemali.pdf</a></p><p><a href="https://hemantkgupta.medium.com/insights-from-paper-part-i-amazon-dynamodb-a-scalable-predictably-performant-and-fully-6d93dfbfe2fb">https://hemantkgupta.medium.com/insights-from-paper-part-i-amazon-dynamodb-a-scalable-predictably-performant-and-fully-6d93dfbfe2fb</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88d6a28cd511" width="1" height="1" alt=""><hr><p><a href="https://towardsaws.com/a-deep-dive-into-dynamos-architecture-and-scale-88d6a28cd511">A deep dive into Dynamo’s architecture and scale</a> was originally published in <a href="https://towardsaws.com/">Towards AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two neat tricks for faster and lighter docker images for Go projects]]></title>
            <link>https://tech.groww.in/two-neat-tricks-for-faster-and-lighter-docker-images-for-go-projects-1ea4912bd0d6?source=rss-d4f96f432560------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ea4912bd0d6</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[infra]]></category>
            <dc:creator><![CDATA[Siddhartha Varma]]></dc:creator>
            <pubDate>Wed, 04 May 2022 14:32:49 GMT</pubDate>
            <atom:updated>2025-04-21T07:01:22.656Z</atom:updated>
            <content:encoded><![CDATA[<h4>“faster” here means faster build time</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*uv0NoHSs3lLs_mXe.png" /><figcaption>Image credit: <a href="https://dev.to/">https://dev.to/</a></figcaption></figure><h3>Intro</h3><p>Imagine this: you’re a developer who has heard a lot of praise about <a href="https://go.dev/"><strong>Go</strong></a>. It’s fast compilation, high performance, easy concurrency, easy-syntax and what not. (of course, it has it’s own set of problems which have been covered in depth by <a href="https://twitter.com/fasterthanlime">@fasterthanlime</a> )</p><p>Consequently, you try out <strong>Go</strong>. You learn the language and build a functional microservice. Then you think, “let’s containerize and deploy it” — and you run into two problems:</p><ol><li>The image size is HUGE (1–2 GBs)</li><li>The build time is super slow (take around 40–50 seconds on a local machine and up to 2 minutes on a CI pipeline)</li></ol><p>I, too, faced these issues while working on a project during my internship at <a href="https://groww.in/">Groww</a>.</p><h3>Fix 1: Reduce Image Size</h3><p>This is pretty simple. Since go binaries are <strong>compiled and self-sufficient</strong>, it doesn’t need any go installation to run, unlike something like JS, which would require the NodeJS image to run.</p><p>Thus, we can use docker multistage builds to reduce the binary size. But first, let’s see the size of a docker image without multistage builds:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6be179792b19c75ac7d398a3b21e3847/href">https://medium.com/media/6be179792b19c75ac7d398a3b21e3847/href</a></iframe><p>We can build a docker image using the command:</p><pre>docker build . -t &lt;some tag&gt; -f &lt;Dockerfile path&gt;</pre><p>Let’s see the build time and size of the image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t0yPoiI68k-Ko5KsYZT9xA.png" /><figcaption>The size of the image built using the above Dockerfile is<strong> 1.65GB!</strong></figcaption></figure><p>Our dockerized application does not need the full suite of Go tools, including the compiler after the application binary had been compiled. Thus it is useless to have it in the dockerized application. Now, let us try to use a multistage docker build:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4e4437d42f271ef34ced72a22ce1e8a/href">https://medium.com/media/c4e4437d42f271ef34ced72a22ce1e8a/href</a></iframe><p>This dockerfile is divided into 2 stages (each FROM is a different stage). The first stage — called buildenv is used to build the go binary. The second stage uses Alpine, a minimal Docker image based on Alpine Linux (only 5MB in size). We copy the binary from the buildenv into the current stage and use CMD to run it.</p><p>We build the docker image from the above Dockerfile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CNeGfWvh4ykvje3uZMt9eA.png" /><figcaption>The size of the multistage build is 53.8MB</figcaption></figure><blockquote>Side note: You can also use <a href="https://stackoverflow.com/questions/22267189/what-does-the-w-flag-mean-when-passed-in-via-the-ldflags-option-to-the-go-comman">ldflags</a> to get even smaller binaries.</blockquote><h3>Fix 2: Improve Build Time</h3><p>Docker uses layer caching to only execute COPY and ADD commands when the contents of the external resources change. As per the docker documentation:</p><blockquote>For the ADD and COPY instructions, the contents of the file(s) in the image are examined and a checksum is calculated for each file. The last-modified and last-accessed times of the file(s) are not considered in these checksums. During the cache lookup, the checksum is compared against the checksum in the existing images. If anything has changed in the file(s), such as the contents and metadata, then the cache is invalidated</blockquote><p>This means if the contents of all external files on the first COPY command are the same, the layer cache will be used and <strong>all subsequent</strong> commands until the next ADD or COPY command will use the layer cache.</p><p>Thus, the trick here is to copy the go.mod and go.sum and run go mod download before copying the project files and building the project. This is done because dependencies don’t change a lot, unlike your project files.</p><p>So, the multistage docker build along with effective caching would look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc71abc638202fcfa829aab97645282a/href">https://medium.com/media/bc71abc638202fcfa829aab97645282a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*zYiGbmd6EFj823cHOj1JTQ.png" /><figcaption>Took 48 seconds the first time</figcaption></figure><p>Then I changed some project files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uSdOL4OpTYRb3p0NPyA9Dw.png" /><figcaption>3 times decrease since the go mod download step was utilising layer cache</figcaption></figure><p>This small change brought down the <strong>build time from 2 minutes to about 30 seconds in our CI pipeline for this project (~75% improvement for subsequent builds)</strong></p><h3>Conclusion</h3><p>Thus, we can see how two small changes in your dockerfile can lead to a much more optimized docker image, which helps speed up your CI pipeline. Hope this blog helped you.</p><h4>References</h4><ul><li><a href="https://docs.docker.com/language/golang/build-images/">Build your Go image</a></li><li><a href="https://docs.semaphoreci.com/ci-cd-environment/docker-layer-caching/">Docker layer caching - Semaphore</a></li></ul><p><a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/">Best practices for writing Dockerfiles | Docker Documentation</a></p><p><a href="https://carlosbecker.com/posts/docker-go-mod/">Faster Docker builds using go modules · Carlos Becker</a></p><p>If you’ve enjoyed this story, please click the 👏 button and share it, so that others can find it as well! Also, feel free to leave a comment below.</p><p><a href="http://tech.groww.in/">Groww Engineering</a> publishes technical anecdotes, the latest technologies, and better ways to tackle common programming problems. You can <a href="https://medium.com/groww-engineering">subscribe here</a> to get the latest updates.</p><p>We are hiring. View job openings <a href="https://groww.in/careers">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ea4912bd0d6" width="1" height="1" alt=""><hr><p><a href="https://tech.groww.in/two-neat-tricks-for-faster-and-lighter-docker-images-for-go-projects-1ea4912bd0d6">Two neat tricks for faster and lighter docker images for Go projects</a> was originally published in <a href="https://tech.groww.in/">The Groww Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Push multiple files under a single commit through GitHub API]]></title>
            <link>https://siddharthav.medium.com/push-multiple-files-under-a-single-commit-through-github-api-f1a5b0b283ae?source=rss-d4f96f432560------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1a5b0b283ae</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Siddhartha Varma]]></dc:creator>
            <pubDate>Fri, 29 Apr 2022 13:01:37 GMT</pubDate>
            <atom:updated>2022-04-29T13:01:37.546Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using Git Database API</h4><h3>Intro</h3><p>Wanted to understand how to push multiple files under a single commit, using GitHub API. Some googling landed me on <a href="https://docs.github.com/en/rest/reference/git">Git Database API Docs</a>. Wasn’t very clear how it worked so I tried getting my hands dirty! Documenting it here for anyone who’s looking for it.</p><p>Disclosure:</p><ol><li>This API needs atleast 1 commit to work. Empty repositories don’t work.</li></ol><h3>Git Database API</h3><p>The Git Database API enables you to read and write raw Git objects to your Git database on GitHub and to list and update Git references (branch heads and tags).</p><p>The whole process is as follows: create blobs corresponding to files, create tree, create a commit for the changes and finally updating refs to reflect the commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*8WAQnh775YuYPo3K.jpg" /></figure><h3>Creating blobs</h3><p>A Git blob (binary large object) is the object type used to store the contents of each file in a repository. The file’s SHA-1 hash is computed and stored in the blob object.</p><p>To create a blob we need to hit the following endpoint:</p><pre><strong>POST</strong> https://api.github.com/repos/{user}/{repo}/git/blobs</pre><p>Let’s create a blob for a file called main.py with 1 line of python code:</p><pre>{<br>    &quot;content&quot;:&quot;print(\&quot;hello world !\&quot;)&quot;,<br>    &quot;encoding&quot;: &quot;utf-8&quot;<br>}</pre><p>We can create blobs for each file we want to upload. In the response, we get SHA of the blob which we need to send while creating the tree. Sample response:</p><pre>{<br>    &quot;sha&quot;: &quot;638eff25696b982124deeb1f3dfcceabfdc81a93&quot;,<br>    &quot;url&quot;: &quot;https://api.github.com/repos/BRO3886/git-db-example/git/blobs/638eff25696b982124deeb1f3dfcceabfdc81a93&quot;<br>}</pre><h3>Creating a tree</h3><p>Now, we need to create a tree with the files we added. For that, first we need to get the SHA of the base tree. Then we need to create a tree for the files we need to add.</p><h4>Get SHA for base_tree</h4><p>The base tree can be thought of as the folder where you&#39;d like to create your commit. If you want to create it at the root folder, you can make request to:</p><pre><strong>GET</strong> https://api.github.com/repos/{user}/{repo}/git/trees/{branch}</pre><p>It returns a response like:</p><pre>{<br>    &quot;sha&quot;: &quot;0d43a3b20104b4baa402c09a6c9c6c3298390e4a&quot;,<br>    &quot;url&quot;: &quot;{url of tree}&quot;,<br>    &quot;tree&quot;: [<br>        {<br>            &quot;path&quot;: &quot;App&quot;,<br>            &quot;mode&quot;: &quot;040000&quot;,<br>            &quot;type&quot;: &quot;tree&quot;,<br>            &quot;sha&quot;: &quot;{sha}&quot;,<br>            &quot;url&quot;: &quot;{url of folder/tree}&quot;<br>        },<br>        {<br>            &quot;path&quot;: &quot;README.md&quot;,<br>            &quot;mode&quot;: &quot;100644&quot;,<br>            &quot;type&quot;: &quot;blob&quot;,<br>            &quot;sha&quot;: &quot;{some SHA}&quot;,<br>            &quot;size&quot;: 885,<br>            &quot;url&quot;: &quot;{some URL}&quot;<br>        },<br>        ...<br>    ],<br>    &quot;truncated&quot;: false<br>}</pre><p>Here, we can extract the SHA from response.sha or SHA of the folder under response.tree[i].sha.</p><h4>Create tree</h4><p>Then, we need to hit the create tree api:</p><pre><strong>POST</strong> <a href="https://api.github.com/repos/%7Buser%7D/%7Brepo%7D/git/trees">https://api.github.com/repos/{user}/{repo}/git/trees</a></pre><p>With the following body:</p><pre>{<br>    &quot;tree&quot;:[<br>        {<br>            &quot;path&quot;:&quot;helloworld/main.py&quot;,<br>            &quot;mode&quot;:&quot;100644&quot;,<br>            &quot;type&quot;:&quot;blob&quot;,<br>            &quot;sha&quot;:&quot;638eff25696b982124deeb1f3dfcceabfdc81a93&quot;<br>        },<br>        {<br>            &quot;path&quot;:&quot;helloworld/main2.py&quot;,<br>            &quot;mode&quot;:&quot;100644&quot;,<br>            &quot;type&quot;:&quot;blob&quot;,<br>            &quot;sha&quot;:&quot;638eff25696b982124deeb1f3dfcceabfdc81a93&quot;<br>        }<br>        ...<br>    ],<br>    &quot;base_tree&quot;:&quot;3c408bafa55eda6b1c51de5df0fc36304f37414c&quot;<br>}</pre><p>Here request.tree would have an array of blobs that you want to push. For each blob we need the SHA that we got as a response from create blob API.</p><p><strong>For the </strong><strong>mode:<br></strong>The file mode; one of 100644 for file (blob), 100755 for executable (blob), 040000 for subdirectory (tree), 160000 for submodule (commit), or 120000 for a blob that specifies the path of a symlink.</p><blockquote><em>GitHub doesn’t store folders, so the only way to make a folder is to set the </em><em>path for the blob as </em><em>{folderName}/{fileName}</em></blockquote><p>Here, we get another SHA in the response, which we need when we create a commit corresponding to the changes:</p><pre>{<br>    &quot;sha&quot;: &quot;a69117177bb067933189072b2b8799c63f388f32&quot;,<br>    &quot;url&quot;: &quot;https://api.github.com/repos/BRO3886/git-db-example/git/trees/a69117177bb067933189072b2b8799c63f388f32&quot;,<br>    &quot;tree&quot;: [<br>        {<br>            &quot;path&quot;: &quot;README.md&quot;,<br>            &quot;mode&quot;: &quot;100644&quot;,<br>            &quot;type&quot;: &quot;blob&quot;,<br>            &quot;sha&quot;: &quot;bc7b1321063b4075c97bf16e6f8130b6f9fa6537&quot;,<br>            &quot;size&quot;: 54,<br>            &quot;url&quot;: &quot;https://api.github.com/repos/BRO3886/git-db-example/git/blobs/bc7b1321063b4075c97bf16e6f8130b6f9fa6537&quot;<br>        },<br>        {<br>            &quot;path&quot;: &quot;helloworld&quot;,<br>            &quot;mode&quot;: &quot;040000&quot;,<br>            &quot;type&quot;: &quot;tree&quot;,<br>            &quot;sha&quot;: &quot;82a82f6788b44fe93774597ff2e76ac66ae1e657&quot;,<br>            &quot;url&quot;: &quot;https://api.github.com/repos/BRO3886/git-db-example/git/trees/82a82f6788b44fe93774597ff2e76ac66ae1e657&quot;<br>        }<br>    ],<br>    &quot;truncated&quot;: false<br>}</pre><p>Here we need response.sha for the next step.</p><h3>Add a commit</h3><p>This step is pretty simple. We just need the response.sha from the previous step. We make a request to the following endpoint:</p><pre><strong>POST</strong> https://api.github.com/repos/{user}/{repo}/git/commits</pre><p>Along with the body:</p><pre>{<br>    &quot;tree&quot;:&quot;a69117177bb067933189072b2b8799c63f388f32&quot;,<br>    &quot;message&quot;:&quot;some commit msg&quot;,<br>    &quot;parents&quot;: [&quot;3c408bafa55eda6b1c51de5df0fc36304f37414c&quot;]<br>}</pre><p><strong>parents</strong>: The SHAs of the commits that were the parents of this commit. If omitted or empty, the commit will be written as a root commit. For a single parent, an array of one SHA should be provided; for a merge commit, an array of more than one should be provided.</p><p>In our case, for the parent, since we want to add another commit on a particular branch, we need to get the SHA for it.</p><p>For that, we need to make a request to the following endpoint:</p><pre><strong>GET</strong> https://api.github.com/repos/BRO3886/git-db-example/git/refs/heads/{branch}</pre><p>It returns a JSON with details about the branch:</p><pre>{<br>    &quot;ref&quot;: &quot;refs/heads/main&quot;,<br>    &quot;node_id&quot;: &quot;REF_kwDOG87gc69yZWZzL2hlYWRzL21haW4&quot;,<br>    &quot;url&quot;: &quot;https://api.github.com/repos/BRO3886/git-db-example/git/refs/heads/main&quot;,<br>    &quot;object&quot;: {<br>        &quot;sha&quot;: &quot;3c408bafa55eda6b1c51de5df0fc36304f37414c&quot;,<br>        &quot;type&quot;: &quot;commit&quot;,<br>        &quot;url&quot;: &quot;https://api.github.com/repos/BRO3886/git-db-example/git/commits/3c408bafa55eda6b1c51de5df0fc36304f37414c&quot;<br>    }<br>}</pre><p>For the parent SHA, we need response.object.sha.</p><p>In the response of create commit API, we’ll get another SHA:</p><pre>{<br>    &quot;sha&quot;: &quot;544aa83c4d4a784c4c8490d6548c248b0e57d0ac&quot;,<br>    &quot;node_id&quot;: &quot;C_kwDOG87gc9oAKDU0NGFhODNjNGQ0YTc4NGM0Yzg0OTBkNjU0OGMyNDhiMGU1N2QwYWM&quot;,<br>    &quot;url&quot;: &quot;https://api.github.com/repos/BRO3886/git-db-example/git/commits/544aa83c4d4a784c4c8490d6548c248b0e57d0ac&quot;,<br>    &quot;html_url&quot;: &quot;https://github.com/BRO3886/git-db-example/commit/544aa83c4d4a784c4c8490d6548c248b0e57d0ac&quot;,<br>...<br>}</pre><p>We’ll need this SHA value for the last step.</p><h3>Updating ref</h3><p>This step is for updating the ref from where we pulled the SHA under parents (create commit step). For my case, since the ref was main, I&#39;ll update it. Make a request to the following endpoint:</p><pre><strong>PATCH</strong> <a href="https://api.github.com/repos/%7Buser%7D/%7Brepo%7D/git/refs/heads/%7Bbranch%7D">https://api.github.com/repos/{user}/{repo}/git/refs/heads/{branch}</a></pre><p>With the following body:</p><pre>{<br>    &quot;sha&quot;:&quot;544aa83c4d4a784c4c8490d6548c248b0e57d0ac&quot;<br>}</pre><p><strong>If in the response the </strong><strong>object.sha is same as the one sent as a part of the request, along with status code 200, that means your changes will be reflected on GitHub.</strong></p><p>I hope you got some idea. Here is the GitHub link of the sample repo you can refer: <a href="https://github.com/BRO3886/git-db-example">github.com/BRO3886/git-db-example</a></p><p>You can always reach out to me via <a href="https://sidv.dev/contact">https://sidv.dev/contact</a></p><p>Please do 👏 if the blog was helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1a5b0b283ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sync GeeksForGeeks solutions to GitHub]]></title>
            <link>https://siddharthav.medium.com/sync-geeksforgeeks-solutions-to-github-6066727becdd?source=rss-d4f96f432560------2</link>
            <guid isPermaLink="false">https://medium.com/p/6066727becdd</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <dc:creator><![CDATA[Siddhartha Varma]]></dc:creator>
            <pubDate>Sun, 28 Nov 2021 20:40:36 GMT</pubDate>
            <atom:updated>2021-11-29T06:23:11.343Z</atom:updated>
            <content:encoded><![CDATA[<h4>How I contributed to LeetHub, and added a GFG sync script to it</h4><h4>Intro 👋</h4><p>While I was preparing for my placements, I used to practice on Leetcode and GeeksForGeeks. I found <a href="https://github.com/QasimWani/LeetHub">LeetHub</a> to be trending one fine day, while browsing through GitHub. Tried it out, it worked wonderfully.</p><p>Naturally, I looked at the opened issues, and I found that people were requesting more sites to be added:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzWb3EhyY5EIVsJpYp8BQw.png" /></figure><p>So I thought, why not add this myself? 😆</p><h4>LeetHub 👩‍💻</h4><p>For those of you who don’t know, <a href="https://github.com/qasimwani/leethub">LeetHub</a> is a wonderful extension that can help you sync your Leetcode submissions to GitHub. When i wrote this blog, it had around 870 stars on GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxZOp6Ck_1A4dm5QgA382A.png" /><figcaption>LeetHub logo by Qasim Wani</figcaption></figure><p>It basically connects to a repository on GitHub and syncs your code solutions along with the question as a README file.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FNKNm0TrUSgs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DNKNm0TrUSgs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FNKNm0TrUSgs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/163a07f7e476330509c082f3aff0b1a6/href">https://medium.com/media/163a07f7e476330509c082f3aff0b1a6/href</a></iframe><h4>Ah yes, Inspect-Element 🚧</h4><p>I added a very simple script, which extended it’s functionality to work on <a href="https://practice.geeksforgeeks.org/">GeeksForGeeks</a> as well. I personally use GeeksForGeeks for practicing more so than I use Leetcode. The content, editorial and solutions discussed are really high quality.</p><p>Writing the script was super fun, <strong>inspect-element to the rescue!</strong></p><p>I got the <strong>class names</strong> for the problem and it’s difficulty. Made functions for both:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/249b8eeda5137e393930f6f2959a1bcc/href">https://medium.com/media/249b8eeda5137e393930f6f2959a1bcc/href</a></iframe><p>Similarly, made another function to get the problem content. This content gets appended to a README (markdown) along with the title and difficulty:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9287a23df2972b9f7d7c269a3b08ad5d/href">https://medium.com/media/9287a23df2972b9f7d7c269a3b08ad5d/href</a></iframe><h4>The Mighty Editor 🔨</h4><p>Now, comes the interesting part. How do I get the entire code, including the driver code that’s mostly present on GeeksForGeeks?</p><p>I thought about it a lot. I inspected the this or the global object to find any references to something I could use. Finally, I stumbled upon the info that GeeksForGeeks uses the <a href="https://ace.c9.io/"><strong>ace editor</strong></a> for code editing.</p><p>So, I went through the editor object to find that it has a getValue function which can give the entire content at once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*35HpdaUhaTEKwqbADoqrEQ.png" /><figcaption>getValue() gives the whole content from the editor at once</figcaption></figure><p>However, I stumbled upon another problem: How do we get the content from an extension, which does not have direct access to the variables created by the website?</p><p>No, this is not possible <a href="https://stackoverflow.com/questions/12395722/can-the-window-object-be-modified-from-a-chrome-extension#:~:text=You%20can%27t%2C%20not%20directly.">directly</a>. Extension scripts run in an isolated environment, with a different execution context. I thought of something, which actually worked!</p><p>So, the method I came up with, injects a script, which gets the content from the editor object, since scripts on the web page execute in the same context and thus have access to the objects in window. It adds the content to a pre tag, and deletes the appended content along with the tag from the document after the submission has been fetched.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d64961300f48344344d0d802ba0e08c8/href">https://medium.com/media/d64961300f48344344d0d802ba0e08c8/href</a></iframe><p>Since we have the content on the pre tag, we can easily get it, since extension scripts can access the DOM. That’s how I pull the code (text) from the pre tag and return it if it’s not null.</p><p>However, I feel there is a scope of improvement to this script. Instead of injecting this script to the DOM again and again, we can inject it once and add an onClick event listener, which can append a pre tag to the page with content every time user presses submit.</p><p>After this, I followed up with Qasim’s logic of adding an onClick listener on the submit button, and used some utility functions to create the filename, get the language of submission and upload to GitHub.</p><p>It basically checks if a container (which I get by className) contains the string “Problem Solved Successfully” to detect there was a successful submission which can be synced.</p><p>You can check the entire script <a href="https://github.com/QasimWani/LeetHub/blob/main/scripts/gfg.js">here</a>. You can also check the repo I contribute my submssions to here: <a href="https://sidv.dev/gh/450dsa">BRO3886/450dsa</a></p><p>There ya go, with some basic knowledge of DOM, and JavaScript, I was able to contribute a feature to a useful extension!</p><p>I would highly recommend everyone to check out GeeksForGeeks, if you’ve not done yet. I personally find it to be very helpful a lot of times.</p><p><strong>Sidenote: </strong>If you liked this blog, do follow me on twitter (<a href="https://sidv.dev/twt">sidv_22</a>), where I occasionally tweet about stuff I’m learning and doing, would really appreciate it 🙋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6066727becdd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conditionally loading a Flutter App’s first screen with AutoRoute and Navigator 2.0]]></title>
            <link>https://siddharthav.medium.com/conditionally-loading-a-flutter-apps-first-screen-with-autoroute-and-navigator-2-0-823f850e317e?source=rss-d4f96f432560------2</link>
            <guid isPermaLink="false">https://medium.com/p/823f850e317e</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[autoroute]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Siddhartha Varma]]></dc:creator>
            <pubDate>Thu, 17 Jun 2021 08:01:11 GMT</pubDate>
            <atom:updated>2021-06-18T08:25:46.884Z</atom:updated>
            <content:encoded><![CDATA[<p>This is just a small blog to help you understand how easy it is to conditionally navigate to a page on app launch with <a href="https://pub.dev/packages/auto_route">auto-route</a>.</p><h4>Introduction</h4><p>I’m assuming you already have auto router setup. If not, check this <a href="https://pub.dev/packages/auto_route#installation">link</a> to see how to set it up with navigator 2.0 in Flutter.</p><p>If you have setup everything, your root widget’s build method would look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d6b5313506edad6451c6454f1e89d22/href">https://medium.com/media/3d6b5313506edad6451c6454f1e89d22/href</a></iframe><p>For context:</p><ul><li>Here _appRouter is initialised before the initState function:</li></ul><pre>final _appRouter = AppRouter();</pre><ul><li>I also have some booleans being fetched from hive at run-time, in the initState method:</li></ul><pre>late bool isSignedIn, isVerified, isTnCAccepted;</pre><p><strong>The code-snippet of importance is this:</strong></p><pre>routerDelegate: _appRouter.delegate(<br>   initialRoutes: [<br>     if (!isSignedIn) LandingScreen(),<br>     if (isSignedIn &amp;&amp; !isTnCAccepted) PledgeScreen(),<br>     if (isSignedIn &amp;&amp; isTnCAccepted) DashboardScreen(),<br>   ],<br>),</pre><p>So, basically we can provide any screens/routes conditionally to the initialRoutes prop in _appRouter.delegate, which is used to setup the routerDelegate for our MaterialApp.</p><h4>Explanation</h4><p>In my case, if the user is <strong>not signed in</strong>, it returns LandingScreen. If the user is signed in and has not accepted the terms, it takes them to the PledgeScreen, else, it takes them to the DashboardScreen.</p><h4>Full Code example</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61694bf7979cc0c9ca5dc7130415b936/href">https://medium.com/media/61694bf7979cc0c9ca5dc7130415b936/href</a></iframe><p>Here PledgeScreen and LandingScreen come from the file of routes generated by auto_router (it might be router.gr.dart for you, check auto_router documentation for reference) .</p><p>These are my routes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a6b7ca75669e538bc54997c2a4b071e/href">https://medium.com/media/4a6b7ca75669e538bc54997c2a4b071e/href</a></iframe><h4>Conclusion</h4><p>This is how easy it was to use AutoRouter with Navigator2.0, when you have to conditionally open a page in the app. In addition to this, AutoRouter also simplifies deep-links, opening the correct page on launch with dynamic links etc. Will be covering that soon! Hope you liked my first blog here :). Would love to hear suggestions to improve.</p><h4>References</h4><p><a href="https://pub.dev/packages/auto_route">auto_route | Flutter package</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=823f850e317e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>