<?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 Rifat on Medium]]></title>
        <description><![CDATA[Stories by Rifat on Medium]]></description>
        <link>https://medium.com/@rifatcse09?source=rss-f3dfc7572ab8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xxj--JQcXntGfMZ6_c8DdQ.jpeg</url>
            <title>Stories by Rifat on Medium</title>
            <link>https://medium.com/@rifatcse09?source=rss-f3dfc7572ab8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 14:44:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rifatcse09/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[SQL Reporting at Scale: Functions vs Procedures vs Views vs Materialized Views]]></title>
            <link>https://rifatcse09.medium.com/sql-reporting-at-scale-functions-vs-procedures-vs-views-vs-materialized-views-08f242df8981?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/08f242df8981</guid>
            <category><![CDATA[database-optimization]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[tech-lead]]></category>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Mon, 13 Apr 2026 13:21:09 GMT</pubDate>
            <atom:updated>2026-04-13T13:21:09.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-52-bPlcmIj_cOsPaR-6EA.png" /></figure><p>When you’re first building an app, a simple SELECT * FROM orders works fine. But as your data grows from thousands to millions of rows, those pretty dashboards start to hang. Suddenly, your &quot;simple&quot; reporting view takes 30 seconds to load, and your users are refreshing the page in frustration.</p><p>Choosing the right database abstraction isn’t just about clean code it’s about survival at scale. Here is the architectural blueprint for building high-performance reporting systems.</p><h3>The Toolbox: Functions, Procedures, and Views</h3><p>Before we look at the strategy, let’s clarify the tools. Most developers misuse these, leading to massive performance bottlenecks.</p><h3><strong>1. Function:</strong></h3><p><strong>Reusable logic/calculations that return a value</strong>. Best for calculations inside queries.<br>Not suitable for large reporting.</p><p>Ex: (Price * Tax) calculations within a row.</p><pre>CREATE OR REPLACE FUNCTION fn_calculate_total_price(<br>    price DECIMAL, <br>    tax_rate DECIMAL<br>) <br>RETURNS DECIMAL AS $$<br>BEGIN<br>    -- Ensure we don&#39;t return NULL if data is missing<br>    RETURN ROUND(COALESCE(price, 0) * (1 + COALESCE(tax_rate, 0) / 100), 2);<br>END;<br>$$ LANGUAGE plpgsql IMMUTABLE;</pre><p>Usage</p><pre>SELECT <br>    id, <br>    product_name, <br>    price, <br>    tax_rate,<br>    𝐟𝐧_𝐜𝐚𝐥𝐜𝐮𝐥𝐚𝐭𝐞_𝐭𝐨𝐭𝐚𝐥_𝐩𝐫𝐢𝐜𝐞(price, tax_rate) AS total_with_tax<br>FROM products;</pre><p>As a backend engineer, you likely want to integrate this with an ORM or a Query Builder. Here is how you would handle it in a <strong>NestJS/Node.js</strong> environment using <strong>TypeORM</strong> or <strong>Knex</strong>.</p><h4>Using TypeORM (Query Builder)</h4><p>By using the database function, you offload the computation to the DB engine, which is highly efficient at handling arithmetic across large datasets.</p><pre>async getProductList() {<br>  return await this.productRepository<br>    .createQueryBuilder(&#39;product&#39;)<br>    .select([<br>      &#39;product.id&#39;,<br>      &#39;product.name&#39;,<br>      &#39;product.price&#39;,<br>      // Calling the DB function directly in the select statement<br>      &#39;fn_calculate_total_price(product.price, product.tax_rate) AS total_price&#39;<br>    ])<br>    .getRawMany();<br>}</pre><h4>Key points</h4><ul><li>Must return something</li><li>Can be used in SELECT, WHERE, JOIN</li><li>No side effects ideally (pure logic)</li></ul><h4>When to use</h4><ul><li>Reusable business logic</li><li>Calculations inside queries</li><li>Derived values</li></ul><h4>Why this matters for Scale</h4><ol><li><strong>Consistency:</strong> If the tax logic changes (e.g., adding a luxury tax floor), you update one SQL function instead of hunting through five different microservices.</li><li><strong>Computed Columns:</strong> You can use this function to create a <strong>Generated Column</strong> in your table. This allows the database to store the value physically and index it, making searches for “products under $50 (including tax)” incredibly fast.</li><li><strong>Reduced Payload:</strong> The backend receives the final, rounded value directly, reducing the need for post-processing logic in your service layer.</li></ol><h3><strong>2. Stored Procedure</strong></h3><ul><li>Executes a set of operations</li><li>May or may not return a value</li><li>Supports transactions (commit/rollback)</li></ul><pre>CREATE PROCEDURE update_salary(emp_id INT, new_salary NUMERIC)<br>LANGUAGE plpgsql<br>AS $$<br>BEGIN<br>  UPDATE employees SET salary = new_salary WHERE id = emp_id;<br>END;<br>$$;</pre><p>Usage</p><pre>CALL update_salary(1, 5000);</pre><h4>Key points</h4><ul><li>Called using CALL</li><li>Can modify data</li><li>Supports transaction control</li></ul><h4>When to use</h4><ul><li>Complex workflows</li><li>Batch processing</li><li>Data updates with logic</li></ul><h3><strong>3. View</strong></h3><p>A <strong>view</strong> is a <strong>virtual table</strong>:</p><ul><li>Based on a SQL query</li><li>Does NOT store data</li><li>Always reflects the latest data</li></ul><pre>CREATE VIEW active_users AS<br>SELECT id, name FROM users WHERE status = &#39;active&#39;;</pre><p>Usage</p><pre>SELECT * FROM active_users;</pre><h4>Key points</h4><ul><li>No storage</li><li>Always real-time</li><li>Simplifies complex queries</li></ul><h4>When to use</h4><ul><li>Abstraction layer</li><li>Security (hide columns)</li><li>Reusable query logic</li></ul><h4>The “View” Trap</h4><p>A standard <strong>View</strong> is just a saved query. Every time you call it, the database runs the entire logic from scratch. If your report joins five tables and aggregates a million rows, a View will force the CPU to do that heavy lifting every single time a user clicks “Refresh.”</p><h3>4. Materialized View</h3><ul><li>Stores the query result physically</li><li>Needs manual/auto refresh</li><li>Faster reads</li></ul><pre>CREATE MATERIALIZED VIEW sales_summary AS<br>SELECT product_id, SUM(amount) as total<br>FROM sales<br>GROUP BY product_id;</pre><p>Refresh:</p><pre>REFRESH MATERIALIZED VIEW sales_summary;</pre><p><strong>Large report + many dynamic filters:</strong></p><ul><li>date range</li><li>status</li><li>user</li><li>region</li><li>product</li><li>custom conditions</li></ul><p>A <strong>single materialized view is NOT enough</strong> because:</p><ul><li>You can’t precompute every filter combination</li><li>It becomes huge and inefficient</li></ul><p>You combine:</p><h3>Materialized View + Base Tables + Indexing</h3><h3>1. Pre-aggregate only stable dimensions</h3><p>Create a materialized view for <strong>common heavy aggregations</strong>, not all filters.</p><pre>CREATE MATERIALIZED VIEW sales_base AS<br>SELECT <br>  DATE(created_at) as day,<br>  product_id,<br>  region_id,<br>  SUM(amount) as total_sales,<br>  COUNT(*) as total_orders<br>FROM orders<br>GROUP BY day, product_id, region_id;</pre><h3>2. Apply dynamic filters at query time</h3><pre>SELECT *<br>FROM sales_base<br>WHERE day BETWEEN &#39;2026-01-01&#39; AND &#39;2026-01-31&#39;<br>  AND region_id = 2<br>  AND product_id = 10;</pre><p>So:</p><ul><li>heavy aggregation → precomputed</li><li>filters → applied dynamically</li></ul><h3>3. Add indexes on materialized view</h3><p>Critical for filter performance:</p><pre>CREATE INDEX idx_sales_base_filters<br>ON sales_base (day, region_id, product_id);</pre><h3>4. For highly dynamic filters</h3><p>If filters are too flexible (e.g., 10+ combinations):</p><p>Use:</p><ul><li>Materialized view for <strong>core aggregation</strong></li><li>Join with <strong>original tables</strong> for rare filters</li></ul><p>Example:</p><pre>SELECT sb.*, u.segment<br>FROM sales_base sb<br>JOIN users u ON u.id = sb.user_id<br>WHERE u.segment = &#39;premium&#39;;</pre><h3>5. Advanced Production Strategy</h3><p>For real systems:</p><h3>Option A: Partitioned tables</h3><ul><li>Partition by date</li><li>Filters become faster automatically</li></ul><h3>Option B: OLAP / Data warehouse</h3><ul><li>BigQuery / ClickHouse / Redshift</li><li>Designed for multi-filter analytics</li></ul><h3>Option C: Caching layer</h3><ul><li>Redis for repeated filter queries</li></ul><h3>When Materialized View is NOT enough</h3><p>If:</p><ul><li>filters are unpredictable</li><li>near real-time needed</li><li>data is massive (billions)</li></ul><p>Then:<br> → Use <strong>OLAP database instead of PostgreSQL</strong></p><h3><strong>OLAP </strong>(Online Analytical Processing)</h3><ul><li>ClickHouse (real-time analytics, very fast)</li><li>BigQuery (serverless, managed)</li><li>Amazon Redshift (AWS ecosystem)</li></ul><h4>Use OLAP when:</h4><ul><li>Data is huge (millions → billions)</li><li>Reports have many filters</li><li>Dashboards need fast response</li><li>Queries are complex (GROUP BY, joins)</li></ul><h3>Key Insight (Important)</h3><p>Think like this:</p><ul><li>Materialized View = reduce computation</li><li>Index = speed up filtering</li><li>Partition = reduce scan size</li><li>OLAP = handle extreme scale</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=08f242df8981" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Choosing the Right API: REST vs GraphQL vs gRPC vs tRPC (Simple Guide)]]></title>
            <link>https://rifatcse09.medium.com/choosing-the-right-api-rest-vs-graphql-vs-grpc-vs-trpc-simple-guide-888cade5780b?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/888cade5780b</guid>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Thu, 19 Mar 2026 09:11:00 GMT</pubDate>
            <atom:updated>2026-03-19T09:11:00.433Z</atom:updated>
            <content:encoded><![CDATA[<p>When building modern applications, one question always comes up:</p><p>👉 <em>Which API style should I use?</em></p><p>REST? GraphQL? gRPC? tRPC?</p><p>The truth is:</p><p>👉 <strong>There is no “best” API — only the right one for your use case.</strong></p><p>Let’s break it down simply.</p><h3>1. REST — The Default Choice</h3><p>REST is the most common API style.</p><p>Example:</p><pre>GET /users/1<br>POST /orders</pre><h4>Why people use REST:</h4><ul><li>Simple and easy to understand</li><li>Works everywhere</li><li>Great for public APIs</li></ul><h4>Problems:</h4><ul><li>Over-fetching or under-fetching data</li><li>Multiple API calls for complex UI</li></ul><p>👉 REST is still the safest and most reliable choice for most projects</p><h3>2. GraphQL — Flexible Data Fetching</h3><p>GraphQL lets the client request exactly what it needs.</p><p>Example:</p><pre>Get only name and email of user</pre><h4>Why use GraphQL:</h4><ul><li>No over-fetching</li><li>One request for complex data</li><li>Strong schema</li></ul><h4>Trade-offs:</h4><ul><li>More complex setup</li><li>Requires careful design</li></ul><p>👉 Best for apps with complex UI and multiple data sources</p><h3>3. gRPC — High Performance for Microservices</h3><p>gRPC is a fast RPC system created by Google.</p><p>It uses:</p><ul><li>Protocol Buffers (binary, not JSON)</li><li>HTTP/2</li></ul><h4>Why use gRPC:</h4><ul><li>Very fast</li><li>Strong contract with .proto files</li><li>Supports streaming</li></ul><h4>Trade-offs:</h4><ul><li>Harder to debug</li><li>Not ideal for browsers</li></ul><p>👉 Best for internal microservices communication</p><h3>4. tRPC — Type Safety for TypeScript</h3><p>tRPC lets you call backend functions directly from the frontend.</p><p>Example:</p><pre>user.getById({ id: 1 })</pre><h4>Why use tRPC:</h4><ul><li>End-to-end type safety</li><li>No API schema needed</li><li>Fast development</li></ul><h4>Trade-offs:</h4><ul><li>Only works with TypeScript</li><li>Not ideal for public APIs</li></ul><p>👉 Best for internal tools and full-stack TypeScript apps</p><h3>5. So… Which One Should You Choose?</h3><p>Here’s the simplest way to decide:</p><pre>REST     → Simple APIs, public APIs<br>GraphQL  → Complex frontend, flexible data<br>gRPC     → Microservices, high performance<br>tRPC     → Full-stack TypeScript apps</pre><h3>6. Real-World Architecture (Important)</h3><p>In real systems, you don’t choose just one.</p><p>You combine them:</p><pre>Frontend → REST / GraphQL (API Gateway)<br>Backend  → gRPC (service-to-service)<br>Internal → tRPC (admin/dashboard tools)</pre><p>👉 The best systems use multiple communication styles together.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=888cade5780b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Access Token vs Refresh Token: Where to Store Them Securely (Without Breaking UX)]]></title>
            <link>https://rifatcse09.medium.com/access-token-vs-refresh-token-where-to-store-them-securely-without-breaking-ux-fab5169506c3?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/fab5169506c3</guid>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[bearer-token]]></category>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Wed, 18 Mar 2026 05:47:49 GMT</pubDate>
            <atom:updated>2026-03-18T05:47:49.539Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UDEkYq3sBQqv9rHRDnZyxg.png" /></figure><p>If you are building a modern SaaS or web application, you’ve probably heard:</p><ul><li>Use access tokens</li><li>Use refresh tokens</li><li>Avoid localStorage</li></ul><p>But the confusion usually starts here:</p><p>👉 Where should I store them?<br>👉 Will the user get logged out on page refresh?<br>👉 How do I keep it both secure and user-friendly?</p><p>Let’s break it down in a simple, real-world way.</p><h3>1. The Two Tokens (Simple Idea)</h3><h4>Access Token</h4><ul><li>Short-lived (10–15 minutes)</li><li>Used for API requests</li><li>Sent in headers</li></ul><pre>Authorization: Bearer &lt;access_token&gt;</pre><h4>Refresh Token</h4><ul><li>Long-lived (days/weeks)</li><li>Used only to generate new access tokens</li><li>Should be highly protected</li></ul><h3>2. The Common Mistake</h3><p>A lot of developers do this:</p><pre>localStorage → access token  <br>localStorage → refresh token</pre><p>Problem:</p><ul><li>JavaScript can access localStorage</li><li>If your app has XSS, an attacker can steal tokens</li></ul><p>👉 Not safe for production apps</p><h3>3. The Best Practice (Modern Approach)</h3><h4>Store tokens like this:</h4><ul><li>Access Token → memory (React state/variable)</li><li>Refresh Token → HttpOnly cookie</li></ul><h3>4. Why This Works</h3><h4>Access Token in Memory</h4><ul><li>Not persisted</li><li>Harder to steal via XSS</li><li>Automatically cleared on page reload</li></ul><h4>Refresh Token in HttpOnly Cookie</h4><ul><li>Not accessible via JavaScript</li><li>Automatically sent by browser</li><li>Secure against XSS</li></ul><p>Example cookie:</p><pre>HttpOnly<br>Secure<br>SameSite=Strict<br>Path=/auth/refresh</pre><p>👉 Important: restrict it to /auth/refresh</p><h3>5. “Wait… If Access Token is in Memory, won’t the user log out on Refresh?”</h3><p>Yes… but also no 🙂</p><p>Here’s what actually happens:</p><h4>Step-by-step:</h4><ol><li>User logs in</li><li>Access token → stored in memory</li><li>Refresh token → stored in cookie</li></ol><h4>Now the user refreshes the page</h4><ul><li>Memory is cleared → <strong>access token is gone</strong></li><li>But the <strong>refresh token cookie still exists</strong></li></ul><p>App startup flow</p><pre>App loads<br>→ Call /auth/refresh<br>→ Browser automatically sends refresh cookie<br>→ Server validates it<br>→ New access token is issued<br>→ User stays logged in</pre><p>👉 This is called <strong>silent authentication</strong></p><h3>6. Important Detail About Cookies</h3><p>By default, cookies are sent with every request.</p><p>But you should configure it like this:</p><pre>Set-Cookie: refreshToken=xyz;<br>HttpOnly;<br>Secure;<br>SameSite=Strict;<br>Path=/auth/refresh</pre><h3>Result:</h3><ul><li>Cookie is ONLY sent to:</li></ul><pre>/auth/refresh</pre><ul><li>NOT sent to:</li></ul><pre>/orders<br>/users<br>/products</pre><p>👉 This reduces exposure and improves security</p><h3>7. Full Flow (Production Ready)</h3><pre>1. Login<br>Client → /auth/login<br>→ access token (response)<br>→ refresh token (cookie)<br><br>2. API Call<br>Client → /orders<br>Authorization: Bearer access_token<br><br>3. Access token expires<br>Client → /auth/refresh<br>(cookie auto sent)<br><br>4. Server returns new access token</pre><h3>8. Extra Security Tips</h3><h4>Use short-lived access tokens</h4><ul><li>10–15 minutes</li></ul><h4>Rotate refresh tokens</h4><ul><li>Issue new refresh token on every refresh</li><li>Invalidate old one</li></ul><h4>Always use HTTPS</h4><ul><li>Never send tokens over HTTP</li></ul><h4>Use HttpOnly + Secure cookies</h4><ul><li>Prevent JavaScript access</li><li>Protect from XSS</li></ul><h3>9. Simple Mental Model</h3><ul><li>Access Token = temporary key</li><li>Refresh Token = master key</li></ul><p>👉 Keep the master key hidden (HttpOnly cookie)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fab5169506c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Scale a Million-Row Database on a $0 Budget]]></title>
            <link>https://rifatcse09.medium.com/how-to-scale-a-million-row-database-on-a-0-budget-1f10871a0cd9?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f10871a0cd9</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Wed, 11 Mar 2026 05:00:52 GMT</pubDate>
            <atom:updated>2026-03-11T05:00:52.718Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rs8__Hy7mDZ1Tk0-IxbSww.png" /></figure><p>We’ve all been there. You’re looking at a legacy system with millions of rows. Day by day, the query times are creeping up. The dashboard is laggy, and users are complaining.</p><p>In a perfect world, you’d split it into microservices, shard the database, or at least click “Auto-scale” in your cloud console. But in the real world? <strong>There is no budget for higher server costs, and the architecture is locked.</strong></p><p>If you can’t scale <strong>out</strong>, you have to scale <strong>deep</strong>. Here is the high-performance checklist for optimizing a massive database on a shoestring budget.</p><h3>1. Stop the “Full Table Scan” Nightmare</h3><p>When a database grows to millions of rows, a single missing index is a death sentence.</p><ul><li><strong>The Composite Index Win:</strong> If your application frequently filters by multiple columns (e.g., status AND created_at), a single index on (status, created_at) is drastically faster than two separate ones.</li><li><strong>Covering Indexes:</strong> Try to include all the columns your query needs in the index itself. This allows the DB to perform an <strong>Index-Only Scan</strong>, meaning it never has to touch the actual table on the disk.</li></ul><blockquote><strong><em>Pro Tip:</em></strong><em> Use </em><em>EXPLAIN ANALYZE on your slowest queries. If you see &quot;Seq Scan&quot; (Sequential Scan) on a table with 10M rows, you’ve found your primary culprit.</em></blockquote><h3>2. Implement a “Cold Storage” Strategy</h3><p>Does your system really need to keep 2019’s log data in the same table as today’s transactions? Probably not.</p><ul><li><strong>Data Archiving:</strong> Move historical data to a “History” or “Archive” table. This keeps your primary “Hot” table lean. Smaller tables mean smaller indexes, which fit better into the server’s <strong>RAM (Buffer Pool)</strong>.</li><li><strong>Partitioning:</strong> If your DB supports it, use <strong>Horizontal Partitioning</strong> (e.g., by month). The engine will automatically ignore partitions that don’t match your query’s date range, saving massive amounts of I/O.</li></ul><h3>3. The Art of “Smart” Denormalization</h3><p>We are taught in school to “Normalize until it hurts.” In high-scale systems, <strong>Normalization is what causes the hurt.</strong></p><p>If a query requires joining five massive tables just to show a username on a receipt, consider <strong>denormalization</strong>. Copy the user_name directly into the orders table. Yes, you have redundant data, but you’ve traded a tiny bit of disk space for a massive jump in query speed.</p><h3>4. Offload the Work from the DB</h3><p>If you can’t make the database faster, make it do less work.</p><p><strong>Materialized Views</strong>: Pre-calculates heavy aggregates (SUM/AVG) so the query is instant.</p><p><strong>Application Caching:</strong> Use local memory or a small Redis instance to store “static” results for 5 minutes.</p><p><strong>Connection Pooling:</strong> Reuses database connections to avoid the high overhead of opening new ones.</p><p><strong>Batch Processing:</strong> Instead of 1,000 tiny inserts, do one big batch insert. It’s significantly easier on the disk.</p><h3><strong>5. The “Read-Write” Split (Replication)</strong></h3><p>If your database is slow because too many people are trying to read data while others are trying to save it, <strong>Replication</strong> is your secret weapon.</p><ul><li><strong>The Master-Slave Setup:</strong> You keep your primary database (the Master) for <strong>INSERT, UPDATE, and DELETE</strong> queries. You then create one or more “Followers” (Slaves) that copy the data in real-time.</li><li><strong>Offloading the Reads:</strong> Move all your heavy “Read” traffic like generating reports, loading user profiles, or search queries to the Follower.</li><li><strong>Why it works:</strong> This prevents “Locking” issues where a big report stops a user from completing a purchase. It’s like opening a second checkout lane in a grocery store without building a whole new building.</li></ul><pre>+-----------------+---------------------------+------------+-----------------------+<br>| Strategy        | Primary Benefit           | Server Cost| Implementation Effort |<br>+-----------------+---------------------------+------------+-----------------------+<br>| 1. Indexing     | Speeds up specific reads  | $0         | Low (Immediate)       |<br>| 2. Replication  | Offloads Read traffic     | Low/Zero   | Medium                |<br>| 3. Archiving    | Shrinks &quot;Hot&quot; table size  | $0         | Medium (Scripting)    |<br>| 4. Partitioning | Faster scans on big data  | $0         | High (Schema change)  |<br>| 5. Caching      | Skips the DB entirely     | $0         | Medium                |<br>+-----------------+---------------------------+------------+-----------------------+</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f10871a0cd9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Distributed Systems vs Microservices vs Event Driven Architecture]]></title>
            <link>https://rifatcse09.medium.com/distributed-systems-vs-microservices-vs-event-driven-architecture-993108f05306?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/993108f05306</guid>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Tue, 10 Mar 2026 09:45:20 GMT</pubDate>
            <atom:updated>2026-03-10T09:45:20.032Z</atom:updated>
            <content:encoded><![CDATA[<p>Many engineers confuse these three terms. They are often used together, but they describe different things. Understanding the difference makes system design discussions much easier.</p><h3><strong>First idea: Distributed System</strong></h3><p>A distributed system is a system that runs on multiple machines or processes and communicates<strong> over a network</strong>.</p><p>Instead of everything running in one application server, different components run separately.</p><p>A distributed system answers one question:<br>Where does the system run?</p><p><strong>If parts of the system run on different machines, it is a distributed system.</strong></p><p>Example architecture:</p><p>Client → API Server → Redis → Database → Worker</p><h3><strong>Second idea: Microservices Architecture</strong></h3><p>Microservices describe how the application is structured.</p><p>Instead of one large codebase that handles everything, the system is split into smaller services. Each service handles a specific business responsibility.</p><p>Example services</p><p>1. User Service<br> 2. Order Service<br> 3. Payment Service<br> 4. Notification Service</p><p>Each service can be deployed independently and often manages its own data.</p><p>Key point</p><p>Microservices answer this question:<br><strong>How is the system divided?</strong></p><p>Important fact</p><blockquote>All microservices systems are distributed systems.<br>But not all distributed systems are microservices.</blockquote><p>Example :</p><p><strong>A large Laravel application running on many servers behind a load balancer is distributed. But it is still a monolith.</strong></p><h3><strong>Third idea: Event Driven Architecture</strong></h3><p>Event driven architecture describes how components communicate.</p><p>Instead of one service calling another directly and waiting for a response, services communicate through events.</p><p><strong>Example events:</strong></p><ol><li>OrderCreated</li><li>UserRegistered</li><li>PaymentSucceeded</li></ol><p><strong>A service publishes an event. Other services subscribe and react to that event.</strong></p><p>Example flow:</p><blockquote>Order Service publishes OrderCreated</blockquote><blockquote>1. Notification Service sends email<br>2. Analytics Service records metrics<br>3. Inventory Service updates stock</blockquote><p>No service needs to directly call another.<br><strong>How do components communicate?</strong></p><p>Typical technologies:</p><ol><li>Kafka</li><li>RabbitMQ</li><li>Redis Streams</li><li>AWS SNS/SQS</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=993108f05306" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redis Caching at Scale: How to Protect Your Database]]></title>
            <link>https://rifatcse09.medium.com/redis-caching-at-scale-how-to-protect-your-database-9e88560611e7?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e88560611e7</guid>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Fri, 06 Mar 2026 17:16:56 GMT</pubDate>
            <atom:updated>2026-03-11T03:32:56.887Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H8VpnhziEOzYcVOKM5DwAg.png" /></figure><p>At first glance, Redis caching feels obvious:</p><pre>If data exists in cache → return it  <br>Else → fetch from DB → store in cache</pre><p>This works fine for small systems.</p><p>But once traffic grows, <strong>bad caching design can crash your database</strong>.</p><p>The real job of Redis is not only to make systems faster it is to <strong>shield the database when traffic spikes or failures happen</strong>.</p><p>To design caching correctly, you must understand three major failure scenarios.</p><h3>The Mental Model</h3><pre>Client Request<br>       │<br>       ▼<br>┌──────────────┐<br>│ Bloom Filter │  ← block impossible keys<br>└──────┬───────┘<br>       │<br>       ▼<br>┌──────────────┐<br>│  Redis Cache │  ← fast access layer<br>└──────┬───────┘<br>       │<br>       ▼<br>┌──────────────┐<br>│   Database   │  ← source of truth<br>└──────────────┘</pre><p>Three things can break this chain. Let’s walk through each.</p><h3>1. Cache Penetration: The Invalid Key Attack</h3><p>Cache penetration happens when users repeatedly request <strong>data that does not exist</strong>.</p><p>Example request:</p><pre>Request (user:99999999)<br>     │<br>     ▼<br>Redis → MISS<br>     │<br>     ▼<br>DB   → MISS<br>     │<br>     ▼<br>404 returned<br>     │<br>(bot sends 10,000 more...)</pre><p>If a bot sends thousands of these requests, the system becomes:</p><pre>Redis miss → DB miss → repeat</pre><p>Eventually the <strong>database becomes overloaded</strong>.</p><h3>Fix A : Cache the Null</h3><p>If the DB returns nothing, store a null marker in Redis.</p><pre>key:   user:99999999<br>value: NULL<br>TTL:   60 seconds</pre><p>Next request hits Redis, sees NULL, returns 404 immediately. DB never touched.</p><h3>Fix B — Bloom Filter (Better at Scale)</h3><p>A Bloom Filter is a <strong>fast membership check</strong> that sits before Redis.</p><p>Architecture:</p><pre>Client Request<br>      ↓<br>Bloom Filter<br>      ↓<br>Redis Cache<br>      ↓<br>Database</pre><p>The Bloom Filter checks whether a key could exist.</p><p>It only returns two answers:</p><pre>Definitely NOT present<br>Maybe present</pre><p>If the filter says <strong>“definitely not present”</strong>, the request stops immediately.</p><p>This prevents invalid keys from reaching Redis or the database.</p><h3>2. Cache Breakdown (Hot Key Problem)</h3><p>Cache breakdown happens when <strong>a very popular key expires</strong>.</p><p>Example:</p><pre>product:iphone15</pre><p>Millions of users request this product page.</p><p>If the Redis cache expires, suddenly every request hits the database.</p><p>Flow:</p><pre>1M users<br>↓<br>Redis miss<br>↓<br>1M DB queries</pre><p>The database collapses instantly.</p><h3>How to fix Cache Breakdown</h3><h3>1. Mutex Lock</h3><p>Only allow <strong>one request to rebuild the cache</strong>.</p><p>Flow:</p><pre>Cache miss<br>   ↓<br>Acquire distributed lock<br>   ↓<br>Fetch data from DB<br>   ↓<br>Update cache</pre><p>Other requests wait or retry.</p><p>This reduces:</p><pre>1M DB queries → 1 DB query</pre><h3>2. Logical Expiration</h3><p>Instead of deleting cache when TTL expires, store expiration inside the data.</p><p>Example:</p><pre>{<br>  data: product_data,<br>  expire_time: 10:30PM<br>}</pre><p>If expired:</p><pre>Serve old data<br>Refresh cache in background</pre><p>Users never hit the database directly.</p><h3>3. Cache Avalanche</h3><p>Cache avalanche occurs when <strong>many cache keys expire at the same time</strong>.</p><p>Example:</p><pre>10,000 keys<br>TTL = 1 hour</pre><p>After exactly one hour:</p><pre>10,000 cache misses<br>↓<br>10,000 DB queries</pre><p>The database becomes overloaded.</p><h3>How to fix Cache Avalanche</h3><h3>1. Randomize TTL</h3><p>Instead of identical expiration times:</p><pre>TTL = 3600 seconds</pre><p>Use random variation:</p><pre>TTL = 3600 + random(0–300)</pre><p>Keys expire gradually instead of all at once.</p><h3>2. Rate Limiting</h3><p>Limit the number of requests that can reach the database.</p><p>Example:</p><pre>max 100 DB queries per second</pre><p>Extra requests can return fallback responses.</p><h3>3. Graceful Degradation</h3><p>If systems are overloaded, return partial or stale responses instead of crashing.</p><p>Example:</p><pre>&quot;Service temporarily unavailable&quot;</pre><p>This keeps the system alive during traffic spikes.</p><h3>Why Redis alone is not enough</h3><p>Many developers think:</p><pre>Use Redis → system becomes scalable</pre><p>But the reality is different.</p><p>Redis is helpful only if the caching strategy is designed properly.</p><p>Without protection mechanisms:</p><pre>Redis miss storms → Database overload</pre><p>A well-designed caching system includes:</p><pre>Bloom Filter → block impossible keys<br>Redis Cache → fast access<br>Database → source of truth</pre><p>Combined with:</p><pre>Mutex locks<br>Random TTL<br>Rate limiting<br>Graceful fallback</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e88560611e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding When React Renders (And How to Prevent Unnecessary Re-renders)]]></title>
            <link>https://rifatcse09.medium.com/when-react-renders-and-how-to-reduce-unnecessary-renders-ced05d2b3836?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ced05d2b3836</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[frontend-development]]></category>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Thu, 05 Mar 2026 09:25:24 GMT</pubDate>
            <atom:updated>2026-03-05T09:27:30.520Z</atom:updated>
            <content:encoded><![CDATA[<p>A simple guide to React rendering, React.memo, useCallback, and useMemo for better performance.</p><p>Understanding <strong>when React renders and how to control it</strong> is essential for writing performant React applications and for technical interviews.</p><p>Let’s break it down simply.</p><h3>1. When Does React Render?</h3><blockquote>React components re-render in <strong>four main situations.</strong></blockquote><h4>1. State Changes</h4><p>When component state changes, React re-runs that component.</p><p>Example:</p><pre>function Counter() {<br>  const [count, setCount] = React.useState(0)<br><br>  return (<br>    &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>      {count}<br>    &lt;/button&gt;<br>  )<br>}</pre><p>Flow:</p><pre>User click<br>→ setState<br>→ component re-executes<br>→ Virtual DOM comparison<br>→ update changed DOM nodes</pre><blockquote>Important:<br> React <strong>does not update the whole DOM</strong>, only the changed parts.</blockquote><p>Example:</p><p>Before:</p><pre>&lt;h1&gt;0&lt;/h1&gt;</pre><p>After:</p><pre>&lt;h1&gt;1&lt;/h1&gt;</pre><p>Only the text node updates.</p><h4>2. Props Changes</h4><p>When a parent passes new props to a child component, the child re-renders.</p><p>Example:</p><pre>function Parent() {<br>  const [name, setName] = React.useState(&quot;Rifat&quot;)<br><br>  return &lt;Child name={name} /&gt;<br>}<br><br>function Child({ name }) {<br>  return &lt;h1&gt;{name}&lt;/h1&gt;<br>}</pre><p>If name changes → Child renders again.</p><h4>3. Parent Component Re-renders</h4><p>This is where many developers get confused.</p><p>When a parent re-renders, <strong>all its children run again</strong>, even if their props did not change.</p><p>Example:</p><pre>function Parent() {<br>  const [count, setCount] = React.useState(0)<br><br>  return (<br>    &lt;&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;+&lt;/button&gt;<br>      &lt;Child /&gt;<br>    &lt;/&gt;<br>  )<br>}<br><br>function Child() {<br>  console.log(&quot;Child render&quot;)<br>  return &lt;h2&gt;Hello&lt;/h2&gt;<br>}</pre><p>Click the button:</p><pre>Parent render<br>Child render</pre><p>Even though Child has no state change.</p><p>Why?</p><p>Because React <strong>re-runs the component tree under the parent</strong>.</p><h4>4. Context Changes</h4><p>If a Context value changes, all components using that context re-render.</p><p>Example:</p><pre>&lt;UserContext.Provider value={user}&gt;</pre><p>If user updates → all consumers render again.</p><h3>Important Concept: React Does NOT Rebuild the Whole DOM</h3><p>Many beginners think React rebuilds the entire page.</p><p>That is not true.</p><p>React uses:</p><p><strong>Virtual DOM + Diffing Algorithm</strong></p><p>Process:</p><pre>State change<br>→ component runs again<br>→ new Virtual DOM created<br>→ React compares with old Virtual DOM<br>→ only changed nodes updated in real DOM</pre><p>Think of it like <strong>Git diff</strong>.</p><p>React applies only the differences.</p><h3>Why Too Many Renders Hurt Performance</h3><p>Re-rendering is not always bad.</p><p>But in large applications:</p><pre>Parent render<br>→ 20 child renders<br>→ 200 component executions</pre><p>This increases:</p><ul><li>CPU usage</li><li>UI lag</li><li>unnecessary calculations</li></ul><p>That’s why React provides optimization tools.</p><h3>How to Reduce Unnecessary Renders</h3><p>Three core tools help optimize React performance.</p><h3>1. React.memo</h3><p>React.memo prevents re-rendering if props have not changed.</p><p>Example:</p><pre>const Child = React.memo(function Child() {<br>  console.log(&quot;Child render&quot;)<br>  return &lt;h2&gt;Hello&lt;/h2&gt;<br>})</pre><p>Now when the parent renders:</p><pre>Parent render<br>Child NOT render</pre><p>React skips rendering because props are unchanged.</p><h3>2. useCallback (Memoizing Functions)</h3><p>Functions are recreated on every render.</p><p>Example:</p><pre>function Parent() {<br>  const handleClick = () =&gt; {<br>    console.log(&quot;clicked&quot;)<br>  }<br><br>  return &lt;Child onClick={handleClick} /&gt;<br>}</pre><p>Each render creates a <strong>new function reference</strong>, so React thinks props changed.</p><p>Solution:</p><pre>const handleClick = React.useCallback(() =&gt; {<br>  console.log(&quot;clicked&quot;)<br>}, [])</pre><p>Now the function reference stays the same.</p><p>Benefit:</p><pre>Parent render<br>Child skip render</pre><h3>3. useMemo (Memoizing Expensive Values)</h3><p>If a calculation is expensive, memoize it.</p><p>Example:</p><pre>const result = useMemo(() =&gt; {<br>  return expensiveCalculation(data)<br>}, [data])</pre><p>Now React recalculates <strong>only when dependencies change</strong>.</p><h3>Quick Performance Optimization Pattern</h3><p>Common pattern in real apps:</p><pre>React.memo<br>+ useCallback<br>+ useMemo</pre><pre>const Child = React.memo(({ onClick }) =&gt; {<br>  return &lt;button onClick={onClick}&gt;Click&lt;/button&gt;<br>})<br><br>function Parent() {<br>  const handleClick = useCallback(() =&gt; {<br>    console.log(&quot;clicked&quot;)<br>  }, [])<br><br>  return &lt;Child onClick={handleClick} /&gt;<br>}</pre><p>This prevents unnecessary renders.</p><p><strong>Why use </strong><strong>useCallback?</strong></p><p>Short answer:</p><blockquote><em>useCallback memoizes a function so React does not recreate it on every render, preventing unnecessary child component re-renders.</em></blockquote><h3>Key Takeaways</h3><p>Remember these three rules:</p><pre>State change → component re-renders<br>Parent render → child components run again<br>DOM update → only changed nodes update</pre><p>And for performance optimization:</p><pre>React.memo<br>useCallback<br>useMemo</pre><p>I’m a backend-focused full-stack engineer working with Laravel, Node.js, and React. <br>I share practical engineering insights about performance, architecture, and real-world development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ced05d2b3836" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Zod Over Traditional NestJS DTOs (with Full Implementation)]]></title>
            <link>https://rifatcse09.medium.com/why-zod-over-traditional-nestjs-dtos-with-full-implementation-a20b145768a9?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a20b145768a9</guid>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Sun, 01 Mar 2026 08:52:47 GMT</pubDate>
            <atom:updated>2026-03-01T08:52:47.803Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>DTO way (2 sources of truth)</strong></p><pre>class CreateUserDto {<br>  @IsEmail()<br>  email: string;<br><br>  @MinLength(8)<br>  password: string;<br>}</pre><p>Then you often still define a <strong>type/interface elsewhere → duplication → mismatch risk.</strong></p><p><strong>Zod way (1 source of truth)</strong></p><pre>const createUserSchema = z.object({<br>  email: z.string().email(),<br>  password: z.string().min(8),<br>});<br><br>type CreateUserInput = z.infer&lt;typeof createUserSchema&gt;;</pre><h4><strong>1) Traditional DTO (class-validator)</strong></h4><pre>pnpm add class-validator class-transformer</pre><p><strong>DTO</strong></p><pre>//create-user.dto.ts<br><br>import { IsEmail, MinLength } from &quot;class-validator&quot;;<br><br>export class CreateUserDto {<br>  @IsEmail()<br>  email: string;<br><br>  @MinLength(8)<br>  password: string;<br>}</pre><p><strong>Use in controller (with global ValidationPipe in main.ts OR local)</strong></p><pre>// user.controller.ts<br><br>import { Body, Controller, Post } from &quot;@nestjs/common&quot;;<br>import { CreateUserDto } from &quot;./create-user.dto&quot;;<br><br>@Controller(&quot;users&quot;)<br>export class UserController {<br>  @Post()<br>  create(@Body() dto: CreateUserDto) {<br>    return { message: &quot;User created&quot;, data: dto };<br>  }<br>}</pre><p>Note: In real apps, you usually enable this globally:<br> app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));</p><p><strong>2) Full Zod Implementation in NestJS</strong></p><ol><li><strong>Install</strong></li></ol><pre>pnpm add zod</pre><p><strong>2) Create schema</strong></p><pre>//user.schema.ts<br><br>import { z } from &quot;zod&quot;;<br><br>export const createUserSchema = z.object({<br>  email: z.string().email(),<br>  password: z.string().min(8),<br>});<br><br>export type CreateUserInput = z.infer&lt;typeof createUserSchema&gt;;</pre><p><strong>3) Create a Zod validation pipe</strong></p><pre>//zod-validation.pipe.ts<br><br>import { PipeTransform, BadRequestException } from &quot;@nestjs/common&quot;;<br>import { ZodSchema } from &quot;zod&quot;;<br><br>export class ZodValidationPipe implements PipeTransform {<br>  constructor(private readonly schema: ZodSchema) {}<br><br>  transform(value: unknown) {<br>    const result = this.schema.safeParse(value);<br><br>    if (!result.success) {<br>      throw new BadRequestException(result.error.flatten());<br>    }<br><br>    return result.data; // validated + typed<br>  }<br>}</pre><p><strong>4) Use it in controller</strong></p><pre>//user.controller.ts<br><br>import { Body, Controller, Post, UsePipes } from &quot;@nestjs/common&quot;;<br>import { createUserSchema, CreateUserInput } from &quot;./user.schema&quot;;<br>import { ZodValidationPipe } from &quot;./zod-validation.pipe&quot;;<br><br>@Controller(&quot;users&quot;)<br>export class UserController {<br>  @Post()<br>  @UsePipes(new ZodValidationPipe(createUserSchema))<br>  create(@Body() body: CreateUserInput) {<br>    return { message: &quot;User created&quot;, data: body };<br>  }<br>}</pre><h3>What you gain (fast)</h3><ul><li><strong>No duplicate DTO + interface</strong></li><li><strong>Reusable schema</strong> (share with Next.js)</li><li>Cleaner, composable validation (extend, pick, merge)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a20b145768a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pagination Deep Dive: Offset vs. Cursor. Which One Should You Choose?]]></title>
            <link>https://rifatcse09.medium.com/pagination-deep-dive-offset-vs-cursor-which-one-should-you-choose-bf24f1ad7aad?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf24f1ad7aad</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[scalability]]></category>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Tue, 24 Feb 2026 15:51:26 GMT</pubDate>
            <atom:updated>2026-02-24T16:01:25.419Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*phtI2Sa5g8brs0AeMZloHQ.png" /></figure><p>In any system dealing with large datasets whether it’s a social media feed, a list of transactions or an e-commerce catalog returning all records at once is a recipe for a performance meltdown.</p><p>As system designers, we use <strong>Pagination</strong>. But the choice between <strong>Offset-based</strong> and <strong>Cursor-based</strong> pagination isn’t just a matter of preference. It’s a decision that impacts database performance, user experience, and system consistency.</p><h3>1. Offset-based Pagination: The Standard Approach</h3><p>This is the most common method, often used with SQL’s LIMIT and OFFSET clauses.</p><ul><li><strong>How it works:</strong> The client sends a page_number and a page_size. The server calculates the offset: offset = (page_number - 1) * page_size.</li><li><strong>The Query:</strong> SELECT * FROM posts ORDER BY created_at DESC LIMIT 10 OFFSET 50;</li></ul><h4>The Pros:</h4><ul><li><strong>Jump to Page:</strong> Allows users to skip to a specific page (e.g., “Go to page 10”).</li><li><strong>Easy to Implement:</strong> Native support in almost all RDBMS.</li></ul><h4>The Cons (The “Scale Killers”):</h4><ul><li><strong>Performance Degradation:</strong> The database must scan through OFFSET + LIMIT rows and discard the first OFFSET rows. At high offsets (e.g., page 10,000), this becomes incredibly slow (O(N) complexity).</li><li><strong>Inconsistency (The Drift):</strong> If a new item is inserted on page 1 while a user is moving to page 2, the user will see the last item of page 1 repeated on page 2.</li></ul><h3>2. Cursor-based Pagination: The Scalable Approach</h3><p>Instead of a page number, we use a “pointer” (the cursor) to the last item fetched.</p><ul><li><strong>How it works:</strong> The client sends a cursor (usually a unique, indexed field like an ID or timestamp). The server fetches results that come <em>after</em> that cursor.</li><li><strong>The Query:</strong> SELECT * FROM posts WHERE id &gt; 1234 ORDER BY id ASC LIMIT 10;</li></ul><h4>The Pros:</h4><ul><li><strong>O(1) Performance:</strong> The database uses an index to jump directly to the specific row. Performance remains constant whether you are on the first page or the millionth.</li><li><strong>Consistency:</strong> Because we are filtering by a specific ID, new insertions at the top of the list don’t “push” items into the next page.</li><li><strong>Perfect for Infinite Scroll:</strong> This is the industry standard for mobile apps and social feeds (Instagram, Slack, Facebook).</li></ul><h4>The Cons:</h4><ul><li><strong>No “Jump to Page”:</strong> Users cannot skip to page 50; they must traverse sequentially.</li><li><strong>Complexity:</strong> Sorting by non-unique columns (like first_name) requires a compound cursor (e.g., timestamp + id) to ensure uniqueness.</li></ul><h3>The System Designer’s Verdict: When to use what?</h3><p><strong>Choose Offset-based Pagination if:</strong></p><ol><li>Your dataset is small (a few thousand rows).</li><li>The UI requires “Jump to Page X” functionality (e.g., Admin Dashboards, Legal Archives).</li><li>The data is static and doesn’t change frequently.</li></ol><p><strong>Choose Cursor-based Pagination if:</strong></p><ol><li>You are building for scale (Millions of rows).</li><li>The UI is an infinite scroll or a “Load More” feed.</li><li>The data is highly dynamic (Real-time feeds).</li></ol><p>Scaling isn’t just about adding more servers; it’s about choosing the right algorithms for your data retrieval.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf24f1ad7aad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I Abandoned CI/CD Pipelines for “Source Deploy” (And You Should Too)]]></title>
            <link>https://rifatcse09.medium.com/why-i-abandoned-ci-cd-pipelines-for-source-deploy-and-you-should-too-c0a01491ab0c?source=rss-f3dfc7572ab8------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a01491ab0c</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[google-cloud-run]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Rifat]]></dc:creator>
            <pubDate>Sun, 15 Feb 2026 14:12:32 GMT</pubDate>
            <atom:updated>2026-02-15T14:13:16.877Z</atom:updated>
            <content:encoded><![CDATA[<p>How to deploy production-ready Serverless apps on Google Cloud and AWS without writing a single line of YAML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2urmJ003FK8woZuwVUmQMg.png" /></figure><h3>The Problem: DevOps is Exhausting</h3><p>We’ve all been there. You just want to ship your Node.js or Python app. But before you can, you have to:</p><ol><li>Write a Dockerfile.</li><li>Set up a Jenkins server (or GitHub Actions).</li><li>Write a 50-line YAML configuration file.</li><li>Manage Service Account keys and secrets.</li><li>Debug why the build is failing on line 42.</li></ol><p>It feels like we spend more time <em>configuring</em> deployment than <em>writing code</em>.</p><h3>The Solution: The “Source Deploy” Revolution</h3><p>Recently, I implemented a new architecture for a high-traffic Crypto Casino platform. I looked at the standard industry practices — Kubernetes, complex CI/CD — and decided to throw them out.</p><p>Instead, I used <strong>Google Cloud Run’s Source Deploy</strong>.</p><h3>What is Source Deploy?</h3><p>It’s a feature where you simply connect your GitHub repository to the cloud provider, and they handle <em>everything</em>.</p><ul><li><strong>No YAML files.</strong></li><li><strong>No manual build steps.</strong></li><li><strong>No key management.</strong></li></ul><p>You push code. It goes live. That’s it.</p><h3>🏗️ The Architecture: Under the Hood</h3><p>Even though it feels like magic, there is a robust architecture underneath. Here is the flow I deployed:</p><h3>1. The Chef (Cloud Build)</h3><p>When I push to main, <strong>Google Cloud Build</strong> wakes up. It clones my repo, detects my</p><p>Dockerfile, and builds the container image. This happens in a secure, ephemeral VM managed by Google.</p><h3>2. The Fridge (Artifact Registry)</h3><p>The build system doesn’t just run the code; it stores the compiled “dish” (Container Image) in <strong>Google Artifact Registry</strong>. This isn’t Docker Hub; it’s a private, encrypted vault for my code.</p><h3>3. The Waiter (Cloud Run)</h3><p>Finally, <strong>Cloud Run</strong> notices a new image in the fridge. It spins up a new “Revision” (a micro-VM) and starts routing traffic to it. If no one visits the site, it scales to zero (costing $0). If 10,000 people visit, it scales up to meet demand.</p><h3>4. The Janitor (Cloud Run Jobs)</h3><p>This was the missing piece. How do you run database migrations? You can’t run them <em>during</em> the web server startup (it slows down the boot).</p><p>I used <strong>Cloud Run Jobs</strong>.</p><ul><li>It pulls the same image.</li><li>It runs npm run migration:up.</li><li>It exits.</li></ul><p>This ensures my database is always in sync with my code before traffic hits.</p><h3>☁️ Cross-Cloud: It Works on AWS Too</h3><p>If you are an AWS shop, you don’t have to miss out.</p><p>The exact equivalent is <strong>AWS App Runner</strong>.</p><ul><li><strong>Source</strong>: Connect GitHub.</li><li><strong>Build</strong>: Automatic (based on Dockerfile).</li><li><strong>Run</strong>: Serverless container.</li></ul><p>It provides the same “push-to-deploy” experience without the headache of managing ECS clusters or Fargate tasks manually.</p><h3>🚀 Why You Should Switch</h3><ol><li><strong>Speed</strong>: I set up the entire production environment in 30 minutes.</li><li><strong>Security</strong>: No long-lived Service Account keys stored in GitHub Secrets. The cloud provider pulls the code directly.</li><li><strong>Cost</strong>: Serverless means you pay for <em>request processing</em>, not for idle servers.</li></ol><h3>Conclusion</h3><p>DevOps doesn’t have to be hard. By embracing these managed “Source Deploy” flows, we can stop being “YAML Engineers” and get back to being <em>Product Engineers</em>.</p><p><em>Follow me for more insights on Serverless, Cloud Architecture, and DevOps simplifications.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a01491ab0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>