<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sayed Naweed Rizvi</title>
    <description>The latest articles on DEV Community by Sayed Naweed Rizvi (@snrizvi).</description>
    <link>https://dev.to/snrizvi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F638607%2F72f64361-dbdf-4891-b745-6320b83096ff.png</url>
      <title>DEV Community: Sayed Naweed Rizvi</title>
      <link>https://dev.to/snrizvi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/snrizvi"/>
    <language>en</language>
    <item>
      <title>Run VMs alongside Containers in a Kubernetes Custer with KubeVirt</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Tue, 29 Jul 2025 09:29:42 +0000</pubDate>
      <link>https://dev.to/snrizvi/run-vms-alongside-containers-in-a-kubernetes-custer-with-kubevirt-20g9</link>
      <guid>https://dev.to/snrizvi/run-vms-alongside-containers-in-a-kubernetes-custer-with-kubevirt-20g9</guid>
      <description>&lt;p&gt;As containers continue to dominate modern application deployment models, many organizations still rely heavily on virtual machines (VMs) for legacy workloads, specialized environments, or complex system-level applications. Instead of choosing between the two, what if we could run both—&lt;strong&gt;VMs and containers—side by side within a single Kubernetes cluster&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;That's exactly what &lt;strong&gt;KubeVirt&lt;/strong&gt; enables.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is KubeVirt?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;KubeVirt&lt;/strong&gt; is an open-source project that extends Kubernetes to manage not only containers but also virtual machines. It treats VMs as first-class citizens in the Kubernetes ecosystem by abstracting VMs into custom resources and scheduling them using Kubernetes-native workflows.&lt;/p&gt;

&lt;p&gt;Simply put: KubeVirt lets you &lt;strong&gt;run VMs like containers&lt;/strong&gt;, but without sacrificing the advantages of virtualization.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Would You Run VMs in Kubernetes?
&lt;/h2&gt;

&lt;p&gt;You might ask: “Isn’t Kubernetes meant for cloud-native, containerized apps?” Yes. But many enterprises face these challenges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Legacy workloads&lt;/strong&gt; that can’t be containerized easily.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Specialized software&lt;/strong&gt; requiring full OS-level control.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gradual migration&lt;/strong&gt; where some components are containerized, and others are not.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hybrid cloud strategies&lt;/strong&gt; with mixed workloads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dev/Test environments&lt;/strong&gt; needing VM support alongside microservices.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How Does KubeVirt Work?
&lt;/h2&gt;

&lt;p&gt;KubeVirt introduces a new CRD (Custom Resource Definition) called &lt;code&gt;VirtualMachineInstance (VMI)&lt;/code&gt;. When you define a VM using a YAML manifest, KubeVirt:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Uses &lt;strong&gt;libvirt&lt;/strong&gt; and &lt;strong&gt;QEMU&lt;/strong&gt; to create the VM.&lt;/li&gt;
&lt;li&gt;Schedules it on a Kubernetes node using the usual scheduler.&lt;/li&gt;
&lt;li&gt;Runs the VM inside a container (usually inside a pod with special privileges).&lt;/li&gt;
&lt;li&gt;Exposes networking and storage through standard Kubernetes mechanisms (e.g., Services, PVCs).&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Example: Spinning Up a VM Using KubeVirt
&lt;/h2&gt;

&lt;p&gt;Here's a simple manifest to launch a VM inside Kubernetes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubevirt.io/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;VirtualMachine&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-vm&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;running&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;kubevirt.io/domain&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-vm&lt;/span&gt;
    &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;domain&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;devices&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;disks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;disk&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;bus&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;virtio&lt;/span&gt;
            &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;containerdisk&lt;/span&gt;
        &lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;requests&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1Gi&lt;/span&gt;
      &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;containerdisk&lt;/span&gt;
        &lt;span class="na"&gt;containerDisk&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubevirt/ubuntu-cloud-container-disk-demo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a lightweight Ubuntu VM managed like any Kubernetes workload.&lt;/p&gt;




&lt;h2&gt;
  
  
  Benefits of Using KubeVirt
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Unified Platform&lt;/strong&gt;: Manage both VMs and containers using the same tooling, policies, and CI/CD pipelines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduced Operational Overhead&lt;/strong&gt;: No need to maintain separate systems like OpenStack or VMware for VMs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kubernetes-native APIs&lt;/strong&gt;: Developers interact with VMs just like any Kubernetes object (via kubectl).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elasticity&lt;/strong&gt;: Leverage Kubernetes autoscaling and scheduling for VMs too.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced Security and Multi-tenancy&lt;/strong&gt;: Apply Kubernetes-native RBAC, NetworkPolicies, and isolation models to VMs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dev/Test Use Cases&lt;/strong&gt;: Great for developers needing full VMs for OS-level testing or legacy software.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Real-World Use Cases
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Legacy Modernization&lt;/td&gt;
&lt;td&gt;Slowly migrate VMs to containers in the same platform.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Secure Sandboxing&lt;/td&gt;
&lt;td&gt;Run apps in full OS environments for added isolation.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dev/Test Labs&lt;/td&gt;
&lt;td&gt;Launch VMs on demand for testing operating systems, agents, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mixed Workloads&lt;/td&gt;
&lt;td&gt;Run microservices and monoliths side-by-side.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Edge Computing&lt;/td&gt;
&lt;td&gt;Use lightweight Kubernetes nodes to host both VMs and containers at the edge.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Challenges &amp;amp; Considerations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance Overhead&lt;/strong&gt;: VMs don’t have the same lightweight performance as containers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security Boundaries&lt;/strong&gt;: Running VMs inside pods introduces complexity in isolation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persistent Storage&lt;/strong&gt;: Proper planning required for VM disks and stateful workloads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Networking&lt;/strong&gt;: Integrating VMs with container networking (CNI plugins) requires some setup.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hey, if you have read thus far.&lt;br&gt;
I work in the Cloud &amp;amp; DevOps space, often exploring the intersections of emerging tools and infrastructure patterns. If you're into cloud-native tech, platform engineering, or DevOps transformations—feel free to follow me here for more hands-on insights and real-world discussions.&lt;/p&gt;

</description>
      <category>containers</category>
      <category>kubernetes</category>
      <category>kubevirt</category>
      <category>virtualmachine</category>
    </item>
    <item>
      <title>Learning Dependency Injection in PHP Was a Game Changer. Here's Why</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Thu, 03 Jul 2025 13:01:20 +0000</pubDate>
      <link>https://dev.to/snrizvi/learning-dependency-injection-in-php-was-a-game-changer-heres-why-4k9j</link>
      <guid>https://dev.to/snrizvi/learning-dependency-injection-in-php-was-a-game-changer-heres-why-4k9j</guid>
      <description>&lt;p&gt;Back in around 2013, I was neck-deep in a project where we had to upgrade a legacy PHP application built on Zend Framework. It was a mix of old-school PHP, some custom abstractions, and a whole lot of things just glued together to work.&lt;/p&gt;

&lt;p&gt;At the time, I had heard about &lt;strong&gt;Dependency Injection (DI)&lt;/strong&gt; in passing — mostly in conversations but during this upgrade, DI went from a buzzword to something I couldn’t live without.&lt;/p&gt;




&lt;h2&gt;
  
  
  What We Started With
&lt;/h2&gt;

&lt;p&gt;The legacy codebase followed a pretty procedural approach. Controllers would instantiate models, helpers, and services directly — like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ReportController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Zend_Controller_Action&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;generateAction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;_getParam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user_id'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="nv"&gt;$mailer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Mailer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$mailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Your report is ready"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Report generated."&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything was tightly coupled. There was no way to replace the &lt;code&gt;Mailer&lt;/code&gt; or &lt;code&gt;Database&lt;/code&gt; without modifying the controller directly.&lt;/p&gt;

