<?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 Iswaryalakshmi Manikandan on Medium]]></title>
        <description><![CDATA[Stories by Iswaryalakshmi Manikandan on Medium]]></description>
        <link>https://medium.com/@engineeringvault?source=rss-3f583be61b8f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*s6wc08IT8vd2Ja19edT8Eg.png</url>
            <title>Stories by Iswaryalakshmi Manikandan on Medium</title>
            <link>https://medium.com/@engineeringvault?source=rss-3f583be61b8f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:47:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@engineeringvault/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[ Go Coding Interview: Tricky String, Hash Map & Go Concepts]]></title>
            <link>https://medium.com/@engineeringvault/go-coding-interview-tricky-string-hash-map-go-concepts-db69d9c2c000?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/db69d9c2c000</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Sun, 09 Aug 2026 07:17:22 GMT</pubDate>
            <atom:updated>2026-08-09T07:17:22.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNDw1TwWB5GZ_IVHsZb-VQ.png" /></figure><p>Go coding interviews often start with simple problems such as reversing a string or finding duplicate characters.</p><p>But the real interview questions usually come from the <strong>small details</strong>:</p><ul><li>Why does a nil map panic?</li><li>Why does for ch := range str give an index?</li><li>Why do we use rune instead of byte?</li><li>Why does a map lookup return zero even when the key doesn’t exist?</li><li>Why do some problems need two passes?</li><li>What is the actual time and space complexity?</li></ul><p>This article covers some common coding problems along with the Go concepts behind them.</p><h4>1. Reverse a String Using Two Pointers</h4><p>Reverse a string without using a built-in reverse function.</p><pre>str := &quot;hello&quot;<br>ch := []rune(str)<br>for i, j := 0, len(ch)-1; i &lt; j; i, j = i+1, j-1 {<br>    ch[i], ch[j] = ch[j], ch[i]<br>}<br>fmt.Println(string(ch))</pre><p>Output</p><pre>olleh</pre><p><strong>Key concept: Two Pointers</strong></p><p>The important part is:</p><pre>for i, j := 0, len(ch)-1; i &lt; j; i, j = i+1, j-1</pre><p>This is the <strong>two-pointer technique</strong>.</p><p>One pointer starts from the beginning and another starts from the end.</p><pre>h e l l o<br>↑       ↑<br>i       j</pre><p>After each iteration:</p><pre>o e l l h<br>  ↑   ↑<br>  i   j</pre><p>The pointers move toward the middle.</p><p><strong>Complexity</strong></p><pre>Time  : O(n)<br>Space : O(n)</pre><p>The reversal itself uses O(1) extra space, but converting the string to []rune requires O(n) space.</p><h4>2. Check Whether Two Strings Are Anagrams</h4><p>Two strings are anagrams if they contain the same characters with the same frequencies.</p><p>Example:</p><pre>listen<br>silent</pre><p>Solution:</p><pre>func areAnagrams(str1, str2 string) bool {<br>    if len(str1) != len(str2) {<br>        return false<br>    }<br>    count := make(map[rune]int)<br>    for _, ch := range str1 {<br>        count[ch]++<br>    }<br>    for _, ch := range str2 {<br>        count[ch]--<br>        if count[ch] &lt; 0 {<br>            return false<br>        }<br>    }<br>    return true<br>}</pre><p><strong>Key concept: Frequency Map</strong></p><p>The important pattern here is a <strong>frequency map</strong></p><pre>character → frequency</pre><p>For &quot;listen&quot;:</p><pre>l → 1<br>i → 1<br>s → 1<br>t → 1<br>e → 1<br>n → 1</pre><p>Then characters from the second string decrease those counts.</p><p><strong>Complexity</strong></p><pre>Time  : O(n)<br>Space : O(n)</pre><h4>3. Find the First Non-Repeating Character</h4><p>Given:</p><pre>programming</pre><p>Find the first character that appears only once.</p><pre>func firstNonRepeating(str string) {<br>    count := make(map[rune]int)<br>    // Count frequencies<br>    for _, ch := range str {<br>        count[ch]++<br>    }<br>    // Find first unique character<br>    for _, ch := range str {<br>        if count[ch] == 1 {<br>            fmt.Printf(&quot;%c&quot;, ch)<br>            return<br>        }<br>    }<br>}</pre><p>Output</p><pre>p</pre><p>The important part is that we need <strong>two passes</strong>.</p><p>Why?</p><p>While counting the first character, we don’t know whether the same character appears later.</p><p>So:</p><pre>Pass 1 → Count characters<br>Pass 2 → Find first character with count == 1</pre><p><strong>Complexity</strong></p><pre>Time  : O(n)<br>Space : O(n)</pre><h4>4. Find Duplicate Characters</h4><p>Given:</p><pre>programming</pre><p>Find characters that appear more than once.</p><pre>func findDuplicates(str string) {<br>    count := make(map[rune]int)<br>    for _, ch := range str {<br>        count[ch]++<br>    }<br>    for ch, frequency := range count {<br>        if frequency &gt; 1 {<br>            fmt.Printf(&quot;%c &quot;, ch)<br>        }<br>    }<br>}</pre><p><strong>Key concept</strong></p><p>Again, this is a <strong>frequency map</strong>.</p><pre>character → number of occurrences</pre><p><strong>Complexity</strong></p><pre>Time  : O(n)<br>Space : O(n)</pre><h4>5. Check Whether a String Is a Palindrome</h4><p>A palindrome reads the same from both directions.</p><p>Example:</p><pre>madam</pre><p>Use two pointers:</p><pre>func isPalindrome(str string) bool {<br>    ch := []rune(str)<br>    for i, j := 0, len(ch)-1; i &lt; j; i, j = i+1, j-1 {<br>        if ch[i] != ch[j] {<br>            return false<br>        }<br>    }<br>    return true<br>}</pre><p><strong>How it works</strong></p><pre>m a d a m<br>↑       ↑<br><br>m == m<br>  ↑   ↑<br>  <br>a == a</pre><p><strong>Complexity</strong></p><pre>Time  : O(n)<br>Space : O(n)</pre><p>The two-pointer comparison itself requires O(1) extra space, but converting the string to []rune requires O(n).</p><h4>6. Count Character Frequency</h4><p>Given:</p><pre>hello</pre><p>Return the frequency of every character.</p><pre>func characterFrequency(str string) map[rune]int {<br>    count := make(map[rune]int)<br>    for _, ch := range str {<br>        count[ch]++<br>    }<br>    return count<br>}</pre><p>For &quot;hello&quot;:</p><pre>h → 1<br>e → 1<br>l → 2<br>o → 1</pre><p><strong>Complexity</strong></p><pre>Time  : O(n)<br>Space : O(n)</pre><p>This is one of the most reusable Hash Map patterns in coding interviews.</p><h4>7. Find the First Duplicate Character</h4><p>This problem is slightly different from finding duplicates.</p><p>Given:</p><pre>&quot;abcdbea&quot;</pre><p>The first character that appears again is:</p><pre>b</pre><p>We can solve it using a map:</p><pre>func firstDuplicate(str string) rune {<br>    seen := make(map[rune]bool)<br>    for _, ch := range str {<br>        if seen[ch] {<br>            return ch<br>        }<br>        seen[ch] = true<br>    }<br>    return 0<br>}</pre><p><strong>Why only one loop?</strong></p><p>We don’t need the total frequency.</p><p>We only need to know:</p><blockquote><em>“Have I already seen this character?”</em></blockquote><p>Therefore:</p><pre>seen[character] → true/false</pre><p><strong>Complexity</strong></p><pre>Time  : O(n)<br>Space : O(n)</pre><h4>8. Check Whether a String Contains Only Unique Characters</h4><p>Example:</p><pre>&quot;abcde&quot; → true<br>&quot;aabbc&quot; → false</pre><pre>func isUnique(str string) bool {<br>    seen := make(map[rune]bool)<br>    for _, ch := range str {<br>        if seen[ch] {<br>            return false<br>        }<br>        seen[ch] = true<br>    }<br>    return true<br>}</pre><p>This is another example of using a Hash Map for <strong>constant-time average lookup</strong>.</p><p><strong>Complexity</strong></p><pre>Time  : O(n)<br>Space : O(n)</pre><h4>9. Nil Map vs Initialized Map</h4><p>Consider:</p><pre>func charFrequency(s string) (freq map[string]int) {<br>    for _, ch := range s {<br>        freq[string(ch)]++<br>    }<br>    return freq<br>}</pre><p>This causes:</p><pre>panic: assignment to entry in nil map</pre><p>Why?</p><p>Because:</p><pre>(freq map[string]int)</pre><p>only declares a named return variable.</p><p>It does <strong>not</strong> initialize the map.</p><p>Conceptually:</p><pre>var freq map[string]int</pre><p>creates:</p><pre>freq → nil</pre><p>It does not create a writable map.</p><p>Therefore this is invalid:</p><pre>freq[&quot;a&quot;] = 1</pre><p>because you are trying to insert into a nil map.</p><p><strong>Correct Version</strong></p><pre>func charFrequency(s string) (freq map[string]int) {<br>    freq = make(map[string]int)<br>    for _, ch := range s {<br>        freq[string(ch)]++<br>    }<br>    return<br>}</pre><p>Now the map has been initialized.</p><h4>10. Nil Map vs Empty Map</h4><p><strong>Nil map</strong></p><pre>var m map[string]int</pre><p>Here:</p><pre>m == nil</pre><p>is true.</p><p>Writing causes a panic:</p><pre>m[&quot;a&quot;] = 1</pre><p>But reading is safe:</p><pre>fmt.Println(m[&quot;a&quot;])</pre><p>Output:</p><pre>0</pre><p><strong>Initialized map</strong></p><pre>m := make(map[string]int)</pre><p>Now:</p><pre>m == nil</pre><p>is false.</p><p>Writing works:</p><pre>m[&quot;a&quot;] = 1</pre><p><strong>Easy rule</strong></p><pre>var m map[string]int<br>        ↓<br>      nil map<br>        ↓<br>   cannot write<br><br>make(map[string]int)<br>        ↓<br> initialized map<br>        ↓<br>     can write</pre><p>This distinction is frequently asked in Go interviews.</p><h4>11. Tricky range Behavior</h4><p>Consider:</p><pre>str := &quot;hello&quot;<br>for ch := range str {<br>    fmt.Println(ch)<br>}</pre><p>What does ch contain?</p><p>Many developers initially expect:</p><pre>h<br>e<br>l<br>l<br>o</pre><p>But it actually prints:</p><pre>0<br>1<br>2<br>3<br>4</pre><p>Why?</p><p>Because when range is used with a string, it normally provides:</p><pre>index, rune</pre><p>So:</p><pre>for i, ch := range str {<br>    fmt.Println(i, ch)<br>}</pre><p>means:</p><pre>i  → index<br>ch → rune</pre><p>If the index isn’t needed:</p><pre>for _, ch := range str {<br>    fmt.Printf(&quot;%c\n&quot;, ch)<br>}</pre><p>The _ means:</p><blockquote><em>Ignore the first value.</em></blockquote><p>This is why frequency-map code commonly uses:</p><pre>for _, ch := range str {<br>    count[ch]++<br>}</pre><p>We don’t need the index.</p><h4>12. Why Use rune?</h4><p>You will frequently see:</p><pre>map[rune]int</pre><p>instead of:</p><pre>map[byte]int</pre><p>A Go string is UTF-8 encoded.</p><p>A character can occupy multiple bytes.</p><p>For example, an ASCII character such as:</p><pre>a</pre><p>uses one byte.</p><p>Unicode characters can require multiple bytes.</p><p>Using:</p><pre>for _, ch := range str</pre><p>iterates over Unicode code points, and ch is a rune.</p><p>Therefore:</p><pre>map[rune]int</pre><p>is generally appropriate when the algorithm should work with Unicode text.</p><h4>13. Map Lookup Has an Interesting Behavior</h4><p>Consider:</p><pre>m := make(map[string]int)<br>fmt.Println(m[&quot;hello&quot;])</pre><p>What happens?</p><p>There is no &quot;hello&quot; key.</p><p>But Go doesn’t panic.</p><p>It prints:</p><pre>0</pre><p>For an int map, the zero value is 0.</p><p>You can explicitly check whether the key exists:</p><pre>value, exists := m[&quot;hello&quot;]<br>if exists {<br>    fmt.Println(&quot;Found:&quot;, value)<br>}</pre><p>This pattern is very important:</p><pre>value, exists := map[key]</pre><p>For example:</p><pre>if count, exists := freq[&quot;a&quot;]; exists {<br>    fmt.Println(count)<br>}</pre><h3>The Patterns Behind These Problems</h3><p>The important thing isn’t memorizing solutions. It’s recognizing the underlying patterns.</p><h4>Pattern 1 — Frequency Map</h4><pre>count := make(map[rune]int)<br>for _, ch := range str {<br>    count[ch]++<br>}</pre><p>Useful for:</p><ul><li>Anagrams</li><li>Character frequency</li><li>First non-repeating character</li><li>Duplicate characters</li><li>Grouping problems</li></ul><h4>Pattern 2 — Seen Set</h4><pre>seen := make(map[rune]bool)<br>if seen[ch] {<br>    // already exists<br>}<br>seen[ch] = true</pre><p>Useful for:</p><ul><li>Duplicate detection</li><li>Unique characters</li><li>First duplicate</li><li>Visited elements</li></ul><h4>Pattern 3 — Two Pointers</h4><pre>for i, j := 0, len(arr)-1; i &lt; j; i, j = i+1, j-1 {<br>    // process arr[i] and arr[j]<br>}</pre><p>Useful for:</p><ul><li>Reverse string</li><li>Palindrome</li><li>Pair problems</li><li>Sorted array problems</li><li>Partitioning</li></ul><h4>Complexity Cheat Sheet</h4><pre>| Problem                       | Pattern       | Time | Space |<br>| ----------------------------- | ------------- | ---: | ----: |<br>| Reverse String                | Two Pointers  | O(n) |  O(n) |<br>| Anagram                       | Frequency Map | O(n) |  O(n) |<br>| First Non-Repeating Character | Frequency Map | O(n) |  O(n) |<br>| Character Frequency           | Frequency Map | O(n) |  O(n) |<br>| First Duplicate               | Seen Map      | O(n) |  O(n) |<br>| Unique Characters             | Seen Map      | O(n) |  O(n) |<br>| Palindrome                    | Two Pointers  | O(n) |  O(n) |</pre><h4>Quick Pattern Reference</h4><pre>| Pattern           | When to Use                                         |<br>| ----------------- | --------------------------------------------------- |<br>| **Two Pointers**  | Problems involving both ends of an array/string     |<br>| **Frequency Map** | Counting occurrences or comparing frequencies       |<br>| **Seen Map**      | Detecting duplicates or previously visited elements |</pre><h4>Final Takeaway</h4><p>The most important thing in a coding interview isn’t remembering the exact code.</p><p>It’s recognizing the pattern behind the problem.</p><pre>Need to count?<br>        ↓<br>Frequency Map<br><br>Need to know whether something appeared?<br>        ↓<br>Seen Map<br><br>Need to process both ends?<br>        ↓<br>Two Pointers<br><br>Need fast average lookup?<br>        ↓<br>Hash Map<br><br>Need to preserve original order?<br>        ↓<br>Iterate over the original input</pre><p>And for Go specifically, remember these three interview traps:</p><pre>1. nil map ≠ initialized map<br><br>2. for ch := range str<br>   → ch is the index<br><br>3. for _, ch := range str<br>   → ch is the rune</pre><p>These small details are often what separates a solution that merely works from a solution that demonstrates strong Go fundamentals.</p><p>Happy Learning! 🚀</p><p><em>Thanks for reading! stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db69d9c2c000" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Saga Pattern: A Deep Dive into Distributed Transactions]]></title>
            <link>https://medium.com/@engineeringvault/saga-pattern-a-deep-dive-into-distributed-transactions-0bc1bb4fe421?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/0bc1bb4fe421</guid>
            <category><![CDATA[high-level-design]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[transactions]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Sat, 08 Aug 2026 10:35:27 GMT</pubDate>
            <atom:updated>2026-08-08T10:35:27.802Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rW3CjVKVn_WuaLEFZcu6gA.png" /></figure><p>In a monolithic application, a business operation can often be handled using a single database transaction.</p><p>For example:</p><pre>BEGIN<br>Create Order<br>Update Inventory<br>Create Payment Record<br>COMMIT</pre><p>If something fails:</p><pre>ROLLBACK</pre><p>The database guarantees atomicity.</p><p>But distributed systems introduce a different problem.</p><p>A single business workflow may span multiple services, with each service owning its own transaction boundary.</p><pre>Order Service<br>      ↓<br>Payment Service<br>      ↓<br>Inventory Service<br>      ↓<br>Shipping Service</pre><p>Now a single ACID transaction cannot easily cover the entire workflow.</p><p>This is where the <strong>Saga Pattern</strong> becomes useful.</p><h3>🎓What Is the Saga Pattern?</h3><p>The <strong>Saga Pattern is an architectural pattern for managing a business transaction that spans multiple independent local transactions.</strong></p><p>Instead of using one global transaction, the business workflow is divided into a sequence of local transactions.</p><p>Each local transaction:</p><ol><li>Performs a business operation.</li><li>Commits independently.</li><li>Triggers the next step.</li></ol><p>If a later step fails, previously completed operations are handled using <strong>compensating transactions</strong>.</p><p>The basic model is:</p><pre>Business Transaction<br>        |<br>        +---- Local Transaction 1<br>        |<br>        +---- Local Transaction 2<br>        |<br>        +---- Local Transaction 3<br>        |<br>        +---- Local Transaction 4</pre><p>The most important idea is:</p><blockquote><em>A Saga coordinates multiple independent transactions that together represent one business workflow.</em></blockquote><h4>Saga Is Not a GoF Design Pattern</h4><p>Saga is different from patterns such as:</p><ul><li>Factory</li><li>Strategy</li><li>Observer</li><li>Adapter</li><li>Decorator</li></ul><p>Those are commonly categorized as <strong>object-oriented design patterns</strong>, especially the 23 Gang of Four patterns.</p><p>Saga belongs to the world of <strong>distributed systems and architectural patterns</strong>.</p><p>It addresses a much higher-level problem:</p><blockquote><strong>How can a distributed business workflow remain consistent when one global transaction cannot cover the entire workflow?</strong></blockquote><h4>🚩The Core Problem</h4><p>Consider an e-commerce system.</p><pre>Order Service<br>      ↓<br>Payment Service<br>      ↓<br>Inventory Service<br>      ↓<br>Shipping Service</pre><p>The business operation is:</p><blockquote><em>Place an order.</em></blockquote><p>From a business perspective, this is one operation.</p><p>Technically, however, it may involve several independent transactions:</p><pre>Order DB<br>Payment DB<br>Inventory DB<br>Shipping DB</pre><p>A traditional transaction cannot simply do:</p><pre>BEGIN<br>Order DB<br>Payment DB<br>Inventory DB<br>Shipping DB<br>COMMIT</pre><p>Each service owns its own transaction boundary.</p><p>Therefore, the workflow becomes:</p><pre>T1 → Create Order<br>T2 → Charge Payment<br>T3 → Reserve Inventory<br>T4 → Create Shipment</pre><p>Each transaction commits independently.</p><h4>🌗Why Not Use a Distributed Transaction?</h4><p>Technically, distributed transaction protocols such as <strong>Two-Phase Commit (2PC)</strong> exist.</p><p>However, distributed transactions can introduce significant complexity:</p><ul><li>coordination overhead</li><li>blocking behavior</li><li>reduced availability</li><li>tight coupling between participants</li><li>operational complexity</li><li>difficult scaling</li></ul><p>Modern microservice architectures often prefer <strong>local transactions + eventual consistency</strong> instead of maintaining one global transaction across services.</p><p>This is one of the reasons Saga is valuable.</p><h4>✅How a Saga Works</h4><p>Consider:</p><pre>Create Order<br>     ↓<br>Charge Payment<br>     ↓<br>Reserve Inventory<br>     ↓<br>Create Shipment</pre><p>Suppose:</p><pre>Create Order       ✅<br>Charge Payment     ✅<br>Reserve Inventory  ❌</pre><p>The first two operations have already committed.</p><p>A global rollback is no longer possible.</p><p>Instead, compensating actions are executed:</p><pre>Reserve Inventory  ❌<br>       ↓<br>Refund Payment     ✅<br>       ↓<br>Cancel Order       ✅</pre><p>The system moves toward a consistent business state.</p><h4>📭Compensation Is Not the Same as Rollback</h4><p>This distinction is extremely important.</p><p>A database rollback is:</p><pre>BEGIN<br>UPDATE account<br>ROLLBACK</pre><p>The database automatically restores the previous state.</p><p>A Saga compensation is different.</p><p>Suppose:</p><pre>Charge Payment</pre><p>successfully completes.</p><p>Later, another step fails.</p><p>The original payment transaction cannot simply be rolled back.</p><p>Instead, a new business transaction is performed:</p><pre>Refund Payment</pre><p>Therefore:</p><pre>Database Rollback<br>    ↓<br>Undo the current transaction</pre><pre>Saga Compensation<br>    ↓<br>Execute another transaction that<br>semantically reverses a previous action</pre><p>A compensation is not necessarily a perfect technical inverse.</p><p>For example:</p><pre>Charge $100</pre><p>may be compensated by:</p><pre>Refund $100</pre><p>rather than deleting a payment record.</p><h4>The Two Types of Saga</h4><p>There are two major ways to coordinate a Saga:</p><ol><li>Choreography</li><li>Orchestration</li></ol><h4>1️⃣Choreography</h4><p>In choreography, there is no central coordinator.</p><p>Each service reacts to events and publishes the next event.</p><pre>Order Service<br>      |<br>      | OrderCreated<br>      ↓<br>    Kafka<br>      |<br>      ↓<br>Payment Service<br>      |<br>      | PaymentCompleted<br>      ↓<br>    Kafka<br>      |<br>      ↓<br>Inventory Service<br>      |<br>      | InventoryReserved<br>      ↓<br>    Kafka<br>      |<br>      ↓<br>Shipping Service</pre><p>The event flow itself coordinates the Saga.</p><p>For example:</p><pre>Order Service<br>      ↓<br>OrderCreated<br>      ↓<br>Payment Service<br>      ↓<br>PaymentCompleted<br>      ↓<br>Inventory Service<br>      ↓<br>InventoryReserved<br>      ↓<br>Shipping Service</pre><p>There is no central component saying:</p><pre>Step 1<br>Step 2<br>Step 3<br>Step 4</pre><p>Each service knows which event it should react to.</p><h4>Advantages of Choreography</h4><p><strong>Loose coupling</strong></p><p>Services communicate through events instead of directly calling one another.</p><p><strong>Natural fit for event-driven systems</strong></p><p>Kafka and other message brokers work naturally with this approach.</p><p><strong>No central coordinator</strong></p><p>There is no single Saga orchestrator controlling the entire workflow.</p><h4>Problems with Choreography</h4><p>Choreography becomes harder to manage as the workflow grows.</p><p>For example:</p><pre>OrderCreated<br>     ↓<br>Payment<br>     ↓<br>PaymentCompleted<br>     ↓<br>Inventory<br>     ↓<br>InventoryReserved<br>     ↓<br>Shipping<br>     ↓<br>ShipmentCreated<br>     ↓<br>Notification<br>     ↓<br>Loyalty<br>     ↓<br>Analytics</pre><p>Understanding the complete workflow becomes difficult.</p><p>A change in one event can affect many consumers.</p><p>Debugging can also become challenging because the business workflow is distributed across multiple services.</p><p>This can eventually turn into what is sometimes described as <strong>event-driven spaghetti</strong>.</p><h4>2️⃣Orchestration</h4><p>Orchestration introduces a central component called a <strong>Saga Orchestrator</strong>.</p><pre>                 Saga Orchestrator<br>                         |<br>          +--------------+--------------+<br>          |              |              |<br>          ↓              ↓              ↓<br>      Order Service  Payment Service  Inventory</pre><p>The orchestrator controls the workflow.</p><p>For example:</p><pre>1. Create Order<br>2. Charge Payment<br>3. Reserve Inventory<br>4. Create Shipment</pre><p>If inventory fails:</p><pre>Inventory Failed<br>       ↓<br>Saga Orchestrator<br>       ↓<br>Refund Payment<br>       ↓<br>Cancel Order</pre><p>The workflow is explicitly represented in one place.</p><h4>Advantages of Orchestration</h4><p><strong>Workflow visibility</strong></p><p>The complete business workflow is easier to understand.</p><p><strong>Centralized failure handling</strong></p><p>Compensation logic can be coordinated from one place.</p><p><strong>Easier recovery</strong></p><p>Saga state can be persisted and resumed.</p><p><strong>Better for complex workflows</strong></p><p>As the number of steps and failure paths grows, explicit orchestration can become easier to manage.</p><h4>Problems with Orchestration</h4><p>The orchestrator becomes an important component.</p><p>It needs to handle:</p><ul><li>Saga state</li><li>retries</li><li>timeouts</li><li>failures</li><li>compensation</li><li>recovery</li><li>observability</li></ul><p>There is also a risk of putting too much business logic into the orchestrator.</p><p>The orchestrator should generally coordinate the workflow rather than becoming the owner of every business rule.</p><h4>Choreography vs Orchestration</h4><pre>|                     | Choreography         | Orchestration        |<br>| ------------------- | -------------------- | -------------------- |<br>| Coordinator         | None                 | Saga Orchestrator    |<br>| Communication       | Events               | Commands/API/events  |<br>| Workflow visibility | Lower                | Higher               |<br>| Coupling            | Distributed          | Centralized workflow |<br>| Debugging           | Harder               | Easier               |<br>| Simple workflows    | Good                 | Good                 |<br>| Complex workflows   | Can become difficult | Usually better       |</pre><p>A simple rule:</p><blockquote><strong><em>Simple event-driven workflow → Choreography can work well.</em></strong></blockquote><blockquote><strong><em>Complex business workflow → Orchestration is often easier to control.</em></strong></blockquote><h4>👤Where Does Kafka Fit?</h4><p>Kafka does not implement Saga by itself.</p><p>Kafka is a <strong>messaging platform</strong>.</p><p>Saga defines the business workflow.</p><p>Kafka can be used as the communication mechanism between Saga steps.</p><p>For example:</p><pre>Order Service<br>      |<br>      | OrderCreated<br>      ↓<br>    Kafka<br>      |<br>      ↓<br>Payment Service<br>      |<br>      | PaymentCompleted<br>      ↓<br>    Kafka<br>      |<br>      ↓<br>Inventory Service</pre><p>Therefore:</p><pre>Saga → Business workflow<br><br>Kafka → Communication mechanism</pre><p>These are different responsibilities.</p><h4>🍥Now Comes the Outbox Problem</h4><p>Suppose Order Service performs:</p><pre>1. Create Order in database<br>2. Publish OrderCreated to Kafka</pre><p>These are two independent operations.</p><p>What happens here?</p><pre>Create Order       ✅<br>Publish Event      ❌</pre><p>The database contains the order.</p><p>Kafka does not contain the event.</p><p>The next service never knows about the order.</p><p>The opposite problem is also possible:</p><pre>Publish Event      ✅<br>Create Order       ❌</pre><p>Kafka says the order exists, but the database does not.</p><p>This is called a <strong>dual-write problem</strong>.</p><h4>📓Transactional Outbox Pattern</h4><p>The Outbox Pattern solves this problem by storing the event in the same database transaction as the business data.</p><p>Instead of:</p><pre>Database<br>    +<br>Kafka</pre><p>the application performs:</p><pre>BEGIN<br>Create Order<br>Insert OrderCreated into Outbox<br>COMMIT</pre><p>For example:</p><pre>orders<br>-------------------------<br>id<br>customer_id<br>status</pre><p>and:</p><pre>outbox<br>-------------------------<br>id<br>event_type<br>payload<br>status<br>created_at</pre><p>The transaction guarantees:</p><pre>Order created<br>      +<br>Outbox event created</pre><p>or:</p><pre>Neither is created</pre><h4>💭 Does the Database Push the Event to Kafka?</h4><p>Normally, <strong>no</strong>.</p><p>The database does not directly push the event to Kafka.</p><p>A publisher process reads the outbox table.</p><pre>Application<br>     |<br>     ↓<br>Database<br>     |<br>     +---- Orders<br>     |<br>     +---- Outbox<br>              |<br>              ↓<br>       Outbox Publisher<br>              |<br>              ↓<br>            Kafka</pre><p>The publisher may run as:</p><ul><li>a background worker inside the service</li><li>a separate publisher service</li><li>a CDC-based pipeline</li></ul><p>The important point is that the outbox event becomes durable before publication is attempted.</p><h4>❔How Does the Outbox Publisher Work?</h4><p>Suppose:</p><pre>outbox<br>id | event_type   | status<br>---+--------------+---------<br>1  | OrderCreated | PENDING</pre><p>The publisher reads pending events:</p><pre>SELECT *<br>FROM outbox<br>WHERE status = &#39;PENDING&#39;;</pre><p>Then publishes:</p><pre>OrderCreated<br>      ↓<br>Kafka</pre><p>After successful processing, the event can be marked as published.</p><pre>PENDING<br>   ↓<br>PUBLISHED</pre><h4>⏰ Does the User Need to Wait?</h4><p>Not necessarily.</p><p>The API can return after the local transaction succeeds:</p><pre>POST /orders<br>↓<br>Create Order<br>Create Outbox Event<br>Commit<br>↓<br>201 Created</pre><p>The background workflow continues:</p><pre>Outbox<br>   ↓<br>Kafka<br>   ↓<br>Payment<br>   ↓<br>Kafka<br>   ↓<br>Inventory</pre><p>The API might return:</p><pre>{<br>  &quot;order_id&quot;: 101,<br>  &quot;status&quot;: &quot;PROCESSING&quot;<br>}</pre><p>The final status can later become:</p><pre>PROCESSING<br>     ↓<br>PAID<br>     ↓<br>CONFIRMED</pre><p>The client can obtain the updated state through polling, WebSocket, Server-Sent Events, or another application-specific mechanism.</p><p>Saga does not require an API request to remain open until the entire workflow completes.</p><h4>✋ Outbox Does Not Guarantee Exactly Once</h4><p>Consider:</p><pre>1. Read event<br>2. Publish to Kafka<br>3. Mark event as PUBLISHED</pre><p>Suppose:</p><pre>Publish to Kafka       ✅<br>Application crashes    ❌<br>Mark PUBLISHED         ❌</pre><p>After restart, the event may still appear as:</p><pre>PENDING</pre><p>It can be published again.</p><p>Therefore, duplicate events are possible.</p><p>This is why Saga systems commonly require <strong>idempotent consumers</strong>.</p><h4>😎 Idempotency</h4><p>Suppose:</p><pre>PaymentCompleted</pre><p>arrives twice.</p><p>Without idempotency:</p><pre>Process PaymentCompleted<br>Process PaymentCompleted</pre><p>could produce an incorrect result.</p><p>A consumer can track processed event IDs:</p><pre>processed_events<br>------------------------<br>event_id = 12345</pre><p>When event 12345 arrives again:</p><pre>Already processed<br>→ Ignore</pre><p>Therefore:</p><blockquote><em>Outbox + at-least-once delivery usually requires idempotent consumers.</em></blockquote><h4>🙎 Saga and Failure Handling</h4><p>Distributed systems fail in many ways.</p><p>A Saga must account for:</p><ul><li>service crashes</li><li>network failures</li><li>Kafka failures</li><li>duplicate messages</li><li>delayed messages</li><li>out-of-order messages</li><li>consumer failures</li><li>timeout</li><li>compensation failure</li></ul><p>Consider:</p><pre>Create Order       ✅<br>Charge Payment     ✅<br>Reserve Inventory  ❌</pre><p>Compensation:</p><pre>Refund Payment</pre><p>But what if:</p><pre>Refund Payment ❌</pre><p>Now the Saga itself is in a partially failed state.</p><p>This is one of the major challenges of Saga.</p><p><strong>Retries</strong></p><p>A failed operation can often be retried.</p><pre>Refund Payment<br>      ↓<br>Failed<br>      ↓<br>Retry<br>      ↓<br>Failed<br>      ↓<br>Retry<br>      ↓<br>Success</pre><p>But retries create another requirement:</p><p><strong>Idempotency.</strong></p><p>A retry must not accidentally perform the business operation multiple times.</p><p><strong>Timeouts</strong></p><p>A Saga can also become stuck.</p><p>For example:</p><pre>Payment Service<br>      ↓<br>Waiting...<br>      ↓<br>No response</pre><p>The Saga needs a timeout:</p><pre>Payment Pending<br>      ↓<br>Timeout<br>      ↓<br>Compensation / Retry / Manual Recovery</pre><p>Timeouts are particularly important for long-running workflows.</p><h4>🌟 Saga State</h4><p>An orchestrated Saga usually needs persistent state.</p><p>For example:</p><pre>saga_instance<br>--------------------------------<br>saga_id<br>order_id<br>current_step<br>status<br>created_at<br>updated_at</pre><p>A Saga could have states such as:</p><pre>STARTED<br>   ↓<br>ORDER_CREATED<br>   ↓<br>PAYMENT_COMPLETED<br>   ↓<br>INVENTORY_RESERVED<br>   ↓<br>COMPLETED</pre><p>Failure:</p><pre>PAYMENT_COMPLETED<br>       ↓<br>INVENTORY_FAILED<br>       ↓<br>REFUNDING_PAYMENT<br>       ↓<br>CANCELLING_ORDER<br>       ↓<br>COMPENSATED</pre><p>This makes a Saga similar to a <strong>state machine</strong>.</p><h4>👆 Saga Does Not Provide Full ACID Isolation</h4><p>Another important limitation:</p><p>Saga is not a replacement for ACID.</p><p>A Saga typically provides a form of <strong>eventual consistency</strong>.</p><p>During execution, different services may temporarily have different views of the business state.</p><p>For example:</p><pre>Order Service<br>status = CONFIRMED<br><br>Inventory Service<br>status = RESERVATION_PENDING</pre><p>The system may eventually converge.</p><p>This is fundamentally different from a single ACID transaction where isolation can hide intermediate states.</p><h4>😞 Compensation Is Not Always Possible</h4><p>Some operations are easy to compensate:</p><pre>Reserve Inventory<br>      ↓<br>Release Inventory</pre><p>Some have a business-level compensation:</p><pre>Charge Payment<br>      ↓<br>Refund Payment</pre><p>Some operations cannot be perfectly reversed:</p><pre>Send Email<br>Publish Notification<br>Ship Physical Product</pre><p>There is no perfect:</p><pre>Undo Email<br>Undo Shipment</pre><p>Therefore, Saga design must consider the reversibility of every step.</p><h4>🌑 The Dark Side of Saga</h4><p>Saga solves one difficult problem but introduces several others.</p><p><strong>1. Eventual consistency</strong></p><p>The system can remain temporarily inconsistent.</p><p><strong>2. Compensation complexity</strong></p><p>Every important step needs a recovery strategy.</p><p><strong>3. Compensation failure</strong></p><p>A compensating action can fail too.</p><p><strong>4. Duplicate messages</strong></p><p>At-least-once delivery can result in repeated events.</p><p><strong>5. Debugging complexity</strong></p><p>One business operation spans multiple services.</p><p><strong>6. Long-running state</strong></p><p>Saga state may need to survive application crashes and restarts.</p><p><strong>7. Concurrency problems</strong></p><p>Multiple Sagas may operate on the same business entity simultaneously.</p><p><strong>8. Operational complexity</strong></p><p>Monitoring, tracing, retries, DLQs, idempotency, and recovery become important.</p><h4>✒️ Saga and Concurrency</h4><p>Consider two simultaneous orders trying to reserve the last available item.</p><pre>Saga A → Reserve Item<br>Saga B → Reserve Item</pre><p>Both may observe:</p><pre>stock = 1</pre><p>If the system isn’t designed correctly, both workflows may succeed.</p><p>Therefore Saga systems may need:</p><ul><li>optimistic locking</li><li>version checks</li><li>database constraints</li><li>reservation records</li><li>locking</li><li>atomic updates</li></ul><p>For example:</p><pre>UPDATE inventory<br>SET quantity = quantity - 1<br>WHERE product_id = 101<br>  AND quantity &gt; 0;</pre><p>The database still plays an important role inside each local transaction.</p><p>Saga does not eliminate the need for strong local consistency.</p><h4>⭐️Saga + Outbox + Kafka</h4><p>A production event-driven architecture may look like:</p><pre>                     Kafka<br>                       ↑<br>                       |<br>                Outbox Publisher<br>                       ↑<br>                       |<br>                    Outbox<br>                       ↑<br>                       |<br>                  Order Service<br>                       |<br>                    Order DB</pre><p>Then:</p><pre>Kafka<br>  ↓<br>Payment Service<br>  ↓<br>Payment DB<br>  ↓<br>Outbox<br>  ↓<br>Kafka<br>  ↓<br>Inventory Service<br>  ↓<br>Inventory DB</pre><p>Each service follows the same basic principle:</p><pre>Local Transaction<br>       ↓<br>Business Data<br>       +<br>Outbox Event<br>       ↓<br>Kafka<br>       ↓<br>Next Service</pre><p>This is a common building block for event-driven Saga implementations.</p><h4>👆 Transactional Outbox vs Saga</h4><p>These concepts should not be confused.</p><h4>Saga answers:</h4><blockquote><em>How should a distributed business workflow be coordinated and compensated?</em></blockquote><h4>Outbox answers:</h4><blockquote><em>How can a service reliably publish an event after committing its local database transaction?</em></blockquote><p>So:</p><pre>Saga<br> ↓<br>Business workflow<br><br>Outbox<br> ↓<br>Reliable event publication<br><br>Kafka<br> ↓<br>Communication</pre><p>They complement each other.</p><p>The important question is not:</p><blockquote><em>“Can Saga be used here?”</em></blockquote><p>The better question is:</p><blockquote><em>“Does this workflow require coordinated consistency across independent transaction boundaries?”</em></blockquote><p>If the answer is yes, Saga becomes a candidate.</p><h4>❓ When Should Saga Be Used?</h4><p>A practical decision process:</p><p><strong>Question 1</strong></p><p>Can the complete business operation fit inside one ACID transaction?</p><p><strong>Yes:</strong></p><p>Use a normal database transaction.</p><p><strong>No:</strong></p><p>Continue evaluating.</p><p><strong>Question 2</strong></p><p>Does the workflow consist of multiple independent transactions?</p><p><strong>Yes:</strong></p><p>Saga may be appropriate.</p><p><strong>Question 3</strong></p><p>Can failed steps be compensated?</p><p><strong>Yes:</strong></p><p>Saga becomes more suitable.</p><p><strong>Question 4</strong></p><p>Is eventual consistency acceptable?</p><p><strong>Yes:</strong></p><p>Saga may be a good architectural choice.</p><h4>💭 A Simple Mental Model</h4><p>Remember this:</p><pre>One transaction<br>      ↓<br>ACID Transaction<br><br>Multiple independent transactions<br>      ↓<br>Saga<br><br>Saga communication<br>      ↓<br>Events / Commands / API calls<br><br>Reliable event publication<br>      ↓<br>Outbox<br><br>Event transport<br>      ↓<br>Kafka<br><br>Duplicate protection<br>      ↓<br>Idempotency<br><br>Failure recovery<br>      ↓<br>Retries + Compensation<br><br>Long-running workflow<br>      ↓<br>Persistent Saga State</pre><h4>💡 Final Takeaway</h4><p>The Saga Pattern is not simply:</p><blockquote><em>“A pattern for multiple databases.”</em></blockquote><p>The deeper concept is:</p><blockquote><strong><em>A Saga manages one business workflow that spans multiple independent transaction boundaries.</em></strong></blockquote><p>A single ACID transaction should be preferred whenever it can solve the problem.</p><p>When a single ACID transaction cannot cover the entire workflow, Saga provides a way to coordinate local transactions and recover from failures through compensation.</p><p>A production-grade Saga often requires more than the Saga pattern itself:</p><pre>Saga<br> +<br>Local Transactions<br> +<br>Compensation<br> +<br>Idempotency<br> +<br>Retries<br> +<br>Timeouts<br> +<br>Outbox<br> +<br>Message Broker<br> +<br>Persistent State<br> +<br>Observability</pre><p>The Saga Pattern solves an important distributed-systems problem, but it also introduces complexity.</p><p>The goal should not be to use Saga everywhere.</p><p>The goal should be to use Saga <strong>only when the business consistency requirements justify the complexity</strong>.</p><blockquote><strong><em>If one ACID transaction can solve the problem, use it.</em></strong></blockquote><blockquote><strong><em>If one ACID transaction cannot span the entire business workflow, consider the Saga Pattern.</em></strong></blockquote><p>Happy Learning! 🚀</p><p><em>Thanks for reading! stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0bc1bb4fe421" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Understanding Load Balancing: From Browser Request to Backend Server — A Complete Guide]]></title>
            <link>https://medium.com/@engineeringvault/understanding-load-balancing-from-browser-request-to-backend-server-a-complete-guide-caa3a1933737?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/caa3a1933737</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Sat, 11 Jul 2026 13:28:53 GMT</pubDate>
            <atom:updated>2026-07-11T13:28:53.897Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A3LUTu-SwGPuzY2B9u3mrg.png" /></figure><p>When I first started learning <strong>Load Balancing</strong>, I thought it was simple:</p><blockquote><em>“A load balancer distributes requests across multiple servers.”</em></blockquote><p>While that’s technically correct, it doesn’t explain <strong>how</strong> it actually works.</p><p>Questions like these kept coming to my mind:</p><ul><li>🤔 How does a request reach the load balancer?</li><li>🤔 How does it choose the correct backend server?</li><li>🤔 What happens when a server becomes unhealthy?</li><li>🤔 What is the difference between AWS ALB and NLB?</li><li>🤔 What are Layer 4 and Layer 7 load balancers?</li><li>🤔 How does the response come back to the client?</li></ul><p>After spending time understanding the internals, I realized that a load balancer is much more than a traffic distributor. It’s one of the most important building blocks of modern distributed systems.</p><p>Let’s dive in. 👇</p><h4>🌍 A Simple Architecture</h4><pre>Browser<br>    │<br>    ▼<br>DNS<br>    │<br>    ▼<br>Public IP<br>    │<br>    ▼<br>Load Balancer<br>    │<br> ┌──┴─────────────┐<br> ▼                ▼<br>Backend-1     Backend-2</pre><p>The browser never connects directly to your backend servers.</p><p>Instead:</p><ol><li>🌐 DNS resolves the domain name.</li><li>📡 The browser connects to the Load Balancer’s public IP.</li><li>⚖️ The Load Balancer chooses a healthy backend.</li><li>🖥️ The backend processes the request.</li><li>📤 The response travels back through the Load Balancer.</li></ol><h4>🎯 Why Do We Need a Load Balancer?</h4><p>Imagine thousands of users hitting a single server.</p><pre>Users<br>   │<br>   ▼<br>Server</pre><p>Eventually:</p><ul><li>🔥 CPU usage increases</li><li>💾 Memory gets exhausted</li><li>🐢 Response time becomes slower</li><li>💥 A single server failure brings down the application</li></ul><p>Instead, we deploy multiple backend servers.</p><pre>Users<br>   │<br>   ▼<br>Load Balancer<br>   │<br> ┌─┴─────────┐<br> ▼           ▼<br>Server A   Server B</pre><p>Now requests are distributed across multiple servers, improving:</p><ul><li>✅ Scalability</li><li>✅ High Availability</li><li>✅ Fault Tolerance</li><li>✅ Better Performance</li></ul><h4>⚖️ How Does the Load Balancer Choose a Server?</h4><p>A Load Balancer doesn’t randomly pick a server.</p><p>It uses algorithms such as:</p><p><strong>🔄 Round Robin</strong></p><p>Requests are distributed one after another.</p><pre>A → B → C → A → B → C</pre><p><strong>📉 Least Connections</strong></p><p>Traffic goes to the server with the fewest active connections.</p><p><strong>⚡ Weighted Round Robin</strong></p><p>Powerful servers receive more traffic.</p><p>Example:</p><pre>Server A (Weight 5)<br>Server B (Weight 2)</pre><p>Server A receives more requests.</p><p><strong>👤 IP Hash</strong></p><p>The same client consistently reaches the same backend.</p><p>Useful for session affinity.</p><h4>❤️ Health Checks</h4><p>What if one server crashes?</p><p>The Load Balancer periodically checks every backend.</p><p>Example:</p><pre>Every 30 seconds<br>GET /health</pre><p>Healthy response:</p><pre>200 OK</pre><p>If a server fails:</p><p>❌ Remove it from the rotation.</p><p>When it recovers:</p><p>✅ Add it back automatically.</p><h4>🍪 Sticky Sessions</h4><p>Suppose a user logs in.</p><p>The session is stored in:</p><pre>Server A</pre><p>The next request goes to:</p><pre>Server B</pre><p>Server B doesn’t know anything about the user’s session.</p><p>One solution is Sticky Sessions.</p><p>The Load Balancer remembers:</p><pre>User A<br>↓<br>Server A</pre><p>Every request goes to the same backend.</p><p>However, Sticky Sessions have drawbacks:</p><ul><li>❌ Uneven traffic distribution</li><li>❌ Poor scalability</li><li>❌ Problems if the server crashes</li></ul><p>Modern applications usually use:</p><ul><li>🗄️ Redis Session Store</li><li>🔐 JWT Tokens</li></ul><p>instead.</p><h4>🏗️ Layer 4 vs Layer 7 Load Balancers</h4><p>One of the most confusing concepts.</p><p><strong>🔹 Layer 4 (Transport Layer)</strong></p><p>Layer 4 understands:</p><ul><li>IP Address</li><li>Port</li><li>TCP</li><li>UDP</li></ul><p>It <strong>does not</strong> inspect HTTP requests.</p><p>Every HTTPS request simply looks like a TCP connection.</p><p><strong>🔹 Layer 7 (Application Layer)</strong></p><p>Layer 7 understands HTTP.</p><p>It can inspect:</p><ul><li>URL Path</li><li>Host Header</li><li>Cookies</li><li>Authorization Header</li><li>HTTP Method</li></ul><p>Example:</p><pre>/users<br>↓<br>User Service<br><br>/payments<br>↓<br>Payment Service</pre><p>Perfect for Microservices.</p><h4>🔄 Reverse Proxy vs Load Balancer</h4><p>Many developers use these terms interchangeably.</p><p>A Reverse Proxy:</p><ul><li>Receives requests</li><li>Hides backend servers</li><li>Forwards requests</li></ul><p>A Load Balancer:</p><ul><li>Decides <strong>which backend</strong> should receive the request.</li></ul><p>If there’s only one backend:</p><pre>Client<br>↓<br>Reverse Proxy<br>↓<br>Backend</pre><p>No Load Balancing happens.</p><p>If multiple backends exist:</p><pre>Client<br>↓<br>Reverse Proxy<br>↓<br>Server A<br>or<br>Server B<br>or<br>Server C</pre><p>Now it becomes a Load Balancer too.</p><p>That’s why Nginx, HAProxy and Envoy can act as both.</p><h4>⚙️ How Does a Load Balancer Work Internally?</h4><p>Internally, there are <strong>two TCP connections</strong>.</p><pre>Client<br>↓<br>TCP Connection #1<br>↓<br>Load Balancer<br>↓<br>TCP Connection #2<br>↓<br>Backend</pre><p>The Load Balancer sits in the middle.</p><p>It forwards bytes in both directions.</p><p>It also maintains a <strong>Connection Table</strong>.</p><pre>Client     Backend<br>-------------------<br>Client A   Server B<br>Client B   Server C</pre><p>Every response is mapped back to the correct client.</p><h4>🔥 NAT — The Magic Behind Load Balancing</h4><p>Suppose the client sends:</p><pre>Destination IP<br>↓<br>Load Balancer</pre><p>But the backend has another IP.</p><p>How does the packet reach it?</p><p>👉 NAT (Network Address Translation).</p><p><strong>DNAT (Destination NAT)</strong></p><p>Changes:</p><pre>Destination IP<br>↓<br>Backend Server</pre><p>Now the backend receives the packet.</p><p><strong>SNAT (Source NAT)</strong></p><p>Sometimes the Load Balancer also changes:</p><pre>Source IP<br>↓<br>Load Balancer IP</pre><p>Why?</p><p>Because responses should return through the Load Balancer.</p><p>Benefits:</p><ul><li>📊 Logging</li><li>🔒 Security</li><li>📈 Metrics</li><li>🔄 Connection Tracking</li></ul><h4>☁️ AWS ALB vs AWS NLB</h4><p>This is one of the most misunderstood topics.</p><p><strong>🟦 AWS ALB (Application Load Balancer)</strong></p><p>ALB works at <strong>Layer 7</strong>.</p><p>It understands HTTP.</p><p>Example:</p><pre>/users<br>↓<br>User Target Group<br><br>/payments<br>↓<br>Payment Target Group</pre><p>It can:</p><ul><li>✅ Path-based Routing</li><li>✅ Host-based Routing</li><li>✅ HTTP Headers</li><li>✅ Cookies</li><li>✅ Authentication</li><li>✅ TLS Termination</li></ul><p>Perfect for Web Applications and Microservices.</p><p><strong>🟩 AWS NLB (Network Load Balancer)</strong></p><p>NLB works at <strong>Layer 4</strong>.</p><p>It doesn’t understand HTTP.</p><p>Instead, it works like this:</p><pre>Incoming TCP Connection<br>↓<br>Find Listener<br>↓<br>Select Target Group<br>↓<br>Run Load Balancing Algorithm<br>↓<br>Choose Backend<br>↓<br>Forward TCP Connection</pre><p>One important lesson I learned:</p><p>Many people think:</p><pre>Port<br>↓<br>Backend</pre><p>❌ Wrong.</p><p>The correct flow is:</p><pre>Port<br>↓<br>Listener<br>↓<br>Target Group<br>↓<br>Load Balancing Algorithm<br>↓<br>Backend Server</pre><p>The <strong>Port does NOT choose the server.</strong></p><p>The <strong>Load Balancing Algorithm</strong> chooses the backend.</p><p>The port only identifies <strong>which Listener</strong> should process the incoming connection.</p><p>This was one of the biggest “Aha!” moments while learning NLB.</p><p>Imagine one NLB serving multiple applications.</p><pre>Client<br>      │<br>      ▼<br>NLB</pre><p>Listener:</p><pre>443<br><br>↓<br><br>Web Application</pre><p>If packet comes to 443, use Web Target Group.</p><p>Listener:</p><pre>3306<br><br>↓<br><br>MySQL</pre><p>If packet comes to 3306, use MySQL Target Group.</p><p>Listener:</p><pre>6379<br><br>↓<br><br>Redis</pre><p>If packet comes to 6379, use Redis Target Group.</p><p>Example:</p><pre>Listener 443 → Target Group A<br>    EC2-1<br>    EC2-2<br>    EC2-3<br><br>Listener 3306 → Target Group B<br>    DB-1<br>    DB-2</pre><h4>📌 Key Takeaways</h4><p>✅ Load Balancers improve Scalability and High Availability.</p><p>✅ Health Checks automatically remove unhealthy servers.</p><p>✅ Sticky Sessions solve session affinity but don’t scale well.</p><p>✅ Layer 4 Load Balancers understand TCP/UDP.</p><p>✅ Layer 7 Load Balancers understand HTTP.</p><p>✅ Reverse Proxies forward requests.</p><p>✅ Load Balancers decide where requests should go.</p><p>✅ NAT rewrites packet headers to route traffic correctly.</p><p>✅ AWS ALB is ideal for HTTP-based applications.</p><p>✅ AWS NLB is ideal for high-performance TCP/UDP workloads.</p><h4>🎉 Final Thoughts</h4><p>Learning Load Balancing isn’t just about AWS or Nginx.</p><p>It’s about understanding <strong>how every request travels through the network</strong>, how backend servers are selected, how failures are handled, and how modern distributed systems remain scalable and highly available.</p><p>Happy Learning! 🚀</p><p><em>Thanks for reading! stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caa3a1933737" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Beyond EC2 vs ECS: Understanding Deployment, Runtime, and Application Orchestration]]></title>
            <link>https://medium.com/@engineeringvault/beyond-ec2-vs-ecs-understanding-deployment-runtime-and-application-orchestration-9ca1b2b85219?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ca1b2b85219</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Sat, 11 Jul 2026 09:14:55 GMT</pubDate>
            <atom:updated>2026-07-11T09:14:55.961Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WsTHXF6lzYXgUGJErtQaAg.png" /></figure><p>When comparing <strong>Amazon EC2</strong> and <strong>Amazon ECS</strong>, the discussion often stops at:</p><ul><li>🖥️ <strong>EC2 → Virtual Machines</strong></li><li>📦 <strong>ECS → Containers</strong></li></ul><p>While technically correct, this comparison doesn’t explain the architectural difference that truly matters in production.</p><p>The real distinction is <strong>who is responsible for managing the application’s lifecycle.</strong></p><h4>⚙️ Understanding the Runtime</h4><p>Consider a Go application.</p><p>After building it, you get a binary:</p><pre>go build -o app</pre><p>When you execute:</p><pre>./app</pre><p>The operating system loads the executable into memory and starts a running process.</p><pre>EC2 Instance<br>     |<br>💾 Disk<br>└── app (binary)<br>     |<br>🧠 RAM<br>└── app (running process)</pre><p>A running process always executes from memory.</p><p>Even if you replace the binary on disk with a newer version, the running process continues executing the old code until it is restarted.</p><p>This behavior is part of how operating systems work and is not specific to AWS.</p><h4>🚀 Deployment on EC2</h4><p>A typical deployment pipeline for an application running on EC2 looks like this:</p><pre>👨‍💻 Developer<br>      │<br>      ▼<br>🔨 Build Binary<br>      │<br>      ▼<br>📤 Copy Binary to EC2<br>      │<br>      ▼<br>🔄 Restart Service<br>      │<br>      ▼<br>✅ Application Starts</pre><p>The restart is important because only a newly started process loads the updated binary.</p><p>Without a restart, the application continues running the previous version already loaded into memory.</p><h4>🖥️ What Does EC2 Actually Provide?</h4><p>EC2 provides <strong>compute infrastructure</strong>.</p><p>That’s it.</p><p>An EC2 instance does <strong>not</strong> know:</p><p>🔹 Which process is your application</p><p>🔹 How your application is started</p><p>🔹 Whether the application is healthy</p><p>🔹 When a deployment begins</p><p>🔹 When traffic should move to another instance</p><p>🔹 How to perform rolling updates</p><p>🔹 How to roll back after a failed deployment</p><p>From AWS’s perspective, an EC2 instance is simply a virtual machine.</p><p>Everything inside it is your responsibility.</p><h4>🌐 Achieving Zero-Downtime Deployments on EC2</h4><p>Running a single EC2 instance is simple, but restarting the application usually introduces downtime.</p><p>A production-grade deployment typically looks like this:</p><pre>                👥 Users<br>                    │<br>                    ▼<br>         ⚖️ Application Load Balancer<br>              │               │<br>              ▼               ▼<br>        🖥️ EC2-1         🖥️ EC2-2<br>           │                 │<br>        Application      Application</pre><p>A rolling deployment generally follows these steps:</p><ol><li>🚫 Remove one instance from the Load Balancer.</li><li>📤 Deploy the new binary.</li><li>🔄 Restart the application.</li><li>❤️ Wait for health checks to pass.</li><li>✅ Add the instance back to the Load Balancer.</li><li>🔁 Repeat for the remaining instances.</li></ol><p>This orchestration isn’t provided by EC2 itself — you build it using CI/CD pipelines and deployment tooling.</p><h4>📦 Deployment on ECS</h4><p>Deployment works differently in ECS.</p><p>Instead of deploying binaries, you deploy <strong>container images</strong>.</p><pre>👨‍💻 Developer<br>      │<br>      ▼<br>🐳 Build Docker Image<br>      │<br>      ▼<br>📤 Push Image<br>      │<br>      ▼<br>🚀 Update ECS Service</pre><p>ECS then performs the deployment.</p><p>A rolling deployment typically looks like this:</p><pre>Running<br>🟢 Version 1<br>🟢 Version 1<br>🟢 Version 1<br>        ↓<br>Start Version 2<br>🔵 Version 2<br>🟢 Version 1<br>🟢 Version 1<br>        ↓<br>❤️ Health Check<br>        ↓<br>Stop One Old Task<br>🔵 Version 2<br>🔵 Version 2<br>🟢 Version 1<br>        ↓<br>Repeat<br>🔵 Version 2<br>🔵 Version 2<br>🔵 Version 2<br></pre><p>Notice something important.</p><p>Deployment isn’t simply replacing code.</p><p>It’s <strong>gradually replacing running application instances while maintaining service availability.</strong></p><h4>🧠 Why ECS Feels More Intelligent</h4><p>The biggest advantage of ECS is <strong>not containers</strong>. It is <strong>application awareness</strong>.</p><p>ECS understands:</p><ul><li>✅ Which containers belong to a service</li><li>✅ Desired task count</li><li>✅ Container health</li><li>✅ Load Balancer registration</li><li>✅ Rolling deployments</li><li>✅ Automatic replacement of unhealthy tasks</li><li>✅ Service discovery</li><li>✅ Deployment progress</li></ul><p>Because ECS manages the application’s lifecycle, it can coordinate deployments safely.</p><h4>⚖️ EC2 vs ECS: The Operational Difference</h4><h4>🖥️ EC2</h4><p>You’re responsible for:</p><ul><li>⚙️ Infrastructure</li><li>🚀 Application deployment</li><li>🔄 Process management</li><li>❤️ Health checks</li><li>🔁 Rolling updates</li><li>⏪ Rollbacks</li><li>📈 Scaling strategy</li><li>🛠️ Deployment orchestration</li></ul><h4>📦 ECS</h4><p>You’re primarily responsible for:</p><ul><li>💻 Building the application</li><li>🐳 Creating the Docker image</li><li>📄 Defining the service</li></ul><p>ECS handles much of the operational workflow involved in running and updating the application.</p><h4>💡 Deployment Is More Than Copying Code</h4><p>One of the biggest misconceptions is that deployment simply means copying new code to a server.</p><p>In reality, deployment also includes:</p><ul><li>🚀 Starting the new version</li><li>❤️ Verifying health</li><li>🌐 Managing traffic</li><li>🔁 Replacing old instances gradually</li><li>🛡️ Recovering automatically if something goes wrong</li></ul><p>Modern platforms focus less on servers and more on <strong>safely managing application instances.</strong></p><h4>🎯 Final Thoughts</h4><p>The comparison between EC2 and ECS is often presented as:</p><ul><li>🖥️ <strong>EC2 = Virtual Machine</strong></li><li>📦 <strong>ECS = Containers</strong></li></ul><p>A more practical way to think about it is:</p><ul><li>🖥️ <strong>EC2 provides infrastructure. You are responsible for building the deployment and operational orchestration.</strong></li><li>📦 <strong>ECS provides infrastructure along with application orchestration, making deployments, scaling, and service management much more streamlined.</strong></li></ul><p>As applications grow, deployments become more frequent, and high availability becomes a requirement, understanding this distinction is far more valuable than simply knowing the difference between virtual machines and containers.</p><p><em>Thanks for reading! stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ca1b2b85219" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Partitioning Explained: A Complete Guide with Real-World Examples]]></title>
            <link>https://medium.com/@engineeringvault/data-partitioning-explained-a-complete-guide-with-real-world-examples-ca807448913c?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca807448913c</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[database-design]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Sun, 28 Jun 2026 11:13:18 GMT</pubDate>
            <atom:updated>2026-06-28T11:13:18.133Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMdNHcP4WerU_MvHN35IgQ.png" /></figure><p>If you’ve worked with databases like MySQL, PostgreSQL, ClickHouse, Oracle, or SQL Server, you’ve probably heard the term <strong>partitioning</strong>.</p><p>When I first learned about it, I had several questions:</p><ul><li>What exactly is partitioning?</li><li>Why do we need it?</li><li>How does the database decide which partition to use?</li><li>Do I need to manually move data into partitions?</li><li>What happens if I delete a partition?</li><li>How does partition pruning work internally?</li></ul><p>In this article, we’ll answer all of these questions with practical examples.</p><h4>❓ What is Data Partitioning?</h4><p>Data partitioning is the process of dividing a large database table into multiple smaller pieces called <strong>partitions</strong>.</p><p>Think of a library.</p><p>Without organization:</p><pre>Library<br>│<br>└── 10 million books in one huge room</pre><p>Finding a book takes time.</p><p>Now imagine the books are organized by category.</p><pre>Library<br>│<br>├── Science<br>├── Technology<br>├── History<br>├── Fiction</pre><p>Finding a book becomes much easier.</p><p>Database partitioning works exactly the same way.</p><p>Instead of storing billions of rows in one massive storage area, the database stores them in multiple logical sections.</p><h4>❓ Why Do We Need Partitioning?</h4><p>Imagine a call history table.</p><pre>call_logs</pre><pre>1 Billion Records</pre><p>Now execute:</p><pre>SELECT *<br>FROM call_logs<br>WHERE created_at=&#39;2026-06-28&#39;;</pre><p>Without partitioning, the database may need to scan a massive amount of data.</p><p>With monthly partitioning:</p><pre>202601<br>202602<br>202603<br>...<br>202606<br>...<br>202612</pre><p>The database immediately knows:</p><blockquote>June 28 belongs to the <strong>202606</strong> partition.</blockquote><p>Only that partition is searched.</p><p>This significantly reduces disk I/O and query execution time.</p><h4>❓ How Does Partitioning Work?</h4><p>Suppose we create a table.</p><pre>CREATE TABLE call_logs (<br>    id BIGINT,<br>    caller VARCHAR(20),<br>    created_at DATETIME<br>);</pre><p>Normally every record is stored together.</p><pre>call_logs<br>------------------------------------<br>Row<br>Row<br>Row<br>Row<br>Row<br>...<br>------------------------------------</pre><p>After partitioning:</p><pre>call_logs<br>├── Partition_202601<br>├── Partition_202602<br>├── Partition_202603<br>├── Partition_202604<br>├── Partition_202605<br>└── Partition_202606</pre><p>Your application still sees <strong>one table</strong>, but internally the database stores the data separately.</p><h4>❓ How Does the Database Know Where to Store Data?</h4><p>Suppose the table is partitioned by:</p><pre>PARTITION BY toYYYYMM(created_at)</pre><p>Now insert:</p><pre>INSERT INTO call_logs<br>VALUES<br>(<br>    1,<br>    &#39;9876543210&#39;,<br>    &#39;2026-06-28&#39;<br>);</pre><p>Internally:</p><pre>created_at<br><br>↓<br><br>2026-06-28<br><br>↓<br><br>toYYYYMM(created_at)<br><br>↓<br><br>202606</pre><p>The database automatically stores the row inside the <strong>202606</strong> partition.</p><p>You never manually choose the partition.</p><p>The database always decides based on the partition expression.</p><h4>🔢 The Four Types of Partitioning</h4><h4>1. Range Partitioning</h4><p>Range partitioning divides data into ranges.</p><p>Example:</p><pre>PARTITION BY RANGE(age)</pre><p>Rules:</p><pre>0-20<br>21-40<br>41-60<br>61+</pre><p>SQL:</p><pre>CREATE TABLE customers<br>(<br>    id INT,<br>    age INT<br>)<br>PARTITION BY RANGE(age)<br>(<br>    PARTITION p0 VALUES LESS THAN (21),<br>    PARTITION p1 VALUES LESS THAN (41),<br>    PARTITION p2 VALUES LESS THAN (61),<br>    PARTITION p3 VALUES LESS THAN MAXVALUE<br>);</pre><p>If:</p><pre>age = 35</pre><p>The row automatically goes into:</p><pre>Partition p1</pre><h4>2. List Partitioning</h4><p>Used when data belongs to predefined categories.</p><p>Example:</p><pre>PARTITION BY LIST(country)</pre><p>Rules:</p><pre>India<br>USA<br>Japan</pre><p>SQL:</p><pre>CREATE TABLE customers<br>(<br>    id INT,<br>    country VARCHAR(30)<br>)<br>PARTITION BY LIST COLUMNS(country)<br>(<br>    PARTITION india VALUES IN (&#39;India&#39;),<br>    PARTITION usa VALUES IN (&#39;USA&#39;),<br>    PARTITION japan VALUES IN (&#39;Japan&#39;)<br>);</pre><p>If:</p><pre>country = India</pre><p>The row goes into:</p><pre>India Partition</pre><h4>3. Hash Partitioning</h4><p>Here, the database distributes rows evenly.</p><p>You simply specify:</p><pre>PARTITION BY HASH(id)<br>PARTITIONS 4;</pre><p>Suppose:</p><pre>id = 1001</pre><p>Database calculates:</p><pre>1001 % 4 = 1</pre><p>The row goes into:</p><pre>Partition 1</pre><p>This provides even distribution.</p><h4>4. Key Partitioning</h4><p>Key partitioning is similar to hash partitioning.</p><pre>PARTITION BY KEY(id)<br>PARTITIONS 4;</pre><p>Instead of using a visible modulo operation, the database uses its own optimized hashing algorithm.</p><h4>💭 Do We Need to Create Partitions While Creating the Table?</h4><p>The answer is:</p><p><strong>Ideally, yes.</strong></p><p>If you expect the table to grow into millions or billions of rows, designing partitions from the beginning is recommended.</p><p>For example:</p><pre>CREATE TABLE call_logs<br>(<br>    id BIGINT,<br>    created_at DATETIME<br>)<br>PARTITION BY RANGE(YEAR(created_at))<br>(<br>    PARTITION p2025 VALUES LESS THAN (2026),<br>    PARTITION p2026 VALUES LESS THAN (2027),<br>    PARTITION pmax VALUES LESS THAN MAXVALUE<br>);</pre><p>The database will automatically route every inserted row into the correct partition.</p><h3>💭 Can We Add Partitioning Later?</h3><p>Yes.</p><p>But adding partitioning to an existing table with hundreds of millions of rows is expensive.</p><p>Usually the database must:</p><ul><li>Create a new partitioned table.</li><li>Copy all existing data.</li><li>Rebuild indexes.</li><li>Replace the original table.</li></ul><p>Planning partitioning early saves a lot of effort.</p><h4>✴️ How Does SELECT Work?</h4><p>Suppose you execute:</p><pre>SELECT *<br>FROM call_logs<br>WHERE created_at=&#39;2026-06-28&#39;;</pre><p>The optimizer calculates:</p><pre>created_at<br>↓<br>202606</pre><p>Instead of reading every partition:</p><pre>202601 ❌<br>202602 ❌<br>202603 ❌<br>202604 ❌<br>202605 ❌<br>202606 ✅</pre><p>Only the required partition is opened.</p><p>This optimization is called <strong>Partition Pruning</strong>.</p><p>It is one of the biggest reasons partitioning improves performance.</p><h4>🌓 What Happens During INSERT?</h4><pre>Application<br>↓<br>Database<br>↓<br>Evaluate Partition Function<br>↓<br>Choose Partition<br>↓<br>Store Row</pre><p>Every insert automatically follows this process. No manual intervention is required.</p><h4>🔯 What Happens if We Drop a Partition?</h4><p>Suppose the table contains:</p><pre>202601<br>202602<br>202603<br>202604<br>202605<br>202606</pre><p>If you execute:</p><pre>ALTER TABLE call_logs DROP PARTITION p202601;</pre><p>The January partition disappears.</p><p>All January records are removed.</p><p>Unlike DELETE, the database does <strong>not</strong> delete rows individually.</p><p>It simply removes the partition’s storage.</p><p>This makes partition deletion extremely fast.</p><h4>🎓 Difference Between DELETE and DROP PARTITION</h4><p>Deleting rows:</p><pre>DELETE<br>FROM call_logs<br>WHERE created_at &lt; &#39;2026-01-01&#39;;</pre><p>The database must locate every row, delete it, update indexes, generate logs, and maintain transactional consistency.</p><p>Dropping a partition:</p><pre>ALTER TABLE call_logs DROP PARTITION p202601;</pre><p>The database simply removes the partition.</p><p>This operation is significantly faster.</p><h4>🔅 Advantages of Partitioning</h4><p>✅<strong> Faster Queries —</strong> Only relevant partitions are scanned.</p><p>✅<strong> Faster Deletion — </strong>Old data can be removed by dropping partitions.</p><p>✅ <strong>Easier Archiving — </strong>Entire partitions can be archived.</p><p>✅ <strong>Easier Maintenance — </strong>Individual partitions can be repaired or rebuilt.</p><p>✅ <strong>Better Backup — </strong>Recent partitions can be backed up independently.</p><p>✅ <strong>Better Scalability — </strong>Works extremely well for billions of rows.</p><h4>🌕 Ideal for Time-Series Data</h4><p>Examples include:</p><ul><li>Call Detail Records</li><li>Server Logs</li><li>IoT Data</li><li>Financial Transactions</li><li>Monitoring Metrics</li><li>Analytics</li></ul><h4>🔅 Disadvantages of Partitioning</h4><p>✅ <strong>Poor Partition Key — </strong>Choosing the wrong partition column can reduce performance.</p><p>✅ <strong>Increased Complexity — </strong>Partition design requires planning.</p><p>✅ <strong>Too Many Partitions — </strong>Large numbers of partitions increase metadata overhead.</p><p>✅ <strong>Full Table Queries </strong>— Queries without filters still scan every partition.</p><p>✅ <strong>Difficult to Change Later — </strong>Changing partition strategy often requires rebuilding the table.</p><h4>🔆 Doesn’t Replace Indexes</h4><p>Partitioning narrows down which partition to search.</p><p>Indexes locate rows inside that partition.</p><p>Both are still important.</p><h4>🧠Partitioning vs Sharding</h4><p>Partitioning divides one table into multiple logical pieces inside a database.</p><pre>One Database<br>├── Partition 1<br>├── Partition 2<br>├── Partition 3</pre><p>Sharding distributes data across multiple database servers.</p><pre>Server A<br>Server B<br>Server C</pre><p>Partitioning improves organization within a database.</p><p>Sharding improves horizontal scalability across databases.</p><h4>💡 Key Takeaways</h4><ul><li>Partitioning divides large tables into smaller logical sections.</li><li>Applications still interact with a single table.</li><li>The database automatically determines where each row belongs.</li><li>Partition pruning allows the optimizer to skip unnecessary partitions.</li><li>Partitioning greatly improves performance for large, filtered queries.</li><li>Dropping a partition removes all data within that partition.</li><li>Partitioning is most effective for time-series and large-scale analytical workloads.</li><li>It complements indexes — it does not replace them.</li></ul><h4>🚀Final Thoughts</h4><p>Partitioning is one of the most valuable techniques for designing scalable database systems. When used correctly, it can dramatically improve query performance, simplify maintenance, speed up data retention operations, and make large datasets easier to manage.</p><p>However, successful partitioning starts with good planning. Choosing the right partition key based on your application’s query patterns is far more important than simply enabling partitioning.</p><p>For systems handling millions or billions of records — such as telephony platforms, financial systems, IoT platforms, and analytics engines — partitioning is often a fundamental building block of an efficient database design.</p><p><em>Thanks for reading! stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca807448913c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Go Structs Deep Dive: Memory, Interfaces, Performance & the Power of struct{}]]></title>
            <link>https://medium.com/@engineeringvault/go-structs-deep-dive-memory-interfaces-performance-the-power-of-struct-9cdfc3ed3dec?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cdfc3ed3dec</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Wed, 22 Apr 2026 14:05:50 GMT</pubDate>
            <atom:updated>2026-04-22T14:05:50.808Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XBuRAdW6LmFW-7vSATVD5Q.png" /></figure><p>Go structs look simple — but under the hood, they play a huge role in performance, memory efficiency, and system design.</p><p>If you’re building high-throughput systems (APIs, streaming pipelines, real-time services), understanding structs deeply can make a real difference.</p><p>Let’s go beyond basics.</p><h3>🔹 1. Structs + Interfaces: How They Really Work</h3><p>In Go, structs implement interfaces implicitly.</p><pre>type Speaker interface {<br>    Speak() string<br>}<br><br>type User struct {<br>    Name string<br>}<br><br>func (u User) Speak() string {<br>    return &quot;Hi, I&#39;m &quot; + u.Name<br>}</pre><p>Usage:</p><pre>var s Speaker = User{Name: &quot;Ken&quot;}<br>fmt.Println(s.Speak())</pre><p>No implements keyword needed.</p><h4>🧠 What’s happening internally?</h4><p>An interface is not just a type — it’s a pair:</p><pre>(interface) = (type, value)</pre><p>So:</p><pre>var s Speaker = User{Name: &quot;isu&quot;}</pre><p>Becomes:</p><pre>type  = User<br>value = {Name: &quot;isu&quot;}</pre><p>If you want to deep dive to into go interfaces click here 👉 <a href="https://medium.com/@engineeringvault/go-interfaces-demystified-implicit-implementation-nil-trap-real-internals-73cf386b92a9">link</a></p><h3>🔹 2. Escape Analysis: Stack vs Heap</h3><p>Go decides whether variables go on:</p><ul><li>Stack (fast)</li><li>Heap (slower, GC involved)</li></ul><p><strong>Example (Escapes to heap)</strong></p><pre>func createUser() *User {<br>    u := User{Name: &quot;isu&quot;}<br>    return &amp;u<br>}</pre><p>👉 u escapes because it’s returned</p><p><strong>Example (Stays on stack)</strong></p><pre>func process() {<br>    u := User{Name: &quot;isu&quot;}<br>    fmt.Println(u.Name)<br>}</pre><p>🔍 Check using:</p><pre>go build -gcflags=&quot;-m&quot;</pre><p><strong>⚡ Why this matters</strong></p><p>In high-performance systems:</p><ul><li>Heap allocations → GC pressure</li><li>GC pauses → latency spikes</li></ul><p>👉 Fewer allocations = better performance</p><h3>🔹 3. Structs in High-Performance Systems</h3><p>Struct design directly impacts:</p><ul><li>Memory usage</li><li>CPU cache efficiency</li><li>GC overhead</li></ul><p>❌ Bad Design</p><pre>type Event struct {<br>    Data map[string]interface{}<br>}</pre><p>Problems:</p><ul><li>Allocations</li><li>Reflection (if JSON)</li><li>GC overhead</li></ul><p>✅ Better Design</p><pre>type Event struct {<br>    UserID int64<br>    Time   int64<br>    Type   uint8<br>}</pre><p>👉 Fixed-size, predictable, fast</p><h4><strong>🔥 Field Alignment Matters</strong></h4><pre>type A struct {<br>    X int8<br>    Y int64<br>}</pre><p>You might expect size = 9 bytes, but it’s actually <strong>16 bytes</strong>.</p><p>👉 Why?</p><p>Because of alignment + padding</p><blockquote>| A (1 byte) | padding (7 bytes) | B (8 bytes) |</blockquote><p><strong>💡 Rule:</strong></p><ul><li>Go aligns fields based on the largest field alignment requirement</li><li>This improves CPU performance</li></ul><p>Better:</p><pre>type A struct {<br>    Y int64<br>    X int8<br>}</pre><p>Now:</p><blockquote>| B (8 bytes) | A (1 byte) | padding (7 bytes) |</blockquote><p>👉 Still 16 bytes? Yes. But in bigger structs, ordering matters a lot.</p><h4><strong>⚡ Avoid Large Copies</strong></h4><pre>func process(e Event) // copies entire struct</pre><p>Use pointer:</p><pre>func process(e *Event)</pre><h4>🚀 Real-world Pattern</h4><p>Use object pooling:</p><pre>var pool = sync.Pool{<br>    New: func() interface{} {<br>        return &amp;Event{}<br>    },<br>}</pre><h3>🔹 4. JSON Marshalling Internals</h3><p>When you do:</p><pre>json.Marshal(user)</pre><p>Go:</p><ol><li>Uses reflection</li><li>Reads struct fields</li><li>Applies tags</li><li>Allocates memory</li></ol><p>Example:</p><pre>type User struct {<br>    Name string `json:&quot;name&quot;`<br>}</pre><h4>⚠️ Why it’s expensive</h4><ul><li>Reflection</li><li>Allocations</li><li>String processing</li></ul><h4>❌ Slow Pattern</h4><pre>type Event struct {<br>    Data map[string]interface{}<br>}</pre><h4>✅ Optimized</h4><pre>type Event struct {<br>    UserID int64  `json:&quot;user_id&quot;`<br>    Action string `json:&quot;action&quot;`<br>}</pre><h3>🔹 5. The Hidden Gem: struct{} (Empty Struct)</h3><p>This is one of the most underrated features in Go.</p><pre>struct{}</pre><p>👉 Takes <strong>0 bytes</strong></p><pre>fmt.Println(unsafe.Sizeof(struct{}{})) // 0</pre><h4>🧠 Key Idea</h4><p>Use struct{} when:</p><blockquote><strong><em>You only care about existence, not value</em></strong></blockquote><h4>🔥 Use Case 1: Set Implementation</h4><p>Go doesn’t have a built-in set.</p><p><strong>❌ Using bool (wasteful)</strong></p><pre>set := make(map[string]bool)<br>set[&quot;apple&quot;] = true</pre><p><strong>✅ Using empty struct</strong></p><pre>set := make(map[string]struct{})<br>set[&quot;apple&quot;] = struct{}{}</pre><p><strong>🔍 Why better?</strong></p><pre>| Type       | Memory per value |<br>| ---------- | ---------------- |<br>| `bool`     | 1 byte           |<br>| `struct{}` | **0 bytes**      |</pre><p>👉 Huge savings for large datasets</p><h4>🔥 Use Case 2: Channel Signaling</h4><pre>done := make(chan struct{})<br><br>go func() {<br>    // work<br>    done &lt;- struct{}{}<br>}()<br><br>&lt;-done</pre><p><strong>Why not </strong><strong>chan bool?</strong></p><ul><li>No meaning of true/false needed</li><li>Slightly more memory</li><li>struct{} clearly expresses: <strong>signal only</strong></li></ul><h4>🔥 Use Case 3: Goroutine Coordination</h4><pre>done := make(chan struct{})<br><br>for i := 0; i &lt; 3; i++ {<br>    go func() {<br>        done &lt;- struct{}{}<br>    }()<br>}<br><br>for i := 0; i &lt; 3; i++ {<br>    &lt;-done<br>}</pre><p>👉 Counting completion without data</p><h4>🔥 Use Case 4: Visited / Dedup Tracking</h4><pre>visited := make(map[int]struct{})<br><br>visited[10] = struct{}{}<br><br>if _, ok := visited[10]; ok {<br>    fmt.Println(&quot;Visited&quot;)<br>}</pre><h4>🧠 Mental Model</h4><p>Think of struct{} as:</p><p>✔ A marker<br>✔ A tick (✓)<br>✔ A presence indicator</p><h4>⚠️ Subtle Behavior</h4><pre>a := struct{}{}<br>b := struct{}{}</pre><p>Even though size is 0:</p><pre>&amp;a == &amp;b // can be true (compiler optimization)</pre><h3>🚀 Final Takeaways</h3><ul><li>Structs are about <strong>memory layout + behavior</strong></li><li>Interfaces = <strong>(type, value)</strong></li><li>Escape analysis = key to performance</li><li>JSON = reflection-heavy → optimize when needed</li><li>struct{} = <strong>zero-cost abstraction for presence</strong></li></ul><h3>💡 One-line Rule</h3><blockquote><em>Use </em><em>struct{} when the value doesn’t matter—only existence does.</em></blockquote><p>If you’re building high-performance Go systems, mastering these concepts will give you a serious edge.</p><p><em>Happy coding !! 🚀</em></p><p><em>Thanks for reading! stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cdfc3ed3dec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go Interfaces Demystified: Implicit Implementation, Nil Trap & Real Internals]]></title>
            <link>https://medium.com/@engineeringvault/go-interfaces-demystified-implicit-implementation-nil-trap-real-internals-73cf386b92a9?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/73cf386b92a9</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Fri, 17 Apr 2026 15:28:20 GMT</pubDate>
            <atom:updated>2026-04-17T15:28:20.703Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-L9RiCsU2SG3iSzZjRCj6Q.png" /></figure><p>If you’re coming from Java or OOP-heavy languages, Go’s interfaces can feel… strange.</p><blockquote>No implements keyword.<br>No explicit declaration.<br>And yet—things just <em>work</em>.</blockquote><p>In this post, we’ll go beyond basics and deeply understand:</p><ul><li>What interfaces really are</li><li>What “implicit implementation” means</li><li>The infamous <strong>nil interface trap</strong></li><li>How interfaces work internally in Go runtime</li><li>Types of interfaces in Go</li></ul><h3>🧱 1. Structs: The Foundation</h3><p>In Go, a struct is simply a <strong>data container</strong>:</p><pre>type Dog struct{}</pre><p>We can add behavior using methods:</p><pre>func (d Dog) Speak() string {<br>    return &quot;Woof&quot;<br>}</pre><p>At this point:</p><ul><li>Dog is just a concrete type</li><li>It has one method: Speak()</li></ul><h3>📜 2. What is an Interface?</h3><p>An interface defines <strong>behavior</strong>, not data:</p><pre>type Speaker interface {<br>    Speak() string<br>}</pre><p>👉 Meaning:</p><blockquote><em>Any type that has a </em><em>Speak() string method can be treated as a </em><em>Speaker.</em></blockquote><h3>🔥 3. Implicit Implementation (Core Concept)</h3><p>Here’s the key difference from languages like Java:</p><p>We NEVER write:</p><pre>type Dog struct{} implements Speaker // ❌ not valid in Go</pre><p>Yet this works:</p><pre>var s Speaker = Dog{}<br>fmt.Println(s.Speak()) // Woof</pre><h4>🧠 What does “implicit implementation” mean?</h4><p>Go automatically checks:</p><ul><li>Does Dog have Speak() string?</li><li>YES ✅</li></ul><p>So Go says:</p><blockquote><em>“Dog satisfies the Speaker interface.”</em></blockquote><p>No keyword. No declaration. Just method matching.</p><h4>🧩 Mental Model</h4><blockquote><em>If it behaves like a </em><em>Speaker, Go treats it as a </em><em>Speaker.</em></blockquote><h3>🧪 4. Multiple Types, Same Interface</h3><pre>type Cat struct{}<br>func (c Cat) Speak() string {<br>    return &quot;Meow&quot;<br>}</pre><p>Now:</p><pre>var s1 Speaker = Dog{}<br>var s2 Speaker = Cat{}<br><br>fmt.Println(s1.Speak()) // Woof<br>fmt.Println(s2.Speak()) // Meow</pre><p>👉 This is polymorphism in Go.</p><h3>⚠️ 5. The Nil Interface Trap (Very Important)</h3><p>This is where many developers get confused.</p><pre>var d *Dog = nil<br>var s Speaker = d<br><br>fmt.Println(d == nil) // true<br>fmt.Println(s == nil) // false ❌</pre><h4>🧠 Why is s != nil?</h4><p>Because internally, an interface is:</p><pre>(type, value)</pre><p>So in this case:</p><pre>s = (type: *Dog, value: nil)</pre><p>👉 Since <strong>type exists</strong>, the interface is NOT nil.</p><h4>📦 Visualization</h4><p><strong>Case 1: True nil interface</strong></p><pre>(type: nil, value: nil) → interface == nil ✅</pre><p><strong>Case 2: Nil pointer inside interface</strong></p><pre>(type: *Dog, value: nil) → interface != nil ❌</pre><h4>💥 Real Bug Example</h4><pre>func PrintSpeaker(s Speaker) {<br>    if s == nil {<br>        fmt.Println(&quot;nil interface&quot;)<br>        return<br>    }<br>    s.Speak() // 💥 panic possible<br>}</pre><p>Calling:</p><pre>var d *Dog = nil<br>PrintSpeaker(d)</pre><p>👉 s != nil but still crashes due to nil pointer dereference.</p><h3>⚙️ 6. How Interfaces Work Internally</h3><p>Internally, Go represents interfaces roughly like this:</p><pre>type iface struct {<br>    tab  *itab<br>    data unsafe.Pointer<br>}</pre><h4>🔍 What is inside?</h4><p><strong>1. </strong><strong>tab (interface table)</strong></p><ul><li>Links interface type + concrete type</li><li>Stores method mappings</li></ul><p><strong>2. </strong><strong>data</strong></p><ul><li>Pointer to actual value</li></ul><p><strong>🧠 Example</strong></p><pre>var s Speaker = Dog{}</pre><p>Internally:</p><pre>type = Dog<br>value = Dog{}</pre><h4>🔄 Method Call Flow</h4><p>When you call:</p><pre>s.Speak()</pre><p>Go does:</p><ol><li>Look at itab</li><li>Find method Speak</li><li>Call Dog.Speak</li></ol><p>👉 This is dynamic dispatch.</p><h3>🧩 7. Pointer vs Value Receiver Gotcha</h3><pre>type Dog struct{}<br><br>func (d *Dog) Speak() string {<br>    return &quot;Woof&quot;<br>}</pre><p>Now:</p><pre>var s Speaker = Dog{}   // ❌ ERROR<br>var s Speaker = &amp;Dog{}  // ✅ OK</pre><p>👉 Only *Dog implements Speaker here.</p><h3>🧱 8. Types of Interfaces in Go</h3><h4>1. Empty Interface</h4><pre>var i interface{}</pre><ul><li>Can hold <strong>any type</strong></li><li>Used in:</li><li>fmt.Println</li><li>JSON parsing</li><li>generic containers</li></ul><p>⚠️ Downside: loses type safety</p><h4>2. Single-Method Interface</h4><pre>type Reader interface {<br>    Read([]byte) (int, error)<br>}</pre><ul><li>Very common in Go</li><li>Encourages small, focused design</li></ul><h4>3. Multi-Method Interface</h4><pre>type File interface {<br>    Read([]byte) (int, error)<br>    Write([]byte) (int, error)<br>}</pre><ul><li>Groups related behaviors</li></ul><h4>4. Embedded Interface (Interface Composition)</h4><pre>type Reader interface {<br>    Read([]byte) (int, error)<br>}<br><br>type Writer interface {<br>    Write([]byte) (int, error)<br>}<br><br>type ReadWriter interface {<br>    Reader<br>    Writer<br>}</pre><p>👉 Combines multiple interfaces</p><h4>5. Marker Interface (Empty Behavior)</h4><pre>type Serializable interface{}</pre><ul><li>Used for tagging</li><li>Rarely used explicitly in Go</li></ul><h4>6. Function-Based Interface (Implicit via funcs)</h4><pre>type Handler interface {<br>    Handle()<br>}</pre><p>You can adapt functions to satisfy interfaces using wrappers.</p><h3>🧠 9. Best Practices</h3><p>✔ Keep interfaces small<br>✔ Define interfaces where they are used<br>✔ Prefer:</p><blockquote><em>accept interfaces, return structs</em></blockquote><p>✔ Avoid:</p><ul><li>large “god interfaces”</li><li>unnecessary abstraction</li></ul><h3>🎯 10. Final Thoughts</h3><p>Go interfaces are powerful because they are:</p><ul><li><strong>Implicit</strong></li><li><strong>Decoupled</strong></li><li><strong>Lightweight</strong></li><li><strong>Runtime-efficient</strong></li></ul><p>But they come with subtle pitfalls like:</p><ul><li>nil interface confusion</li><li>pointer vs value receiver issues</li></ul><p><em>Thanks for reading! stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73cf386b92a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering defer, panic, and recover in Go (With Real-World Examples)]]></title>
            <link>https://medium.com/@engineeringvault/mastering-defer-panic-and-recover-in-go-with-real-world-examples-82a6c9c64307?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/82a6c9c64307</guid>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Wed, 08 Apr 2026 00:44:02 GMT</pubDate>
            <atom:updated>2026-04-08T00:44:02.416Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZG6va__Rvm92U-m5nXnCkQ.png" /></figure><p>Error handling and resource management are critical in any backend system. In Go, three powerful constructs — defer, panic, and recover—help you write clean, safe, and production-ready code.</p><p>In this post, we’ll break them down with <strong>clear explanations, real-world use cases, and tricky edge cases</strong> often asked in interviews.</p><h3>🔹 What is defer?</h3><p>defer is used to <strong>delay the execution</strong> of a function until the surrounding function returns.</p><p>✅ Basic Example</p><pre>func main() {<br>    fmt.Println(&quot;Start&quot;)<br>    defer fmt.Println(&quot;Deferred&quot;)<br>    fmt.Println(&quot;End&quot;)<br>}</pre><p>Output:</p><pre>Start<br>End<br>Deferred</pre><p>👉 Deferred statements always run after the function completes.</p><h4>🔁 LIFO Execution (Stack Behavior)</h4><pre>defer fmt.Println(&quot;1&quot;)<br>defer fmt.Println(&quot;2&quot;)<br>defer fmt.Println(&quot;3&quot;)</pre><p>Output:</p><pre>3<br>2<br>1</pre><p>👉 Defer follows <strong>Last-In, First-Out (LIFO)</strong></p><h4>⚠️ Important: 1. Arguments are evaluated immediately</h4><pre>func main(){<br>  x := 10<br>  defer fmt.Println(x)<br>  x = 20<br>}</pre><p>Output:</p><pre>10</pre><p>👉 The value is captured at the time of defer, not execution.</p><h4><strong>2. With functions (closure behavior)</strong></h4><pre>func main(){<br>  x :=10<br>  <br>  defer func() {<br>    fmt.Println(x)<br>  }()<br><br>  x = 20<br>}</pre><p>Output:</p><pre>20</pre><p>👉 Because closure captures variable, not value.</p><h4>🔥 Real-World Use Case</h4><pre>file, err := os.Open(&quot;file.txt&quot;)<br>if err != nil {<br>    return err<br>}<br>defer file.Close()</pre><p>👉 Ensures resources are always released.</p><h4>🧠 Tricky: Modifying Return Values</h4><pre>func test() (result int) {<br>    defer func() {<br>        result++<br>    }()<br>    return 5<br>}</pre><p>Output:</p><pre>6</pre><p>👉 defer can modify named return values.</p><h3>💥 What is panic?</h3><p>panic is used when something goes seriously wrong.</p><ul><li>Stops normal execution</li><li>Runs deferred functions</li><li>Crashes the program (if not handled)</li></ul><p>Example</p><pre>func main() {<br>    panic(&quot;Something went wrong!&quot;)<br>}</pre><p>Output:</p><pre>panic: Something went wrong!</pre><h4>🔁 Panic + Defer</h4><pre>defer fmt.Println(&quot;Cleanup&quot;)<br>panic(&quot;Crash&quot;)</pre><p>Output:</p><pre>Cleanup<br>panic: Crash</pre><p>👉 Even during panic, defer still executes.</p><h4>⚠️ Multiple Panics (Tricky)</h4><pre>defer func() {<br>    panic(&quot;panic in defer&quot;)<br>}()<br>panic(&quot;original panic&quot;)</pre><p>Output:</p><pre>panic: panic in defer</pre><p>👉 Last panic wins — original panic is lost.</p><h3>🛟 What is recover?</h3><p>recover is used to catch a panic and prevent the program from crashing.</p><p>⚠️ It only works inside a deferred function.</p><p>Example</p><pre>defer func() {<br>    if r := recover(); r != nil {<br>        fmt.Println(&quot;Recovered:&quot;, r)<br>    }<br>}()<br>panic(&quot;error occurred&quot;)</pre><p>Output:</p><pre>Recovered: error occurred</pre><p>👉 Program continues normally.</p><p><strong>❌ Wrong Usage</strong></p><pre>defer wrapper()<br>func wrapper() {<br>    recover() // ❌ won&#39;t work<br>}</pre><p>👉 recover() must be called directly inside defer</p><p><strong>✅ Correct Usage</strong></p><pre>defer func() {<br>    wrapper()<br>}()<br><br>func wrapper() {<br>    fmt.Println(recover()) // ✅ works<br>}</pre><h4>⚠️ Goroutine Panic (Important)</h4><pre>go func() {<br>    panic(&quot;error&quot;)<br>}()</pre><p>👉 This will crash your entire application ❌</p><p>✅ Safe Goroutine</p><pre>go func() {<br>    defer func() {<br>        if r := recover(); r != nil {<br>            fmt.Println(&quot;Recovered:&quot;, r)<br>        }<br>    }()<br>    <br>    panic(&quot;error&quot;)<br>}()</pre><p>👉 Always handle panic inside goroutines.</p><h3>🚀 Real-World Backend Pattern</h3><p><strong>HTTP Middleware Example</strong></p><pre>func recoveryMiddleware(next http.Handler) http.Handler {<br>    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {<br>        defer func() {<br>            if err := recover(); err != nil {<br>                log.Println(&quot;Recovered:&quot;, err)<br>                http.Error(w, &quot;Internal Server Error&quot;, 500)<br>            }<br>        }()<br>        next.ServeHTTP(w, r)<br>    })<br>}</pre><p>👉 Prevents a single bad request from crashing your server.</p><h3>🔥 Tricky Interview Questions</h3><h4>❓ Will defer run with os.Exit?</h4><pre>defer fmt.Println(&quot;Hello&quot;)<br>os.Exit(0)</pre><p>👉 Output:</p><pre>(no output)</pre><p>❗ defer does NOT run with os.Exit</p><h4>❓ Recover without panic?</h4><pre>defer func() {<br>    fmt.Println(recover())<br>}()</pre><p>👉 Output:</p><pre>&lt;nil&gt;</pre><h4>❓ Panic + Recover Order</h4><pre>defer func() {<br>    fmt.Println(&quot;Recovered:&quot;, recover())<br>}()<br><br>defer func() {<br>    panic(&quot;panic 2&quot;)<br>}()<br><br>panic(&quot;panic 1&quot;)</pre><p>👉 Output:</p><pre>Recovered: panic 2</pre><h4>🧩 Summary</h4><pre>| Concept |    Purpose                              |<br>--------------------------------------------------- |<br>| defer   |  Execute code later (cleanup, logging)  |<br>| panic   |  Stop execution on critical failure     |<br>| recover |  Catch panic and continue execution     |</pre><h4>💡 Best Practices</h4><p>✔️ Use defer for cleanup (files, DB, locks)<br>✔️ Use panic only for critical failures<br>✔️ Always use recover in:</p><ul><li>HTTP middleware</li><li>Goroutines</li><li>Background jobs</li></ul><p>❌ Don’t use panic for normal error handling<br>❌ Don’t ignore panic in goroutines</p><p><em>Thanks for reading! stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82a6c9c64307" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Low-Level Design (LLD): SOLID Principles & Design Patterns with Go Examples]]></title>
            <link>https://medium.com/@engineeringvault/mastering-low-level-design-lld-solid-principles-design-patterns-with-go-examples-eb73be23833b?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb73be23833b</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Sun, 05 Apr 2026 13:51:57 GMT</pubDate>
            <atom:updated>2026-04-05T13:51:57.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aVfzjENOW-et5bTtorxO1A.png" /></figure><h3>🚀 Introduction</h3><p>Low-Level Design (LLD) is one of the most important skills for backend engineers.<br>While many developers focus on writing code that <em>works</em>, fewer focus on writing code that is:</p><ul><li>Scalable</li><li>Maintainable</li><li>Easy to extend</li></ul><p>In real-world systems, clean design matters more than just working code.</p><p>In this article, we’ll break down LLD concepts in a simple and practical way using Go:</p><ul><li>SOLID Principles</li><li>Design Patterns (Singleton, Factory, Strategy, Observer)</li></ul><p>By the end, you’ll understand how to design clean, production-ready code.</p><h3>🧩 What is Low-Level Design (LLD)?</h3><p>Low-Level Design focuses on how individual components are designed internally.</p><p>It includes:</p><ul><li>Struct/class design</li><li>Interfaces</li><li>Function responsibilities</li><li>Code organization</li></ul><blockquote>👉 In short:<br>LLD = Writing clean, flexible, and maintainable code</blockquote><h3>⚙️ SOLID Principles</h3><p>SOLID principles help you avoid messy, tightly coupled code.</p><p>Let’s understand them using a Payment System example.</p><h4>🔹 1. Single Responsibility Principle (SRP)</h4><p>👉 A struct/class should have only one responsibility</p><p><strong>❌ Bad Design</strong></p><pre>type PaymentService struct{}<br>func (p PaymentService) Pay() {}<br>func (p PaymentService) SaveToDB() {}<br>func (p PaymentService) SendEmail() {}</pre><p>👉 One struct doing everything 😵</p><p><strong>✅ Good Design</strong></p><pre>type PaymentService struct{}<br>type PaymentRepository struct{}<br>type NotificationService struct{}</pre><p>👉 Each component has one job</p><h4>🔹 2. Open/Closed Principle (OCP)</h4><p>👉 Open for extension, closed for modification</p><p><strong>❌ Bad Design</strong></p><pre>func Pay(method string) {<br>    if method == &quot;upi&quot; {<br>        fmt.Println(&quot;UPI payment&quot;)<br>    } else if method == &quot;card&quot; {<br>        fmt.Println(&quot;Card payment&quot;)<br>    }<br>}</pre><p>👉 Adding new method → modify existing code ❌</p><p><strong>✅ Good Design (Using Interface)</strong></p><pre>type Payment interface {<br>    Pay(amount float64)<br>}<br>type UPI struct{}<br>func (u UPI) Pay(amount float64) {<br>    fmt.Println(&quot;UPI payment&quot;)<br>}<br>type Card struct{}<br>func (c Card) Pay(amount float64) {<br>    fmt.Println(&quot;Card payment&quot;)<br>}</pre><p>Usage</p><pre>func ProcessPayment(p Payment, amount float64) {<br>    p.Pay(amount)<br>}</pre><p>👉 The caller decides the type:</p><pre>p := UPI{}<br>ProcessPayment(p, 100)</pre><p>👉 Add new method WITHOUT changing existing code:</p><pre>type Wallet struct{}<br>func (w Wallet) Pay(amount float64) {<br>    fmt.Println(&quot;Wallet payment&quot;)<br>}</pre><p>✅ No modification needed → OCP achieved</p><h4>🔹 3. Liskov Substitution Principle (LSP)</h4><p>👉 Child should replace parent without breaking behavior</p><p><strong>❌ Bad Design</strong></p><pre>type Payment interface {<br>    Pay(amount float64)<br>}<br>type FreePayment struct{}<br>func (f FreePayment) Pay(amount float64) {<br>    panic(&quot;not supported&quot;)<br>}</pre><p>👉 This breaks expectations ❌</p><p><strong>✅ Good Design</strong></p><pre>type UPI struct{}<br>func (u UPI) Pay(amount float64) {<br>    fmt.Println(&quot;UPI paid:&quot;, amount)<br>}<br>type Card struct{}<br>func (c Card) Pay(amount float64) {<br>    fmt.Println(&quot;Card paid:&quot;, amount)<br>}</pre><p>👉 All implementations behave correctly ✅</p><h4>🔹 4. Interface Segregation Principle (ISP)</h4><p>👉 Don’t force unnecessary methods</p><p><strong>❌ Bad Design</strong></p><pre>type Payment interface {<br>    Pay()<br>    Refund()<br>    Cashback()<br>}</pre><p><strong>✅ Good Design</strong></p><pre>type Payer interface {<br>    Pay()<br>}<br>type Refunder interface {<br>    Refund()<br>}</pre><p>👉 Small and focused interfaces 👍</p><h4>🔹 5. Dependency Inversion Principle (DIP)</h4><p>👉 Depend on abstractions, not concrete implementations</p><p><strong>❌ Bad Design</strong></p><pre>type PaymentService struct {<br>    upi UPI<br>}</pre><p><strong>✅ Good Design</strong></p><pre>type PaymentService struct {<br>    payment Payment<br>}</pre><p>👉 Flexible and testable ✅</p><h3>🧠 Design Patterns</h3><p>Design patterns are reusable solutions to common problems.</p><h4>🧩 1. Singleton Pattern</h4><p><strong>📌 Problem</strong></p><p>Need only one instance (e.g., DB connection)</p><p><strong>✅ Implementation</strong></p><pre>var instance *DB<br>var once sync.Once<br>type DB struct{}<br>func GetDB() *DB {<br>    once.Do(func() {<br>        instance = &amp;DB{}<br>    })<br>    return instance<br>}</pre><p>Usage</p><pre>db1 := GetDB()<br>db2 := GetDB()<br>fmt.Println(db1 == db2) // true</pre><h4>🏭 2. Factory Pattern</h4><p><strong>📌 Problem</strong></p><p>Object creation logic is messy</p><p><strong>✅ Implementation</strong></p><pre>func GetPayment(method string) Payment {<br>    switch method {<br>    case &quot;upi&quot;:<br>        return UPI{}<br>    case &quot;card&quot;:<br>        return Card{}<br>    default:<br>        return nil<br>    }<br>}</pre><p>Usage</p><pre>p := GetPayment(&quot;upi&quot;)<br>p.Pay(100)</pre><h4>🎯 3. Strategy Pattern</h4><p><strong>📌 Problem</strong></p><p>Multiple ways to perform same task</p><p><strong>✅ Implementation</strong></p><pre>type PaymentStrategy interface {<br>    Pay(amount float64)<br>}<br>type PaymentService struct {<br>    strategy PaymentStrategy<br>}<br>func (p *PaymentService) Execute(amount float64) {<br>    p.strategy.Pay(amount)<br>}</pre><h3>Usage</h3><pre>service := PaymentService{strategy: UPI{}}<br>service.Execute(100)<br>service.strategy = Card{}<br>service.Execute(200)</pre><p>👉 Behavior changes at runtime 🔥</p><h4>👀 4. Observer Pattern</h4><p><strong>📌 Problem</strong></p><p>Notify multiple systems when an event occurs</p><p><strong>✅ Implementation</strong></p><pre>type Observer interface {<br>    Update(msg string)<br>}<br>type Email struct{}<br>func (e Email) Update(msg string) {<br>    fmt.Println(&quot;Email:&quot;, msg)<br>}<br>type SMS struct{}<br>func (s SMS) Update(msg string) {<br>    fmt.Println(&quot;SMS:&quot;, msg)<br>}</pre><p>Subject</p><pre>type Subject struct {<br>    observers []Observer<br>}<br>func (s *Subject) Add(o Observer) {<br>    s.observers = append(s.observers, o)<br>}<br>func (s *Subject) Notify(msg string) {<br>    for _, o := range s.observers {<br>        o.Update(msg)<br>    }<br>}</pre><p>Usage</p><pre>sub := Subject{}<br>sub.Add(Email{})<br>sub.Add(SMS{})<br>sub.Notify(&quot;Order placed!&quot;)</pre><p>👉 One event → multiple listeners 🚀</p><h4>🔥 Real-World Mapping</h4><p>How these concepts are used in real systems:</p><ul><li><strong>Singleton</strong> → DB connections, Redis clients</li><li><strong>Factory</strong> → API request handling</li><li><strong>Strategy</strong> → Payment systems, rate limiting</li><li><strong>Observer</strong> → Event-driven systems (logs, messaging)</li></ul><h3>🧠 Key Takeaways</h3><ul><li>LLD is about writing maintainable and scalable code</li><li>SOLID principles reduce tight coupling</li><li>Design patterns solve common design problems</li><li>Clean design makes systems easier to extend and test</li></ul><p><em>Thanks for reading! stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb73be23833b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Transactions, ACID, and Isolation Levels in Databases]]></title>
            <link>https://medium.com/@engineeringvault/understanding-transactions-acid-and-isolation-levels-in-databases-265e3b6794f7?source=rss-3f583be61b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/265e3b6794f7</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[data-management]]></category>
            <category><![CDATA[database-design]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Iswaryalakshmi Manikandan]]></dc:creator>
            <pubDate>Sat, 04 Apr 2026 13:10:06 GMT</pubDate>
            <atom:updated>2026-04-04T13:10:06.076Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*okM92GV4QaIKtKF8Ypizlw.png" /></figure><p>When building backend systems, one of the most critical aspects is ensuring that your data remains <strong>correct, consistent, and safe</strong>, even when multiple users interact with it at the same time.</p><p>If you’ve ever wondered:</p><ul><li>What happens if a system crashes during an operation?</li><li>How does a database prevent partial updates?</li><li>Why do concurrent queries sometimes return unexpected results?</li></ul><p>This is where Transactions, ACID properties, and Isolation Levels come into play.</p><h3>🧠 1. What is a Transaction?</h3><p>A <strong>transaction</strong> is a group of database operations executed as a single unit.</p><blockquote>Transaction = Unit of work</blockquote><p>👉 Either all operations succeed, or none of them do.</p><p><strong>💡 Real-World Example: Bank Transfer</strong></p><p>Transferring ₹100 involves:</p><ol><li>Deduct ₹100 from Account A</li><li>Add ₹100 to Account B</li></ol><p>Both steps must succeed together.</p><p><strong>❌ Without Transaction</strong></p><pre>UPDATE accounts SET balance = balance - 100 WHERE id = 1;<br>-- system crash 😵<br>UPDATE accounts SET balance = balance + 100 WHERE id = 2;</pre><p>👉 Money is lost → inconsistent data</p><p><strong>✅ With Transaction</strong></p><pre>BEGIN;<br><br>UPDATE accounts SET balance = balance - 100 WHERE id = 1;<br>UPDATE accounts SET balance = balance + 100 WHERE id = 2;<br><br>COMMIT;</pre><p>If something fails:</p><pre>ROLLBACK;</pre><p><strong>⚙️What Happens Inside DB?</strong></p><p>When you start a transaction:</p><p>👉 DB does NOT immediately make changes permanent</p><p>Instead:</p><ul><li>Keeps changes in temporary state</li><li>Waits for COMMIT</li></ul><p><strong>🧠 Mental Model</strong></p><p>Think of a transaction like <strong>draft mode</strong>:</p><ul><li>Changes are temporary</li><li>COMMIT → finalize</li><li>ROLLBACK → discard</li></ul><p><strong>🧵 Multiple Users Problem (Why Transactions Matter)</strong></p><p>Imagine:</p><p>User A and User B both updating same data.</p><p>Without transactions:</p><ul><li>Data gets corrupted 😵</li></ul><p>With transactions:</p><ul><li>DB manages order safely ✅</li></ul><p><strong>🧠 Example (E-commerce)</strong></p><p>Placing an order:</p><ol><li>Create order</li><li>Reduce inventory</li><li>Deduct payment</li></ol><p>👉 All must succeed → else rollback</p><p><strong>🧱 Savepoints</strong></p><p>You can rollback partially.</p><pre>BEGIN;<br><br>INSERT INTO users VALUES (1, &#39;A&#39;);<br><br>SAVEPOINT sp1;<br><br>INSERT INTO users VALUES (1, &#39;B&#39;); -- error<br><br>ROLLBACK TO sp1;<br><br>COMMIT;</pre><p>👉 Result:</p><ul><li>First insert stays ✅</li><li>Second removed ❌</li></ul><p><strong>⚡ Insight</strong></p><p>Transactions also handle:</p><ul><li>Concurrency (many users)</li><li>Data correctness</li><li>System failures</li></ul><p>👉 But they come with cost:</p><ul><li>Slower performance</li><li>Locks resources</li></ul><h4>🚀 When You Should Use Transactions</h4><p><strong>✅ MUST use</strong></p><ul><li>Payments 💰</li><li>Orders 🛒</li><li>Inventory 📦</li></ul><p><strong>❌ Avoid</strong></p><ul><li>Logging systems</li><li>Analytics</li><li>High-speed inserts</li></ul><h4>🎯Quick Summary</h4><ul><li>Transaction = group of queries as one unit</li><li>BEGIN → COMMIT → ROLLBACK</li><li>Prevents partial updates</li><li>Ensures data safety</li></ul><h3>⚙️ 2. ACID Properties (Why Transactions Are Reliable)</h3><p>ACID defines the guarantees that make transactions safe.</p><p><strong>🔹 A — Atomicity (All or Nothing)</strong></p><p>👉 Either the entire transaction succeeds or fails completely.</p><p>If any step fails → everything is rolled back.</p><p>❌ Without Atomicity</p><pre>UPDATE A (deduct money) ✅<br>-- crash 😵<br>UPDATE B (add money) ❌</pre><p>👉 Money lost</p><p>✅ With Atomicity</p><p>If any step fails → entire transaction is undone</p><pre>ROLLBACK;</pre><p><strong>🧠 Think Like</strong></p><blockquote>“No partial work allowed”</blockquote><p><strong>🔹 C — Consistency (Valid Data Only)</strong></p><p>👉 Database always moves from one valid state to another.</p><p>Examples:</p><ul><li>Balance ≥ 0</li><li>No duplicate primary keys</li><li>Foreign keys must exist</li><li>Business rules must be satisfied</li></ul><p><strong>🧠 Think Like</strong></p><blockquote>“No illegal data allowed”</blockquote><p><strong>🔹 I — Isolation (No Interference)</strong></p><p>👉 Multiple transactions should not interfere with each other.</p><p>Even if many users access the database simultaneously, each transaction behaves independently.</p><p><strong>Real Scenario</strong></p><p>Two users updating same balance:</p><p>❌ Without Isolation</p><pre>T1 reads balance = 100<br>T2 updates balance = 200<br>T1 updates based on old value → WRONG 😵</pre><p>✅ With Isolation</p><p>DB ensures:</p><ul><li>Proper order</li><li>No interference</li></ul><p><strong>🧠 Think Like</strong></p><blockquote>“Each transaction runs alone (even if many run together)”</blockquote><p><strong>🔹 D — Durability (Permanent Storage)</strong></p><p>👉 Once a transaction is committed, it is permanently saved.</p><p>Even in case of:</p><ul><li>System crash 💥</li><li>Power failure ⚡</li></ul><p>Example</p><pre>COMMIT;</pre><p>👉 After this:</p><ul><li>Data MUST be safe</li></ul><p><strong>🧠 Think Like</strong></p><blockquote>“Once saved → cannot be lost”</blockquote><h4>🧠 Simple Summary</h4><pre>| Property    | What it Guarantees |<br>| ----------- | ------------------ |<br>| Atomicity   | No partial updates |<br>| Consistency | Data always valid  |<br>| Isolation   | No conflicts       |<br>| Durability  | Data never lost    |</pre><h4>⚡Real-Life Analogy (Best Way to Remember)</h4><p><strong>🏦 Bank Transfer</strong></p><pre>| ACID | Meaning                         |<br>| ---- | ------------------------------- |<br>| A    | Either full transfer OR nothing |<br>| C    | No invalid balance              |<br>| I    | Other users don’t interfere     |<br>| D    | Once done, it stays             |</pre><h4>🚨 Important Insight</h4><p>👉 Not all systems use full ACID</p><p>Why?</p><p>ACID = safe but slower<br> Non-ACID = fast but risky</p><h4>⚖️ Trade-off</h4><pre>| ACID               | Performance   |<br>| ------------------ | ------------- |<br>| Strong consistency | Slower        |<br>| High safety        | More overhead |</pre><h3>🔒 3. Why Isolation is Important</h3><p>In real systems, multiple transactions run at the same time.</p><p>👉 Without isolation, data can become inconsistent.</p><p>Isolation is achieved using <strong>2 main techniques</strong>:</p><p>🔑 1. Locks</p><p>🔑 2. MVCC (Multi-Version Concurrency Control)</p><p>👉 Every database (like PostgreSQL or MySQL) uses one or both.</p><h4>🔒 1. Locks</h4><h4>🧠 Idea:</h4><blockquote>“If I am using data, others must wait”</blockquote><p><strong>Types of Locks</strong></p><p><strong>🔹 Read Lock (Shared Lock)</strong></p><ul><li>Many users can read</li><li>No one can write</li></ul><p><strong>🔹 Write Lock (Exclusive Lock)</strong></p><ul><li>Only one transaction can write</li><li>Others must wait (read/write blocked)</li></ul><p>🔥 Example</p><p>T1:</p><pre>BEGIN;<br>UPDATE users SET balance = 200 WHERE id = 1;</pre><p>👉 DB applies <strong>write lock</strong></p><p>T2 tries:</p><pre>SELECT * FROM users WHERE id = 1;</pre><p>👉 It will:</p><ul><li>Wait ⏳ OR</li><li>Read old value (depends on DB)</li></ul><p>✅ Result</p><p>👉 Prevents:</p><ul><li>Dirty reads</li><li>Conflicts</li></ul><p><strong>❌ Problem with Locks</strong></p><ul><li>Slows system</li><li>Causes waiting</li><li>Can lead to deadlocks</li></ul><h4>⚡ 2. MVCC (Modern Approach)</h4><p>Used by:</p><ul><li>PostgreSQL</li><li>MySQL (InnoDB)</li></ul><h4>🧠 Idea:</h4><blockquote><strong><em>“Instead of blocking, create multiple versions of data”</em></strong></blockquote><p>🔥 Example</p><p>Balance = 100</p><p>T1:</p><pre>BEGIN;<br>UPDATE balance = 200;<br>-- NOT committed</pre><p>👉 DB creates:</p><ul><li>Old version → 100</li><li>New version → 200</li></ul><p>T2:</p><pre>SELECT balance;</pre><p>👉 T2 sees:</p><ul><li><strong>100 (old committed version)</strong> ✅</li></ul><p><strong>🎯 Key Point</strong></p><p>👉 No waiting<br>👉 No blocking<br>👉 Safe reads</p><p><strong>🧠 Think Like</strong></p><blockquote>“Each transaction sees its own snapshot of data”</blockquote><h4>⚠️ Common Problems</h4><h4>🧨 1. Dirty Read</h4><p>Reading uncommitted data.</p><pre>T1: UPDATE balance = 500 (not committed)<br>T2: SELECT balance → 500 ❌<br>T1: ROLLBACK</pre><h4>🔁 2. Non-Repeatable Read</h4><p>Same query returns different results.</p><pre>T1: SELECT balance → 100<br>T2: UPDATE balance → 200<br>T1: SELECT balance → 200 ❌</pre><h4>👻 3. Phantom Read</h4><p>New rows appear during a transaction.</p><pre>T1: SELECT orders WHERE amount &gt; 100 → 2 rows<br>T2: INSERT new order (150)<br>T1: SELECT again → 3 rows ❌</pre><h4>🧱 Isolation Levels Explained</h4><p>Isolation levels define how much a transaction can see from others.</p><p><strong>🥉 Read Uncommitted</strong></p><ul><li>No locks</li><li>No MVCC safety</li><li>Allows dirty reads ❌</li><li>Rarely used</li></ul><p>👉 Reads everything (even uncommitted)</p><p><strong>🥈 Read Committed</strong></p><ul><li>MVCC (read only committed versions)</li><li>Prevents dirty reads ✅</li><li>Allows other anomalies</li></ul><p>👉 Default in many databases</p><p><strong>Behavior:</strong></p><ul><li>You only see committed data</li><li>Each query may see new data</li></ul><p><strong>🥇 Repeatable Read</strong></p><ul><li>MVCC snapshot</li><li>Same query returns same result ✅</li><li>Phantom reads may still occur</li></ul><p><strong>Behavior:</strong></p><ul><li>Same transaction → same snapshot</li><li>Even if others update → you don’t see it</li></ul><p><strong>🏆 Serializable</strong></p><ul><li>Strong locks OR advanced MVCC</li><li>Highest isolation</li><li>Transactions behave as if executed one by one</li></ul><p>👉 Safest but slowest</p><p><strong>Behavior:</strong></p><ul><li>Transactions act like running one-by-one</li></ul><p><strong>📊 Comparison Table</strong></p><pre>| Level            | Dirty Read | Non-Repeatable    | Phantom  |<br>| ---------------- | ---------- | --------------    | -------  |<br>| Read Uncommitted | ❌          | ❌              | ❌       |<br>| Read Committed   | ✅          | ❌              | ❌       |<br>| Repeatable Read  | ✅          | ✅              | ❌       |<br>| Serializable     | ✅          | ✅              | ✅       |</pre><h4>⚡ Real-World Insights</h4><ul><li>Most applications use <strong>Read Committed</strong></li><li>Financial systems prefer <strong>Repeatable Read or Serializable</strong></li><li>Higher isolation improves safety but reduces performance</li></ul><h3>🎯 Final Thoughts</h3><p>Understanding these concepts helps you build systems that are:</p><ul><li>Reliable</li><li>Consistent</li><li>Scalable</li></ul><p>👉 In simple terms:</p><ul><li><strong>Transaction</strong> → What you are doing</li><li><strong>ACID</strong> → Why it is safe</li><li><strong>Isolation Levels</strong> → How it behaves with others</li></ul><p><em>Thanks for reading! Stay tuned.</em></p><p>Thanks for reading,<br>- Iswaryalakshmi Manikandan 👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=265e3b6794f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>