<?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"><channel><title><![CDATA[Pradip Thapa]]></title><description><![CDATA[Pradip Thapa]]></description><link>https://blog.pradipthapa.net</link><generator>RSS for Node</generator><lastBuildDate>Tue, 05 May 2026 15:40:35 GMT</lastBuildDate><atom:link href="https://blog.pradipthapa.net/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The Secrets Behind Redis's Single-Thread High-Speed Execution]]></title><description><![CDATA[Hello everyone!
As software engineers, it’s always better to understand the internals of the systems we use. Knowing how things work under the hood gives us deeper insight, helps us debug smarter, and makes us better at designing reliable application...]]></description><link>https://blog.pradipthapa.net/the-secrets-behind-rediss-single-thread-high-speed-execution</link><guid isPermaLink="true">https://blog.pradipthapa.net/the-secrets-behind-rediss-single-thread-high-speed-execution</guid><category><![CDATA[Redis]]></category><category><![CDATA[Databases]]></category><dc:creator><![CDATA[Pradip Thapa]]></dc:creator><pubDate>Mon, 05 Jan 2026 15:53:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1767628309662/8546d7d9-0938-44da-9f78-e5fcc2009c68.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello everyone!</p>
<p>As software engineers, it’s always better to understand the <strong>internals of the systems we use</strong>. Knowing how things work under the hood gives us deeper insight, helps us debug smarter, and makes us better at designing reliable applications.</p>
<p>In this blog, I’ll share the <strong>internals of Redis</strong> - the parts that finally “clicked” for me while learning. My goal is simple: to help you build a better mental model of Redis so you can use it more effectively in your own projects.</p>
<p><strong>Redis</strong> is an in‑memory data structure store that can be used as a database, cache, message broker, and more. Because it keeps data in RAM, reads and writes are extremely fast.</p>
<p>A common surprise is that <strong>Redis is single threaded</strong>. That means the core server processes commands on one thread. That raises an obvious question: if two clients send requests at the same time, doesn’t one have to wait for the other? Wouldn’t multithreading give better parallelism?</p>
<p>Technically, requests are handled sequentially. But in practice this isn’t a bottleneck for Redis. Accessing RAM takes nanoseconds, so simple commands like <code>SET</code> or <code>GET</code> complete extremely quickly. Even if thousands of requests are queued, the single thread can process them in a tiny fraction of a second. Introducing multithreading would add context switches, locks, and synchronization overhead that often slow things down more than they help.</p>
<p>Redis uses <strong>IO multiplexing</strong>: one thread watches many I/O sources and reacts only when they’re ready. On Linux, Redis uses the <code>epoll</code> system call to get notified when sockets have activity.</p>
<p>The Redis server loop performs two main tasks: it accepts new connections, which can be from your backend services or <code>redis-cli</code>, and it executes commands received on existing connections, such as <code>GET</code> or <code>SET</code>.</p>
<p>When the server starts, it registers sockets with <code>epoll</code>. The main thread runs an event loop that waits for <code>epoll</code> to indicate which sockets are ready. When <code>epoll</code> reports an event, Redis handles it right away, such as accepting a connection or reading and executing a command. If a client is connected but idle, Redis doesn't wait for that client; it just keeps processing other ready events. This event‑driven architecture keeps the server responsive without the complexity of many threads.</p>
<p>You can think of Redis’s <code>main()</code> function as an infinite loop that listens for <code>epoll</code> events and dispatches them to a handler. Because commands are executed one at a time on the main thread, <strong>each operation is atomic</strong>: Redis won’t context switch in the middle of a command and start another.</p>
<p>When two clients increment the same counter using <code>INCR page_views</code>, Client A sends <code>INCR page_views</code>, and Client B sends <code>INCR page_views</code>.</p>
<p>Redis guarantees one increment completes before the next starts. The counter will go <code>10 → 11 → 12</code>, never lose an update.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Redis’s speed isn’t magic - it’s the result of a deliberate, simple design: keep data in memory, use an event loop driven by <code>epoll</code>, and avoid the complexity of multithreading where it would add overhead. Good engineering often comes from simplifying the system and removing unnecessary components, not from adding complexity for its own sake.</p>
]]></content:encoded></item><item><title><![CDATA[Mastering the OSI Model: A Backend Developer's Essential Guide]]></title><description><![CDATA[How Data Flows Through the OSI Model: A Guide for Backend Developers
As a backend developer, grasping how data travels across a network is essential for creating robust, efficient, and scalable applications. The OSI (Open Systems Interconnection) Mod...]]></description><link>https://blog.pradipthapa.net/mastering-the-osi-model-a-backend-developers-essential-guide</link><guid isPermaLink="true">https://blog.pradipthapa.net/mastering-the-osi-model-a-backend-developers-essential-guide</guid><category><![CDATA[OSI Model]]></category><category><![CDATA[backend systems]]></category><category><![CDATA[backend developments]]></category><dc:creator><![CDATA[Pradip Thapa]]></dc:creator><pubDate>Mon, 07 Jul 2025 15:07:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/SpCrTUG2nu8/upload/de19e9ef8212026df23da8d9dd29bdfb.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>How Data Flows Through the OSI Model: A Guide for Backend Developers</strong></p>
<p>As a backend developer, grasping how data travels across a network is essential for creating robust, efficient, and scalable applications. The OSI (Open Systems Interconnection) Model is a fundamental framework that breaks down network communication into seven distinct layers. Each layer has a specific role, ensuring data is transferred accurately and reliably between devices.</p>
<p>In this guide, we'll explore the OSI Model from a backend developer's perspective, using the example of sending an email. By following data through the OSI layers, you'll gain insight into the complex process behind network communication.</p>
<h3 id="heading-the-seven-layers-of-the-osi-model"><strong>The Seven Layers of the OSI Model</strong></h3>
<p>The OSI Model divides communication into seven layers:</p>
<ol>
<li><p><strong>Application Layer</strong></p>
</li>
<li><p><strong>Presentation Layer</strong></p>
</li>
<li><p><strong>Session Layer</strong></p>
</li>
<li><p><strong>Transport Layer</strong></p>
</li>
<li><p><strong>Network Layer</strong></p>
</li>
<li><p><strong>Data Link Layer</strong></p>
</li>
<li><p><strong>Physical Layer</strong></p>
</li>
</ol>
<p>Let's see how data flows through each layer.</p>
<h3 id="heading-scenario-sending-an-email"><strong>Scenario: Sending an Email</strong></h3>
<h4 id="heading-step-1-application-layer-layer-7"><strong>Step 1: Application Layer (Layer 7)</strong></h4>
<p>Imagine a boyfriend sending an email to his girlfriend. He opens his email app, writes the message, and hits ‘send.’ At this stage, the data is at the <strong>application layer</strong>. The app uses <strong>SMTP (Simple Mail Transfer Protocol)</strong> to format and send the email across the network.</p>
<h4 id="heading-step-2-presentation-layer-layer-6"><strong>Step 2: Presentation Layer (Layer 6)</strong></h4>
<p>The <strong>presentation layer</strong> translates data into a format both devices understand. It may compress or encrypt the email for efficiency and security, ensuring the data is ready for the next step.</p>
<h4 id="heading-step-3-session-layer-layer-5"><strong>Step 3: Session Layer (Layer 5)</strong></h4>
<p>The <strong>session layer</strong> sets up, maintains, and manages the communication session. It keeps the connection open during the transfer and handles synchronization.</p>
<h4 id="heading-step-4-transport-layer-layer-4"><strong>Step 4: Transport Layer (Layer 4)</strong></h4>
<p>The data reaches the <strong>transport layer</strong>, where it’s divided into smaller segments. This segmentation allows for efficient management and error correction. <strong>TCP (Transmission Control Protocol)</strong> or <strong>UDP (User Datagram Protocol)</strong> ensures error-checking, flow control, and reliable data transfer.</p>
<h4 id="heading-step-5-network-layer-layer-3"><strong>Step 5: Network Layer (Layer 3)</strong></h4>
<p>The <strong>network layer</strong> breaks segments into packets and adds the <strong>IP (Internet Protocol)</strong> address, routing the email correctly through the network.</p>
<h4 id="heading-step-6-data-link-layer-layer-2"><strong>Step 6: Data Link Layer (Layer 2)</strong></h4>
<p>The <strong>data link layer</strong> packages data into frames, including physical addresses (MAC addresses) of the sender and receiver. It ensures error detection during transmission.</p>
<h4 id="heading-step-7-physical-layer-layer-1"><strong>Step 7: Physical Layer (Layer 1)</strong></h4>
<p>Finally, the data reaches the <strong>physical layer</strong>, converting it into a bitstream of 1s and 0s. This raw data is transmitted through the physical medium, like cables or Wi-Fi.</p>
<h3 id="heading-receiving-the-email"><strong>Receiving the Email</strong></h3>
<p>On the girlfriend's computer, the process reverses:</p>
<ol>
<li><p>The <strong>physical layer</strong> receives the bitstream, converts it into frames, and passes it to the <strong>data link layer</strong>.</p>
</li>
<li><p>The <strong>data link layer</strong> reassembles frames into packets for the <strong>network layer</strong>.</p>
</li>
<li><p>The <strong>network layer</strong> assembles packets into segments for the <strong>transport layer</strong>.</p>
</li>
<li><p>The <strong>transport layer</strong> reassembles segments into the full email.</p>
</li>
<li><p>The <strong>session layer</strong> manages session closure.</p>
</li>
<li><p>The <strong>presentation layer</strong> decompresses or decrypts the data.</p>
</li>
<li><p>The <strong>application layer</strong> delivers the email to the app for reading.</p>
</li>
</ol>
<h3 id="heading-why-backend-developers-should-care"><strong>Why Backend Developers Should Care</strong></h3>
<p>Understanding the OSI Model helps you design efficient, scalable, and secure systems:</p>
<ul>
<li><p><strong>Data Handling</strong>: Optimize performance and manage large data effectively.</p>
</li>
<li><p><strong>Networking Protocols</strong>: Troubleshoot and implement solutions by understanding protocol layers.</p>
</li>
<li><p><strong>Security</strong>: Identify vulnerabilities and secure applications, like encryption at the presentation layer.</p>
</li>
<li><p><strong>Scalability</strong>: Make informed decisions on load balancing and network optimization.</p>
</li>
</ul>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>The OSI Model is crucial for backend development, providing a clear structure for understanding data flow over networks. By familiarizing yourself with each layer, you can design, optimize, and secure your applications more effectively. Keep the OSI Model in mind as a guide to navigate the complexities of networking in backend development.</p>
]]></content:encoded></item></channel></rss>