&lt;p&gt;When we began upgrading to Zend Framework 2, it came with a proper &lt;strong&gt;ServiceManager&lt;/strong&gt; — Zend’s way of introducing &lt;strong&gt;Dependency Injection Containers&lt;/strong&gt;. That’s where things clicked for me.&lt;/p&gt;




&lt;h2&gt;
  
  
  My First Real Refactor
&lt;/h2&gt;

&lt;p&gt;Instead of hardcoding dependencies, we started defining services in the &lt;code&gt;module.config.php&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'service_manager'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'factories'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nc"&gt;Mailer&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;MailerFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;ReportService&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;ReportServiceFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in the &lt;code&gt;ReportServiceFactory&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ReportServiceFactory&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;FactoryInterface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;ContainerInterface&lt;/span&gt; &lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$requestedName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$mailer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Mailer&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ReportService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$mailer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, &lt;code&gt;ReportService&lt;/code&gt; just looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ReportService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$mailer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Database&lt;/span&gt; &lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Mailer&lt;/span&gt; &lt;span class="nv"&gt;$mailer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;mailer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$mailer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$userId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$userId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;mailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Report ready."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Why This Changed How I Write Code
&lt;/h2&gt;

&lt;p&gt;Looking back, this was an important lesson I learned as a PHP developer. Here's why:&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ It Made Testing Feasible
&lt;/h3&gt;

&lt;p&gt;Before, testing &lt;code&gt;ReportService&lt;/code&gt; meant spinning up a DB and suppressing email sending. Now, I could inject mocks and focus purely on logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$mockDb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MockDatabase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nv"&gt;$mockMailer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SpyMailer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nv"&gt;$service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ReportService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$mockDb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$mockMailer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$service&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No real database. No real emails. Just clean, fast unit tests.&lt;/p&gt;




&lt;h3&gt;
  
  
  ✅ It Forced Better Design
&lt;/h3&gt;

&lt;p&gt;I started thinking in &lt;strong&gt;interfaces&lt;/strong&gt; instead of concrete classes. When you pass dependencies in, you start asking: “What &lt;em&gt;should&lt;/em&gt; this class really depend on?” That naturally pushed me toward &lt;strong&gt;Single Responsibility Principle&lt;/strong&gt; and cleaner separation of concerns.&lt;/p&gt;




&lt;h3&gt;
  
  
  ✅ It Simplified Maintenance
&lt;/h3&gt;

&lt;p&gt;When a new requirement came in — say, queue emails instead of sending them instantly — I didn’t have to touch &lt;code&gt;ReportService&lt;/code&gt;. I just changed the binding in the factory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$container&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Mailer&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;QueueMailer&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zero changes to business logic. That felt like magic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Dependency Injection Isn’t a Framework Feature — It’s a Design Choice
&lt;/h2&gt;

&lt;p&gt;I used to think DI was something Laravel or Symfony gave you. But in reality, it’s a &lt;strong&gt;principle&lt;/strong&gt;: don’t create your dependencies; accept them from the outside.&lt;/p&gt;

&lt;p&gt;Zend just gave me the tools to see what was possible — and once I got it, I started applying the same approach even in plain PHP projects.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;That Zend upgrade taught me more about architecture, at the time, we were just trying to get the app to a newer version — but what I walked away with was a deeper appreciation for how good architecture enables flexibility, testability, and long-term maintainability.&lt;/p&gt;

</description>
      <category>dependencyinjection</category>
      <category>webdev</category>
      <category>php</category>
      <category>zendframework</category>
    </item>
    <item>
      <title>Making Sense of Cloud Costs with the FOCUS Framework</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Thu, 26 Jun 2025 04:39:05 +0000</pubDate>
      <link>https://dev.to/snrizvi/making-sense-of-cloud-costs-with-the-focus-framework-3j52</link>
      <guid>https://dev.to/snrizvi/making-sense-of-cloud-costs-with-the-focus-framework-3j52</guid>
      <description>&lt;h2&gt;
  
  
  Why the FOCUS Framework Matters in Real-World FinOps
&lt;/h2&gt;

&lt;p&gt;When you’ve worked with cloud bills for long enough, a few truths become obvious.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Every cloud provider structures data differently&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Normalizing cost and usage data across teams is a pain&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Building dashboards is easy — making them reliable and actionable is not&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s where the FOCUS Framework steps in.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is the FOCUS Framework?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;FOCUS&lt;/strong&gt; stands for FinOps Open Cost and Usage Specification. It's a standard schema for representing cloud cost and usage data — regardless of provider.&lt;/p&gt;

&lt;p&gt;Think of it as a common language for cloud billing data, whether you’re using AWS, Azure, GCP, or all three. It’s open, extensible, and vendor-neutral — built by practitioners through the &lt;a href="https://www.finops.org/framework/" rel="noopener noreferrer"&gt;FinOps Foundation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why It Matters?
&lt;/h2&gt;

&lt;p&gt;Cloud cost optimization often breaks down not because of tools, but because of inconsistent data.&lt;/p&gt;

&lt;p&gt;Here’s what usually happens in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finance gets raw billing data in different formats&lt;/li&gt;
&lt;li&gt;Engineering builds cost dashboards off inconsistent or incomplete tagging&lt;/li&gt;
&lt;li&gt;Leadership wants a clean view of business unit or product-level cost&lt;/li&gt;
&lt;li&gt;Everyone spends hours aligning spreadsheets — not solving the real issue&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With FOCUS, you start from a standardized foundation — meaning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One data structure to query across clouds&lt;/li&gt;
&lt;li&gt;Simplified onboarding of new business units or teams&lt;/li&gt;
&lt;li&gt;Easier integration with BI tools, cost platforms, or internal reporting systems&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Use Cases
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Multi-Cloud Reporting&lt;br&gt;
If your org is using more than one cloud provider, you’ve probably written glue code to make their billing data look “sort of” the same. With FOCUS, you define one schema and load every provider’s data into it. Reporting becomes provider-agnostic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Business Unit Showback&lt;br&gt;
Finance teams need to allocate cloud spend by department, project, or BU. If tagging or account hierarchies vary across cloud providers, FOCUS helps normalize the key dimensions — so you can reliably report and drive accountability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Benchmarking and KPIs&lt;br&gt;
Want to track cost per environment (dev/test/prod) or cost per user? FOCUS provides standard dimensions like &lt;em&gt;environment, resource_type, and product_family&lt;/em&gt; — making it easier to define and compare key metrics over time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Feeding FinOps Tools or Internal Platforms&lt;br&gt;
Whether you're using a commercial FinOps platform or an in-house data warehouse, FOCUS can serve as the source of truth. Many vendors are already adopting it as a supported input format — making future integrations easier.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Adopting FOCUS doesn't mean throwing out everything you have.&lt;br&gt;
Most teams start by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mapping their existing cost data (e.g., CUR, Azure Usage, GCP Billing Export) to FOCUS&lt;/li&gt;
&lt;li&gt;Building a transformation layer (ETL or dbt, for example) to load it into a FOCUS-compliant model&lt;/li&gt;
&lt;li&gt;Validating key metrics (e.g., total spend, daily cost by project) to ensure parity&lt;/li&gt;
&lt;li&gt;Slowly moving downstream dashboards and reports to use the FOCUS model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re using BigQuery, Snowflake, or Redshift — this is very doable with the open schema and transformation templates the community provides.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;FOCUS isn’t a silver bullet. It won’t tag your resources or fix broken cost allocations on its own. But it does give your team a clean, consistent foundation — and that’s something most FinOps programs are sorely missing.&lt;/p&gt;

