<?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 Davy on Medium]]></title>
        <description><![CDATA[Stories by Davy on Medium]]></description>
        <link>https://medium.com/@davidnjesh1460?source=rss-08179f64d483------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GUczus1ccp2P7ytO_JGxlQ.png</url>
            <title>Stories by Davy on Medium</title>
            <link>https://medium.com/@davidnjesh1460?source=rss-08179f64d483------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:24:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@davidnjesh1460/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[Architecting Zero-Downtime: My Journey with Terraform, Docker, and GitHub Actions.]]></title>
            <link>https://medium.com/@davidnjesh1460/architecting-zero-downtime-my-journey-with-terraform-docker-and-github-actions-431e4c133a9a?source=rss-08179f64d483------2</link>
            <guid isPermaLink="false">https://medium.com/p/431e4c133a9a</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[eveops]]></category>
            <dc:creator><![CDATA[Davy]]></dc:creator>
            <pubDate>Mon, 27 Apr 2026 14:14:02 GMT</pubDate>
            <atom:updated>2026-04-27T14:14:02.430Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Writing code is only half the battle; the real challenge is building its “home.” For my <strong>library management system,</strong> I moved beyond local hosting to engineer a professional cloud architecture.</p><p>By containerizing the <strong>MERN stack</strong> and using <strong>Terraform (IaC)</strong>, I’ve built a self-managing system deployed in <strong>AWS South Africa</strong>. Optimized with <strong>CloudFront</strong> for ultra-low latency in Kenya and powered by a <strong>GitHub CI/CD pipeline</strong>, this project demonstrates how to achieve zero-downtime updates and global performance from a single source. Here is how I bridged the gap from localhost to the cloud.</p><h3>1. User Architecture: Dual-Role Management</h3><p>The system uses <strong>Role-Based Access Control (RBAC)</strong> to provide tailored experiences for two user groups:</p><ul><li><strong>Students:</strong> A clean, card-based dashboard built with <strong>React and Tailwind CSS</strong> to track active loans, overdue books, and membership status at a glance.</li><li><strong>Admins:</strong> Full control over book inventory, user management, and campus-wide transaction monitoring.</li><li><strong>Backend:</strong> A robust <strong>Node.js and MongoDB</strong> core manages data persistence and complex logic across both roles.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*medC61AVB9DW4duOms9gVA.png" /><figcaption>Nomal user UI</figcaption></figure><h3>2. The Deployment Engine: GitHub Actions Pipeline</h3><p>To ensure professional-grade reliability, I automated the deployment process to eliminate human error:</p><ul><li><strong>Code Quality:</strong> Every push triggers an automated <strong>linting</strong> process to maintain industry standards.</li><li><strong>Automated Containerization:</strong> The pipeline builds Docker images and pushes them to <strong>Amazon ECR</strong>, ensuring an identical environment from development to the AWS South Africa region.</li><li><strong>Instant Updates:</strong> A final <strong>CloudFront invalidation</strong> step clears old cached data at edge locations in Kenya, delivering the latest features to users immediately after deployment.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G9y85LHxQ_zTcMcE9GvMKA.png" /><figcaption>CI/CD pipeline</figcaption></figure><h3>2. Infrastructure as Code: Modularizing with Terraform</h3><p>Provisioning a cloud environment manually through the AWS console is prone to human error. To ensure my <strong>library management system</strong> was reproducible and scalable, I adopted a modular <strong>Infrastructure as Code (IaC)</strong> approach using Terraform.</p><h3>The Modular Structure</h3><p>To ensure the environment is reproducible and scalable, I modularized the infrastructure into distinct components. This separation of concerns provides the following:</p><ul><li><strong>Code Reusability:</strong> The same core logic powers both my <strong>development</strong> (single instance) and <strong>staging</strong> (dual-instance) environments.</li><li><strong>Risk Mitigation:</strong> Isolation allows for specific updates — like modifying a security group rule — without affecting core VPC networking.</li><li><strong>Architectural Clarity:</strong> Each module has a dedicated responsibility, making the system easier to audit, debug, and scale.</li></ul><h3>Multi-Environment Management: Dev vs. Staging</h3><p>Using the same modular code with different terraform.tfvars parameters, I managed two distinct environments:</p><ul><li><strong>Dev Environment:</strong> Optimized for cost-efficiency using a <strong>single t3.micro instance</strong> — perfect for rapid feature testing and integration checks.</li><li><strong>Staging Environment:</strong> A production-grade mirror featuring <strong>two t3.micro instances</strong> behind an application load balancer<strong> (ALB)</strong>. This setup allows for rigorous testing of high-availability, load balancing, and the health-check logic required for <strong>zero-downtime deployments</strong>.</li></ul><h3>State Management and Reliability</h3><p>You’ll notice an errored.tfstate file in the staging directory. In a real-world DevOps workflow, infrastructure updates don’t always go perfectly. Handling state locks and recovery is part of the process, ensuring that the “source of truth” for the infrastructure remains consistent even when a deployment is interrupted. This is achieved by the use of S3-backed DynamoDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*Khm43X6WLjd_szBgkluKLg.png" /><figcaption>Terraform modules</figcaption></figure><h3>3. Bringing the Architecture to Life: Deployment &amp; Validation</h3><p>This stage of the journey is seeing the Terraform plan manifest into a running environment. This is where the <strong>user-data scripts</strong> and <strong>ECR integration</strong> work together to turn raw virtual machines into a functional application server.</p><h3>Automated Bootstrapping with User Data</h3><p>In the ASG-lt module, I utilized an AWS <strong>User Data script</strong> to automate the setup of each EC2 instance. Rather than manually SSHing into servers to install software, the launch template handles the heavy lifting:</p><ol><li><strong>Environment Setup:</strong> Installing Docker and the AWS CLI on a fresh Ubuntu 22.04 LTS image.</li><li><strong>ECR Authentication:</strong> Securely logging into the Amazon ECR registry using the instance’s IAM role.</li><li><strong>The “Pull &amp; Run”:</strong> Fetching the latest mern-frontend and mern-backend images directly from ECR and spinning them up as containers.</li></ol><h3>Validation: High Availability in Action</h3><p>As shown in the EC2 dashboard screenshot, the <strong>staging</strong> environment successfully launched <strong>two t3.micro instances</strong>. Notice that these are distributed across different Availability Zones (<strong>af-south-1a</strong> and <strong>af-south-1b</strong>). This is a critical design choice; if one data center in Cape Town faces an issue, the Library Management System stays online because the load balancer simply routes traffic to the healthy instance in the other zone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3fbKnXZmmbjmWe7Oj3rz-g.png" /><figcaption>Two EC2 instances, each in one AZ</figcaption></figure><h3>Under the Hood: Running Containers</h3><p>To verify the deployment, a peek inside the instances reveals the heart of the system. By running docker ps -a, we can see the MERN stack in its final form:</p><ul><li><strong>mern-frontend:</strong> Running an Nginx-based container to serve the React interface.</li><li><strong>MERN backend:</strong> Powering the API logic and connecting to the database.</li></ul><p>Both containers show a status of “Up,” proving that the GitHub pipeline successfully pushed the images and the Terraform-managed infrastructure pulled them correctly without manual intervention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*crFfZFyFtD7_c51Fk73HLQ.png" /><figcaption>Docker containers running from an EC2 instance</figcaption></figure><h3>4. Performance Optimization: Achieving 18ms Latency in Kenya</h3><p>The ultimate goal of this project was to provide a seamless, lightning-fast experience for students and staff. By combining a regional deployment in <strong>af-south-1</strong> with <strong>Amazon CloudFront</strong>, I was able to transform a cross-continental request into a near-instant interaction.</p><h3>Global Content Delivery</h3><p>As seen in this image, the Library Management System is accessed via a CloudFront distribution URL. By offloading the frontend delivery to the edge, we ensure that static assets (HTML, CSS, JS) are served from the closest possible cache point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*0V-o5UaNZmHhwOsOq3REmA.png" /><figcaption>Accessing the website from cloudfront</figcaption></figure><h3>The Numbers: Why Latency Matters</h3><p>The true validation of this setup is found in the network performance. In this image, a ping test to the CloudFront domain reveals an impressive average response time of <strong>18ms</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*dEHzBus8HfyY9CWh9rNytQ.png" /><figcaption>Low latency access to the website</figcaption></figure><ul><li>take <strong>150 ms—250 ms.</strong></li><li><strong>Localized Routing:</strong> By leveraging the CloudFront edge locations and the proximity of the South Africa region, I reduced that delay by over <strong>90%</strong>. For a user, this is the difference between a website that “lags” and one that feels instantaneous.</li></ul><h3>The Infrastructure Behind the Speed</h3><p>The final image shows the <strong>Terraform state — the</strong> complete list of 21 resources provisioned to make this possible. This state list is the “blueprint” of the entire system, including:</p><ul><li><strong>Networking &amp; Security:</strong> VPCs, subnets, and security groups that guard the data.</li><li><strong>IAM Roles:</strong> Specifically the ecr_read_only and secrets_access policies that allow the EC2 instances to pull images and configuration securely.</li><li><strong>Compute &amp; Scaling:</strong> The Auto Scaling Group (aws_autoscaling_group.asg) and Load Balancer ensure the site stays up even under heavy traffic.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*dDEPfsP1VmNX_qqSDMC2jg.png" /><figcaption>Deployed Infrustructure</figcaption></figure><h3>5. Data Flow: From Edge to Instance</h3><p>To make the architecture real, let’s trace exactly how a student’s request in Kenya reaches our containers in Cape Town. This flow highlights the synergy between the CDN, load balancer, and standard infrastructure.</p><h3>The Request Path:</h3><ol><li><strong>Optimized Entry:</strong> A student accesses the site. Thanks to CloudFront local peering, their static content is pulled directly from the <strong>Nairobi edge location</strong> for maximum speed.</li><li><strong>Backbone Forwarding:</strong> For dynamic API requests (a “cache miss&quot;), the traffic travels over the highly optimized <strong>AWS backbone</strong> network from Kenya to the application load balancer in <strong>Cape Town</strong>.</li><li><strong>High Availability:</strong> The ALB handles the request and intelligently routes it to a <strong>healthy EC2 instance</strong> within our Auto Scaling Group, where the actual MERN backend container is running.</li><li><strong>Instant Refresh:</strong> When our CI/CD pipeline deploys new code, the “CloudFront Invalidation” clears the Nairobi cache, while the instances immediately <strong>pull the fresh Docker image</strong> from ECR to ensure the user sees the absolute latest version of the app.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8-4clzltFiyqOar3fpmRw.png" /><figcaption>The architecture flow</figcaption></figure><h3>Conclusion: Engineering for the Future</h3><p>Building this library management system was more than just a coding exercise; it was a full-cycle DevOps journey. From writing the first line of the MERN stack to watching Terraform spin up a high-availability environment in Cape Town, the focus remained on <strong>automation, security, and performance.</strong></p><p>With a CI/CD pipeline that handles everything from linting to CloudFront invalidation, the system is now ready to scale, serving users with the reliability they expect in a modern digital environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=431e4c133a9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Zero Downtime: Mastering Blue-Green Deployments with Terraform and AWS]]></title>
            <link>https://medium.com/@davidnjesh1460/zero-downtime-mastering-blue-green-deployments-with-terraform-and-aws-c1bc532b5dec?source=rss-08179f64d483------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1bc532b5dec</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[blue-green-deployment]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Davy]]></dc:creator>
            <pubDate>Thu, 02 Apr 2026 14:24:37 GMT</pubDate>
            <atom:updated>2026-04-02T14:24:37.370Z</atom:updated>
            <content:encoded><![CDATA[<p>In the modern digital landscape, availability is everything. A few minutes of downtime can mean lost revenue, frustrated users, and a dented reputation. That is why <strong>Zero Downtime Deployment</strong> is the gold standard for production environments.</p><p>Achieving zero downtime means your application remains accessible to users even while you are rolling out updates, changing infrastructure, or updating server scripts. One of the most effective ways to manage this is through a <strong>Blue-Green Deployment</strong> strategy.</p><h3>The Strategy: Seamless Transitions</h3><p>The goal of this project was to update a web server cluster without dropping a single request. By leveraging Terraform’s lifecycle management and AWS Auto Scaling Groups (ASG), I created a workflow where the “New” (Green) version of the infrastructure is fully operational before the “Old” (Blue) version is retired.</p><h3>1. The Initial Architecture</h3><p>I began by deploying a modular infrastructure using <strong>Terraform</strong>. This included:</p><ul><li>An <strong>Application Load Balancer (ALB)</strong> to distribute traffic.</li><li>An <strong>Auto Scaling Group</strong> managing EC2 instances.</li><li>A <strong>launch template</strong> containing a user-data.sh script to bootstrap the web server.</li></ul><p>In the initial state (the “Blue” environment), the script was serving <strong>“Green Version 1.0.&quot;</strong></p><h3>2. Implementing the Update</h3><p>To trigger the deployment, I modified the user-data.sh script in the modules to reflect the new update: <strong>&quot;No downtime.&quot;</strong></p><p>The magic happens in the Terraform configuration using the create_before_destroy lifecycle rule. This ensures that when the launch template changes, Terraform doesn&#39;t just kill the existing instances. Instead:</p><ol><li>It creates the <strong>new</strong> launch template version.</li><li>It triggers the ASG to spin up <strong>new</strong> instances.</li><li>The load balancer waits for these new instances to pass health checks.</li><li>Only once the new instances are healthy does Terraform begin terminating the old ones.</li></ol><h3>3. Proof in the Terminal</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o19xpHrBUBg8PxJp5pAcaw.png" /><figcaption>100% uptime, creation of instances before destroying</figcaption></figure><p>As seen in the screenshot, I ran a continuous curl loop against the load balancer URL while running terraform apply.</p><p>The terminal logs show a flawless transition:</p><ul><li><strong>18:52:42:</strong> Requests are hitting the original instances (<strong>Green Version 1.0</strong>).</li><li><strong>18:56:42:</strong> The new instances (<strong>no downtime)</strong> begin appearing in the rotation alongside the old ones.</li><li><strong>18:57:37:</strong> Both versions coexist briefly as the load balancer shifts traffic to the healthy new nodes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*ndLammnj-xhqrxwxJUXVlQ.png" /><figcaption>Zero Downtime illustration as shown</figcaption></figure><ul><li><strong>19:01:51:</strong> The old instances are gracefully drained and terminated, leaving only the “No downtime&quot; version active.</li></ul><p>Throughout the entire process, the status code remained <strong>200 OK</strong>. Not a single request was lost during the handoff.</p><h3>Conclusion</h3><p>Zero downtime isn’t just about fancy tools; it’s about predictable, automated workflows. By combining Terraform’s infrastructure-as-code with AWS Auto Scaling lifecycles, we can turn a risky deployment into a non-event. This project demonstrates that with the right configuration, you can update production environments with total confidence, ensuring your users never see a “503 Service Unavailable” page again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1bc532b5dec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>