<?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 Parth Surati on Medium]]></title>
        <description><![CDATA[Stories by Parth Surati on Medium]]></description>
        <link>https://medium.com/@parthsurati096?source=rss-4c0dcdb893d5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qYDnybebiXkAFiNB</url>
            <title>Stories by Parth Surati on Medium</title>
            <link>https://medium.com/@parthsurati096?source=rss-4c0dcdb893d5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 10:28:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@parthsurati096/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[Mastering Asyncio- 1| asynchronous programming |Python Expert]]></title>
            <link>https://towardsdev.com/mastering-asyncio-1-asynchronous-programming-python-expert-82348e7abe54?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/82348e7abe54</guid>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Sat, 06 Jun 2026 09:34:52 GMT</pubDate>
            <atom:updated>2026-06-30T13:10:08.293Z</atom:updated>
            <content:encoded><![CDATA[<p>To master it, you first need to shatter a very common misconception: <strong>asyncio does not make Python run multiple things at the exact same time.</strong> Instead, it allows Python to <em>wait</em> for multiple things at the same time.</p><h3>1. The Core Concept: Concurrency vs. Parallelism</h3><ul><li><strong>Parallelism (Multiprocessing):</strong> You have 4 cooks in a kitchen, each making a different dish simultaneously. This requires multiple CPU cores.</li><li><strong>Concurrency (</strong><strong>asyncio):</strong> You have exactly <strong>1 cook</strong> (a single thread on a single CPU core). However, this cook is highly efficient. They put water on the stove to boil. Instead of staring at the pot for 10 minutes (blocking code), they pivot to chopping vegetables, then pivot to marinating chicken. They only return to the pot when the water is bubbling.</li></ul><p>asyncio is a system for writing <strong>concurrent</strong> code using a single thread. It thrives on multitasking during downtime.</p><h3>2. The Brain: The Event Loop</h3><p>At the very center of asyncio is the <strong>Event Loop</strong>. Think of it as a master traffic controller. It is basically an infinite while loop running in the background. Its entire job is to keep track of tasks, see which ones are waiting for data, and execute the ones that are ready to run.</p><p>If Task A hits a slow network request, the Event Loop says, “Okay, Task A is paused. Task B, it’s your turn to use the CPU.”</p><h3>3. The Vocabulary of Asyncio</h3><p>To write async code, you need to master three fundamental keywords/concepts:</p><ul><li><strong>Coroutines (</strong><strong>async def):</strong> Standard Python functions run from top to bottom. If you prefix a function with async def, it becomes a coroutine. This is a special function that has the ability to be paused and resumed later.</li><li><strong>The Pause Button (</strong><strong>await):</strong> You place this in front of operations that take time (like fetching a web page). It literally tells the Event Loop: <em>&quot;I am going to be stuck waiting here for a second. Take control of the CPU and go run another task, then wake me up when my data arrives.&quot;</em></li><li><strong>Tasks (</strong><strong>asyncio.create_task()):</strong> If you just await a coroutine, it runs sequentially. If you wrap a coroutine in a Task, you are scheduling it onto the Event Loop to run concurrently in the background.</li></ul><h3>4. When to Use It (And When Absolutely Not To)</h3><p>asyncio is incredibly powerful, but it is not a silver bullet. If you use it for the wrong problem, you will actually make your code slower.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*5PjGFQn4KgbHX98PMrNkRQ.png" /></figure><p><strong>Key Differences: Async, Threading, and Multiprocessing :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*PlDBFaAqmsWWB4UuWlMUsg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82348e7abe54" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/mastering-asyncio-1-asynchronous-programming-python-expert-82348e7abe54">Mastering Asyncio- 1| asynchronous programming |Python Expert</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL | backup-dump-restore | part -1]]></title>
            <link>https://medium.com/@parthsurati096/postgresql-backup-dump-restore-part-1-1920981e78a1?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1920981e78a1</guid>
            <category><![CDATA[backup-and-restore]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[postgresql-backup]]></category>
            <category><![CDATA[database-backup]]></category>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Tue, 31 Mar 2026 12:28:03 GMT</pubDate>
            <atom:updated>2026-03-31T12:28:03.299Z</atom:updated>
            <content:encoded><![CDATA[<h3>Method 1: The “Compressed Logical” Export (Best for most users)</h3><p>This uses pg_dump with high-level compression for the file itself. While it &quot;unpacks&quot; the Timescale compression internally to read the data, it &quot;re-packs&quot; it into a highly compressed .dump file for the move.</p><ol><li><strong>On the Server (Export):</strong> Use the <strong>Directory Format</strong> (-Fd). It is much faster because it allows parallel processing.</li></ol><pre># -j 4 uses 4 CPU cores, -Z 9 is max compression<br>pg_dump -h localhost -U [user] -Fd -j 4 -Z 9 -f ~/my_compressed_db.dir [db_name]  </pre><p><strong>2. Transfer to Local:</strong> Compress the directory into one file and download it:</p><pre>tar -cvzf my_db.tar.gz ~/my_compressed_db.dir<br>scp user@server-ip:~/my_db.tar.gz ~/Downloads/</pre><p><strong>3. On Local (Setup &amp; Restore):</strong></p><ul><li><strong>Step A:</strong> Install Postgres and TimescaleDB (versions must match the server).</li><li><strong>Step B:</strong> Run the pre-restore command in your local DB: SELECT timescaledb_pre_restore();</li><li><strong>Step C:</strong> Restore using pg_restore:</li></ul><pre>pg_restore -U [local_user] -d [local_db] -j 4 -Fd ~/Downloads/my_compressed_db.dir</pre><pre>pg_restore -U postgres -d target_db --disable-triggers -j 4 /home/jnm/my_compressed_db</pre><p><strong>Step D:</strong> Finalize: SELECT timescaledb_post_restore();</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1920981e78a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multiple Redis Instances Setup Guide]]></title>
            <link>https://medium.com/@parthsurati096/multiple-redis-instances-setup-guide-ad4e5b6bc8da?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad4e5b6bc8da</guid>
            <category><![CDATA[redis-cluster]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[caching]]></category>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Wed, 18 Mar 2026 11:27:41 GMT</pubDate>
            <atom:updated>2026-03-18T11:27:41.274Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Create a New Configuration File</h3><p>Instead of editing the default file, copy it to create a template for your new instance.</p><pre>sudo cp /etc/redis/redis.conf /etc/redis/redis-6380.conf</pre><h3>2. Configure the New Instance</h3><p>Open the new file with your preferred editor:</p><pre>sudo nano /etc/redis/redis-6380.conf</pre><p>Find and update the following lines to ensure the instances don’t “bump” into each other:</p><ul><li><strong>port:</strong> Change 6379 to 6380.</li><li><strong>pidfile:</strong> Change /run/redis/redis-server.pid to /run/redis/redis-server-6380.pid.</li><li><strong>logfile:</strong> Change /var/log/redis/redis-server.log to /var/log/redis/redis-server-6380.log.</li><li><strong>dbfilename:</strong> Change dump.rdb to dump-6380.rdb.</li><li><strong>dir:</strong> Change /var/lib/redis to /var/lib/redis-6380.</li></ul><blockquote><strong><em>Note:</em></strong><em> Creating a separate data directory (</em><em>dir) prevents the instances from overwriting each other&#39;s database files.</em></blockquote><h3>3. Setup Data Directory &amp; Permissions</h3><p>Now, create the directory you just specified in the config and give Redis permission to use it.</p><pre>sudo mkdir /var/lib/redis-6380<br>sudo chown redis:redis /var/lib/redis-6380<br>sudo chmod 770 /var/lib/redis-6380</pre><h3>4. Create a Systemd Service File</h3><p>To manage this instance like a professional service (start/stop/restart), create a new service unit:</p><pre>sudo nano /etc/systemd/system/redis-6380.service</pre><pre>[Unit]<br>Description=Redis In-Memory Data Store (Port 6380)<br>After=network.target<br><br>[Service]<br>User=redis<br>Group=redis<br>ExecStart=/usr/bin/redis-server /etc/redis/redis-6380.conf<br>ExecStop=/usr/bin/redis-cli -p 6380 shutdown<br>Restart=always<br><br>[Install]<br>WantedBy=multi-user.target</pre><h3>5. Start and Verify</h3><p>Reload the systemd daemon to recognize the new service, then start it.</p><pre># Reload and Start<br>sudo systemctl daemon-reload<br>sudo systemctl start redis-6380<br>sudo systemctl enable redis-6380<br><br># Check status<br>sudo systemctl status redis-6380</pre><p>redis-cli -p 6380 ping | # Expected output: PONG | ps aux | grep redis</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad4e5b6bc8da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master PostgreSQL | Part -1]]></title>
            <link>https://medium.com/@parthsurati096/master-postgresql-part-1-f1507b5431b3?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1507b5431b3</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Fri, 06 Mar 2026 12:03:46 GMT</pubDate>
            <atom:updated>2026-03-06T12:03:46.387Z</atom:updated>
            <content:encoded><![CDATA[<p>To master anything in the world, you must first understand its roots — how it works and the background processes behind it. 🌱</p><p>Let’s first understand the root components of PostgreSQL and how they work together to form a complete database.</p><p>At its core, PostgreSQL relies on a <strong>Client/Server</strong> architecture. Let’s break down the “roots” of Postgres into four main pillars: <strong>The Processes, The Memory, The Storage, and The Query Pipeline.</strong></p><h3><strong>1. The Core Processes (The Brains and Workers)</strong></h3><p>When you start PostgreSQL, you aren’t just starting one program; you are waking up an entire team of processes that work together.</p><h4>The Boss: The postgres Server Process (formerly postmaster)</h4><p>This is the master process. It is the very first thing that starts when you boot up the database.</p><ul><li><strong>What it does:</strong> It listens for incoming connections from clients (your app, pgAdmin, psql).</li><li><strong>How it works:</strong> Whenever a client says “I want to connect,” the postgres boss process <strong>forks</strong> (spawns) a brand-new, dedicated &quot;Backend Process&quot; specifically for that user.</li></ul><h4>The Janitors and Guardians (Background Processes)</h4><p>While the backend processes handle your queries, a team of background workers keeps the database healthy:</p><ul><li><strong>Checkpointer:</strong> Periodically takes all the modified data in memory (dirty pages) and writes it permanently to the physical disk. This ensures crash recovery is fast.</li><li><strong>Background Writer (bgwriter):</strong> A helper to the checkpointer. It slowly and continuously writes a few modified pages to disk in the background. This ensures that when your active queries need free memory, they don’t have to wait for the disk to write.</li><li><strong>WAL Writer:</strong> The guardian of your data. It takes changes recorded in the Write-Ahead Log (WAL) buffers and flushes them to disk. (More on WAL below — it’s crucial!).</li><li><strong>Autovacuum Launcher/Workers:</strong> The garbage collectors. Because Postgres uses MVCC (saving old versions of rows so readers aren’t blocked by writers), deleted or updated rows leave “dead tuples” behind. Autovacuum cleans these up so your database doesn’t bloat.</li></ul><h3>2. The Memory Landscape (Where the Magic Happens)</h3><p>PostgreSQL hates reading directly from the hard drive because disks are slow. Instead, it relies heavily on memory (RAM), split into two areas:</p><h4>Shared Memory (Accessible by all processes)</h4><ul><li><strong>Shared Buffers:</strong> The most important memory pool. When you ask for data, Postgres fetches it from the disk and puts it here. Future queries for the same data read it instantly from RAM.</li><li><strong>WAL Buffers:</strong> Before changes are written to the actual database files, they are briefly stored here as transaction logs.</li></ul><h4>Local Memory (Private to your specific query)</h4><ul><li><strong>work_mem:</strong> Memory used for sorting data (ORDER BY), grouping, and complex joins. If a query needs more space than this, it spills over to the hard drive (temp files), which slows things down massively.</li><li><strong>maintenance_work_mem:</strong> Used for heavy lifting tasks like creating indexes or running VACUUM.</li></ul><h3><strong>3. The Safety Net: WAL (Write-Ahead Logging)</strong></h3><p>If the power goes out while data is only in the Shared Buffers (RAM), wouldn’t you lose it? Yes — except for <strong>WAL</strong>.</p><ul><li><strong>How it works:</strong> <em>Before</em> Postgres actually writes your updated data into the main database files, it writes a quick, sequential log of the <em>change itself</em> to the WAL on disk.</li><li><strong>Why it matters:</strong> Writing a quick log is much faster than finding the exact row in a massive database file. If the server crashes, Postgres simply reads the WAL upon reboot and replays the changes to restore the database to its exact state.</li></ul><h3>4. The Query Pipeline (How a Query gets Executed)</h3><p>When you send a SELECT statement, it goes through a strict assembly line inside that dedicated Backend Process we mentioned earlier:</p><ol><li><strong>The Parser:</strong> Checks your spelling and grammar. Did you write SEELCT instead of SELECT? It throws an error here.</li><li><strong>The Analyzer/Rewriter:</strong> Checks if the tables and columns actually exist. It also applies any “Rules” (for example, if you query a View, it rewrites the query to look at the underlying tables).</li><li><strong>The Planner/Optimizer (The Genius):</strong> This is the smartest part of Postgres. It looks at the database statistics and figures out the fastest way to get your data. Should it scan the whole table? Should it use an index? It generates a “Query Plan.”</li><li><strong>The Executor:</strong> The blue-collar worker. It takes the Query Plan, fetches the data from the Shared Buffers (or disk, if it’s not in memory), and hands it back to you.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*wMOWzPRwrcAN3mKfCCH53w.png" /></figure><h3><strong>Root Concepts You Must Master :</strong></h3><ol><li><strong>PostgreSQL process architecture</strong></li><li><strong>Query planner &amp; optimizer</strong></li><li><strong>MVCC</strong></li><li><strong>WAL logging</strong></li><li><strong>Buffer cache</strong></li><li><strong>Index structures</strong></li><li><strong>Vacuum / Autovacuum</strong></li><li><strong>Locking system</strong></li><li><strong>Replication</strong></li><li><strong>Checkpoints</strong></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1507b5431b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redis Optimisation For 90K live connections | part — 1]]></title>
            <link>https://medium.com/@parthsurati096/redis-optimisation-for-90k-live-connections-part-1-ba3721618702?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba3721618702</guid>
            <category><![CDATA[live-streaming]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[redis-cluster]]></category>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Mon, 02 Mar 2026 09:02:59 GMT</pubDate>
            <atom:updated>2026-03-02T09:02:59.833Z</atom:updated>
            <content:encoded><![CDATA[<h3>Layer 1 — OS / Kernel Tuning | 1.1 — TCP &amp; Socket Limits</h3><p>Add to /etc/sysctl.conf and run sysctl -p:</p><pre># Max open file descriptors (already 1,048,576 on your machine ✅)<br>fs.file-max = 1048576<br><br># TCP connection queue depth (critical for 50K+ connections)<br>net.core.somaxconn = 65535<br>net.ipv4.tcp_max_syn_backlog = 65535<br><br># Reduce TIME_WAIT socket reuse - stops port exhaustion at high connections<br>net.ipv4.tcp_tw_reuse = 1<br>net.ipv4.tcp_fin_timeout = 15<br><br># Increase local port range for outgoing connections<br>net.ipv4.ip_local_port_range = 1024 65535<br><br># Network buffer sizes (critical for high-throughput pub/sub)<br>net.core.rmem_max = 134217728<br>net.core.wmem_max = 134217728<br>net.ipv4.tcp_rmem = 4096 87380 134217728<br>net.ipv4.tcp_wmem = 4096 65536 134217728<br><br># Increase backlog queue for busy sockets<br>net.core.netdev_max_backlog = 65536<br></pre><p>Set user limits in /etc/security/limits.conf:</p><pre>* soft nofile 1048576<br>* hard nofile 1048576<br>* soft nproc  65535<br>* hard nproc  65535</pre><h3>Layer 2 — Redis Configuration Upgrades</h3><p>If you are running ≤ <strong>Redis 6.0.16 </strong>. This is single-threaded for ALL operations. <strong>Redis 7.x</strong> has I/O threading that can push throughput 3–4× higher at 50K+ connections.</p><h3>2.2 — redis.conf Tuning for 90K Connections</h3><pre># === Connection Limits ===<br>maxclients 100000          # Raise from current 20,000 ← REQUIRED<br>tcp-backlog 65535          # Match kernel somaxconn<br><br># === I/O Threads (Redis 7.x only — massive win) ===<br>io-threads 4               # Use 4 I/O threads (leave 4 for OS/Flink)<br>io-threads-do-reads yes    # Enable threaded reads too<br><br># === Memory ===<br>maxmemory 4gb              # Cap at 4GB, leaving 4GB for Flink/OS<br>maxmemory-policy noeviction<br><br># === Performance ===<br>hz 100                     # Poll frequency — increase from default 10<br>dynamic-hz yes             # Auto-scale hz under load<br>aof-use-rdb-preamble yes<br>lazyfree-lazy-eviction yes # Non-blocking eviction<br>lazyfree-lazy-expire yes<br><br># === Pub/Sub specific ===<br># No specific config but reduce latency with:<br>latency-tracking yes<br>latency-tracking-info-percentiles 50 99 99.9<br><br># === Network ===<br>tcp-keepalive 60           # Keep idle connections alive<br>timeout 300                # Drop truly dead connections after 5 min<br>bind 127.0.0.1             # Only bind to loopback if Flink is local</pre><p>Apply without restart:</p><pre>   redis-cli config rewrite </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba3721618702" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create role for PosgreSQL]]></title>
            <link>https://medium.com/@parthsurati096/how-to-create-role-for-posgresql-1511219ffce6?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1511219ffce6</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[roles-and-permissions]]></category>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Sat, 28 Feb 2026 05:02:20 GMT</pubDate>
            <atom:updated>2026-02-28T05:02:20.413Z</atom:updated>
            <content:encoded><![CDATA[<p>In <strong>pgAdmin 4</strong>, you can accomplish this through the graphical interface without writing manual SQL. Since permissions are database-specific, make sure you are connected to the specific database you want to share.</p><p>Here is the step-by-step guide to creating a read-only user:</p><h3>1. Create the Login Role</h3><ol><li>Right-click on <strong>Login/Group Roles</strong> in the browser tree.</li><li>Select <strong>Create</strong> &gt; <strong>Login/Group Role…</strong></li><li><strong>General Tab:</strong> Enter a name (e.g., readonly_user).</li><li><strong>Definition Tab:</strong> Enter a secure password.</li><li><strong>Privileges Tab:</strong> Ensure “Can login?” is set to <strong>Yes</strong>. Leave everything else (like Superuser or Create DB) as <strong>No</strong>.</li><li>Click <strong>Save</strong>.</li></ol><h3>2. Grant Database Connection</h3><ol><li>Right-click on your <strong>Database</strong> name.</li><li>Select <strong>Properties</strong> &gt; <strong>Security</strong> tab.</li><li>Click the <strong>+</strong> icon to add a row.</li><li>Select your readonly_user under <strong>Grantee</strong>.</li><li>Check the <strong>Connect</strong> privilege.</li><li>Click <strong>Save</strong>.</li></ol><h3>3. Grant Schema &amp; Table Access</h3><p>Now you need to tell Postgres that this user can “see” the tables inside your schema (usually public).</p><ol><li>Navigate to <strong>Databases</strong> &gt; <strong>[Your Database]</strong> &gt; <strong>Schemas</strong> &gt; <strong>public</strong>.</li><li>Right-click <strong>public</strong>, select <strong>Properties</strong> &gt; <strong>Security</strong> tab.</li><li>Add your readonly_user as a Grantee and check <strong>Usage</strong>. Click <strong>Save</strong>.</li><li><strong>To grant access to all current tables:</strong> * Right-click the <strong>public</strong> schema again.</li></ol><ul><li>Select <strong>Grant Wizard</strong>.</li><li>In <strong>Object Selection</strong>, check <strong>Tables</strong>. Click <strong>Next</strong>.</li><li>In <strong>Privileges</strong>, select your readonly_user.</li><li>Check <strong>SELECT</strong> only.</li><li>Click <strong>Finish</strong>.</li></ul><h3>4. Ensure Future Tables are Readable (Crucial)</h3><p>If you add new tables later, pgAdmin won’t automatically show them to this user unless you set “Default Privileges.”</p><ol><li>Right-click the <strong>public</strong> schema one last time.</li><li>Select <strong>Properties</strong> &gt; <strong>Default Privileges</strong> tab.</li><li>Click the <strong>Tables</strong> sub-tab.</li><li>Click the <strong>+</strong> icon.</li><li>Set <strong>Grantee</strong> to readonly_user and check <strong>SELECT</strong>.</li><li>Click <strong>Save</strong>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1511219ffce6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Caching in RAM -cache | REST Api | Make your API superfast]]></title>
            <link>https://medium.com/@parthsurati096/caching-in-ram-cache-rest-api-make-your-api-superfast-f7b4fafca859?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7b4fafca859</guid>
            <category><![CDATA[inmemory-cache]]></category>
            <category><![CDATA[caching-strategies]]></category>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 10:01:13 GMT</pubDate>
            <atom:updated>2026-02-18T10:01:13.154Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*HLN4ZP-PYuiW91uvn_WJiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*I8Gf5j_spdBfBfOw1tTu4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*K1oiKa_kgVhHR32-48de0w.png" /></figure><h3>1. What Tech/Library did I use?</h3><p>Build vs Buy: I chose Build. I did NOT use an external library like Redis or Memcached for this specific implementation. Instead, I built a custom, lightweight In-Memory Cache using standard Python.</p><ul><li>Why is it so fast?: Because it stores data in the Server’s RAM. Accessing RAM takes nanoseconds. Accessing Redis (even on localhost) involves network/socket overhead which takes milliseconds. For a single-server setup, RAM is always the speed king.</li></ul><p>Cleanup (Eviction) Logic: I implemented two cleaning strategies to keep it efficient:</p><ol><li>Lazy Expiration (Data Access)</li><li>Safety Valve (Data Insertion) :</li></ol><ul><li>If full, I loop through and mass-delete all expired items to free up space.</li><li>If it&#39;s <em>still</em> full (very rare), I clear the whole thing to prevent the server from crashing due to running out of RAM.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7b4fafca859" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ClickHouse: Incremental Materialized View vs Refreshable Materialized View]]></title>
            <link>https://medium.com/@parthsurati096/clickhouse-incremental-materialized-view-vs-refreshable-materialized-view-17734faf881d?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/17734faf881d</guid>
            <category><![CDATA[advanced-analytics]]></category>
            <category><![CDATA[advanced-technology]]></category>
            <category><![CDATA[clickhouse]]></category>
            <category><![CDATA[speed-optimization]]></category>
            <category><![CDATA[databse]]></category>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Wed, 09 Jul 2025 06:37:05 GMT</pubDate>
            <atom:updated>2025-07-09T06:37:05.172Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*GRqPFJnrGWFcIyvLPkvx-Q.png" /></figure><p><strong>Materialized Views</strong> (MVs) are used to precompute and store query results to speed up read-heavy workloads. However, there are different types of materialized views that help optimize different use cases. Two common types are <strong>Incremental Materialized Views</strong> and <strong>Refreshable Materialized Views</strong>. Let’s go through the differences, usage patterns, and logic behind them.</p><h3>1. <strong>Incremental Materialized View (IMV)</strong></h3><h4>Definition:</h4><p>An <strong>Incremental Materialized View (IMV)</strong> is designed to only process and store the changes (i.e., new or updated data) that are appended to the underlying source table. It does not need to refresh the entire data set every time, instead it works incrementally by processing new incoming data in real-time or near-real-time.</p><h4>Key Characteristics:</h4><ul><li><strong>Incremental Processing</strong>: It only computes and stores new rows that are inserted into the source table after the materialized view was created or after the last refresh.</li><li><strong>Efficiency</strong>: It reduces the need to recompute the entire query for every new row and saves processing time.</li><li><strong>Real-time Updates</strong>: Data is updated incrementally as new rows are inserted, making it useful for time-sensitive use cases.</li><li><strong>Automatic Updates</strong>: The MV updates automatically when new data is inserted into the source table.</li></ul><h4>Usage Pattern:</h4><ul><li>When you have large datasets with frequent insertions.</li><li>When you need near-real-time processing of new data.</li><li>For logs, clickstreams, transactional systems, and other sources where new data is frequently appended.</li></ul><h4>How It Works:</h4><ul><li><strong>Source Table</strong>: You define an incremental materialized view based on a source table that receives new data over time.</li><li><strong>MV Logic</strong>: The view computes only the changes in the data (e.g., new rows or updated rows).</li><li><strong>Triggers on Insert</strong>: Every time new data is inserted into the source table, ClickHouse evaluates whether the inserted data matches the conditions defined in the materialized view’s SELECT query and processes only the new or changed data.</li></ul><pre>CREATE MATERIALIZED VIEW mv_incremental<br>ENGINE = SummingMergeTree()<br>PARTITION BY toYYYYMM(timestamp)<br>ORDER BY (user_id)<br>AS<br>SELECT<br>    user_id,<br>    sum(event_count) AS total_events,<br>    toStartOfDay(timestamp) AS event_date<br>FROM events<br>WHERE event_type = &#39;click&#39;<br>GROUP BY user_id, event_date;</pre><p><strong>How it works</strong>: This view will store the sum of event_count for each user_id and event_date. When new events are inserted, only the new records for the given event_type will be processed and added to the view.</p><h3>2. <strong>Refreshable Materialized View (RMV)</strong></h3><h4>Definition:</h4><p>A <strong>Refreshable Materialized View (RMV)</strong> is a materialized view that needs to be <strong>explicitly refreshed</strong> either on-demand or at scheduled intervals. It doesn’t automatically update when new data is inserted into the source table. Instead, you must manually trigger a refresh operation to re-compute the entire view.</p><h4>Key Characteristics:</h4><ul><li><strong>Manual Refresh</strong>: You need to trigger a refresh operation either manually or through a scheduled job.</li><li><strong>Full Refresh</strong>: When the view is refreshed, ClickHouse recomputes the entire result set based on the underlying data in the source table.</li><li><strong>Heavy Computation</strong>: Since the full view is recalculated every time, it can be computationally expensive depending on the volume of data.</li><li><strong>Use Case</strong>: Suitable when you need a periodic refresh and when full recomputation is acceptable.</li></ul><h4>Usage Pattern:</h4><ul><li>When you have an analytical query that requires recomputation of the entire dataset (e.g., aggregate calculations, complex transformations).</li><li>For reports or dashboards where you don’t need real-time data but require periodic updates.</li><li>For less frequent updates, but with large amounts of data.</li></ul><h4>How It Works:</h4><ul><li><strong>Source Table</strong>: The materialized view is based on the data from the source table, just like with the incremental view.</li><li><strong>Refresh Logic</strong>: When the view is refreshed, ClickHouse performs a <strong>full recomputation</strong> of the query defined in the materialized view.</li><li><strong>Manual or Scheduled</strong>: You can trigger the refresh either manually (REFRESH MATERIALIZED VIEW) or via a scheduled task (e.g., cron jobs, ClickHouse’s system tables, or third-party schedulers).</li></ul><pre>CREATE MATERIALIZED VIEW mv_refreshable<br>ENGINE = MergeTree()<br>PARTITION BY toYYYYMM(date)<br>ORDER BY (date)<br>AS<br>SELECT<br>    date,<br>    sum(sales) AS total_sales<br>FROM sales_data<br>GROUP BY date;</pre><p><strong>How it works</strong>: You can manually refresh the mv_refreshable view by running the command:</p><pre>REFRESH MATERIALIZED VIEW mv_refreshable;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17734faf881d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ClickHouse: Materialized View + Advance Materialized View Uasge]]></title>
            <link>https://medium.com/@parthsurati096/clickhouse-materialized-view-advance-materialized-view-uasge-db437d1889b7?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/db437d1889b7</guid>
            <category><![CDATA[clickhouse]]></category>
            <category><![CDATA[advanced-querying]]></category>
            <category><![CDATA[advanced-technology]]></category>
            <category><![CDATA[materializedviews]]></category>
            <category><![CDATA[advanced-analytics]]></category>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Wed, 09 Jul 2025 06:26:25 GMT</pubDate>
            <atom:updated>2025-07-09T06:26:25.194Z</atom:updated>
            <content:encoded><![CDATA[<p>In ClickHouse, <strong>Materialized Views</strong> are a mechanism that allows you to store the result of a query in a table automatically. Essentially, they are <strong>precomputed views</strong> that are updated as new data is inserted into the source table. This can dramatically speed up read performance because the results are stored as actual data on disk, rather than having to be computed from scratch every time a query is run.</p><h3>Key Features of Materialized Views:</h3><ol><li><strong>Precomputed Data</strong>: The view stores the result of a query. When new data is inserted into the base table, the materialized view is updated automatically.</li><li><strong>Performance</strong>: Instead of recomputing complex queries each time they are needed (especially in OLAP use cases), the materialized view serves the precomputed result. This reduces latency for certain types of queries.</li><li><strong>Automatic Updates</strong>: Materialized views in ClickHouse are automatically updated whenever new data is inserted into the underlying table. You don’t have to manually refresh them.</li><li><strong>Storage</strong>: Since the data is stored on disk, it consumes additional storage. However, it can save computation time for complex aggregations and joins.</li><li><strong>Use Cases</strong>:</li></ol><p><strong>Aggregation</strong>: Pre-aggregating data for fast reporting or analytics.</p><p><strong>Filtering</strong>: Storing a subset of data based on certain conditions, reducing the amount of data that needs to be scanned during queries.</p><p><strong>Optimization</strong>: Making frequently-run, resource-intensive queries faster by caching their results.</p><h3>How It Works:</h3><p>When you create a materialized view, it typically “listens” to changes in an existing table. Every time data is inserted into the base table, the materialized view is updated according to the query logic defined in its definition.</p><pre>CREATE MATERIALIZED VIEW daily_user_activity<br>ENGINE = SummingMergeTree()<br>PARTITION BY toYYYYMM(date)<br>ORDER BY (date, user_id)<br>AS<br>SELECT<br>    toDate(event_time) AS date,<br>    user_id,<br>    count() AS activity_count<br>FROM events<br>GROUP BY date, user_id;c</pre><h4>Key Points:</h4><ul><li><strong>Engine</strong>: You define the engine for the materialized view just like you do for a normal table. Engines like MergeTree, SummingMergeTree, ReplacingMergeTree, etc., can be used depending on the type of data processing you want.</li><li><strong>Partitioning</strong>: You can partition materialized views, especially useful when you need to process large datasets incrementally.</li><li><strong>Query Performance</strong>: Because the data is pre-aggregated and stored, querying the materialized view is much faster than performing the same aggregation on the base table.</li></ul><h3>1. Chained Materialized Views (Cascading MVs)</h3><p>You can create multiple materialised views that depend on each other. This is useful in cases where you need multiple stages of aggregation or transformation on the data.</p><p>For example, you might have a first materialized view that performs a daily aggregation and a second that aggregates further to a weekly or monthly level. This allows you to incrementally process data without recalculating the entire dataset.</p><pre>-- First MV: Daily aggregation<br>CREATE MATERIALIZED VIEW daily_stats<br>ENGINE = SummingMergeTree()<br>PARTITION BY toYYYYMM(date)<br>ORDER BY (date, product_id)<br>AS<br>SELECT<br>    toDate(order_time) AS date,<br>    product_id,<br>    sum(amount) AS total_sales<br>FROM orders<br>GROUP BY date, product_id;<br><br>-- Second MV: Weekly aggregation based on the first MV<br>CREATE MATERIALIZED VIEW weekly_stats<br>ENGINE = SummingMergeTree()<br>PARTITION BY toYYYYMM(date)<br>ORDER BY (date, product_id)<br>AS<br>SELECT<br>    toStartOfWeek(date) AS week_start,<br>    product_id,<br>    sum(total_sales) AS weekly_sales<br>FROM daily_stats<br>GROUP BY week_start, product_id;</pre><p>In this example, weekly_stats is a <strong>cascading materialized view</strong>, depending on daily_stats. This structure allows efficient computation at different time granularities.</p><h3>2. <strong>Use of Complex Aggregation Engines</strong></h3><p>ClickHouse supports a variety of engines that can be used in materialized views, which are tailored for specific types of aggregation or optimization.</p><ul><li><strong>SummingMergeTree</strong>: Automatically sums up values when data is merged.</li><li><strong>ReplacingMergeTree</strong>: Replaces rows based on some condition (often used for deduplication).</li><li><strong>AggregatingMergeTree</strong>: Stores pre-aggregated data using specialized types for efficient grouping and aggregation.</li><li><strong>CollapsingMergeTree</strong>: Used for automatically collapsing records that have a specific sign (often used for events that cancel each other out).</li></ul><h3>3. <strong>Using Materialized Views for Event Processing &amp; Time Series Data</strong></h3><p>Materialized views can be very effective when working with <strong>event-based data</strong> or <strong>time series data</strong>. By using a well-designed materialized view, you can maintain near-real-time aggregates and summaries without hitting performance bottlenecks.</p><p>For example, if you’re storing clickstream data and need to compute user activity statistics on the fly (like daily active users, page views, etc.), a materialized view can be updated as events are ingested, allowing for fast and real-time querying.</p><pre>CREATE MATERIALIZED VIEW user_activity<br>ENGINE = SummingMergeTree()<br>PARTITION BY toYYYYMMDD(event_time)<br>ORDER BY (user_id, event_time)<br>AS<br>SELECT<br>    user_id,<br>    toDate(event_time) AS date,<br>    count() AS event_count<br>FROM user_events<br>GROUP BY user_id, date;</pre><p>This materialized view will allow you to efficiently query <strong>daily active users</strong> or even break them down into hourly or weekly buckets.</p><h3>4. Handling Replaces and Deletes with Materialized Views</h3><p>One of the limitations of materialized views in ClickHouse is that they don’t <strong>delete</strong> or <strong>update</strong> rows based on changes in the base table. However, this can be worked around with a combination of <strong>ReplacingMergeTree</strong> or by setting up proper triggers or cleanup tasks.</p><p>For example, if you’re using a ReplacingMergeTree engine for materialized views, you could set up an MV that only keeps the latest row for a given user_id:</p><pre>CREATE MATERIALIZED VIEW latest_user_data<br>ENGINE = ReplacingMergeTree(version)<br>PARTITION BY toYYYYMMDD(update_time)<br>ORDER BY (user_id)<br>AS<br>SELECT<br>    user_id,<br>    update_time,<br>    data,<br>    row_number() OVER (PARTITION BY user_id ORDER BY update_time DESC) AS version<br>FROM user_updates;</pre><p>This will store only the latest update for each user in the materialized view.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db437d1889b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shared Service (Angular 19) | Angular’s component life-cycle]]></title>
            <link>https://medium.com/@parthsurati096/shared-service-angular-19-angulars-component-life-cycle-dd19067cd085?source=rss-4c0dcdb893d5------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd19067cd085</guid>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[angular-19]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Parth Surati]]></dc:creator>
            <pubDate>Wed, 30 Apr 2025 08:01:42 GMT</pubDate>
            <atom:updated>2025-04-30T08:01:42.432Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Step 1: Create a shared service</strong></p><pre>ng generate service shared</pre><p><strong>shared.service.ts</strong></p><pre>import { Injectable } from &#39;@angular/core&#39;;<br>import { BehaviorSubject } from &#39;rxjs&#39;;<br><br>@Injectable({<br>  providedIn: &#39;root&#39;<br>})<br>export class SharedService {<br>  private titleSource = new BehaviorSubject&lt;string&gt;(&#39;Default Title&#39;);<br>  currentTitle$ = this.titleSource.asObservable();<br><br>  setTitle(title: string) {<br>    this.titleSource.next(title);<br>  }<br>}</pre><p><strong>Step 2: Sidebar Component — Send selected title</strong></p><p>In sidebar.component.ts, inject the service and call setTitle when an option is clicked:</p><pre>import { Component } from &#39;@angular/core&#39;;<br>import { SharedService } from &#39;../shared.service&#39;;<br><br>@Component({<br>  selector: &#39;app-sidebar&#39;,<br>  templateUrl: &#39;./sidebar.component.html&#39;<br>})<br>export class SidebarComponent {<br>  constructor(private sharedService: SharedService) {}<br><br>  selectOption(title: string) {<br>    this.sharedService.setTitle(title);<br>  }<br>}</pre><p>And in sidebar.component.html, trigger it on a click:</p><pre>&lt;ul&gt;<br>  &lt;li (click)=&quot;selectOption(&#39;Dashboard&#39;)&quot;&gt;Dashboard&lt;/li&gt;<br>  &lt;li (click)=&quot;selectOption(&#39;Settings&#39;)&quot;&gt;Settings&lt;/li&gt;<br>&lt;/ul&gt;</pre><p><strong>Step 3: Header Component — Subscribe to title</strong></p><p>In header.component.ts, subscribe to the title observable:</p><pre>import { Component, OnInit } from &#39;@angular/core&#39;;<br>import { SharedService } from &#39;../shared.service&#39;;<br><br>@Component({<br>  selector: &#39;app-header&#39;,<br>  templateUrl: &#39;./header.component.html&#39;<br>})<br>export class HeaderComponent implements OnInit {<br>  currentTitle: string = &#39;&#39;;<br><br>  constructor(private sharedService: SharedService) {}<br><br>  ngOnInit(): void {<br>    this.sharedService.currentTitle$.subscribe(title =&gt; {<br>      this.currentTitle = title;<br>    });<br>  }<br>}</pre><p>Then in header.component.html, show the current title:</p><pre>&lt;h1&gt;{{ currentTitle }}&lt;/h1&gt;</pre><p>if you want to freely develop Angular web we should focus on <strong>Angular’s component life-cycle</strong></p><p>Angular components follow a defined lifecycle, and different hooks are called at specific points during this lifecycle. The lifecycle starts when the component is <strong>created</strong> and ends when it is <strong>destroyed</strong>. Here’s the basic flow:</p><p><strong>Creation Phase</strong>:</p><ul><li><strong>ngOnChanges</strong> (if inputs change)</li><li><strong>ngOnInit</strong></li><li><strong>ngDoCheck</strong></li></ul><p><strong>Change Detection Phase</strong> (after creation and when inputs change):</p><ul><li><strong>ngAfterContentInit</strong></li><li><strong>ngAfterContentChecked</strong></li><li><strong>ngAfterViewInit</strong></li><li><strong>ngAfterViewChecked</strong></li></ul><p>Destruction Phase :</p><ul><li>ngOnDestroy</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd19067cd085" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>