<?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 wellisrite on Medium]]></title>
        <description><![CDATA[Stories by wellisrite on Medium]]></description>
        <link>https://medium.com/@wellisrite?source=rss-3b262d55ce69------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*50NOCRc3GJa89SQCqvQDVQ.png</url>
            <title>Stories by wellisrite on Medium</title>
            <link>https://medium.com/@wellisrite?source=rss-3b262d55ce69------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 00:22:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wellisrite/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[Why Switching from Map to Array Boosts Performance in Sliding Window Problems 24 ms vs 2 ms]]></title>
            <link>https://wellisrite.medium.com/why-switching-from-map-to-array-boosts-performance-in-sliding-window-problems-24-ms-vs-2-ms-ca236fbe464a?source=rss-3b262d55ce69------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca236fbe464a</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[dsa-training]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <dc:creator><![CDATA[wellisrite]]></dc:creator>
            <pubDate>Tue, 05 Aug 2025 13:12:30 GMT</pubDate>
            <atom:updated>2025-08-05T13:12:30.209Z</atom:updated>
            <content:encoded><![CDATA[<p>When solving <strong>Longest Repeating Character Replacement (LeetCode 424)</strong>, many implementations use a map (or dictionary) to count character frequencies. While correct, this approach often runs <strong>2–10× slower</strong> than using a fixed-size array. Here’s why.</p><h3>Problem Recap</h3><p>We need the length of the longest substring where all characters can be made the same after at most k replacements.</p><p>Core logic:</p><ul><li>Expand a sliding window</li><li>Track <strong>frequency of characters</strong> in current window</li><li>Validate window: (window size - maxFreq) &lt;= k</li></ul><p>The heavy-lifting here is <strong>frequency counting</strong> — which we can optimize.</p><h3>Map Approach: Correct but Slower</h3><p>Typical Go implementation:</p><pre>count := make(map[byte]int)<br>count[s[right]]++</pre><h3>Why is it slower?</h3><ol><li><strong>Hashing Overhead</strong></li></ol><ul><li>Every count[ch]++ involves hashing ch → map lookup → potential rehash.</li><li>Even forsingle-byte keys (A-Z), this adds measurable overhead.</li></ul><p><strong>2. Dynamic Memory Allocations</strong></p><ul><li>map in Go grows dynamically → triggers reallocation as size increases.</li></ul><p><strong>3. Cache Unfriendliness</strong></p><ul><li>Map entries aren’t contiguous in memory → worse CPU cache locality.</li></ul><h3>Array Approach: Fixed &amp; Cache-Friendly</h3><p>Optimized version:</p><pre>count := make([]int, 26)<br>count[s[right]-&#39;A&#39;]++</pre><h3>Why is it faster?</h3><ol><li><strong>Direct Indexing (O(1))</strong></li></ol><ul><li>No hashing — index is s[right] - &#39;A&#39;.</li><li>26 fixed slots, constant-time access.</li></ul><p><strong>2. No Reallocations</strong></p><ul><li>Array size is fixed (26), no growth cost.</li></ul><p><strong>3. Better Cache Locality</strong></p><ul><li>Contiguous memory → CPU prefetching boosts performance.</li></ul><p><strong>4. Predictable Performance</strong></p><ul><li>No variance from hash collisions or map rebalancing.</li></ul><h3>Performance Impact</h3><p>On LeetCode:</p><ul><li><strong>Map version:</strong> ~20–40ms</li><li><strong>Array version:</strong> ~4–8ms (5× faster)</li></ul><p>For long strings (1⁰⁵ chars), array saves millions of operations:</p><ul><li>Map: O(n) with high constant factor (hashing)</li><li>Array: O(n) with minimal constant factor (direct index)</li></ul><h3>When to Use Array Over Map</h3><p>Use array when:</p><ul><li>Character set is <strong>small &amp; fixed</strong> (e.g., A-Z, a-z, digits)</li><li>Index can be calculated (ch - &#39;A&#39; or ch - &#39;a&#39;)</li><li>Frequency count needed in tight loops (e.g., sliding window, prefix sums)</li></ul><p>Use map when:</p><ul><li>Character set is <strong>dynamic or large</strong> (Unicode, arbitrary strings)</li><li>Keys are not easily mapped to integers</li></ul><pre>func characterReplacement(s string, k int) int {<br>    count := make([]int, 26) // frequency of A-Z<br>    left, maxCount, res := 0, 0, 0<br><br>    for right := 0; right &lt; len(s); right++ {<br>        idx := s[right] - &#39;A&#39;<br>        count[idx]++<br>        if count[idx] &gt; maxCount {<br>            maxCount = count[idx]<br>        }<br><br>        // Shrink window if replacements exceed k<br>        if (right-left+1) - maxCount &gt; k {<br>            count[s[left]-&#39;A&#39;]--<br>            left++<br>        }<br><br>        if right-left+1 &gt; res {<br>            res = right - left + 1<br>        }<br>    }<br><br>    return res<br>}</pre><h3>Conclusion</h3><p>For frequency-based sliding window problems like LeetCode 424:</p><ul><li>Array = <strong>faster, simpler, predictable</strong></li><li>Map = <strong>flexible, but slower</strong></li></ul><p>This micro-optimization often makes the difference between <strong>24ms vs 2ms</strong> runtime.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca236fbe464a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Subtle Context Bug That Froze Mobile Trading at Saham Rakyat]]></title>
            <link>https://wellisrite.medium.com/the-subtle-context-bug-that-froze-mobile-trading-at-saham-rakyat-c773b042200b?source=rss-3b262d55ce69------2</link>
            <guid isPermaLink="false">https://medium.com/p/c773b042200b</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[wellisrite]]></dc:creator>
            <pubDate>Mon, 04 Aug 2025 11:27:59 GMT</pubDate>
            <atom:updated>2025-08-05T09:00:23.798Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Sam — Backend Engineer</em></p><h3>The Unexpected Freeze</h3><p>While maintaining Saham Rakyat’s mobile trading backend, I encountered a bug that completely froze trading sockets for some users. Everything looked fine at first: connections opened, market data streamed, trades executed.</p><p>Then, <strong>after a timeout</strong>, users suddenly stopped receiving updates — and trades silently failed.</p><p>After digging into the code, the cause boiled down to a <strong>context value stored inside the socket</strong>.</p><h3>What Happened</h3><p>Our WebSocket handler attached request-related data (like userID) to context.Context and later <strong>referenced it inside the socket’s state</strong>.</p><p>Example simplified code:</p><pre>func handleSocket(ctx context.Context, conn *websocket.Conn) {<br>    socket := &amp;Socket{<br>        Conn: conn,<br>        Ctx:  ctx, // storing context directly<br>    }<br>    go socket.listen()<br>    func (s *Socket) listen() {<br>        for {<br>            // Accessing value repeatedly from context<br>            userID := s.Ctx.Value(&quot;userID&quot;).(string)<br>            if userID == &quot;&quot; {<br>                log.Println(&quot;userID is nil or expired, blocking socket&quot;)<br>                continue<br>            }<br>            processMessages(userID)<br>        }<br>    }<br>}</pre><p>The problem: <strong>the context had a deadline tied to the API request that opened the socket</strong>.<br> Once that deadline expired, s.Ctx.Value(&quot;userID&quot;) returned nil, even though the socket connection itself stayed open. This stalled the entire trading flow.</p><h3>The Fix</h3><p>Instead of storing and re-reading ctx.Value() inside the socket, I <strong>extracted the value at initialization</strong> and passed the real value directly into the socket’s struct.</p><p>Fixed version:</p><pre>func handleSocket(ctx context.Context, conn *websocket.Conn) {<br>    // Extract value once at connection setup<br>    userID, ok := ctx.Value(&quot;userID&quot;).(string)<br>    if !ok || userID == &quot;&quot; {<br>        log.Println(&quot;invalid userID in context&quot;)<br>        return<br>    }<br>    socket := &amp;Socket{<br>            Conn:   conn,<br>            UserID: userID, // store the actual value<br>        }<br>        go socket.listen()<br>    }<br>    func (s *Socket) listen() {<br>        for {<br>            // Use the real stored value, not ctx.Value()<br>            processMessages(s.UserID)<br>        }<br>    }<br>}</pre><p>This ensured the socket lifecycle was <strong>independent of the original context deadline</strong>.</p><h3>Why This Matters</h3><ul><li><strong>Context is meant for deadlines/cancellation</strong>, not persistent state.</li><li><strong>Attaching it to sockets can lead to silent failures</strong> when the deadline expires.</li><li><strong>Explicitly passing values</strong> (like userID) makes the socket stable and easier to reason about.</li></ul><h3>Result</h3><p>After deploying the fix:</p><ul><li>Mobile trading sockets no longer froze after the deadline expired.</li><li>Nil value errors disappeared from logs.</li><li>The architecture became cleaner: API context is now separate from socket state.</li></ul><h3>Lessons Learned</h3><ol><li><strong>Don’t store context inside persistent objects</strong> like sockets.</li><li><strong>Extract needed values upfront</strong> at connection time.</li><li><strong>Separate lifecycles</strong> — request vs. long-lived socket.</li></ol><h3>About Me</h3><p>I’m a backend engineer focused on <strong>real-time fintech systems</strong>. I also created AuditFlag, an AI-powered fraud detection platform.</p><p>Follow me on Medium (@wellisrite) for more debugging deep-dives and backend war stories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*jpRfUAOu8lzJSuq8TGen5Q.png" /><figcaption>GO mascot</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c773b042200b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AuditFlag: Building an AI-Powered Fraud Detection MVP in Weeks]]></title>
            <link>https://wellisrite.medium.com/auditflag-building-an-ai-powered-fraud-detection-mvp-in-weeks-3d00b865bf7d?source=rss-3b262d55ce69------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d00b865bf7d</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[fintech]]></category>
            <dc:creator><![CDATA[wellisrite]]></dc:creator>
            <pubDate>Sun, 03 Aug 2025 22:05:36 GMT</pubDate>
            <atom:updated>2025-08-05T10:10:13.285Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s fintech landscape, fraud detection isn’t just a feature — it’s a necessity. Transactions, documents, and user activity can reveal subtle anomalies that hint at fraudulent behavior, but manually detecting them is slow and error-prone.</p><p>This is the problem <strong>AuditFlag</strong> aims to solve: an AI-powered fraud detection tool that helps businesses identify suspicious transactions and forged documents in seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X8xGwIHxJWEBAonWYhHodw.png" /><figcaption><a href="https://auditflag.tech/">https://auditflag.tech/</a></figcaption></figure><h3>From Concept to MVP</h3><p>When I first started AuditFlag, the goal was clear: <strong>detect transaction anomalies and document forgery using AI</strong> — without requiring users to have any technical background.</p><p>The MVP focuses on three pillars:</p><ol><li><strong>Transaction Fraud Detection (CSV Upload)</strong></li></ol><ul><li>Upload transaction data as CSV</li><li>AI-powered anomaly detection</li><li>Flagged rows stored and visualized in dashboards</li></ul><p><strong>2. Document Forgery Detection</strong></p><ul><li>Compare suspected and reference documents</li><li>AI-powered OCR and similarity scoring</li><li>Visual result page with forgery likelihood</li></ul><p><strong>3. User Management</strong></p><ul><li>Sign-up, login, and profile pages</li><li>User-specific reports and history</li></ul><h3>Tech Stack Decisions</h3><p>Initially, I experimented with Tailwind CSS for rapid UI development, but later pivoted to <strong>Bootstrap (CDN)</strong> for simplicity and fast prototyping — no npm or compilation required.</p><p>The backend is <strong>Django</strong>, chosen for its robust ORM, authentication system, and fast MVP development speed. AI processing integrates via <strong>OpenAI API</strong> for fraud flagging and OCR-driven document checks.</p><p>Deployment runs on <strong>AWS EC2</strong> behind <strong>Nginx + Gunicorn</strong> with <strong>Let’s Encrypt SSL</strong> for secure HTTPS (<a href="https://auditflag.tech/">auditflag.tech</a>). Automatic certificate renewal ensures no downtime.</p><h3>Key Features Completed</h3><ul><li>Fraud detection via CSV upload</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qt0q5KnCBJiSDnDfuV1qMA.png" /><figcaption>AI integrted Fraud Transactions Identifier</figcaption></figure><ul><li>Document forgery detection (AI OCR + comparison)</li><li>Dashboard with report counts and history</li><li>Secure user authentication (sign-up/login)</li><li>Deployed live at auditflag.tech</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SrsSKDbp3vsiZxox" /></figure><h3>What’s Next?</h3><p>The next phase focuses on <strong>AI upgrades</strong> and <strong>monetization</strong>:</p><ul><li><strong>Per-transaction risk scoring</strong></li><li><strong>Fraud category tagging</strong> (e.g., AML patterns)</li><li><strong>AI recommendations</strong> (next steps for flagged transactions)</li><li><strong>Export options</strong> (JSON/CSV) and <strong>webhooks for integrations</strong></li><li><strong>Free/Paid tiers</strong> with Stripe or PayPal</li></ul><h3>Why This Matters</h3><p>Fraud costs businesses billions annually. By lowering the barrier to entry for fraud detection (simple CSV upload, AI insights in seconds), AuditFlag empowers small teams and startups to secure their data without hiring full-scale compliance departments.</p><h3>Try It Out</h3><p>The MVP is live at <a href="https://auditflag.tech/"><strong>auditflag.tech</strong></a> — feel free to explore and share feedback.</p><p>This is just the start. Over the coming weeks, I’ll be refining the platform, adding risk scoring, and preparing for wider beta testing. If you’re interested in early access or partnership, reach out!</p><h3>Follow me for updates on building AI tools in fintech — from backend architecture to deployment hacks.</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d00b865bf7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two Codes, Same Time Complexity, 100× Difference in Runtime]]></title>
            <link>https://wellisrite.medium.com/two-codes-same-time-complexity-100-difference-in-runtime-97c114f2646b?source=rss-3b262d55ce69------2</link>
            <guid isPermaLink="false">https://medium.com/p/97c114f2646b</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[wellisrite]]></dc:creator>
            <pubDate>Wed, 30 Jul 2025 16:40:12 GMT</pubDate>
            <atom:updated>2025-07-30T16:40:12.250Z</atom:updated>
            <content:encoded><![CDATA[<p>When we talk about algorithm performance, we often focus on <strong>Big-O complexity</strong>:<br> O(n) vs O(n log n) vs O(n²).</p><p>But here’s the catch: <strong>two algorithms with the same Big-O complexity can still run at drastically different speeds</strong>.</p><h3>Case Study: Equal Row and Column Pairs (LeetCode 2352)</h3><p><strong>The task:</strong><br> Count how many pairs (row, column) in a square grid are identical.</p><h4>Solution 1 — String Conversion Approach</h4><pre>func equalPairs(grid [][]int) int {<br>    rows := make(map[string]int)<br>    n := len(grid)<br><br>    for i := 0; i &lt; n; i++ {<br>        key := &quot;&quot;<br>        for j := 0; j &lt; n; j++ {<br>            key += &quot;,&quot; + strconv.Itoa(grid[i][j])<br>        }<br>        key = key[1:]<br>        rows[key]++<br>    }<br><br>    res := 0<br>    for c := 0; c &lt; n; c++ {<br>        key := &quot;&quot;<br>        for r := 0; r &lt; n; r++ {<br>            key += &quot;,&quot; + strconv.Itoa(grid[r][c])<br>        }<br>        key = key[1:]<br>        res += rows[key]<br>    }<br>    return res<br>}</pre><ul><li><strong>Time Complexity:</strong> O(n²)</li><li><strong>Runtime:</strong> ~186 ms for n = 200</li></ul><h4>Solution 2 — Fixed Array Map Keys</h4><pre>func equalPairs(grid [][]int) int {<br>    n := len(grid)<br>    rows := make(map[[200]int]int, n)<br><br>    for i := 0; i &lt; n; i++ {<br>        var row [200]int<br>        copy(row[:], grid[i])<br>        rows[row]++<br>    }<br><br>    res := 0<br>    for c := 0; c &lt; n; c++ {<br>        var col [200]int<br>        for r := 0; r &lt; n; r++ {<br>            col[r] = grid[r][c]<br>        }<br>        res += rows[col]<br>    }<br>    return res<br>}</pre><ul><li><strong>Time Complexity:</strong> O(n²) (same as before)</li><li><strong>Runtime:</strong> ~2 ms for n = 200</li></ul><h3>Why the Huge Difference?</h3><h3>1. String Building Is Expensive</h3><p>Concatenating strings repeatedly creates new allocations.<br> Every map lookup requires hashing each character of the string key.</p><h3>2. Array Keys Are Native</h3><p>[200]int is a fixed-size array (comparable in Go).<br> The Go runtime hashes it efficiently as a memory block — no extra allocations.</p><h3>3. Constant Factors Matter</h3><p>Big-O notation tells us <strong>how runtime grows</strong> as input grows, <strong>not how fast it runs</strong> for specific data sizes.<br> Two O(n²) algorithms can easily differ by <strong>100×</strong> in real runtime.</p><h3>Key Takeaways</h3><ol><li><strong>Same Big-O doesn’t mean same speed</strong></li><li>Avoid unnecessary allocations (string vs array)</li><li>Use native types as map keys if possible</li><li>Always measure runtime, not just complexity</li></ol><h3>Final Thought</h3><p>When solving algorithm problems:</p><ul><li><strong>Step 1:</strong> Get a correct solution with acceptable complexity</li><li><strong>Step 2:</strong> Analyze memory and key representation</li><li><strong>Step 3:</strong> Optimize constant factors</li></ul><p>That’s how one solution went from <strong>186 ms → 2 ms</strong> without changing complexity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*jpRfUAOu8lzJSuq8TGen5Q.png" /><figcaption>Go mascot</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97c114f2646b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The More You Know, The More You Realize You Know Nothing: Rediscovering Fundamentals]]></title>
            <link>https://wellisrite.medium.com/the-more-you-know-the-more-you-realize-you-know-nothing-rediscovering-fundamentals-ef0b689d02c4?source=rss-3b262d55ce69------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef0b689d02c4</guid>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[wellisrite]]></dc:creator>
            <pubDate>Tue, 29 Jul 2025 17:09:35 GMT</pubDate>
            <atom:updated>2025-07-29T17:09:35.451Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*zzR2wrxen_tZB2Ix" /></figure><p>After five years in software engineering, I thought I had everything figured out. I’ve shipped production features, debugged outages at 3 AM, optimized APIs, and survived countless sprints. But when I recently decided to prepare for interviews again — cracking algorithms and system design questions — I had an unsettling realization:</p><p>I’ve forgotten the fundamentals.</p><p>It wasn’t just about <em>recalling</em> how to reverse a linked list or implement BFS. It was deeper — I had been building abstractions on top of abstractions for so long that I lost touch with the building blocks beneath them.</p><p>And that humbled me.</p><h3>Failing My Agoda System Design Interview</h3><p>A few months ago, I interviewed for a Senior backend role at Agoda. I was confident — I had built complex systems before. But during the <strong>system design round</strong>, things unraveled:</p><ul><li>I overcomplicated the design instead of focusing on core requirements.</li><li>I struggled to explain trade-offs between databases and caching strategies.</li><li>My API design lacked clear scalability considerations.</li></ul><p>The feedback was blunt: I failed to demonstrate <strong>structured thinking</strong> and mastery of fundamentals.</p><p>That failure stung — but it also became the catalyst for change. It forced me to confront a harsh truth: <strong>experience building features doesn’t automatically mean you’re good at system design.</strong></p><h3>The Illusion of Mastery</h3><p>In Persona games, there’s an archetype called the <strong>Fool Arcana</strong>. At first glance, it sounds negative — who wants to be a fool? But in the game’s tarot system, the Fool represents <strong>potential and infinite growth</strong>. It’s the starting point of a journey, someone unbound by fixed roles or rigid thinking.</p><p>That’s exactly how I feel now.</p><p>Five years into this career, I realize I’m back at square one. The more I learn about distributed systems, concurrency models, and algorithmic trade-offs, the more I see how much I <em>don’t</em> know. And that’s not defeatist — that’s liberating.</p><h3>Forgetting Fundamentals Is Normal (But Dangerous)</h3><p>In my day-to-day work, I rarely write algorithms from scratch. Frameworks handle routing. Databases handle indexing. Cloud providers handle scaling. This comfort is great for shipping products, but it hides the underlying mechanics:</p><ul><li>Can you still explain why O(log n) is fast enough for most real-time queries?</li><li>Can you implement a simple hash map if stripped of your standard library?</li><li>Do you know why two-phase commit matters for distributed transactions?</li></ul><p>I couldn’t. And that was a wake-up call.</p><h3>Humility as a Superpower</h3><p>Relearning fundamentals feels like admitting defeat, but it’s actually the opposite:</p><ul><li>It sharpens problem-solving skills (beyond copy-pasting patterns).</li><li>It makes debugging deeper issues easier (you understand the <em>why</em> behind failures).</li><li>It gives you confidence — knowing you can rebuild the tower from the ground up.</li></ul><p>The Fool Arcana teaches that mastery starts with acknowledging ignorance. Only by embracing that humility can you grow without limits.</p><h3>My New Learning Approach</h3><ol><li><strong>Revisit Algorithms and Data Structures</strong><br> Practicing classics like Two Sum, DFS/BFS, and dynamic programming daily — not to memorize solutions, but to rebuild intuition.</li><li><strong>Strengthen System Fundamentals</strong><br> Reviewing OS concepts, networking, and database internals I once skimmed over.</li><li><strong>Re-learn System Design, Properly This Time</strong><br> Breaking problems into requirements, trade-offs, scalability, and fault tolerance instead of jumping into tech buzzwords.</li><li><strong>Document the Journey</strong><br> Writing about my learning process — like this article — helps solidify concepts and inspire others feeling the same imposter syndrome.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XQm06zozQuLvZtItx98Hgw.png" /></figure><h3>Closing Thoughts</h3><p>If you’re a few years into your career and feel behind because you’ve “forgotten” the fundamentals, you’re not alone. That discomfort you feel? That’s growth knocking at your door.</p><p>The more you know, the more you realize you know nothing. And that’s the start of mastery — the Fool’s journey toward infinite potential.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef0b689d02c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Naive Recursion to O(1) DP: Solving Maximum Sum of Non-Adjacent Elements in Go]]></title>
            <link>https://wellisrite.medium.com/from-naive-recursion-to-o-1-dp-solving-maximum-sum-of-non-adjacent-elements-in-go-d0c2b740d731?source=rss-3b262d55ce69------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0c2b740d731</guid>
            <category><![CDATA[dynammic-programming]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[wellisrite]]></dc:creator>
            <pubDate>Mon, 28 Jul 2025 19:21:40 GMT</pubDate>
            <atom:updated>2025-07-28T19:21:40.705Z</atom:updated>
            <content:encoded><![CDATA[<p>A few days ago, I was watching a mock coding interview on YouTube. The interviewer asked the candidate to solve the <strong>Maximum Sum of Non-Adjacent Elements</strong> problem — also known as the <em>House Robber</em> problem.</p><p>What caught my attention was how they went through <strong>four different solutions</strong> for the same problem, each improving on the last. The final one (Solution #4) was incredibly elegant: it ran in <strong>linear time</strong> and used only <strong>constant space</strong>.</p><p>As someone learning Go and preparing for technical interviews, I decided to dive deeper into this problem. Here’s what I learned.</p><h3>Problem Statement</h3><p><strong>Given an array of integers, find the maximum sum of elements such that no two chosen elements are adjacent.</strong></p><p><strong>Example</strong></p><pre>Input:  [3, 2, 7, 10]<br>Output: 13  (3 + 10)</pre><h3>Approach 1: Naive Recursion (Exponential Time)</h3><h3>Idea</h3><p>At each index:</p><ul><li><strong>Take</strong> the current element and move two steps back.</li><li><strong>Skip</strong> the current element and move one step back.<br> Return the maximum of both choices.</li></ul><pre>func naive(i int, nums []int) int {<br>    if i &lt; 0 {<br>        return 0<br>    }<br>    take := nums[i] + naive(i-2, nums)<br>    skip := naive(i-1, nums)<br>    return max(take, skip)<br>}<br><br>func max(a, b int) int {<br>    if a &gt; b {<br>        return a<br>    }<br>    return b<br>}</pre><p><strong>Time Complexity:</strong> O(2^n)<br> <strong>Space Complexity:</strong> O(n) (recursion depth)</p><h3>Approach 2: Memoization (Top-Down DP)</h3><h3>Idea</h3><p>Same recursive logic, but <strong>store results in a map</strong> so we don’t recompute overlapping subproblems.</p><h3>Code (Go)</h3><pre>func memo(i int, nums []int, dp map[int]int) int {<br>    if i &lt; 0 {<br>        return 0<br>    }<br>    if val, ok := dp[i]; ok {<br>        return val<br>    }<br>    dp[i] = max(nums[i] + memo(i-2, nums, dp), memo(i-1, nums, dp))<br>    return dp[i]<br>}<br><br>func maxSumMemo(nums []int) int {<br>    return memo(len(nums)-1, nums, make(map[int]int))<br>}</pre><p><strong>Time Complexity:</strong> O(n)<br> <strong>Space Complexity:</strong> O(n) (map + recursion stack)</p><h3>Approach 3: Tabulation (Bottom-Up DP)</h3><h3>Idea</h3><p>Instead of recursion, build a DP table iteratively:</p><ul><li>dp[i] = max(nums[i] + dp[i-2], dp[i-1])</li></ul><h3>Code (Go)</h3><pre>func maxSumTab(nums []int) int {<br>    n := len(nums)<br>    if n == 0 {<br>        return 0<br>    }<br>    if n == 1 {<br>        return nums[0]<br>    }<br>    dp := make([]int, n)<br>    dp[0] = nums[0]<br>    dp[1] = max(nums[0], nums[1])<br>    for i := 2; i &lt; n; i++ {<br>        dp[i] = max(nums[i] + dp[i-2], dp[i-1])<br>    }<br>    return dp[n-1]<br>}</pre><p><strong>Time Complexity:</strong> O(n)<br> <strong>Space Complexity:</strong> O(n)</p><h3>Approach 4: Space-Optimized DP (Best Solution)</h3><h3>Idea</h3><p>Notice that dp[i] only depends on dp[i-1] and dp[i-2].<br> We can replace the DP array with two variables:</p><h3>Code (Go)</h3><pre>func maxNonAdjacentSum(nums []int) int {<br>    prev2 := 0 // dp[i-2]<br>    prev1 := 0 // dp[i-1]<br>    for _, val := range nums {<br>        current := max(val+prev2, prev1)<br>        prev2 = prev1<br>        prev1 = current<br>    }<br>    return prev1<br>}</pre><p><strong>Time Complexity:</strong> O(n)<br> <strong>Space Complexity:</strong> O(1)</p><h3>Why Interviewers Love Solution #4</h3><ul><li>Same time complexity as DP table: <strong>O(n)</strong></li><li>Minimal space: only two variables instead of O(n)</li><li>No recursion → no stack overflow risk</li><li>Clean and demonstrates understanding of DP optimization</li></ul><h3>Takeaway</h3><p>Watching that mock interview helped me realize something important:<br> <strong>Interviewers aren’t just testing if you can solve the problem — they’re looking for how you optimize and explain your solution.</strong></p><p>If you’re preparing for interviews in Go (or any language), practice taking problems from brute force to optimized step-by-step. This shows not just problem-solving, but growth in thought process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/0*t8Zax3NBZ2dt6bVO" /><figcaption>Go Mascot</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0c2b740d731" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Built a Scalable Article View Count System with Go, PostgreSQL, and Redis: Handling Race…]]></title>
            <link>https://wellisrite.medium.com/how-i-built-a-scalable-article-view-count-system-with-go-postgresql-and-redis-handling-race-ad3dbd069813?source=rss-3b262d55ce69------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad3dbd069813</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[wellisrite]]></dc:creator>
            <pubDate>Sat, 26 Jul 2025 23:47:20 GMT</pubDate>
            <atom:updated>2025-07-27T10:22:22.766Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I Built a Scalable Article View Count System with Go, PostgreSQL, and Redis</h3><p><strong>Tracking article views sounds simple — until it’s not.</strong> When you have thousands of users reading content at the same time, keeping counts accurate and scalable becomes a real challenge.</p><p>At <strong>SIRKA.io</strong>, I had to solve this problem. Here’s how I built a robust view count system in <strong>Golang</strong>, <strong>PostgreSQL</strong>, and <strong>Redis</strong> — and how I handled <strong>race conditions</strong> that could break everything.</p><h3>The Problem: Race Conditions</h3><p>When multiple users view an article simultaneously, every request increments the view count. Without proper handling, increments get lost.</p><p><strong>Example:</strong></p><ul><li>Transaction A reads views = 100</li><li>Transaction B reads views = 100</li><li>Both increment to 101 locally</li><li>Both write back 101</li></ul><p>The result? The count increases by <strong>1</strong> instead of <strong>2</strong>.</p><h3>Step 1: Atomic Updates in PostgreSQL</h3><p>PostgreSQL supports <strong>atomic increments</strong>, which makes the simplest solution straightforward:</p><pre>UPDATE articles<br>SET views = views + 1<br>WHERE id = $1;</pre><p>In Go (using pgx):</p><pre>_, err := db.Exec(ctx, &quot;UPDATE articles SET views = views + 1 WHERE id = $1&quot;, articleID)<br>if err != nil {<br>    log.Fatal(err)<br>}</pre><p>This works well — <strong>until traffic spikes to thousands of requests per second</strong>. At that scale:</p><ul><li>Disk I/O increases</li><li>Transaction logs bloat</li><li>Row locks slow everything down</li></ul><h3>Step 2: Introducing Redis as a Write-Back Cache</h3><p>To scale further, I moved to <strong>Redis</strong> for in-memory counting:</p><ul><li>Use INCR in Redis for atomic increments</li><li>Periodically <strong>flush counts</strong> to PostgreSQL in batches (e.g., every 10 seconds)</li></ul><p><strong>Why Redis?</strong></p><ul><li>Incredibly fast atomic operations</li><li>Reduces database write load</li><li>Keeps user-facing responses fast</li></ul><h3>Step 3: Avoiding Race Conditions in Redis + Flush</h3><p><strong>Is Redis safe from race conditions?</strong><br> Yes — INCR is atomic. Concurrent increments won’t be lost.</p><p><strong>But what about flushing to PostgreSQL?</strong><br> If multiple workers flush the same key, you could double-count. The fix:</p><ul><li>Use <strong>atomic increments</strong> in PostgreSQL during flush:</li></ul><pre>UPDATE articles SET views = views + $count WHERE id = $1;</pre><ul><li>Ensure flushes are <strong>idempotent</strong> so retries won’t corrupt data.</li></ul><h3>Step 4: Putting It All Together (Go Example)</h3><h3>Increment in Redis</h3><pre>func IncrementView(articleID string) error {<br>    return redisClient.Incr(ctx, &quot;article:&quot; + articleID + &quot;:views&quot;).Err()<br>}</pre><h3>Flush Redis to PostgreSQL</h3><pre>func FlushViews() {<br>    keys, err := redisClient.Keys(ctx, &quot;article:*:views&quot;).Result()<br>    if err != nil {<br>        log.Println(&quot;Error fetching keys:&quot;, err)<br>        return<br>    }<br>    for _, key := range keys {<br>      countStr, err := redisClient.Get(ctx, key).Result()<br>      if err != nil {<br>          log.Println(&quot;Error getting count:&quot;, err)<br>          continue<br>      }<br>      count, err := strconv.Atoi(countStr)<br>      if err != nil {<br>          log.Println(&quot;Error parsing count:&quot;, err)<br>          continue<br>      }<br>      parts := strings.Split(key, &quot;:&quot;)<br>      articleID := parts[1]<br>      _, err = db.Exec(ctx, &quot;UPDATE articles SET views = views + $1 WHERE id = $2&quot;, count, articleID)<br>      if err != nil {<br>          log.Println(&quot;DB update error:&quot;, err)<br>          continue<br>      }<br>      redisClient.Del(ctx, key)<br>  }<br>}</pre><h3>Step 5: Preparing for Failures</h3><p>In production, things break. Here’s how I safeguarded the system:</p><ul><li>Enabled <strong>Redis AOF persistence</strong> to survive restarts</li><li>Added <strong>retry logic</strong> for database flushes</li><li>Ensured database updates were <strong>atomic</strong>, so retries were safe</li></ul><h3>Conclusion</h3><p>Scalable and accurate view counting requires:</p><ul><li><strong>Atomic increments</strong> in PostgreSQL</li><li><strong>Redis counters</strong> with periodic flush</li><li><strong>Failure-safe design</strong> for retries and persistence</li></ul><p>This combination allowed us at <strong>SIRKA.io</strong> to handle <strong>millions of views reliably</strong> — without losing a single count.</p><p><a href="https://www.sirka.health/">https://www.sirka.health/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*gpsLz_8z3sZZu4iZk44NRw.png" /><figcaption><a href="https://www.sirka.health/blog/2025/05/26/apakah-penderita-diabetes-boleh-makan-keju-ini-jawabannya/">https://www.sirka.health/blog/2025/05/26/apakah-penderita-diabetes-boleh-makan-keju-ini-jawabannya/</a></figcaption></figure><p>previously known as sirka.io</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad3dbd069813" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Crashed a Closed Beta MMO With 0.2% Auction Fees and a Float Overflow]]></title>
            <link>https://wellisrite.medium.com/how-i-crashed-a-closed-beta-mmo-with-0-2-auction-fees-and-a-float-overflow-bba5d9a2155f?source=rss-3b262d55ce69------2</link>
            <guid isPermaLink="false">https://medium.com/p/bba5d9a2155f</guid>
            <category><![CDATA[software-security]]></category>
            <category><![CDATA[game-test]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cybersecurity-awareness]]></category>
            <dc:creator><![CDATA[wellisrite]]></dc:creator>
            <pubDate>Mon, 14 Jul 2025 17:56:50 GMT</pubDate>
            <atom:updated>2025-07-14T17:56:50.842Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Or: Why you should never share currency across characters with no guardrails</em></p><h3>🗓️ Background</h3><p>During the Closed Beta Test (CBT) of an online MMORPG (which I’ll keep unnamed for now), I discovered a critical exploit involving the game’s auction house, a shared currency pool, and some good old-fashioned float and integer math.</p><p>I submitted the report through their official channels — but got no response. No acknowledgment, no bug bounty. And shortly afterward, the developers <strong>disabled the auction feature entirely</strong>, without explanation.</p><p>So here’s what actually happened.</p><h3>💰 The Setup</h3><p>In this game:</p><ul><li>Every <strong>account has up to 3 characters</strong></li><li>All characters <strong>share the same cash pool</strong></li><li>The auction system allows you to <strong>list and buy items across characters</strong></li><li>The <strong>listing fee is only 0.2%</strong> of the sale price</li><li>Cash appears to be stored as a <strong>32-bit float</strong> (or uint32), based on memory behavior</li></ul><p>Sounds simple enough — until you stack those mechanics together.</p><h3>💥 The Exploit Chain</h3><ol><li>I intentionally inflated my account’s <strong>cash value to 4.2 billion</strong> (near the uint32 limit: 4,294,967,295)</li><li>Using <strong>Character A</strong>, I listed an item for sale in the auction at 500,000 cash<br> → <strong>Fee charged</strong>: 0.2% = <strong>1,000 cash</strong></li><li>Using <strong>Character B</strong> (on the same account), I bought the item<br> → 500,000 was deducted<br> → 500,000 refunded back to the <strong>same shared account cash pool</strong></li></ol><h4>Result:</h4><ul><li>Net cost: 1,000 cash per loop</li><li>But because I was operating near the edge of float/integer boundaries…</li><li><strong>The refund caused rounding, overflow, or NaN</strong></li><li>And eventually: <strong>💣 the server crashed</strong></li></ul><h3>⚠️ Why This Happens</h3><ul><li><strong>32-bit floats lose precision</strong> above ~16.7M (²²⁴)</li><li>At 4.2B, float math like += 500,000 or -= 0.2% can cause:</li><li>Inaccurate values</li><li>Precision loss</li><li><strong>NaN</strong> (Not a Number) or <strong>inf</strong></li><li>Shared cash between characters means the buyer and seller are… you</li></ul><p>This is like laundering money through yourself — and the system couldn’t handle it.</p><h3>🧠 What Should Have Happened?</h3><p>At a minimum:</p><ul><li>The system should prevent buying your own items</li><li>It should <strong>clamp cash values</strong> to a safe range</li><li>It should <strong>check for type safety</strong> before applying auction refunds</li><li>It should have <strong>separate wallets per character</strong></li></ul><p>None of that happened.</p><h3>🔕 What Devs Did Instead</h3><p>After reporting this exploit:</p><ul><li>I received <strong>no response</strong></li><li>A few hours later, the <strong>entire auction system was disabled</strong></li><li>There was <strong>no patch note</strong>, no bug bounty, and no acknowledgment</li></ul><p>So either:</p><p>They saw it, understood it, and quietly panicked</p><p>Or they’re still trying to figure out what I did</p><p>Either way — the silence was louder than a crash log.</p><h3>📉 The Bigger Problem</h3><p>This wasn’t just a neat trick. This kind of logic flaw:</p><ul><li>Crashes entire servers</li><li>Can lead to <strong>economy-breaking exploits</strong></li><li>Often turns into <strong>item dupes</strong> or <strong>infinite money loops</strong></li><li>Can resurface later if the system is re-enabled</li></ul><h3>✅ What I Did Right</h3><ul><li>Documented every step</li><li>Verified memory and float behavior</li><li>Reported through proper CBT channels</li><li>Didn’t go public until after CBT ended</li></ul><p>Even without recognition, this is now part of my real-world security portfolio.</p><h3>🧠 For Game Devs</h3><p>Please:</p><ul><li>Never use float for currency</li><li>Always separate buyer and seller logic</li><li>Cap values and sanitize input/output</li><li>Treat every CBT report like a chance to <strong>avoid a disaster later</strong></li></ul><p>Ignoring security feedback is like taping over a fire alarm.</p><h3>🧑‍💻 Final Words</h3><p>I didn’t do this for clout or chaos — I did it because this kind of vulnerability, if left unchecked, can ruin a live MMO’s economy and reputation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uptwPWxYjeeo3JPHdAz30w.png" /></figure><p>Fix your auction logic. Validate your math. And maybe…<br> Give your hackers a thank-you next time.</p><p>—</p><p>✍️ <em>Sam</em><br> Security hobbyist, MMO enjoyer, Software Engineer</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bba5d9a2155f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>