&lt;p&gt;As cloud adoption grows and multi-cloud becomes the norm, standards like FOCUS are how we keep FinOps practices scalable and measurable.&lt;/p&gt;

&lt;p&gt;If you’re serious about moving beyond cloud cost monitoring to true cloud accountability, FOCUS is worth looking into.&lt;/p&gt;

</description>
      <category>finops</category>
      <category>focusframework</category>
      <category>cloudcost</category>
      <category>cloud</category>
    </item>
    <item>
      <title>LocalStack: Simulating AWS Locally for Faster Development and Testing</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Mon, 26 May 2025 04:38:51 +0000</pubDate>
      <link>https://dev.to/snrizvi/localstack-simulating-aws-locally-for-faster-development-and-testing-45n9</link>
      <guid>https://dev.to/snrizvi/localstack-simulating-aws-locally-for-faster-development-and-testing-45n9</guid>
      <description>&lt;p&gt;Working with AWS is powerful, but developing and testing cloud-native applications can be time-consuming, expensive, and error-prone — especially when you're deploying frequently just to test small changes.&lt;/p&gt;

&lt;p&gt;That’s where &lt;strong&gt;LocalStack&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;LocalStack lets you run a fully functional local AWS cloud stack. It simulates key AWS services on your machine so you can prototype, build, and test against real APIs — without ever hitting the cloud.&lt;/p&gt;

&lt;p&gt;This blog walks you through what LocalStack is, when to use it, how to get started, and a few real-world scenarios where it can save time and cost.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What is LocalStack?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;LocalStack is an open-source tool that emulates a wide range of AWS services locally. It’s built for developers who want to avoid the friction of deploying to AWS just to verify whether something works.&lt;/p&gt;

&lt;p&gt;It supports services like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;S3&lt;/li&gt;
&lt;li&gt;DynamoDB&lt;/li&gt;
&lt;li&gt;Lambda&lt;/li&gt;
&lt;li&gt;API Gateway&lt;/li&gt;
&lt;li&gt;SQS&lt;/li&gt;
&lt;li&gt;SNS&lt;/li&gt;
&lt;li&gt;CloudWatch (limited)&lt;/li&gt;
&lt;li&gt;And many more&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can run it using Docker and interact with it using the AWS CLI or SDKs just like you would with the real AWS environment.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Why Use LocalStack?&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Faster Feedback Loop&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;No need to wait for cloud provisioning. You can deploy, test, and debug in seconds.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Offline Development&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Perfect for working in environments with limited or no internet access.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Cost Efficiency&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Running AWS services locally during development avoids incurring unnecessary cloud bills.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Safe Testing&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can simulate failure scenarios and edge cases without impacting real infrastructure.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Getting Started with LocalStack&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Install Docker
&lt;/h3&gt;

&lt;p&gt;LocalStack runs in a Docker container, so you need Docker installed and running.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Pull and Run LocalStack
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull localstack/localstack
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 4566:4566 &lt;span class="nt"&gt;-p&lt;/span&gt; 4571:4571 localstack/localstack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Step 3: Set Up Your AWS CLI
&lt;/h3&gt;

