<?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 Rajeen Balasuriya on Medium]]></title>
        <description><![CDATA[Stories by Rajeen Balasuriya on Medium]]></description>
        <link>https://medium.com/@rajeenbalasuriya1?source=rss-13677e04dcf6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hVxOliWsOtjG6m5Z</url>
            <title>Stories by Rajeen Balasuriya on Medium</title>
            <link>https://medium.com/@rajeenbalasuriya1?source=rss-13677e04dcf6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:13:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajeenbalasuriya1/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[How Node.js Handles Thousands of Requests Efficiently]]></title>
            <link>https://medium.com/@rajeenbalasuriya1/how-node-js-handles-thousands-of-requests-efficiently-a08b2ad07b59?source=rss-13677e04dcf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a08b2ad07b59</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript-event-loop]]></category>
            <category><![CDATA[epoll]]></category>
            <category><![CDATA[libuv]]></category>
            <dc:creator><![CDATA[Rajeen Balasuriya]]></dc:creator>
            <pubDate>Sat, 07 Mar 2026 07:34:59 GMT</pubDate>
            <atom:updated>2026-03-07T07:34:59.298Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDzLu8c-u5k2YROqXLWYlQ.png" /><figcaption>Source: <a href="https://medium.com/preezma/node-js-event-loop-architecture-go-deeper-node-core-c96b4cec7aa4">https://medium.com/preezma/node-js-event-loop-architecture-go-deeper-node-core-c96b4cec7aa4</a></figcaption></figure><p>Node.js is often described as <em>single-threaded</em>, but that statement can be misleading if you don’t understand what happens behind the scenes. To really grasp why Node behaves this way, it helps to look at how a connection from a client actually reaches the server and how it is handled by the operating system before Node even touches it.</p><p>In this article, we will first explore <strong>how TCP connections are established</strong>, how the kernel organizes them in <strong>queues</strong>, and how the server eventually accepts them. Once we understand this process, it will become clear why Node.js can handle thousands of connections efficiently using a single thread.</p><h3>How Connections Are Made to a Server</h3><p><strong>1.Operating System: Handling Connection Queues</strong></p><p>When a server starts listening on a network port, for example using server.listen(3000) in Node.js, the operating system creates a <strong>listening socket</strong>. This socket is passive it cannot yet communicate with clients, but it is ready to accept connection requests. At this stage, the OS maintains internal structures to manage all incoming connections efficiently.</p><ol><li>SYN queue(Waiting queue for acknowledgement)</li><li>Accept queue</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ZfL5Ft4yEzdxt2m2hvfRQ.png" /></figure><p>The first step of a connection is initiated by the client, which sends a <strong>SYN packet</strong> as part of the TCP three-way handshake. The kernel places this request in a <strong>SYN queue</strong>, also known as the half-open queue. The server responds with a SYN-ACK, waiting for the client to complete the handshake by sending the final ACK. If the client never responds, the connection remains in the SYN queue. This is important because malicious clients or network issues can cause these half-open connections to pile up, potentially overflowing the queue and preventing legitimate clients from connecting.</p><p>Once the client completes the handshake by sending the final ACK, the connection is considered fully established. The OS moves it into the <strong>accept queue</strong>. This queue holds all connections that are ready for the server application to handle. You can imagine it as visitors who have finished registering at the reception desk and are waiting to be called in. The server is not responsible for handling them immediately,the kernel ensures that connections are queued safely until the application is ready.</p><p><strong><em>At this point, the OS has finished establishing the connection, and it is now up to the application to accept and process it from the accept queue.</em></strong></p><p><strong>2.Application: Accepting and Handling Connections</strong></p><p>In order for the application to handle a connection, it must retrieve it from the accept queue, and to do this, the server uses the <strong>accept() </strong>system call . This call returns a dedicated socket for that client, allowing the application to read requests, process them, and send responses. Until the application accepts the connection, it remains safely queued by the kernel. This design allows the server to handle incoming traffic at its own pace, efficiently managing multiple connections without being blocked by the network.</p><p><strong><em>You may be wondering that you have never directly called </em></strong><strong><em>accept() in Node.js ,so how does Node make this system call under the hood?</em></strong></p><h3>How Node.js Retrieves Accepted Connections from the OS</h3><p>Node.js uses a <strong>single thread</strong> to manage and accept incoming connections, leveraging the <strong>libuv library</strong> to interact with the operating system.</p><p>Normally, system calls like accept() are <strong>blocking</strong>, meaning the thread would wait until a connection is ready before continuing. However, libuv avoids blocking by using platform-specific mechanisms such as <strong>epoll</strong> on Linux, <strong>kqueue</strong> on macOS, and <strong>IOCP</strong> on Windows. These allow libuv to be notified <strong>only when a connection is available</strong>.</p><p>As a result, Node.js can perform the accept operation non-blockingly, allowing the <strong>single main thread</strong> to handle thousands of connections efficiently without ever being stuck waiting for a socket. This design is the key reason Node.js can maintain high concurrency while remaining single-threaded.</p><p>Additionally, libuv contains a small thread pool (default 4 threads) for handling tasks that cannot be done asynchronously by the OS, such as DNS lookups, file system operations, and certain CPU-bound tasks. These worker threads perform the blocking work in the background and then schedule callbacks on the main event loop, so your JavaScript code still executes on a single thread. This hybrid design allows Node.js to handle both network I/O and other asynchronous tasks efficiently, while keeping the main thread free to execute JavaScript.</p><h3>Summary</h3><p>Node.js is often called single-threaded because all JavaScript execution happens on a single main thread. However, it can handle thousands of simultaneous connections efficiently thanks to libuv, which monitors sockets non-blockingly using mechanisms like epoll, kqueue, and IOCP. Connections are queued by the operating system and retrieved by libuv only when ready, while worker threads in libuv handle tasks like DNS queries and file operations in the background. This design allows Node.js to maintain high concurrency without blocking the main thread, combining simplicity with performance.</p><p>Thank you for reading! I hope this article helped clarify why Node.js is single-threaded but can still handle massive numbers of concurrent connections.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a08b2ad07b59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[End-to-End CI/CD Pipeline for Node.js on AWS EC2 Using GitHub Actions and Nginx]]></title>
            <link>https://medium.com/@rajeenbalasuriya1/end-to-end-ci-cd-pipeline-for-node-js-on-aws-ec2-using-github-actions-and-nginx-fa565f9f034f?source=rss-13677e04dcf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa565f9f034f</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Rajeen Balasuriya]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 11:51:07 GMT</pubDate>
            <atom:updated>2026-02-12T11:51:07.712Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vx4ohLa_RS3RBiWTqmtd-g.png" /></figure><h3>Understanding the Importance of CI/CD</h3><p>Modern software development demands speed, reliability, and automation. Manually building and deploying applications every time a change is made is not only inefficient but also risky. Even a small mistake during deployment can cause downtime or production issues. This is where CI/CD pipelines become essential.</p><p>CI/CD (Continuous Integration and Continuous Deployment) is a practice that automates the process of building, testing, and deploying applications whenever code changes occur. Instead of manually updating servers, a pipeline ensures that every change is automatically validated and deployed in a consistent, repeatable, and reliable way.</p><h3>Project Overview</h3><p>In this project, I built an automated CI/CD pipeline to deploy a Node.js REST API on an AWS EC2 Ubuntu instance. The application connects to MongoDB Atlas for database operations, uses Nginx as a reverse proxy, and is managed by PM2 to ensure it runs continuously in the background.</p><p>To automate deployment, I configured a self-hosted GitHub Actions runner inside the EC2 instance. Whenever changes are pushed to the main branch, the workflow automatically pulls the latest code, installs dependencies, updates environment variables, and restarts the application. This setup eliminates manual deployment and ensures a consistent, reliable release process.</p><p>1.Set Up the Database &amp; Validate the Application Locally<br>2.Launch EC2 Instance and connect via ssh<br>3.Setting Up the GitHub Self-Hosted Runner &amp; NGINX<br>4.Configuring the CI/CD Workflow</p><h3>1.Set Up the Database &amp; Validate the Application Locally</h3><p>First create the MongoDB cluster, navigate to <strong>Network Access → IP Access List</strong> and add an IP address.</p><p>For learning and testing purposes, you can allow access from <strong>any IP address (0.0.0.0/0)</strong>. This enables the application to connect to the database from anywhere, including your local machine and EC2 instance.</p><p>⚠️ However, in a production environment, this is not recommended. Instead, you should restrict access to specific trusted IP addresses, such as your EC2 instance’s public IP. This improves security by limiting database access to known sources only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQ-nj6DI9OWKqmnZ6DrfYA.png" /></figure><p>After configuring network access, navigate to <strong>Clusters → Connect → Drivers</strong> in MongoDB Atlas and copy the connection URI provided. Replace the username and password placeholders with your database credentials. Then, add this URI to the .env file of your Node.js application (for example, MONGO_URI=your_connection_string). Finally, run the application locally and verify that it successfully connects to the database before proceeding to deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9FNWBGA3uXAIggo0K8Hayw.png" /></figure><h3>2.Launch EC2 Instance and connect via ssh</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5SbFCEeO98OtQxy-l-E9zg.png" /><figcaption>Creating the EC2 instance</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*09L9kwN8KqIb5uRsmlrP0A.png" /><figcaption>Creating the key pair</figcaption></figure><p>To host the application, launch a new Ubuntu EC2 instance in your AWS account. During the instance creation process, generate or select an existing key pair and download the .pem file. This private key is required to securely connect to the server via SSH. AWS uses key-based authentication instead of passwords, making access more secure. Store the .pem file safely, as it is the only way to log in to the EC2 instance and manage your application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QMHBLG9Iece1ake07o0GMQ.png" /></figure><p>After the instance is launched, select it in the AWS console and navigate to the <strong>Connect</strong> tab to copy the provided ‘ssh-i… ‘ command. Open your terminal, go to the directory where your .pem file is saved, and run the command to establish the connection. If you encounter a permission error, it is usually because SSH requires the private key to be readable only by the owner. Adjusting the file permissions resolves this issue easily. Once authenticated successfully, you will be inside your Ubuntu EC2 environment and ready to proceed with the setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FnaJaiJ6_VizuiBFGwmBNQ.png" /></figure><h3><strong>3.Setting Up the GitHub Self-Hosted Runner</strong></h3><p>Once inside the Ubuntu EC2 environment, navigate to your GitHub repository and go to <strong>Settings → Actions → Runners</strong>. Add a new <strong>self-hosted runner</strong> and select Linux as the operating system. GitHub will provide a set of commands to download and configure the runner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vBiDNoqC2qcN3_cK-2yGRA.png" /></figure><p>Run those commands inside your EC2 instance to download the runner package, configure it with your repository URL and token, and start the runner. After installation, you can register it as a system service so it runs continuously in the background.</p><p>At this stage, the runner is operating in interactive mode using ./run.sh. However, this process will stop if the SSH session closes or the server restarts. To ensure the runner operates continuously in the background, it should be registered as a system service:</p><pre>sudo ./svc.sh install<br>sudo ./svc.sh start</pre><p>In addition, the EC2 instance must have the required server dependencies installed to run the application. Install Node.js and Nginx using the following commands:</p><pre>sudo apt update<br>curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -<br>sudo apt-get install -y nodejs nginx</pre><p>Node.js is required to execute the application, while Nginx will act as a reverse proxy to handle incoming traffic.</p><p>After installing Node.js on the EC2 instance, configure Nginx to act as a reverse proxy for the Node.js application. Nginx will forward incoming HTTP requests to the backend service running on localhost:5000. Open the Nginx configuration file located at /etc/nginx/sites-available/default and add a location block that proxies /api requests to the application port. Once the configuration is updated, restart Nginx to apply the changes. This setup allows external traffic to be handled securely and efficiently before reaching the Node.js server.</p><pre>location /api {<br>  rewrite ^\/api\/(.*)$ /api/$1 break;<br>  proxy_pass http://localhost:5000;<br>  proxy_set_header Host $host;<br>  proxy_set_header X-Real-IP $remote_addr;<br>  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>}</pre><h3>4 Configuring the CI/CD Workflow</h3><p>Before creating the workflow file, it is important to understand that environment variables such as the MongoDB connection string are not stored directly in the repository. Since these values contain sensitive information, they should never be committed to source control.</p><p>In order to deploy the application securely, these environment variables must be added to the <strong>GitHub repository secrets</strong>. Navigate to <strong>Settings → Secrets and variables → Actions</strong>, create a new repository secret (for example, MONGO_DB_URL), and paste the database connection string as its value. The workflow can then securely access this value using ${{ secrets.MONGO_DB_URL }} during deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_4JX4shjrfqWm8bW2bP8g.png" /></figure><p>To automate the deployment process, we use the predefined <strong>Node.js workflow template</strong> provided by GitHub Actions. In the repository, navigate to <strong>Actions → New workflow</strong> and select the <strong>Node.js</strong> template. This generates a ready-to-use workflow file with basic steps such as installing dependencies and building the application.</p><p>We then modify this generated workflow according to our requirements configuring it to run on the self-hosted runner, injecting environment variables from GitHub Secrets, and restarting the application after deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gwLB3qN7ngpckVl_DtnA0w.png" /></figure><p>The original Node.js workflow template provided by GitHub is mainly designed for Continuous Integration. It runs on ubuntu-latest, installs dependencies, builds the project, and executes tests across multiple Node.js versions. Since our goal is deployment to an EC2 server, we modified the workflow to run on self-hosted so it executes directly on our EC2 instance. We simplified the Node version to a single production version, removed the test step for now, and added a step to dynamically create the .env file using GitHub Secrets.</p><pre># This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node<br># For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs<br><br>name: Node.js CI<br><br>on:<br>  push:<br>    branches: [ &quot;main&quot; ]<br>  pull_request:<br>    branches: [ &quot;main&quot; ]<br><br>jobs:<br>  build:<br><br>    runs-on: self-hosted<br><br>    strategy:<br>      matrix:<br>        node-version: [24.x]<br>        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/<br><br>    steps:<br>    - uses: actions/checkout@v4<br>    - name: Use Node.js ${{ matrix.node-version }}<br>      uses: actions/setup-node@v4<br>      with:<br>        node-version: ${{ matrix.node-version }}<br>        cache: &#39;npm&#39;<br>    - run: npm ci<br>    - run: |<br>        touch .env<br>        echo &quot;${{ secrets.MONGO_DB_URL }}&quot; &gt; .env<br>    - run: npm run build --if-present</pre><p>The initial version of the workflow handled code checkout, dependency installation, environment variable injection, and project build. After the first successful execution, the application was started manually using PM2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GzMz5xbbjyF7crXjuEoXyQ.png" /></figure><p>Once verified, the workflow was enhanced to include a pm2 restart step, enabling fully automated deployments on subsequent pushes.</p><pre># This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node<br># For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs<br><br>name: Node.js CI<br><br>on:<br>  push:<br>    branches: [ &quot;main&quot; ]<br>  pull_request:<br>    branches: [ &quot;main&quot; ]<br><br>jobs:<br>  build:<br><br>    runs-on: self-hosted<br><br>    strategy:<br>      matrix:<br>        node-version: [24.x]<br>        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/<br><br>    steps:<br>    - uses: actions/checkout@v4<br>    - name: Use Node.js ${{ matrix.node-version }}<br>      uses: actions/setup-node@v4<br>      with:<br>        node-version: ${{ matrix.node-version }}<br>        cache: &#39;npm&#39;<br>    - run: npm ci<br>    - run: |<br>        touch .env<br>        echo &quot;${{ secrets.MONGO_DB_URL }}&quot; &gt; .env<br>    - run: npm run build --if-present<br>    - run: pm2 restart api</pre><p>By integrating MongoDB Atlas, AWS EC2, GitHub Actions, Nginx, and PM2, we created a complete end-to-end CI/CD pipeline for a Node.js application. The infrastructure handles secure database connectivity, reverse proxy configuration, automated builds, and seamless application restarts.</p><p>With this architecture, every push to the repository becomes a deployable event. The process is reliable, repeatable, and production-ready, significantly reducing deployment errors and operational overhead. This approach not only improves development efficiency but also establishes a solid DevOps foundation for scaling applications in real-world environments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa565f9f034f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Is LangChain and Why Do We Need It?]]></title>
            <link>https://medium.com/@rajeenbalasuriya1/what-is-langchain-and-why-do-we-need-it-a4cbdc822e5f?source=rss-13677e04dcf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4cbdc822e5f</guid>
            <dc:creator><![CDATA[Rajeen Balasuriya]]></dc:creator>
            <pubDate>Wed, 26 Nov 2025 11:20:11 GMT</pubDate>
            <atom:updated>2025-11-26T11:20:11.228Z</atom:updated>
            <content:encoded><![CDATA[<p>AI models like GPT-4o, Claude, and Llama are incredibly powerful on their own. You can ask a question, request a paragraph, or generate ideas with a single prompt. But the moment you try to build a <em>real</em> AI application something that performs multiple steps, interacts with tools, or transforms content you hit an immediate limitation: one LLM call is not enough.</p><p>Real-world AI requires structure. It needs memory, workflows, tool integrations, and the ability to break a complex task into smaller pieces. This is exactly where <strong>LangChain</strong> becomes essential. It isn’t “another AI model” it’s the framework that helps you <em>use</em> AI models properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ftIrpo4KyOcVX96q7JUSTQ.png" /></figure><h3>Why One Prompt Isn’t Enough</h3><p>Most people begin with the simple model:</p><p><strong>Prompt → Answer</strong></p><p>That works for:</p><ul><li>quick questions</li><li>small paragraphs</li><li>conversational tasks</li></ul><p>But it breaks down the moment you try to build something more serious, like:</p><ul><li>a blog-writing assistant</li><li>an agent that uses external tools</li><li>a summarization engine</li><li>a research assistant</li><li>a RAG search system</li><li>or any multi-step workflow</li></ul><p>Ask an LLM to generate a title, rewrite a paragraph, summarize the text, AND produce an image prompt in one message, and it will almost always struggle. Models mix instructions, lose context, or ignore parts of the prompt entirely.</p><p><em>LangChain introduces a simple but powerful pattern</em></p><h3>Break a big job into small steps, then chain them together.</h3><p>Just like modular software engineering, each step becomes its own component:</p><ul><li><strong>Step 1:</strong> Generate a title</li><li><strong>Step 2:</strong> Generate a description</li><li><strong>Step 3:</strong> Improve a paragraph</li><li><strong>Step 4:</strong> Produce an image prompt</li></ul><p>LangChain passes data cleanly from one step to the next, turning your workflow into something that is:</p><ul><li>predictable</li><li>modular</li><li>easier to debug</li><li>cheaper to run</li><li>and more accurate overall</li></ul><p>It feels less like “prompt engineering” and more like building real software.</p><h3>A Simple Example: From One Article to a Complete Pipeline</h3><p>Imagine you want an AI tool that transforms an article into a full “publish-ready” package:</p><ul><li>A catchy title</li><li>An SEO-friendly description</li><li>An improved paragraph</li><li>A prompt for a cover image</li></ul><p>Trying to get all of this in one huge prompt leads to chaotic results.</p><p>With LangChain, the same task becomes clean and structured:</p><p><strong>Step 1 — Title generation</strong><br> chain_one produces a dictionary:</p><pre>{ &quot;article_title&quot;: &quot;...&quot; }</pre><p><strong>Step 2 — Description generation</strong><br> chain_two now receives both the article and the generated title.</p><p><strong>Step 3 — Paragraph editing</strong><br> This chain can even return structured output (like JSON containing the original paragraph, the improved version, and feedback).</p><p><strong>Step 4 — Image prompt generation</strong><br> Finally, the image prompt goes to DALL·E, completing the pipeline.</p><p>Each chain handles one job.<br>Each chain receives only the context it needs.</p><p>This is the foundation of real AI engineering.</p><h3>Why Chaining Reduces Cost</h3><p>This is one of the biggest advantages of LangChain, even though many developers overlook it.</p><p>Different steps require different levels of intelligence.<br>With chaining, you can intentionally pick the cheapest or most capable model <em>per step</em>:</p><ul><li>Use <strong>GPT-4o mini</strong> for simple tasks like title generation</li><li>Use <strong>GPT-4o</strong> only where deeper reasoning is needed (like editing a paragraph)</li><li>Use models that support structured output for clean JSON</li><li>Use DALL·E only when generating images</li><li>Avoid re-sending the entire article multiple times.</li></ul><p>If you tried doing all these tasks in <em>one</em> prompt with GPT-4o, you would pay:</p><ul><li>more tokens,</li><li>for a more expensive model,</li><li>and usually get <em>lower</em> accuracy.</li></ul><p>Chaining allows you to optimize cost and compute at every stage.</p><h3>So Why Is LangChain Needed?</h3><p>Because it transforms raw LLMs into usable building blocks for full applications.</p><p><em>LLMs can generate text.<br>LangChain lets you build systems.</em></p><p>If your work requires more than one prompt and almost every real AI workflow does LangChain becomes the tool that keeps everything organized and scalable.</p><p>As AI models evolve, the need for structured workflows and modular pipelines only becomes more important. LangChain isn’t just a helper library; it’s becoming a foundational layer for building serious AI products.</p><p>Thanks for reading ,and feel free to leave your thoughts or questions in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4cbdc822e5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seeing the Big Picture: A Simple Guide to Abstraction]]></title>
            <link>https://medium.com/@rajeenbalasuriya1/seeing-the-big-picture-a-simple-guide-to-abstraction-f7e52d28cbe3?source=rss-13677e04dcf6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7e52d28cbe3</guid>
            <dc:creator><![CDATA[Rajeen Balasuriya]]></dc:creator>
            <pubDate>Fri, 21 Nov 2025 11:46:24 GMT</pubDate>
            <atom:updated>2025-11-21T11:46:24.113Z</atom:updated>
            <content:encoded><![CDATA[<p>When I was learning OOP concepts, the one idea that made absolutely no sense to me was <strong>abstraction</strong>. As a beginner, the definition felt understandable on the surface, but <em>how it was useful in real code</em> didn’t make sense at all.</p><p>So in this article, we’ll take it step by step.</p><ol><li>First, we’ll look at the <strong>simple definition</strong> of abstraction.</li><li>Then, we’ll break it down using a <strong>real-world example</strong> so the idea. becomes easier to visualize.</li><li>Finally, we’ll <strong>implement that scenario in Java</strong> to see abstraction in action and understand why it matters.</li></ol><blockquote><strong>Abstraction means focusing on what an object does instead of how it does it. It lets you use an object without understanding all of its internal complexity, which helps developers write reusable and maintainable code.</strong></blockquote><p>To understand abstraction, think about how a car works.When you press the gas pedal, a lot of complex mechanisms start working fuel pumps activate, air flows into the engine, combustion happens, and many internal parts move together to make the car accelerate.</p><p>Now imagine if, as drivers, we had to manually control every one of those steps: adjusting levers, pulling cables, regulating air and fuel flow ourselves. We would need to learn the entire engineering behind car mechanics just to make it move.</p><p><strong>Instead, car manufacturers give us a simple interface steering wheel, pedals, and a gear selector to hide all that complexity.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZCtKS4MhW6Nk5btG5gG8IA.png" /></figure><p>We only interact with what’s necessary, while the complicated internal processes stay hidden.<strong>This is exactly what abstraction does in OOP: it hides unnecessary details and presents a simple interface to work with.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tuQE_6UubsIYbC-z_c28Q.png" /></figure><p>Hiding complex details doesn’t just make things easier to use it also gives us a lot of <strong>flexibility</strong>.In the real world, different car brands have different engines, different parts, and different internal mechanisms. A Toyota engine and a Honda engine work differently inside.But every car manufacturer agrees to provide the <strong>same interface</strong> to the driver:</p><p><strong>A</strong> <strong>steering wheel, gas pedal, brake pedal, and gear selector.</strong></p><p>Drivers rely on this common abstraction.Because of this, a person doesn’t have to learn how every brand works internally they only need to know how to use the interface. Whether it’s Toyota, Honda, or BMW, the driver behaves the same way because the interface stays consistent.</p><p>This means the user is <strong>decoupled</strong> from the actual implementation.The implementation (engine, fuel system, electronics) can change, improve, or be completely redesigned, and the user can still use the car without learning anything new.</p><p>This also gives the user the flexibility to switch to a different brand without confusion.</p><p>The same idea applies in OOP:<br><strong>Depending on abstractions (interfaces or abstract classes) instead of concrete implementations makes our code flexible, easier to extend, and easier to maintain.</strong></p><h3>❌ <strong>Incorrect Implementation (NO abstraction)</strong></h3><pre>class HondaCar {<br>    public void pressRacingPedal() {<br>        System.out.println(&quot;Honda: Racing pedal → Fast acceleration!&quot;);<br>    }<br><br>    public void turnSteeringWheel() {<br>        System.out.println(&quot;Honda: Steering wheel turned.&quot;);<br>    }<br>}</pre><pre>class ToyotaCar {<br>    public void pressSmoothPedal() {<br>        System.out.println(&quot;Toyota: Smooth pedal → Gentle acceleration.&quot;);<br>    }<br><br>    public void turnSteeringWheel() {<br>        System.out.println(&quot;Toyota: Steering wheel turned.&quot;);<br>    }<br>}</pre><pre>class User {<br>    private HondaCar car;   // 🔴 Still concrete type!<br><br>    public User(HondaCar car) {   // 🔴 Must be Honda only<br>        this.car = car;<br>    }<br><br>    public void drive() {<br>        car.pressRacingPedal();   // 🔴 Method tied to Honda<br>        car.turnSteeringWheel();<br>    }<br>}</pre><h3>❌ PROBLEMS with this design</h3><ol><li>User class depends on a <strong>specific car type</strong></li><li>User’s methods depend on <strong>Honda-specific method names</strong></li><li>Switching brands means:</li></ol><ul><li>Change field type</li><li>Change constructor parameter</li><li>Rewrite method calls</li><li>Possibly add new logic for Toyota</li></ul><p>4.User class becomes <strong>tightly coupled</strong>, not flexible</p><p>5.User cannot accept new car brands unless modified</p><p>Following code will demonstrate above problems using the Honda and Toyota class.</p><pre>public class WrongDemo {<br>    public static void main(String[] args) {<br><br>        HondaCar honda = new HondaCar();<br>        User user = new User(honda);<br>        user.drive();<br><br>        // If user wants ToyotaCar:<br>        ToyotaCar toyota = new ToyotaCar();<br><br>        // 🔴 User cannot accept ToyotaCar → COMPILATION ERROR!<br>        // User user2 = new User(toyota);  <br>    }<br>}</pre><h3>✅ <strong>Correct Implementation Using Abstraction (Interface)</strong></h3><p>Car Interface</p><pre>interface Car {<br>    void pressGasPedal();<br>    void turnSteeringWheel();<br>}</pre><p>Honda car</p><pre>class HondaCar implements Car {<br>    public void pressGasPedal() {<br>        System.out.println(&quot;Honda: Racing pedal → Fast acceleration!&quot;);<br>    }<br><br>    public void turnSteeringWheel() {<br>        System.out.println(&quot;Honda: Steering wheel turned.&quot;);<br>    }<br>}</pre><p>Toyota car</p><pre>class ToyotaCar implements Car {<br>    public void pressGasPedal() {<br>        System.out.println(&quot;Toyota: Smooth pedal → Gentle acceleration.&quot;);<br>    }<br><br>    public void turnSteeringWheel() {<br>        System.out.println(&quot;Toyota: Steering wheel turned.&quot;);<br>    }<br>}</pre><p>User</p><pre>class User {<br>    private Car car;   // ✔ Interface, not brand<br><br>    public User(Car car) {   // ✔ We can pass ANY car<br>        this.car = car;<br>    }<br><br>    public void drive() {<br>        car.pressGasPedal();<br>        car.turnSteeringWheel();<br>    }<br>}</pre><p>Following code will power of abstraction using above three classes.</p><pre>public class CorrectDemo {<br>    public static void main(String[] args) {<br><br>        Car honda = new HondaCar();<br>        User user1 = new User(honda);<br>        user1.drive();<br><br>        System.out.println(&quot;----- Switching car brand -----&quot;);<br><br>        Car toyota = new ToyotaCar();<br>        User user2 = new User(toyota);<br>        user2.drive();<br>    }<br>}</pre><p>🎉 Now we have flexibility :</p><p><em>No changes in User class</em></p><p><em>Add new brands without modifying existing code</em></p><p><em>User is completely decoupled from Honda/Toyota</em></p><p><em>Perfect example of OOP Abstraction</em></p><h3>Summary</h3><p>Abstraction in OOP helps developers focus on what an object does rather than how it works internally. By hiding unnecessary details and exposing only the essential actions, we make our code easier to use, easier to maintain, and much more flexible.</p><p>The car example clearly shows why abstraction is important. Even though different car brands have different internal engines and mechanisms, all drivers use the same simple interface steering wheel, pedals, and gears. This common interface hides complexity and allows users to switch between brands without learning anything new.</p><p>In programming, depending on concrete classes (like HondaCar or ToyotaCar) makes code rigid and difficult to change. But when we depend on an abstraction (an interface such as Car), our code becomes reusable, extendable, and independent of specific implementations.</p><p>Abstraction is therefore a key principle in OOP: it decouples the user from the implementation, reduces dependency, and gives our programs the flexibility to grow and adapt over time.</p><p><em>Thank you for reading !</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7e52d28cbe3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>