<?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 Pratikkashyap on Medium]]></title>
        <description><![CDATA[Stories by Pratikkashyap on Medium]]></description>
        <link>https://medium.com/@pratikkashyap07?source=rss-1b95954346ce------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GmI04laIXPlAn5ed</url>
            <title>Stories by Pratikkashyap on Medium</title>
            <link>https://medium.com/@pratikkashyap07?source=rss-1b95954346ce------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 05:25:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pratikkashyap07/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[Beyond the Rewrite — What Still Keeps the System Busy]]></title>
            <link>https://medium.com/@pratikkashyap07/the-architecture-we-didnt-plan-but-eventually-needed-a4abb2c4d1c4?source=rss-1b95954346ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4abb2c4d1c4</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[clickhouse]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[achitecture]]></category>
            <dc:creator><![CDATA[Pratikkashyap]]></dc:creator>
            <pubDate>Fri, 12 Dec 2025 15:38:44 GMT</pubDate>
            <atom:updated>2025-12-12T17:51:15.587Z</atom:updated>
            <content:encoded><![CDATA[<h3>Beyond the Rewrite — What Still Keeps the System Busy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPA-dOS8zqI6-_Cyw3_bBw.png" /></figure><p>At our company, we build a platform that ingests <strong>developer breadcrumbs</strong> — commits, pull requests, issues, forks, page visits, and numerous behavioural signals — from a wide range of sources. These events form the foundation for the <strong>insights, scoring models, and dashboards</strong> we deliver to developer-focused SaaS companies.</p><p>The service I own sits at the heart of this ecosystem. It is responsible for:</p><ul><li>Integrating with heterogeneous activity sources</li><li>Aggregating, enriching, and normalizing activity data</li><li>Computing multi-tenant metrics</li><li>Powering the analytics experience for end customers</li></ul><p>Over time, this service evolved dramatically. What began as a simple real-time orchestrator eventually became a full-scale distributed computation engine — after going through several stages of growth, stress, architectural limitations, and ultimately a complete redesign.</p><p>This is the story of how we got there.</p><h3>🟦 Phase 1 — Real-Time Fetching: When Simplicity Worked… Until It Didn’t</h3><p>Our earliest version relied on <strong>real-time data pulls</strong> from external activity sources.<br>For a small customer base, this model was acceptable. Latency was manageable, and the multi-tenant nature didn’t impose significant stress.</p><p>However, as our data footprint grew — and since historical data is integral to our scoring models — we were unable to archive anything. This meant:</p><ul><li>API calls became heavier</li><li>Queries became slower</li><li>Aggregations became increasingly memory-bound</li><li>Customers began noticing delays</li></ul><p>It became clear that real-time aggregation was not sustainable.</p><p>Architecturally, we had hit the first inflection point.</p><h3>🟦 Phase 2 — Precomputation: Introducing a Scheduler at Scale</h3><p>To solve latency issues, we introduced a <strong>precomputation scheduler</strong>:</p><ul><li>Hundreds of scheduled computations per tenant</li><li>Tens of thousands of events per minute</li><li>Complex Java-based data aggregation flows</li><li>A multi-source enrichment pipeline</li></ul><p>The scheduler fetched raw data, processed it, and persisted computed metrics so that our dashboards delivered an instantaneous experience.</p><p>To improve throughput, we layered <strong>Redis</strong> as a high-speed cache for our activity sources.</p><p>And for a while, the performance gains were meaningful.</p><h4>❌ The Redis Bottleneck: Size Limits Are Very Real</h4><p>Eventually, Redis itself became a constraint:</p><ul><li>Individual data sources produced datasets too large for single keys</li><li>Splitting data across keys introduced fragmentation</li><li>Fetching distributed fragments increased latency</li><li>Memory usage spiked disproportionately</li></ul><p>Caching helped the system — but also complicated it.</p><p>We had solved one bottleneck and created another.</p><h3>🟦 Phase 3 — Consolidation in Postgres: A Unified Activity Table</h3><p>Our next attempt was to simplify the architecture:</p><ul><li>We consolidated all activity events into a <strong>single unified Postgres table</strong></li><li>Added dynamic indexes and partitioning strategies</li><li>Reduced dependency on Redis</li><li>Pulled data into memory for on-the-fly computation</li></ul><p>This gave us predictable semantics and improved consistency.</p><p>But with rapid customer growth came the next set of problems.</p><h4>❌ Postgres Couldn’t Keep Up</h4><p>A multi-tenant analytics workload is extremely read-heavy and write-heavy at the same time.</p><p>We soon ran into:</p><ul><li>Index bloat</li><li>High I/O wait times</li><li>Insufficient memory for index caching</li><li>Constant disk pressure</li><li>Query plans growing more expensive over time</li></ul><p>We optimized vertically:</p><ul><li>Larger machines</li><li>More RAM</li><li>More CPU</li></ul><p>We optimized horizontally:</p><ul><li>Added more Java workers</li><li>Expanded heap sizes</li><li>Rewrote query logic</li></ul><p>But these were temporary fixes.<br>The infrastructure bill began surpassing monthly revenue.</p><p>That was the moment we knew the existing architecture had reached its limits.</p><h3>🟦 Phase 4 — A Paradigm Shift: Migrating to ClickHouse + Go</h3><p>After evaluating multiple analytical databases, <strong>ClickHouse</strong> stood out immediately:</p><ul><li>Columnar storage designed for analytical workloads</li><li>Extremely fast scans and aggregations</li><li>Efficient compression and low storage footprint</li><li>Ability to handle billions of rows gracefully</li></ul><p>The architectural alignment was almost perfect.</p><p>We decided not only to migrate the database — but to completely <strong>rethink the computation layer</strong>.</p><p>This was the point at which we rewrote the service in <strong>Go</strong>:</p><ul><li>Lower memory overhead than Java</li><li>Better concurrency primitives</li><li>Higher throughput for I/O–compute mixed workloads</li><li>More deterministic performance behavior</li></ul><p>The biggest shift, however, was conceptual:</p><h4>Earlier</h4><p>We fetched large volumes of activity data into memory and computed metrics at the application layer.</p><h4>Now</h4><p>We generate <strong>dynamic, multi-hundred-line ClickHouse queries</strong> that push computation directly into the database engine — where the architecture is purpose-built for such workloads.</p><p>This change alone transformed the system’s performance characteristics.</p><h3>⚡ The Outcome — Orders of Magnitude Faster</h3><p>Post-migration, the improvements were substantial:</p><ul><li>Query times reduced by <strong>10x to 50x</strong></li><li>Scheduler throughput dramatically increased</li><li>Postgres load dropped to near zero</li><li>Redis usage almost vanished</li><li>Infrastructure cost dropped significantly</li><li>Dashboards began feeling “instant” even at scale</li></ul><p>It was the architectural payoff we needed.</p><h3>🧠 “Why didn’t you start with ClickHouse from Day 1?”</h3><p>A question we’ve been asked many times.</p><p>The honest answer is simple:</p><blockquote><strong><em>Early architecture should be pragmatic, not predictive.<br> You build only what you need at the stage you’re in.</em></strong></blockquote><p>Adopting ClickHouse from day one would have required:</p><ul><li>Unnecessary upfront complexity</li><li>High engineering cost</li><li>Premature assumptions about scale</li><li>Longer time-to-market</li></ul><p>We were not inexperienced; we were practical.<br> You evolve architecture as scale evolves.</p><p>Some may call it an immature approach, but in reality, it reflects a fundamental truth of building real systems:</p><p><strong>You cannot design a v10 architecture when you are still validating v1.</strong></p><h3>👊🏻 Current Challenges — Because No System Is Ever “Done”</h3><p>ClickHouse is exceptional, but it introduces its own considerations:</p><ul><li>Updates are not straightforward (append-only model)</li><li>Write-heavy + read-heavy workloads require careful schema design</li><li>MergeTree tuning is non-trivial</li><li>Distributed clusters require operational maturity</li></ul><p>We are still refining our architecture, and we continue to learn.<br> But the foundation is now robust, scalable, and deeply aligned with our workload.</p><h3>🏁 Final Thoughts</h3><p>This journey reinforced several architectural truths:</p><ul><li><strong>Systems must evolve, not remain static</strong></li><li><strong>Refactoring is a sign of maturity, not failure</strong></li><li><strong>Caching is not a cure-all — sometimes it conceals deeper issues</strong></li><li><strong>Database architecture matters more than application code for analytical workloads</strong></li><li><strong>The right technology, introduced at the right time, changes everything</strong></li></ul><p>Today, our Go + ClickHouse–powered pipeline delivers the reliability, speed, and elasticity we always aimed for.<br> And tomorrow, we’ll keep iterating — because scale never stops teaching.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4abb2c4d1c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>