&lt;p&gt;Configure your AWS CLI to point to LocalStack:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws configure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Use dummy credentials (LocalStack doesn't verify them):&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AWS Access Key ID [None]: test
AWS Secret Access Key [None]: test
Default region name [None]: us-east-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then set the endpoint URL when calling services:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws &lt;span class="nt"&gt;--endpoint-url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;http://localhost:4566 s3 mb s3://my-test-bucket
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Sample Use Case: Testing S3 Uploads&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s say you have an app that uploads files to S3. You can simulate that like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a bucket&lt;/span&gt;
aws &lt;span class="nt"&gt;--endpoint-url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;http://localhost:4566 s3 mb s3://demo-bucket

&lt;span class="c"&gt;# Upload a file&lt;/span&gt;
aws &lt;span class="nt"&gt;--endpoint-url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;http://localhost:4566 s3 &lt;span class="nb"&gt;cp &lt;/span&gt;sample.txt s3://demo-bucket/

&lt;span class="c"&gt;# List contents&lt;/span&gt;
aws &lt;span class="nt"&gt;--endpoint-url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;http://localhost:4566 s3 &lt;span class="nb"&gt;ls &lt;/span&gt;s3://demo-bucket/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This gives you the exact same experience as AWS, without using real cloud storage.&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;What LocalStack Can’t Do (Yet)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;While LocalStack is incredibly powerful, it’s not a 100% replacement for AWS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not all AWS services are fully supported&lt;/li&gt;
&lt;li&gt;Some advanced features (like IAM roles, VPC configurations) are limited&lt;/li&gt;
&lt;li&gt;Behavior may differ slightly from production under certain edge cases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use it for development and early testing, but always validate final behavior in real AWS environments.&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;LocalStack fills a much-needed gap in cloud-native development. If you’re building apps that use AWS services, adding LocalStack to your workflow can significantly improve your speed, confidence, and local testing experience.&lt;/p&gt;

&lt;p&gt;It’s not a replacement for real-world staging environments, but it’s a solid step toward more efficient and cost-effective development.&lt;/p&gt;

&lt;p&gt;Try out setting up S3 bucket on LocalStack now, it's easy 👇&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/snrizvi/setup-aws-s3-bucket-locally-with-localstack-3n4o" class="crayons-story__hidden-navigation-link"&gt;Setup AWS S3 bucket locally with LocalStack&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/snrizvi" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F638607%2F72f64361-dbdf-4891-b745-6320b83096ff.png" alt="snrizvi profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/snrizvi" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Sayed Naweed Rizvi
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Sayed Naweed Rizvi
                
              
              &lt;div id="story-author-preview-content-1110994" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/snrizvi" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F638607%2F72f64361-dbdf-4891-b745-6320b83096ff.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Sayed Naweed Rizvi&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/snrizvi/setup-aws-s3-bucket-locally-with-localstack-3n4o" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jun 11 '22&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/snrizvi/setup-aws-s3-bucket-locally-with-localstack-3n4o" id="article-link-1110994"&gt;
          Setup AWS S3 bucket locally with LocalStack
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/localstack"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;localstack&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/aws"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;aws&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/s3"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;s3&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/terraform"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;terraform&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/snrizvi/setup-aws-s3-bucket-locally-with-localstack-3n4o" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;58&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/snrizvi/setup-aws-s3-bucket-locally-with-localstack-3n4o#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              1&lt;span class="hidden s:inline"&gt; comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            2 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;/div&gt;
&lt;br&gt;


</description>
      <category>localstack</category>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>What Is the Purpose of main() in Java?</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Wed, 14 May 2025 17:39:49 +0000</pubDate>
      <link>https://dev.to/snrizvi/what-is-the-purpose-of-main-in-java-1155</link>
      <guid>https://dev.to/snrizvi/what-is-the-purpose-of-main-in-java-1155</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwv0omvhojwh4elrtv4nz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwv0omvhojwh4elrtv4nz.png" alt="Blog cover showing public static void main" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you're first introduced to Java, one of the first things you’ll write is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works, it prints something, and you're told that &lt;em&gt;main()&lt;/em&gt; is the "entry point" of your application. &lt;/p&gt;

&lt;h3&gt;
  
  
  But why is main() the method that Java looks for? Why does it have to be &lt;em&gt;public static void main(String[] args)&lt;/em&gt; and not anything else?
&lt;/h3&gt;

&lt;p&gt;Let's take a look through a practical lens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Java Needs a Starting Point
&lt;/h2&gt;

&lt;p&gt;Every program needs an entry point — a location where execution begins. In Java, this role is filled by the main() method.&lt;br&gt;
When you run a Java application using: &lt;code&gt;java HelloWorld&lt;/code&gt;&lt;br&gt;
the Java Virtual Machine (JVM) looks for a method that matches this exact signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s why each part matters:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;public&lt;/strong&gt;– The JVM must be able to call this method from outside the class. If it were private or protected, the JVM wouldn’t have access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;static&lt;/strong&gt; – The JVM doesn’t create an object of your class to call main(). That would be inefficient and unnecessary just to start execution. So main() needs to be static to be callable without instantiating the class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;void&lt;/strong&gt;– The JVM doesn’t expect any return value. It’s not waiting for output from main(), just looking to execute your logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String[] args&lt;/strong&gt;– This allows users to pass command-line arguments. You can run your Java app with java MyApp arg1 arg2, and those arguments land in this array.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Happens If You Change the Signature?
&lt;/h2&gt;

&lt;p&gt;Let’s say you try to change the signature slightly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static int main(String[] args)  // Won’t work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The JVM won’t recognize it as a valid entry point and throws an error, it’s not what the JVM is looking for.&lt;/p&gt;

&lt;p&gt;This strict contract is defined in the &lt;a href="https://docs.oracle.com/javase/specs/jls/se24/html/jls-12.html#jls-12.1.4" rel="noopener noreferrer"&gt;Java Language Specification&lt;/a&gt;. It's what allows the JVM to find your code and start running it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Use Cases of main()
&lt;/h2&gt;

&lt;p&gt;Most real-world Java applications don't live their entire life inside the main() method. But main() is still the launching pad. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spring Boot apps often have a main() method that calls SpringApplication.run() to bootstrap the framework.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {
    SpringApplication.run(MyApp.class, args);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Command-line tools written in Java also rely on main() to accept input arguments and run logic accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing frameworks or build tools like JUnit or Maven don’t use main() in the same way, because they are run by other tools, not as standalone applications. But even then, somewhere under the hood, a main() is used to launch the process.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Can You Have More Than One main()?
&lt;/h2&gt;

&lt;p&gt;No, in a single Java class, you can only have one method named main() with the exact signature:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;public static void main(String[] args)&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
You can overload the main() method — that is, you can have other methods in the same class named main with different parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MainOverloadExample {

    public static void main(String[] args) {
        System.out.println("Main method with String[] args");

        // You can manually call other overloaded main() methods
        main("Single String");
        main(5);
        main(new int[]{1, 2, 3});
    }

    public static void main(String arg) {
        System.out.println("Overloaded main with a single String: " + arg);
    }

    public static void main(int number) {
        System.out.println("Overloaded main with an int: " + number);
    }

    public static void main(int[] numbers) {
        System.out.print("Overloaded main with int[]: ");
        for (int n : numbers) {
            System.out.print(n + " ");
        }
        System.out.println();
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But these are not recognized by the JVM as entry points. Only the one with the exact signature — public static void main(String[] args) — is considered the application's starting point.&lt;/p&gt;

&lt;p&gt;So practically speaking, for a class to be executable as a Java program, it must contain only one valid main() method. If you try to define more than one with the same signature, the compiler will throw an error due to duplicate method definitions.&lt;/p&gt;

&lt;p&gt;However, across multiple classes in the same project, you can have one main() in each class — this is useful when creating utilities, demos, or testing individual components. But again, when you run the program, the JVM will only execute the main() of the class you specify.&lt;/p&gt;

</description>
      <category>java</category>
      <category>javatutorial</category>
      <category>programmingbasics</category>
      <category>mainmethod</category>
    </item>
    <item>
      <title>Just published a tiny npm tool: tree-generator 🌲 Turn a text-based folder structure into real folders/files instantly. https://www.npmjs.com/package/tree-generator-cli #npm #opensource #javascript #productivitytools #devtools #nodejs</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Thu, 10 Apr 2025 12:08:53 +0000</pubDate>
      <link>https://dev.to/snrizvi/just-published-a-tiny-npm-tool-tree-generator-turn-a-text-based-folder-structure-into-real-49ll</link>
      <guid>https://dev.to/snrizvi/just-published-a-tiny-npm-tool-tree-generator-turn-a-text-based-folder-structure-into-real-49ll</guid>
      <description></description>
      <category>npm</category>
      <category>opensource</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Var, Let , Const - Javascript basics</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Thu, 28 Mar 2024 13:06:24 +0000</pubDate>
      <link>https://dev.to/snrizvi/var-let-const-javascript-basics-20a2</link>
      <guid>https://dev.to/snrizvi/var-let-const-javascript-basics-20a2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Var&lt;/em&gt;, &lt;em&gt;let&lt;/em&gt; &amp;amp; &lt;em&gt;Const&lt;/em&gt; are used to declare variables, objects and constants in JavaScript.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Var
&lt;/h2&gt;

&lt;p&gt;Var keyword has been used for a longtime for variable declaration.&lt;br&gt;
It is &lt;strong&gt;Function Scoped&lt;/strong&gt;, it makes variables accessible only within the function boundary where it is declared.&lt;br&gt;
Take a look at this snippet&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getX(){
    var x = 1;
}
getX();
console.log(x)

//ReferenceError: x is not defined

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can &lt;strong&gt;re-declare&lt;/strong&gt; same variable in same scope with Var.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (true){
    var x = 2;
    var x = 3;
}
console.log(x)

// 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let
&lt;/h2&gt;

&lt;p&gt;Let was introduced in ES6&lt;a href="https://262.ecma-international.org/6.0/" rel="noopener noreferrer"&gt;ECMAScript2015&lt;/a&gt;.&lt;br&gt;
It is &lt;strong&gt;Block Scoped&lt;/strong&gt;, any code written within &lt;code&gt;{}&lt;/code&gt; is said to be in a Block. So, that's the restriction that ECMA wanted to implement with let, making variables inaccessible outside the block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function exampleLet() {
  if (true) {
    let y = 20;
  }
  console.log(y); // Error: y is not defined
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, you cannot re-declare same variable within the same scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (true){
    let x = 2;
    let x = 3;
}
// SyntaxError: Identifier 'x' has already been declared
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Const
&lt;/h2&gt;

&lt;p&gt;Const as the name suggests is used to declare Constants.&lt;br&gt;
Declaration with consts are *&lt;em&gt;Block Scoped *&lt;/em&gt;&lt;br&gt;
Constant needs to be initialized at the time of declaration, else it throws Syntax error&lt;br&gt;
Re-assigning or re-declaration is not allowed, it throws Syntax or Type Error.&lt;br&gt;
Check out the snippet below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (true){
    const x;
}
// SyntaxError: Missing initializer in const declaration

if (true){
    const x = 1;
    x = 2; // TypeError: Assignment to constant variable.
}

if (true){
    const x = 1;
    const x = 2;
} 
// SyntaxError: Identifier 'x' has already been declared

const x = 2;
if (true){
    const x = 1;
}
// Output : x = 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/QJsRx8_wdmU"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Strict Mode
&lt;/h2&gt;

&lt;p&gt;A feature introduced in ES5, it enforces stricter parsing and error handling.&lt;/p&gt;

&lt;p&gt;To enable strict mode, you need to put &lt;code&gt;_use strict;_&lt;/code&gt; at the beginning of code or function block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Global variable
var globalVar = "I'm a global variable";

function baz() {
  var localVar = "I'm a local variable";
  console.log(localVar); // Accessible inside the function

  if (true) {
    let blockVar = "I'm a block-scoped variable";
    console.log(blockVar); // Accessible inside the block
  }
  // console.log(blockVar); // Error: blockVar is not defined (not accessible outside the block)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;div&gt;
    &lt;iframe src="https://www.youtube.com/embed/jtpYvZa54H8"&gt;
    &lt;/iframe&gt;
  &lt;/div&gt;


</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What are JSON Web Tokens (JWT)</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Sun, 25 Dec 2022 13:55:56 +0000</pubDate>
      <link>https://dev.to/snrizvi/what-are-json-web-tokens-jwt-4pc</link>
      <guid>https://dev.to/snrizvi/what-are-json-web-tokens-jwt-4pc</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ohz27wfespe66flsqub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ohz27wfespe66flsqub.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may be asking yourself, "What in the world is a JSON Web Token and why do I need to know about it?"&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a JSON Web Token (JWT)
&lt;/h2&gt;

&lt;p&gt;In a nutshell, JWTs are a way to securely transmit information between parties. Think of it like a digital version of a secret club password. Only the people who know the password can get in and access the information.&lt;/p&gt;

&lt;p&gt;JWTs are means of transferring data between client &amp;amp; server in an API call in a secure &amp;amp; encrypted JSON format.&lt;/p&gt;

&lt;p&gt;The information can be trusted since it is digitally signed, any change to data in transit would make the token invalid.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does JWT work?
&lt;/h2&gt;

&lt;p&gt;A JWT consists of 3 parts&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Header &lt;br&gt;
The header specifies the algorithm being used to generate the JWT.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Payload &lt;br&gt;
The payload contains the &lt;em&gt;claims&lt;/em&gt;, Claims are statements about an entity (typically, the user) and additional data. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Signature&lt;br&gt;
The signature is used to verify that the sender of the JWT is who it says it is and to ensure that the message wasn't changed along the way.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why use them
&lt;/h2&gt;

&lt;p&gt;JWTs have a few key benefits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Self-Contained&lt;/strong&gt;&lt;br&gt;
JWTs are self-contained. This means that all of the information needed to verify the authenticity of the token is contained within the token itself. No need to check a separate database to verify the user's identity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stateless&lt;/strong&gt;&lt;br&gt;
JWTS are stateless. This means that the server doesn't need to keep track of the token or the user's session. This can make things a lot easier and more efficient for the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Platform Agnostic&lt;/strong&gt;&lt;br&gt;
JSON Web Tokens (JWTs) are a widely used industry standard for securely transmitting information between parties. As a result, there are libraries available for implementing JWTs in a variety of programming languages.&lt;/p&gt;

&lt;p&gt;Here is a non-exhaustive list of some popular programming languages and the libraries that can be used for working with JWTs in those languages:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;JavaScript: jsonwebtoken, jwt-simple, jwt-decode&lt;br&gt;
Python: PyJWT, python-jwt&lt;br&gt;
Java: java-jwt, jjwt&lt;br&gt;
Go: jwt-go&lt;br&gt;
Ruby: jwt, ruby-jwt&lt;br&gt;
C#: System.IdentityModel.Tokens.Jwt&lt;br&gt;
PHP: firebase/php-jwt&lt;br&gt;
Swift: JWT&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is just a small sampling of the many libraries that are available for working with JWTs in different programming languages. There are likely even more options available depending on the specific needs of your application.&lt;/p&gt;

&lt;p&gt;It's worth noting that while there are many libraries available for working with JWTs, the core principles of how JWTs work and how they are implemented are generally the same across languages. This means that once you have a solid understanding of how JWTs work, you should be able to apply that knowledge when working with JWTs in any language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where are JWTs used
&lt;/h2&gt;

&lt;p&gt;One common use case for JSON Web Tokens (JWTs) is for authorization purposes. &lt;br&gt;
Here's an example of how JWTs might be used for authorization in a web application:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The user logs into the web application and provides their credentials (e.g. username and password).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The server verifies the user's credentials and, if they are valid, generates a JWT and sends it back to the user's browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The user's browser stores the JWT in a cookie or local storage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For subsequent requests to the server, the user's browser includes the JWT in the header of the request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The server verifies the JWT and, if it is valid, allows the request to proceed. If the JWT is invalid or has expired, the server returns an error and denies the request.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This process allows the server to verify the user's identity and authorize their actions without maintaining a session or storing information about the user on the server. This can make the application more scalable and efficient, as it reduces the amount of data the server needs to store and manage.&lt;/p&gt;

&lt;p&gt;It's important to note that JWTs should be signed using a &lt;em&gt;secure algorithm&lt;/em&gt; and should be stored in a secure location on the client (e.g. an HttpOnly cookie). This helps to prevent unauthorized access to the JWT and ensures that it can't be tampered with by attackers.&lt;/p&gt;

&lt;p&gt;So, there you have it! A crash course on JSON Web Tokens.&lt;/p&gt;

</description>
      <category>jwt</category>
      <category>jsonwebtoken</category>
      <category>webdev</category>
      <category>api</category>
    </item>
    <item>
      <title>How to do Code Review</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Fri, 23 Dec 2022 03:12:02 +0000</pubDate>
      <link>https://dev.to/snrizvi/how-to-do-code-review-4k8f</link>
      <guid>https://dev.to/snrizvi/how-to-do-code-review-4k8f</guid>
      <description>&lt;p&gt;Code review is an essential part of the software development process. If done properly, it will not only improve the quality of the code, but it will also reduce the chances of bugs. Besides, code reviews provide a great opportunity to learn.&lt;/p&gt;

&lt;p&gt;There are several ways to review code effectively and productively:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understand the context and purpose of the code:&lt;/strong&gt; It's important to understand the overall goals and requirements of the code you are reviewing. This will help you identify potential issues and improvements more effectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use a checklist:&lt;/strong&gt; A checklist or Pull Request template can help you focus on specific aspects of the code, such as readability, security, and performance. This can help ensure that you don't miss anything important during the review process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collaborate with others:&lt;/strong&gt; Sharing your code review with other team members can help ensure that multiple perspectives are considered. This can be especially helpful if the code being reviewed is complex or involves multiple subsystems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use tools:&lt;/strong&gt; Tools, such as a SonarQube or a linter, can help you identify issues in the code more quickly and efficiently.&lt;/p&gt;

&lt;p&gt;The key to an effective code review is to approach it with an open mind and a focus on continuous improvement. By following these guidelines, you can help ensure that the code you review is of high quality and meets the project's goals and requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools for conducting reviews
&lt;/h2&gt;

&lt;p&gt;There are many modern tools available for conducting code reviews. Some popular options include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: GitHub is a popular version control system that allows developers to collaborate on code and track changes. It also includes features for conducting code reviews, including the ability to leave comments on specific lines of code and request changes.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GitLab: GitLab is another version control system that includes features for conducting code reviews. It offers tools for managing code review workflow, such as the ability to assign reviewers and set merge policies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reviewable: Reviewable is a code review tool that integrates with GitHub. It offers features such as inline commenting, code highlighting, and the ability to view the diff of code changes side-by-side.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gerrit: Gerrit is an open-source code review tool that is often used in large organizations. It offers features such as inline commenting, code highlighting, and the ability to view the diff of code changes side-by-side.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Phabricator: Phabricator is an open-source code review and project management tool. It offers features such as inline commenting, code highlighting, and the ability to view the diff of code changes side-by-side.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tools for checking code quality
&lt;/h2&gt;

&lt;p&gt;There are many open-source tools available for checking code quality. Here are a few examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;SonarQube: SonarQube is a tool for continuous code inspection that helps developers identify and fix code quality issues. It supports multiple programming languages and provides a web-based interface for reviewing and managing code quality issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PMD: PMD is a static code analysis tool that checks for common coding mistakes, such as unused variables or methods, and helps developers write clean, maintainable code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;FindBugs: FindBugs is a static code analysis tool that uses static analysis to look for bugs in Java code. It can detect a wide range of issues, including null pointer exceptions and infinite recursive loops.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Checkstyle: Checkstyle is a static code analysis tool that checks Java code for compliance with a set of coding standards, such as naming conventions and formatting rules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lint: Lint is a tool for checking code quality in a variety of programming languages, including C, C++, and Java. It can identify issues such as syntax errors and potential security vulnerabilities.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are just a few examples of the many code review tools that are available. The right tool for your team will depend on your specific needs and preferences. It's worth noting that these tools can be used in combination to get a more comprehensive view of the code quality in a project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Think about this
&lt;/h2&gt;

&lt;p&gt;As a Software Engineer, reviewing code written by peers is part of the job. But it will be more impactful if it comes with added responsibility and accountability on the reviewer.&lt;/p&gt;

&lt;p&gt;Reviewers should not think that their reviews are something done out of humility, they have to be made accountable for every line of code that they pass and every comment that they add.&lt;/p&gt;

</description>
      <category>codereview</category>
      <category>reviewcode</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Javascript Callback functions &amp; Promises</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Mon, 15 Aug 2022 16:20:00 +0000</pubDate>
      <link>https://dev.to/snrizvi/javascript-callback-functions-promises-17lp</link>
      <guid>https://dev.to/snrizvi/javascript-callback-functions-promises-17lp</guid>
      <description>&lt;p&gt;Callback functions are known to many programming languages, with almost similar style and purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Callback functions
&lt;/h2&gt;

&lt;p&gt;In simple terms, a function passed as an argument to another function is a Callback function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need them ?
&lt;/h2&gt;

&lt;p&gt;You must be wondering, what's so special about these Callback functions, couldn't we already call one function from inside the other.&lt;/p&gt;

&lt;p&gt;To get our answers, let's look at these 2 types of network calls.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sync&lt;/li&gt;
&lt;li&gt;Async&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Sync Vs Async Calls
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23qdpc84g6xwlfarath3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23qdpc84g6xwlfarath3.png" alt="sync vs async calls" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Callback functions are particularly used for handling the Async responses.&lt;/p&gt;




&lt;h2&gt;
  
  
    &lt;iframe src="https://www.youtube.com/embed/4kBX73mRNpI"&gt;
  &lt;/iframe&gt;

&lt;/h2&gt;

&lt;h2&gt;
  
  
  Callback Hell
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Anything that can go wrong will go wrong&lt;/em&gt;. - Murphy's I Law&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A Callback hell is a situation you might intentionally or unintentionally create to make things works, which can have few consequences.&lt;/p&gt;

&lt;p&gt;Consider having a tree of nested &lt;code&gt;setTimeout()&lt;/code&gt; function, In the world of programming Nesting is infamous and notorious.&lt;br&gt;
Why - Well, they make code unreadable, complex, vulnerable to breaking. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fef3pi6nx4bvjgduqsf0z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fef3pi6nx4bvjgduqsf0z.png" alt="callback Hell" width="652" height="443"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Promises
&lt;/h2&gt;

&lt;p&gt;Promises in JavaScript are similar to their literal meaning. It's an object through which you can associate handlers for async operations, way ahead in time, similar to a callback functions just that Promises are more clean and easy to manage.&lt;br&gt;
and yes, you can avoid Callback hell with Promises.&lt;/p&gt;

&lt;p&gt;Promises can be one of these states &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;pending - initial/default state&lt;/li&gt;
&lt;li&gt;fulfilled - promise is resolved, using &lt;code&gt;resolve()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;rejected - promise is rejected, using &lt;code&gt;reject()&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxz77s4rpcjeabvvwubdo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxz77s4rpcjeabvvwubdo.png" alt="Promises states" width="348" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let's create a simple promise&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promise = new Promise((resolve, reject) =&amp;gt; {
    if(res) {
        resolve('resolved')
    } else {
        reject('reject')
    }
})

promise.then(function(){
// On Successful response
// do whatever you feel like

})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we are creating a promise object by instantiating it with a &lt;code&gt;constructor&lt;/code&gt;. &lt;br&gt;
The constructor takes in a callback function which has handlers for &lt;code&gt;resolved&lt;/code&gt; and &lt;code&gt;rejected&lt;/code&gt; promises.&lt;/p&gt;

&lt;p&gt;What happens after a Promise is resolved or rejected is decided by &lt;code&gt;then()&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
    &lt;iframe src="https://www.youtube.com/embed/8lk5OxGoxSw"&gt;
  &lt;/iframe&gt;

&lt;/h2&gt;
&lt;h2&gt;
  
  
  Promise Chains
&lt;/h2&gt;

&lt;p&gt;When you are working with API calls, after receiving a response you would generally want to perform another call.&lt;br&gt;
so we need to create &lt;strong&gt;promise chains,&lt;/strong&gt; by appending one &lt;code&gt;then()&lt;/code&gt; after the other.&lt;/p&gt;

&lt;p&gt;Do remember that all the resolved promises will be handled by &lt;code&gt;resolve handlers&lt;/code&gt; and rejected promises will be handled by &lt;code&gt;reject handlers&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;checkout this code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function promise() {
    const jobPromise = new Promise((resolve, reject) =&amp;gt; {
        let selected = true; 

        setTimeout(() =&amp;gt; {
            if (selected) {
                resolve('Passed Interview');
            } else {
                reject('Failed Interview');
            }
        }, 1000);

    })

    return jobPromise
}

promise()
    .then(decision, jobSearch)
    .then(joining, negotiate)

function decision(param){
    console.log(param)
    let accept = true;
    return new Promise ((resolve, reject) =&amp;gt; {
        if (accept) {
            resolve('accept offer')
        } else {
            reject('reject offer')
        } 

    });

}

function jobSearch (outcome) {
    console.log(outcome)
    console.log('Back to Job Search')
    return new Promise((resolve, reject) =&amp;gt; { reject() })
}

function negotiate () {
    console.log('negotiation starts..... ')
}
function joining (decision) {
    console.log('Revert to the Company', decision);
    console.log('Joining Company')
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What could go wrong
&lt;/h2&gt;

&lt;p&gt;If promises are handled injudiciously, an error could easily pass by unnoticed.&lt;br&gt;
Make sure to return a promise in your callback handlers within then() or throw an Error, otherwise the next resolve handler in chain will be invoked and we don’t want that.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>callbacks</category>
      <category>promises</category>
      <category>callbackhell</category>
    </item>
    <item>
      <title>Building Microservices - Fundamentals</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Sun, 10 Jul 2022 04:19:48 +0000</pubDate>
      <link>https://dev.to/snrizvi/building-microservices-fundamentals-faj</link>
      <guid>https://dev.to/snrizvi/building-microservices-fundamentals-faj</guid>
      <description>&lt;p&gt;Over the years, applications have evolved from being a &lt;strong&gt;Monolithic Centralised&lt;/strong&gt; deployments to &lt;strong&gt;Distributed Microservices&lt;/strong&gt;.&lt;br&gt;
If you are looking to &lt;em&gt;transition-into&lt;/em&gt; or &lt;em&gt;build-from-scratch&lt;/em&gt; a Microservice, Here some points to consider.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh192fgcld1d2xv9j2295.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh192fgcld1d2xv9j2295.png" alt="system evolution towards microservices" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Functional Design
&lt;/h2&gt;

&lt;p&gt;After product requirements are finalised, we start identifying working parts of the system i.e. &lt;strong&gt;functional components&lt;/strong&gt; which will eventually shape up as a service.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h6&gt;
  
  
  &lt;em&gt;“If I only had an hour to chop down a tree, I would spend the first 45 minutes sharpening my axe.” – Abraham Lincoln&lt;/em&gt;
&lt;/h6&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you have worked on Agile projects, you must have seen how requirements change from sprints to sprints specially during initial phases when product is not mature.&lt;/p&gt;

&lt;p&gt;Now, Here are some of the task which would help in creating a solid functional design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identifying &lt;strong&gt;logical flow&lt;/strong&gt; of the system, what are the business requirements.&lt;/li&gt;
&lt;li&gt;Understanding &lt;strong&gt;User interactions&lt;/strong&gt; with the system, is it through web/mobile interfaces or through API's.&lt;/li&gt;
&lt;li&gt;Knowing the &lt;strong&gt;Data&lt;/strong&gt; flowing IN &amp;amp; OUT, should help in designing the database.&lt;/li&gt;
&lt;li&gt;Listing the input &lt;strong&gt;validations&lt;/strong&gt; and business rules.&lt;/li&gt;
&lt;li&gt;Identifying &lt;strong&gt;external dependencies&lt;/strong&gt; which needs to be integrated, could be in the form of &lt;em&gt;content, api, payment gateways&lt;/em&gt; etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  It may seem enticing to jump into code and infrastructure asap. With half-baked functional design, its going to be challenging and unproductive to code.
&lt;/h6&gt;




&lt;h2&gt;
  
  
  Technical Design
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Identifying the Services
&lt;/h3&gt;

&lt;p&gt;Time to breakdown each functional component into one(&lt;em&gt;ideally&lt;/em&gt;) or more(&lt;em&gt;edge-case&lt;/em&gt;) smaller/independent services. Each service takes ownership of a specific functionality - &lt;strong&gt;Separation of Concerns&lt;/strong&gt;.&lt;/p&gt;

&lt;h6&gt;
  
  
  Here's a food delivery app example, you can see how each service is catering to a &lt;strong&gt;specific&lt;/strong&gt; need.
&lt;/h6&gt;

&lt;p&gt;Services can communicate with each other or with external interfaces either through REST API's or Websockets, Synchronously/Asynchronously with Messaging systems like Kafka, RabbitMQ.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc1za1cxq8gq7j436ov6w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc1za1cxq8gq7j436ov6w.png" alt="food delivery app example of microservices" width="592" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Quest to simplify &amp;amp; isolate the services shouldn't end up over-populating the system with a lot of services running - It only makes things difficult to monitor and manage.
&lt;/h6&gt;

&lt;h3&gt;
  
  
  Technology Stack - &lt;em&gt;Pick &amp;amp; Move&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;With &lt;strong&gt;Service Oriented Architecture&lt;/strong&gt;(SOA), we always have a choice of kind of programming language to use for each service. As far as they are able to communicate through an efficient &amp;amp; secure channel, it's all good.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38xt0hs5rn6rabsdfewk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38xt0hs5rn6rabsdfewk.png" alt="Technology Stack" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As an example, &lt;br&gt;
Python for building an analytical service which requires ML. &lt;br&gt;
Java's async/multithreading for building compute intensive services like big data, video process.&lt;br&gt;
Go with NodeJs for its non-blocking I/O capabilities, running multiple queries on MySQL or MongoDb at the same time keeping things simple and smooth.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa80qm9902j9y6higbvr7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa80qm9902j9y6higbvr7.png" alt="choice of programming language" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Persistance
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Separate database Vs Shared database&lt;/em&gt; - Let the debate begin  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ji6ts05mfu3650wmzvs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ji6ts05mfu3650wmzvs.png" alt="shared vs separate database" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we extrapolate the concept of loose coupling and distribution to databases, each service should end up owning a "database" which can be individually &lt;strong&gt;scaled&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Imagine multiple teams working on shared database, how difficult it is to keep track of every change.&lt;/p&gt;

&lt;p&gt;Separate databases are easier to migrate, you can fine tune each depending on requirement.&lt;/p&gt;

&lt;p&gt;Also you get &lt;strong&gt;Polyglot Persistence&lt;/strong&gt;, a fancy term  to choose a desired database as per requirement. &lt;br&gt;
For example: &lt;br&gt;
For unstructured data -&amp;gt; NoSQL. &lt;br&gt;
For co-related &amp;amp; structured dataset -&amp;gt; RDBMS &lt;br&gt;
For TextSearch -&amp;gt; ElasticSearch&lt;/p&gt;

&lt;h3&gt;
  
  
  Messaging
&lt;/h3&gt;

&lt;p&gt;So now we have multiple services running separately, the question is how will they communicate with each other or with an external interfaces.&lt;/p&gt;

&lt;p&gt;Service communication can broadly divided in to &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Synchronous - &lt;em&gt;real time&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;Asynchronous - &lt;em&gt;not expecting immediate response&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Synchronous&lt;/strong&gt; (Sync)&lt;br&gt;
Happens in real time, client sends the request and waits for response. HTTP request/response is a good example of Sync messaging, when you send a http request you are waiting for a response  (200,404,400,500). If the response takes time, the client is blocked and eventually timeouts.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h6&gt;
  
  
  They say Sync is an Anti-Pattern, communicating parties need to be aware of eachother - &lt;em&gt;What do you think, reply in the comment&lt;/em&gt;.
&lt;/h6&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Asynchronous&lt;/strong&gt; (Async) &lt;br&gt;
With Async, communicating parties don't have to wait for server response and transactions to complete. If a service is unavailable, messages will be delivered when the services are up and running with help of &lt;strong&gt;Message Brokers&lt;/strong&gt; who receive, store, route and deliver messages between different services.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;Apache Kafka&lt;/a&gt; &amp;amp; &lt;a href="https://www.rabbitmq.com/" rel="noopener noreferrer"&gt;RabbitMQ&lt;/a&gt; which have been quite popular Message Brokers .&lt;/p&gt;

&lt;h3&gt;
  
  
  CI/CD Workflow
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;The great Mono vs Multi Repo debate&lt;/em&gt;&lt;br&gt;&lt;br&gt;
When we are designing microservices, we should be thinking holistically. The loose coupling should we visible in almost all areas from coding to deployment.&lt;br&gt;
Each service should be hosted in repository of its own and should be deployed through an isolated CI/CD pipeline which can be easily triggered from another upstream pipeline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81aq1i7hn1n26y2022q8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81aq1i7hn1n26y2022q8.png" alt="Version &amp;amp; release" width="771" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Monitoring - &lt;em&gt;Do we need to discuss it&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Ah, a pain area for microservices. Monolithic systems are better off, as they are tightly coupled &amp;amp; more constrained. If anything goes wrong, it's easier to find and fix.&lt;/p&gt;

&lt;p&gt;With Microservices, you never know what would go wrong and where. Lots of small parts, things are distributed, log needs to be read from multiple places.&lt;/p&gt;

&lt;p&gt;So, We should be investing in a &lt;strong&gt;Centralised logging&lt;/strong&gt; framework such as &lt;strong&gt;ELK stack (Elasticsearch-Logstash-Kibana)&lt;/strong&gt; which can fetch logs from different services, accumulate it and you can view &amp;amp; analyse them at will.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
We are building a system which can be developed, deployed and tested atomically. Each part is as loosely coupled as possible.&lt;/p&gt;

&lt;p&gt;If you are in a dilemma - Should you go for it now, look months or years down the line.&lt;/p&gt;

&lt;p&gt;Be careful of &lt;strong&gt;choice overload&lt;/strong&gt; :  There are tons of design pattern, choice of programming language, what cloud services to got with and so on. The key is to leverage as much as you can - keep cost &amp;amp; timeline low.&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Setting up communication between GitLab Runner and Deployment Server with SSH</title>
      <dc:creator>Sayed Naweed Rizvi</dc:creator>
      <pubDate>Wed, 06 Jul 2022 11:33:16 +0000</pubDate>
      <link>https://dev.to/snrizvi/setting-up-communication-between-gitlab-runner-and-deployment-server-with-ssh-434k</link>
      <guid>https://dev.to/snrizvi/setting-up-communication-between-gitlab-runner-and-deployment-server-with-ssh-434k</guid>
      <description>&lt;p&gt;If you are setting up &lt;strong&gt;gitlab-ci&lt;/strong&gt; pipeline, you will need to establish a secure connection between the &lt;strong&gt;runner&lt;/strong&gt; machine and server where you are going to deploy. &lt;br&gt;
Here's a quick and easy way to do it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Gitlab CI Pipeline&lt;/li&gt;
&lt;li&gt;OpenSSH client &amp;amp; server installed on runner and deployment server.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;SSH (Secure Shell) protocol uses public-key cryptography to authenticate Client machine with a remote Server machine on a network.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's get started, we will first create SSH key-pair.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://www.ssh.com/academy/ssh/keygen" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.ssh.com%2Fhubfs%2Fssh-og.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://www.ssh.com/academy/ssh/keygen" rel="noopener noreferrer" class="c-link"&gt;
            What is ssh-keygen &amp;amp; How to Use It to Generate a New SSH Key?
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Ssh-keygen is a tool for creating new authentication key pairs for SSH. Such key pairs are used for automating logins, single sign-on..
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.ssh.com%2Fhubfs%2FSSH_Web_Favicon_48x48.png" width="48" height="48"&gt;
          ssh.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;I have created these keys for illustration on linux, SSH key paths may differ based on your OS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Private key (~/.ssh/id_rsa)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQCAD0ZKDVKEyqPd+N+7N1O/fPjDYAHa8xL24ADRHegqurUa8cTL
tCQX82ysu6uxqfVyOMY3YGOh2HCH8S+jB6GTuSY1tIsYaU46d5H9w7YXAr/MMWRJ
L9wkUoU7bB/I8vK3eTVHsC72ufYhohQVXDY6+ZoG3Bsxyxy7SDbJqVBqXwIDAQAB
AoGABCH6D7u8VQLBJRG6Dq2razuaP5vik3FSxFrYS+deLbrWy2bQBg7rN0ao1C4+
TT6B6EzCwNjAfmGgyBJVijpd0X3iQzt5iPT5vMA2TrybbpMLZnikRtbo5rkgk+Tg
m7AiqXzOSHv02ZtrpgDV3pQ+qa/Tk9FU/7hjefKMF2Ru6EkCQQDINwkKizU3Uw4T
IwMAMTITOrLiswR4tJOmsG01Xe47dMkmERrtI47fYJcPLsNgnBjs6Pus8ALscOCM
xinMBwFdAkEAo72Ir7d0BL/GmogKgmELXmVS6t1jzNok0ioi4w7EefYMaDrlMrlk
rI7VMnExScPHc8ksezRBOJSS89cIIzYy6wJABrrq3+LcEBcHoxcLM8dzknfnqX0x
CkmvqOvHUALvTipX1KLAj/YhCFs72LPOt4GnyNbwFtkekAofUjwbDZOytQJAXd8X
McX22ZIohgdgHwcLwX5NXyC1Sof1fBd0EMAym8kXq9m39LCcquDoERcbrrJy8kpv
GeMHUSy8Ytbwb19vKQJAT/lYWZqTpr+DfmTdmvRbCOz9hWOw4Hj+nfjfSsfzU9vg
bWqKz2KvKlSvYBV4uKBfxsv6ML5dkaiHb5l3pKfDUw==
-----END RSA PRIVATE KEY-----
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Public key (~/.ssh/id_rsa.pub)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCAD0ZKDVKEyqPd+N+7N1O/fPjDYAHa8xL24ADRHegqurUa8cTLtCQX82ysu6uxqfVyOMY3YGOh2HCH8S+jB6GTuSY1tIsYaU46d5H9w7YXAr/MMWRJL9wkUoU7bB/I8vK3eTVHsC72ufYhohQVXDY6+ZoG3Bsxyxy7SDbJqVBqXw==
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;&lt;strong&gt;What Next, Where do we store these keys ?&lt;/strong&gt;&lt;br&gt;
The SSH keys created above will be stored in the following locations to enable an encrypted and authenticated session between Gitlab Runner &amp;amp; the deployment Server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Gitlab CI Environment Variables&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body flex items-center justify-between"&gt;
        &lt;a href="https://docs.gitlab.com/ci/variables/" rel="noopener noreferrer" class="c-link fw-bold flex items-center"&gt;
          &lt;span class="mr-2"&gt;docs.gitlab.com&lt;/span&gt;
          

        &lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;Store both &lt;strong&gt;private&lt;/strong&gt; &amp;amp; &lt;strong&gt;public&lt;/strong&gt; key by giving them a name (&lt;strong&gt;SSH_PRIVATE_KEY/SSH_PUBLIC_KEY&lt;/strong&gt;), you can store the keys at the group level and inherit it in your project by selecting from the Environment Scope dropdown.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszp1ztridernmx97yh65.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszp1ztridernmx97yh65.png" alt=" " width="700" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Gitlab Runner Machine (SSH folder)&lt;/strong&gt;&lt;br&gt;
The private &amp;amp; public keys should be stored in the Gitlab Runner machine’s [~/.ssh ]folder. To do that, you need to add following bash commands in your projects .gitlab-ci.yml file.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;$SSH_PRIVATE_KEY&lt;/code&gt; &amp;amp; &lt;code&gt;$SSH_PUBLIC_KEY&lt;/code&gt; are variables which we created in the step above.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Replace gitlab.local.net with url where you have hosted your Gitlab.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;before_script:
  - eval $(ssh-agent -s)
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - echo -e "Host *\n\tStrictHostKeyChecking no\n" &amp;gt; ~/.ssh/config;
  - cat "$SSH_PRIVATE_KEY" | tr -d '\r' &amp;gt; ~/.ssh/id_rsa
  - cat "$SSH_PUBLIC_KEY" | tr -d '\r' &amp;gt; ~/.ssh/id_rsa.pub
  - chmod 600 ~/.ssh/id_rsa;
  - chmod 764 ~/.ssh/id_rsa.pub;
  - ssh-keyscan -H gitlab.local.net &amp;gt;&amp;gt; ~/.ssh/known_hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Create &lt;code&gt;authorized_keys&lt;/code&gt; on the Server&lt;/strong&gt;&lt;br&gt;
On the server where you will be deploying your application, create a authorized_keys file inside ~/.ssh.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Now, You would either be running your application on a Physical Server (nostalgic) or a VM — Virtual Machine (still there) or a Container (there you are).&lt;br&gt;
Then, Copy and paste the public key to the end of &lt;code&gt;authorized_keys&lt;/code&gt;file&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;~/.ssh/authorized_keys&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCAD0ZKDVKEyqPd+N+7N1O/fPjDYAHa8xL24ADRHegqurUa8cTLtCQX82ysu6uxqfVyOMY3YGOh2HCH8S+jB6GTuSY1tIsYaU46d5H9w7YXAr/MMWRJL9wkUoU7bB/I8vK3eTVHsC72ufYhohQVXDY6+ZoG3Bsxyxy7SDbJqVBqXw==
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Please note that you can append as many public keys as you want here, depending on the connections you wish to establish.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With that final step, you have successfully setup an encrypted communication channel between Gitlab Runner and the server on which you will be deploying your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do keep in mind&lt;/strong&gt;&lt;br&gt;
You need to be very careful with SSH keys, set the right permissions and ownership.&lt;/p&gt;

&lt;p&gt;Thank You !!&lt;/p&gt;

</description>
      <category>cicd</category>
      <category>gitlab</category>
      <category>gitlabci</category>
    </item>
  </channel>
</rss>
