<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Westwing Tech Blog - Medium]]></title>
        <description><![CDATA[The official technology blog of the Westwing Tech Team. - Medium]]></description>
        <link>https://medium.com/westwing-tech?source=rss----78f68546e6ed---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Westwing Tech Blog - Medium</title>
            <link>https://medium.com/westwing-tech?source=rss----78f68546e6ed---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 23:14:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/westwing-tech" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Multiple Terraform projects in a mono-repo. How to survive a mess?]]></title>
            <link>https://medium.com/westwing-tech/multiple-terraform-projects-in-a-mono-repo-how-to-survive-a-mess-e1ec5a136d17?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/e1ec5a136d17</guid>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[devops-tool]]></category>
            <dc:creator><![CDATA[demmonico]]></dc:creator>
            <pubDate>Fri, 26 Jan 2024 15:46:35 GMT</pubDate>
            <atom:updated>2024-01-26T15:46:35.259Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Do you have a set of projects sitting in a mono-repo and having various workspaces, file structures, and Terraform versions? A pain of switching the versions and remembering all path/workspace combinations? Uncertainty about the correctness of the workspace, or plan file before applying it?<br>I feel you! I’d share my experience in managing such projects, an approach to make it much easier, and a simple tool I wrote a few years ago for that. How is it related to Docker Compose? I’ll tell you…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*nHpefAPEoYO5dOR97I5zdQ.jpeg" /><figcaption>Does your Terraform repository look like that?</figcaption></figure><h3>TL;DR</h3><p>In this article, I would like to introduce the <a href="https://github.com/demmonico/terra-compose">Terra Compose</a> tool. It aims to simplify the management of multiple Terraform projects within a single mono-repo. By solving problems with fragile and long maintenance and uncertainty about the correctness changes, caused by low visibility of the workspace.</p><p>For that, it follows the approach of the Docker Compose and puts all the needed information into the YAML config. This way it gets rid of human involvement as much as possible, minimizing the risk of human error.</p><p>For those, who like to make their hands dirty instead of reading articles, I would suggest checking out the <a href="https://github.com/demmonico/terra-compose-demo">Terra Compose Demo project</a>.</p><h3>Table of Contents</h3><p><a href="#3151">Problem Deep Dive</a><br><a href="#477a">Exploring existing solutions</a><br><a href="#aac4">Introducing Terra Compose</a><br><a href="#7dbd">Demo<br></a><a href="#7412">Final words</a></p><h3>Problem Deep Dive</h3><p>In this section will be listed problems, that are faced while managing multiple Terraform projects in mono-repos.</p><p>Prerequisites are:</p><ul><li>set of projects in a mono-repo with various file structures</li><li>various workspaces that are almost equal to environments</li><li>various Terraform versions in the projects</li></ul><h4>Terms</h4><p>A few terms, used below:</p><ul><li><strong><em>Project</em></strong> — is a part of an infrastructure that is deployed separately and has a separate state. For example, one of the platform components (like runners or alerts) or application-specific infrastructure (like a dedicated application Redis cluster, Security Group, or Database).</li><li><strong><em>Environment</em></strong> — is an isolated space of the application infrastructure’s stack. In general, an application has more than one environment, which almost always is equivalent to the Terraform workspace.</li><li><strong><em>Alias</em></strong> — is a combination of the <strong><em>Project</em></strong> / <strong><em>Environment</em></strong>, that can be described like Runners in the production environment. Unique across the repository.</li></ul><h4>Various file structures</h4><p>Diving a bit deeper, in such mono-repos there is one of different approaches to structure Terraform projects — <em>workspace</em>-based and <em>environment</em>-based. Or even a mix of them.</p><p>Moreover, sometimes a project has a complex file structure because of the internal modules or components, that add an extra layer to the project structure. In the given example below there is a project portal, having 2 components — app and platform.</p><pre>├── ...<br>├── common<br>│   └── *.tf<br>├── environments<br>│   ├── docs<br>│   │   └── *.tf<br>│   └── images<br>│       ├── prod<br>│       │   └── *.tf<br>│       └── staging<br>│           └── *.tf<br>├── modules<br>│   └── common<br>│       └── sg<br>│           └── *.tf<br>└── projects<br>    ├── cms<br>    │   └── *.tf<br>    ├── portal<br>    │   ├── app<br>    │   │   └── *.tf<br>    │   └── platform<br>    │       └── *.tf<br>    └── runners<br>        └── *.tf</pre><p>Despite their differences, these projects often share common components or modules, such as VPC or Security Group (see the common project).</p><h4>Various workspaces</h4><p>As was mentioned before, each project usually has a few environments (often Terraform workspaces). In legacy repositories or when projects are maintained by different teams, workspaces and file names follow different naming patterns, the same as the file structure.</p><pre>├── ...<br>├── common<br>│   ├── nonprod.tfvars<br>│   ├── prod.tfvars<br>│   └── ...<br>└── projects<br>    ├── cms<br>    │   ├── production.tfvars<br>    │   ├── release.tfvars<br>    │   ├── staging.tfvars<br>    │   ├── training.tfvars<br>    │   └── ...<br>    ├── portal<br>    │   ├── app<br>    │   │   ├── integration.tfvars<br>    │   │   ├── live.tfvars<br>    │   │   └── ...<br>    │   └── platform<br>    │       ├── integration.tfvars<br>    │       ├── live.tfvars<br>    │       └── ...<br>    └── ...</pre><h4>Various versions</h4><p>The projects also might have specific Terraform versions. Especially, in big repositories. I saw cases where across different projects in a repository at the same time there were several different Terraform versions from 0.12.x to 1.3.x.</p><p>Sometimes, during the Terraform version upgrade process, there might be also different Terraform versions across the project environments.</p><h4>Pain points</h4><p>Summarizing it, we have identified several pain points.</p><p>The first challenge is simply memorizing different file structures, workspaces, and Terraform versions. This diversity with the lack of visibility doubling effect, especially for newcomers, makes it challenging to maintain and troubleshoot effectively.</p><p>The second issue involves the inability to use unified automation due to differences in file structures and workspaces.</p><p>Further categories of concern include upgrading and switching Terraform versions. This process is not that hard, but it requires having a few Terraform versions locally at the same time and being able to quickly switch between them. For sure, there are already solutions for this problem, for instance, the <a href="https://github.com/tfutils/tfenv">tfenv</a> tool can help here. However, it has some limitations and requires a bit of effort to configure it.</p><p>Lastly, as-is it breaks the IaaC approach because so far workspaces are not trackable by any version control system. With that, we have all bad outcomes, related to having it not as a code…</p><p><strong>In essence, these challenges manifest as specific and fragile maintenance, and extended maintenance times (especially for larger projects).</strong></p><p><strong>A low visibility of the workspace escalates the uncertainty about the correctness while planning and applying the changes.</strong></p><p><em>One generic approach to solving the problem partially could be to split mono-repo into separate repositories, referencing common elements using modules. With that, there might be reasons not to do this. One of them is that it increases the count of moving parts and infrastructure maintenance overhead. Another one, it potentially raises security concerns with different ownership and membership.</em></p><h3>Exploring existing solutions</h3><p>What about the market? Are there any available solutions? While there are several options, none of them comprehensively address the challenges at hand.</p><p><a href="https://developer.hashicorp.com/terraform/cloud-docs">Terraform Cloud</a> is a native for Terraform SaaS solution. It offers a shared state, secret data protection, a private modules registry, self-controlled policy changes, and many more. While it is an excellent solution, it might limit you or be too expensive, especially if there are numerous team members to be licensed. Besides that, SaaS is not for everyone…</p><p><a href="https://terragrunt.gruntwork.io/">Terragrunt</a> is a powerful Terraform wrapper that helps to follow the DRY principles and code re-usage. It is widely recognized, but it comes with significant overhead. It requires separate configuration creation for each folder, specifying properties that <a href="https://terragrunt.gruntwork.io/">Terragrunt</a> relies on. Moreover, it does not solve all mentioned pain points.</p><p><a href="https://terramate.io/">Terramate</a> is yet another wrapper for Terraform that provides code generation, stack change detection, orchestration, and data sharing. While it looks promising, it introduces even more additional complexity due to a new stack concept. It might work well when starting a new project from scratch, but jumping into it with an existing one might be challenging. Also, it seems, the core feature in <a href="https://terramate.io/">Terramate</a> is the generation code, thereby using mostly internal or external modules makes this tool useless overall.</p><p><a href="https://terraspace.cloud/">Terraspace</a> is a framework with structure conventions, code generation, and tooling. It has the same downsides, as <a href="https://terramate.io/">Terramate</a> does, and demands even more extensive adaptation effort, but fails to address all our problems.</p><h4>Comparing solutions</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94369c9cfae307a1a288b28f4c0ddad4/href">https://medium.com/media/94369c9cfae307a1a288b28f4c0ddad4/href</a></iframe><p>When comparing these solutions, it becomes evident that none completely solves our problems. Whether it is version or workspace or project path switching, needs to memorize them, or pain of switch, none of the tools provide a comprehensive solution. They lack certain features and will not be free of charge for such scale projects.</p><p>Lastly, considering the three-year journey of the <a href="https://github.com/demmonico/terra-compose">Terra Compose</a>, initiated before tools like <a href="https://terramate.io/">Terramate</a> or <a href="https://terraspace.cloud/">Terraspace</a> came into the picture, it becomes clear that neither then, nor nowadays these problems could not be fully solved with the current market offerings.</p><h3>Introducing Terra Compose</h3><h4>The idea</h4><blockquote>Haven’t we faced it before?</blockquote><p>I found that the situation is similar to working with <a href="https://www.docker.com/">Docker</a>, which gets tricky with lengthy command lines, involving lots of arguments. It very quickly becomes a hassle, trying to even print multiple command arguments.</p><p>Drawing parallels with <a href="https://www.docker.com/">Docker</a>, a solution emerged in the form of <a href="https://docs.docker.com/compose/">Docker Compose</a>. This tool simplifies the setup with a straightforward YAML file, describing the services to run and their configurations.</p><blockquote>Compose simplifies the control of your entire application stack, making it easy to manage services, networks, and volumes in a single, comprehensible YAML configuration file. Then, with a single command, you create and start all the services from your configuration file.</blockquote><p>It significantly enhances the developer experience, making the process of running Docker commands error-free and increasing visibility by implementing the Config-as-a-Code approach.</p><p>Recognizing the similarities, I pondered, <strong>“Why couldn’t we have something similar for Terraform?”</strong></p><h4>Terra Compose: Use cases</h4><p>Just like <a href="https://docs.docker.com/compose/">Docker Compose</a> simplifies Docker commands, <a href="https://github.com/demmonico/terra-compose">Terra Compose</a> handles various Terraform commands efficiently, providing flexibility in using different Terraform versions in Docker and workspace preparation with automation scripts.</p><p>Here we need to define yet another term — <strong><em>action</em></strong>. So, in <a href="https://github.com/demmonico/terra-compose">Terra Compose</a> it is a set of chained commands to perform a consistent operation. It has the following stages:</p><ul><li>pre-actions, e.g. change directory, select workspace, init Terraform backend, etc.</li><li>action, the target command runs.</li><li>post-action, e.g. clean-ups</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*uLPJ3FrN0AvF7J0CyTNopA.png" /><figcaption>Use-cases diagram</figcaption></figure><p>To streamline the process, there are shortcuts for common actions plan and apply, ensuring a consistent and reproducible behavior. These shortcuts wrap sequences of Terraform commands, reducing errors and improving reliability.</p><p>For instance, plan action automatically includes Terraform init, workspace selection, format check, and validation. Thus it <a href="https://devops.com/devops-shift-left-avoid-failure/"><strong>shifts left</strong></a> possible failures. As a result, it saves the plan to the file, which then will be used in apply action. In this way, it ensures that only verified changes were applied. Apply action also protects the operator from applying stale changes by highlighting the “s<em>ince-plan-creation</em>” time.</p><p>Besides them, there are:</p><ul><li>run — a proxy action for <strong>ANY</strong> command to be run inside the Docker container.</li><li>workspaces — a simple shortcut for running terraform workspace ls command.</li><li>shell — spins up an interactive shell inside the Docker container. Useful for troubleshooting, debugging, and some complex Terraform tasks.</li><li>help — outputs some information about available actions in <a href="https://github.com/demmonico/terra-compose">Terra Compose</a> and, when there is a config file available, a list of available aliases.</li></ul><h4>Terra Compose: The workflow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*LUXfa2UIFmoyu238PxnXJA.png" /><figcaption>Collaboration diagram</figcaption></figure><p><a href="https://github.com/demmonico/terra-compose">Terra Compose</a> reads the config file, finds the project by the path property if alias, and runs the requested Terraform command in the Docker container with the specified Terraform workspace, version, and tfvars file. Within the run execution, it includes automation at the pre- and post-stages, like changing directories or selecting workspace, and hooks if were defined.</p><p>This setup simplifies the collaboration and ensures a consistent and reliable Terraform workflow with improved visibility and developer experience.</p><h4>Terra Compose: Configuration</h4><p>Maintaining the <a href="https://github.com/demmonico/terra-compose">Terra Compose</a> requires only a single config in a YAML file, which is easy to manage. It contains project details, defining aliases along the relevant properties. It is a part of the codebase with the same visibility.</p><p>Here is an example of the YAML file. There are two main sections: default and aliases. In default section there are common properties (so far only tfversion), that could be overwritten by the property in aliases. In the aliases section, there are all the needed definitions, including Terraform workspace, version, and tfvars file name (if used).</p><pre>default:<br>  tfversion: &quot;1.0.0&quot;<br><br>aliases:<br>  common:<br>    path: &quot;common&quot;<br>    tfvars: &quot;common&quot;<br>  alerts:<br>    path: &quot;projects/alerts&quot;<br>    workspace: &quot;prod&quot;<br>    tfversion: &quot;1.3.0&quot;<br>    backend_config: &quot;key=experiment&quot;<br>    hooks:<br>        before_tf_init: &quot;rm -rf ./.terraform&quot;</pre><p>Additional properties, like backend_config and hooks, allow to customize further the workflow. There are 5 hooks supported so far, allowing to run custom scripts before/after some of the stages, for example before_tf_init, after_all or before_container_run.</p><h3>Demo</h3><p>The full demo can be found in the <a href="https://github.com/demmonico/terra-compose-demo">Terra Compose Demo project</a>. Below you can find a small example of the simple usage of plan, apply, workspaces and run actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i-XA5Pi4NE_4eSPuXMwyMw.gif" /><figcaption>Simple plan and apply actions example</figcaption></figure><p>Besides that, it shows the debug mode usage. Debug mode skips pre- and post-stage on plan and apply actions. It aims to speed up the development and debugging processes on repetitive actions.</p><h3>Final words</h3><p>Thus, the <a href="https://github.com/demmonico/terra-compose">Terra Compose</a> tool composes multiple Terraform commands, such as plan or apply, providing a validated plan, and speeding up the maintenance process.</p><h4>Pain points revise</h4><p>Let’s check our <strong>pain points,</strong> focusing on the <a href="https://github.com/demmonico/terra-compose">Terra Compose</a>:</p><ol><li><strong>Version Switching</strong> ✔️<br>Successfully tackled by running Terraform in a Docker container and having Terraform versions as a property in the config YAML file.</li><li><strong>Structure: Snippets and Compatibility </strong>✔️<strong><br></strong>Addressed by abstracting the project root path and adding it to the configuration. Some flexibility improvements are planned for the future.</li><li><strong>Workspace Visibility </strong>✔️<strong><br></strong>Improved it by printing it in several places in the <a href="https://github.com/demmonico/terra-compose">Terra Compose</a> output.</li><li><strong>Workspace Low Tracking </strong>✔️<strong><br></strong>Now it’s part of the codebase and trackable by VCS, the issue is solved.</li><li><strong>Routines Automation / Chaining commands </strong>♻<strong><br></strong>The issue is partially solved, as automation is currently hard-coded but feasible. Hooks mechanism extends it also a lot. With that, some improvements in the chaining mechanism, like customization, are planned for the future.</li><li><strong>Structure, Workspace, Version Management </strong>✔️<strong><br></strong>Successfully addressed by adding it to the config YAML file, which made it solid.</li><li><strong>Complexity and Implementation Time </strong>✔️<strong><br></strong><a href="https://github.com/demmonico/terra-compose">Terra Compose</a> is an open-source project, thus — free<br>The setup process is straightforward, includes configuring a simple YAML config file, and is quick to implement (approximately an <strong><em>hour</em></strong> to onboard a new project).</li></ol><h4>Future Plans</h4><p>There are also a few tasks planned for the future:</p><ul><li>Improve <a href="https://github.com/demmonico/terra-compose">Terra Compose</a> command interface. It was designed 3 years ago as a quick wrapper, so no solid strategy was behind it. Now it’s time to re-think that.</li><li>Make commands customizable to offer users more flexibility in their workflows. The flexible way of chaining commands in action could be an example here.</li></ul><h4>Conclusion</h4><p>The <strong><em>open-source</em></strong> tool is available for use, and I want to encourage contributions from the community. Feel free to check <a href="https://github.com/demmonico/terra-compose">its repository</a> for more details. From my experience, it consistently protected me and saved me a lot of time. Therefore, I find it very useful and I believe it could be valuable for you too.</p><p><em>P.S. It was my first article here, so please clap it :)</em></p><p><strong><em>Links:</em></strong><em><br>- </em><a href="https://github.com/demmonico/terra-compose"><em>Terra Compose project on GitHub</em></a><em><br>- </em><a href="https://github.com/demmonico/terra-compose-demo"><em>Terra Compose Demo project on GitHub</em></a><em><br>- </em><a href="https://www.linkedin.com/in/dmytro-prekrasnyi-9327a4a9/"><em>LinkedIn</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1ec5a136d17" width="1" height="1" alt=""><hr><p><a href="https://medium.com/westwing-tech/multiple-terraform-projects-in-a-mono-repo-how-to-survive-a-mess-e1ec5a136d17">Multiple Terraform projects in a mono-repo. How to survive a mess?</a> was originally published in <a href="https://medium.com/westwing-tech">Westwing Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The tale of unexpected tech hiccups: How a Simple Command can almost Break your System]]></title>
            <link>https://medium.com/westwing-tech/the-tale-of-unexpected-tech-hiccups-how-a-simple-command-can-almost-break-your-system-0b64ea0eaa3c?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/0b64ea0eaa3c</guid>
            <category><![CDATA[pods]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[technology-trends]]></category>
            <category><![CDATA[tech-hiccups]]></category>
            <dc:creator><![CDATA[Rehmat Sayany]]></dc:creator>
            <pubDate>Tue, 16 Jan 2024 09:40:45 GMT</pubDate>
            <atom:updated>2024-01-16T09:40:45.242Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qq_RuvYZtITDl6oAc-CxjA.png" /><figcaption>App throughput abruptly stopped at 4 30 pm</figcaption></figure><h4>Introduction:</h4><p>At Westwing, where innovation and excellence converge, we often find ourselves navigating the intricate landscape of software development. In this chronicle, we unfold the narrative of an unforeseen tech hiccup — the ‘Console.log Conundrum.’ An incident that unfolded like a puzzle, revealing the unexpected challenges lurking within seemingly innocuous lines of code.</p><h4><strong>The Initial Puzzle:</strong></h4><p>It all started with a red alert — CPU usage for our mobile apps k8s pods exceeded acceptable levels. Our go-to monitoring tools, Grafana and NewRelic, presented a perplexing scenario: dwindling traffic and dropping CPU usage. Something deeper was at play, and we were determined to get to the bottom of it.</p><h4>The Decisive Moment:</h4><p>As we delved into the first mystery, another alert shook our focus — k8s_bff_Apps_pod_cpu_utilization was spiking. Quick thinking led us to increase manually k8s replica count, adding additional pods into the Mobile application Backend and increasing the number of microservice pods from 4 to 6. After bumping pods from 4 to 6, I found that something was suspicious, CPU usage was not dropping. Little did we know that this decision would set the stage for an unforeseen storm.</p><h4>The Unseen Threat:</h4><p>Pod readiness checks revealed an alarming reality — pods were starting logs were growing and then they were evicted, but it took probably hours between start and eviction. numerous app pods were evicted one after the other, leaving only one survivor. Panic set in as the last stable Apps backend microservice pod succumbed at exactly 17:18. Adding to the complexity, the K8s cluster events showed Calico pull errors for the <strong>docker.io/calico/pod2daemon-flexvol:v3.25.1</strong> image. The pods that were evicted were gone, new pods cannot be spawned due to missing calico image. Calico primarily focuses on networking and network security for containerized workloads and does not directly handle the replication or management of pods in the context of Kubernetes. However, it does play a crucial role in ensuring the proper communication and connectivity between pods, which indirectly contributes to the reliability and availability of replicated pods</p><h4>The Race Against Downtime:</h4><p>With the downtime clock ticking, we had to act swiftly. We downsized other parts of our system and managed to bring the Apps backend back online. The entire ordeal, though intense, concluded in less than 30 minutes.</p><h4>The Unexpected Culprit:</h4><p>Indeed, our investigation unveiled multiple contributing factors to the incident. One significant issue arose from errors related to the Calico image, leading to the unsuccessful creation of replica pods and subsequent evictions. This complication hindered the proper functioning of our application, emphasizing the critical role of a stable networking infrastructure in the overall reliability of our system.</p><p>The other one and most interesting one was a seemingly harmless console.log. A day prior, during a live issue, we deployed a hotfix to debug the problem successfully. However, in the rush to address the immediate concern, we inadvertently left behind the debug logs, leading to the accumulation of data and subsequent pod space issues. Now, you might be wondering why we deployed a hotfix in the first place. The urgency of the situation demanded a swift resolution to a critical issue affecting our live environment. In such cases, deploying a hotfix is often the fastest way to address the problem and restore normalcy. Unfortunately, amidst the urgency, we neglected to remove the hotfix deployment, causing unintended consequences.</p><p>Additional Lessons Learned: As we reflected on this incident, several valuable lessons came to light:</p><ol><li><strong>Mindful Hotfix Cleanup</strong>: While hotfixes are essential for quick issue resolution, it’s equally crucial to prioritize cleanup. Ensure that temporary code and debug logs are promptly removed after their purpose is served.</li><li><strong>Proactive Issue Management</strong>: Keep a close eye on your production environment, and promptly address critical issues. However, always maintain a balance between urgency and diligence to prevent oversights.</li><li><strong>Thorough Cluster Monitoring</strong>: Regularly monitor your Kubernetes cluster for events that could impact pod stability. In our case, the Calico pull errors for the docker.io/calico/pod2daemon-flexvol:v3.25.1 image added an extra layer of complexity, emphasizing the importance of staying vigilant in your cluster’s health.</li><li><strong>Communication and Coordination</strong>: In high-pressure situations, effective communication and coordination among team members are paramount. Everyone should be on the same page regarding the status and necessary follow-up actions.</li><li><strong>Importance of Alerts:</strong> Incorporating PingDom alerts, especially for monitoring pod counts falling below the expected threshold, proves invaluable. Diversifying alert configurations further enhances system stability and availability, providing proactive insights to promptly address potential issues.</li><li><strong>Limit log size</strong>: Implementing size limits and a rotation mechanism to address log accumulation beyond predefined thresholds is vital. This practice not only ensures efficient resource utilization but also contributes to the overall health and resilience of the system</li></ol><h4>Conclusion:</h4><p>In the dynamic world of software development, our journey highlights the critical role of timely alerts, efficient log management, and proactive issue resolution. As we dissect the ‘<strong>Console.log Conundrum,</strong>’ the importance of balancing immediate concerns with a broader system perspective becomes evident. Let this experience serve as a reminder of the ever-present need for resilient practices in the face of unexpected challenges, propelling us toward a future of more robust and adaptive software development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b64ea0eaa3c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/westwing-tech/the-tale-of-unexpected-tech-hiccups-how-a-simple-command-can-almost-break-your-system-0b64ea0eaa3c">The tale of unexpected tech hiccups: How a Simple Command can almost Break your System</a> was originally published in <a href="https://medium.com/westwing-tech">Westwing Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When Collaboration Becomes Vulnerable: Exposing SQL Injection]]></title>
            <link>https://medium.com/westwing-tech/when-collaboration-becomes-vulnerable-exposing-sql-injection-b6712fcd60e6?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/b6712fcd60e6</guid>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Sushant Soni]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 12:35:53 GMT</pubDate>
            <atom:updated>2023-11-16T12:35:53.329Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*om6Oot3DV8MAf3zE" /></figure><h3>Introduction</h3><p>In an era where collaboration is key to business agility, a popular document collaboration tool had its security compromised. Aimed at streamlining document review and approvals, this software unfortunately hosted a ticking time bomb within its digital walls, in the form of a SQL Injection vulnerability, threatening the integrity of the very documents it was meant to protect.</p><h3>Discovery Process</h3><p>The chase began with the Wappalyzer extension, which lays bare the technologies underpinning websites. A routine check unveiled that the site was running on OnlyOffice software v5.4.2. My curiosity was piqued when I realized that this version was obsolete and, more critically, had an associated CVE (Common Vulnerabilities and Exposures) entry, pointing towards a possible SQL Injection exploit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*c2YdcUBLSCSHaDlktlMtsQ.png" /></figure><h3>Technical Details</h3><p>Diving into the technical trenches, I confirmed the presence of <a href="https://www.cvedetails.com/cve/CVE-2020-11537/">CVE-2020–11537</a>. The flaw could be exploited via the WebSocket API — an unexpected backdoor in an otherwise secure protocol. After some hands-on testing with crafted payloads, the vulnerability was unmistakable. An injected SQL command containing a sleep function delayed the response by 6 seconds, unequivocally demonstrating the security gap.</p><h3>Exploitation</h3><p><a href="https://www.cvedetails.com/cve/CVE-2020-11537/">CVE-2020–11537</a>: A SQL Injection issue was discovered in ONLYOFFICE Document Server 5.5.0. An attacker can execute arbitrary SQL queries via injection to DocID parameter of Websocket API.</p><p>In the DocID parameter, enter the payload <strong><em>‘ union select 1,2 from pg_sleep(6); —</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tgDd_t2DtUx9ptyaSwR1Vg.png" /></figure><h3>Impact Assessment</h3><p>SQL Injection is like leaving the key to your front door under the mat. It could allow an attacker unfettered access to manipulate or retrieve sensitive data directly from the database, possibly leading to unauthorized data exposure, system compromise, and a loss of trust that can be hard to rebuild.</p><h3>Reporting Process</h3><p>The reporting process was a swift direct line to the organization. Their receptiveness to the vulnerability report was commendable, and the issue was patched in the following weeks, fortifying their digital defenses.</p><h3>Conclusion and Learning</h3><p>The lesson here is twofold: the relentless advancement of digital threats necessitates perpetual vigilance, and the importance of keeping software up to date cannot be overstated. Regular security audits are not just a good practice; they’re an imperative checkpoint in the marathon to keep cyber threats at bay.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6712fcd60e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/westwing-tech/when-collaboration-becomes-vulnerable-exposing-sql-injection-b6712fcd60e6">When Collaboration Becomes Vulnerable: Exposing SQL Injection</a> was originally published in <a href="https://medium.com/westwing-tech">Westwing Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Must have PHP Tools]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/westwing-tech/must-have-php-tools-868a1aac6eb7?source=rss----78f68546e6ed---4"><img src="https://cdn-images-1.medium.com/max/2462/1*TsyPL108RC4LBsAbsZPoYQ.png" width="2462"></a></p><p class="medium-feed-snippet">PHP has been evolving dynamically in recent years with the introduction of new versions of the language containing a range of new features&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/westwing-tech/must-have-php-tools-868a1aac6eb7?source=rss----78f68546e6ed---4">Continue reading on Westwing Tech Blog »</a></p></div>]]></description>
            <link>https://medium.com/westwing-tech/must-have-php-tools-868a1aac6eb7?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/868a1aac6eb7</guid>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[dependency-management]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Marcin Czarnecki]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 08:57:47 GMT</pubDate>
            <atom:updated>2023-04-06T08:57:47.666Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Part 3 — Why sometimes Full Table Scan is better than index Scan]]></title>
            <link>https://medium.com/westwing-tech/part-3-things-you-should-know-about-disk-i-o-43e01542c562?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/43e01542c562</guid>
            <category><![CDATA[disk]]></category>
            <category><![CDATA[index]]></category>
            <category><![CDATA[full-table-scan]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Rehmat Sayany]]></dc:creator>
            <pubDate>Tue, 06 Dec 2022 15:33:00 GMT</pubDate>
            <atom:updated>2022-12-14T09:59:54.764Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 3 — Why sometimes Full Table Scan is better than index Scan</h3><p>This is the third and last part of my blog series. If you haven’t read the second part please have a look at <a href="https://medium.com/westwing-tech/part-2-common-indexing-mistakes-that-lead-your-query-slow-3067fd2d6b12">https://medium.com/westwing-tech/part-2-common-indexing-mistakes-that-lead-your-query-slow-3067fd2d6b12</a> as its compulsory because I will take the existing example to explain the concept of disk I/O.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*klS43GqcpHCmIDDeE7m57g.jpeg" /><figcaption>Payment Table</figcaption></figure><p><strong>What is Disk I/O?</strong></p><p>So whenever the data is not present in memory it has to read from the disk. It depends on the individual case, whether the database should choose an index or if reading from disk (Full table scan) is a better choice. To understand this let&#39;s take the same example mentioned in the second part of my blog.</p><p>Your Manager wants a sale report of all the sales in the year 2022. It looks simple you write a query. Let&#39;s assume that you have already an index on <strong>payment(payment_date).</strong></p><p>Let’s test the following equivalent query:</p><pre>SELECT sum(amount) FROM payment where payment_date between ‘2022–01–01 00:00:00’ AND ‘2022–12–31 23:59:59’</pre><p>Let’s see the execution plan again in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tG3-n1n_Fpg4Q_tv2q6McA.png" /></figure><p>Its acces_type is ALL which means still a full table scan has been performed. Here we know that we don&#39;t have an index on the amount column that&#39;s why we can see ALL access types. But that is not the actual reason.</p><p>If we look carefully at the query, the query is referring to the sum of the amount which is not in the index so the database has to take the ROWID from the index, go back to the table, fetch the corresponding row ( that is a read from disk ) fetch the column, sum it up and do this operation 64506 times which means the database has to perform 64506 times read from disk.</p><p>That is bad, But consider if we have a only 100k record in the payment table so the Full table scan is even worse because it has to do the same operation 100k times.</p><p>No, it isn&#39;t. The database is very smart enough to know if it has to do a <strong>FULL </strong>table scan in anyways because if we look into the rows column when we run <strong>EXPLAIN</strong> statement. We can see that database has to look for sixty-four thousand five hundred six rows which are more than 60 percent of the total data.</p><p>So the database will never read them one by one. It will batch read in pages, which means a couple of thousand at a time and the amount of disk I/O will be way less in the above example.</p><p>It&#39;s way faster even though you have to look at 2 times as many rows but you cut down the disk I/O and in total, that is much faster than having an index and then reading from the disk one by one. So the database rightly decided in this case that a full table scan is faster than using the index.</p><p>To verify this let&#39;s do one more query in which we will only fetch the sales report for April 2022. Here we are limiting results to show data for the month of April.</p><p>Here also we have the same index on <strong>payment(payment_date).</strong></p><pre> EXPLAIN SELECT sum(amount) FROM payment where payment_date  between  &#39;2022-04-01 00:00:00&#39; AND &#39;2022-04-01 23:59:59&#39;</pre><p>Let’s see the execution plan again in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nHtTxGk1SDLFT3d68vjy8w.png" /></figure><p>Here the database is deliberately choosing an index scan rather than doing the full table scan. The reason is that here the rows are limited to 4096 which is 4 percent of the total data.</p><p>Let&#39;s take another example, you are working on a ticketing system and you have a table called Tickets. Over time, more and more ticket status change to <strong>CLOSED</strong>, while a small constant number of <strong>OPEN</strong> tickets remain in the system. The OPEN/CLOSED ratio is like 1/99 which means 99% of data is with ticket status closed and only 1% are open tickets.</p><p>We have an index on column <strong>Tickets(closed). </strong>We need a query to get all closed tickets. Let’s test the following equivalent query:</p><pre>SELECT * FROM Tickets where closed=&#39;Y&#39;</pre><p>When we see the execution plan, A FULL TABLE Scan is performed. The reason behind this is also the same. Here Full Table scan is way faster than index because you cut down the disk I/O and batch read a couple of thousand records of the data in pages.</p><p>So to conclude these let&#39;s say, the <strong>index</strong> will be selected if you select rows less than or up to 5% of the total number of rows but there is no golden rule as to when an index will be used (or ignored) - too many variables play part into that decision.</p><p>If the database thinks that it has to look at more data when choosing an index then a full table scan is chosen. A full table scan performs the sequential reads, many blocks simultaneously from disk and an index scan read single block, random IO’s. Sequential reading is the fastest type of I/O since it reads many blocks at a time. Reading a single block is a slow process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43e01542c562" width="1" height="1" alt=""><hr><p><a href="https://medium.com/westwing-tech/part-3-things-you-should-know-about-disk-i-o-43e01542c562">Part 3 — Why sometimes Full Table Scan is better than index Scan</a> was originally published in <a href="https://medium.com/westwing-tech">Westwing Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we use Hackathons to rethink and simplify our in-house built applications — Robocop…]]></title>
            <link>https://medium.com/westwing-tech/how-we-use-hackathons-to-rethink-and-simplify-our-in-house-built-applications-robocop-2596a9a65097?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/2596a9a65097</guid>
            <category><![CDATA[hackathons]]></category>
            <dc:creator><![CDATA[Adam Maschek]]></dc:creator>
            <pubDate>Mon, 28 Nov 2022 08:23:25 GMT</pubDate>
            <atom:updated>2022-11-28T08:23:25.873Z</atom:updated>
            <content:encoded><![CDATA[<h3>How we use Hackathons to rethink and simplify our in-house built applications — Robocop replacement</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PiEH4_HYy-g4s47z35jFNA.jpeg" /></figure><p><strong>Outline: </strong>Many of our teams are currently working on migrating to a new Data Warehouse (Snowflake). With such a multi-year project comes a multitude of complications, one of which being the amount of tools which connect to our current Data Warehouse and need to be reconfigured or rebuilt in order to work with Snowflake. One such tool is an in-house built report sender known as Robocop.</p><p><strong>What is Robocop, what was the problem?</strong></p><p>Robocop is a bundle for Symfony which is able to collect information from different sources e.g. Webshop database, Warehouse Management database, Vertica (via SQL queries). The queries are executed (as per cron schedule) and Robocop publishes the collected data as reports via e-mail to a set of subscribed users. Entries of new queries must be inserted directly to the database, due to the fact that we never had time to develop a UI for the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wV0ZQqz_-rBw3ewFebFBtQ.jpeg" /><figcaption>Robocop is used to collect data and automatically send this out in reports via E-mail to a set of subscribed users</figcaption></figure><p><strong>Architecture overview</strong></p><p>The current Robocop architecture can be seen on the diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5zqCtvOXG8Er5v9V9-d0OQ.png" /></figure><p>Users (Analysts or Engineers) would normally add new queries to the query storage, then a cron engine picks them up, executes them, renders the results and sends them out in an email to the target users of the reports. If anything fails in the execution, Engineers can debug based on the logs.</p><p>There were many problems with the existing solution. Apart from what we mentioned, that there was no UI at all to manage the queries, the following main weaknesses we wanted to address as well:</p><ul><li>Easy to make mistakes when operating directly in the database</li><li>The engine is written in PHP and is fragile. One bad query can bring down the whole query execution engine</li><li>Email attachments can become too big</li><li>Lack of functionality to trigger queries on-demand/manually</li><li>Lack of change control (who changed a query, when and why?)</li><li>Lack of 4-eyes principle/approvals</li></ul><p><strong>Structure of the Hackathon</strong></p><p>As Westwing Tech work in a remote-first environment, our Hackathon was single-day event in a hybrid of in-office and remote attendees. All interested parties were welcome to join which culminated in a group made up of software developers, product managers, project managers, domain experts and more. The organisers of the Hackathon gathered as much information on the topic and the problem in advance. This information was presented as an introduction to the hackathon at which point the attendees could also add their input to ensure everyone agreed on how the current process looked like and what exact problem needed to be solved on the day.</p><p>At this point, we had an open brainstorming session for everyone to put forward their ideas on how they could envisage a solution. Each attendee then decided which solution they wanted to be a part of and split off into small groups (made up of 2–3 persons) for the rest of day to work on a Proof of Concept(POC).</p><p>Finally we met again at the end of the day to present each groups’ progress and findings. Each attendee then voted on the solution which they thought was the best that should be taken forward.</p><p><strong>Potential solutions</strong></p><p>When we started the hackathon, we had the goal in mind to provide an alternative solution, that re-uses our existing building blocks, thus no new tooling investment would be needed. We generally also wanted a solution, that is cheap, user-friendly, low-maintenance and highly scalable. (Don’t we always want those?:))</p><p>So we started brainstorming what existing building blocks could we <em>even </em>use, instead of the PHP application. We came up with a <em>possible </em>solution-space like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6p3QBtaFUuWeqaZTyQwg2g.png" /></figure><p><strong>Tableau </strong>was a straightforward choice, as it could do many of the things that we wanted, however it has one big disadvantage: Tableau can only send reports to registered tableau users. No external emails, no group emails, only paid and licensed tableau users. We know that Looker for example can do this without a problem, but it is not a tool we were willing to switch over for this project. We know that there is an extension called <a href="https://github.com/tableau/VizAlerts">VizAlerts </a>that can do this for Tableau, but it is not officially supported, complicated to set up and does not seem to be too actively maintained.</p><p>Therefore we investigated other possibilities.</p><p>At the end of the hackathon day, two PoCs were viable and we made them almost fully functional within a single day.</p><p><strong>PoC #1 = Git/Airflow/S3</strong></p><p>The first PoC used the power of Git/Gitlab to track query changes and envisioned a standard front-matter/header or metafile to describe the schedule, recipients, other metadata for the query.</p><p>The execution and reporting was orchestrated by Airflow and managed by small Python scripts.</p><p>The architecture with its pros and cons can be seen on the following diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o5337uvXBD_choYaX1Fi-g.png" /></figure><p><strong>PoC #2 = Monday.com/AWS Eventbridge/Lambda</strong></p><p>The second PoC used the powerful UI and notification capabilities of monday.com, the scalability of AWS Eventbridge and Lambda.</p><p>The execution and reporting was orchestrated by Eventbridge and executed in Lambda, using Nodejs.</p><p>The architecture with its pros and cons can be seen on the following diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7pv5-qvp04RtmFWHqvJRcA.png" /></figure><p><strong>The winning solution</strong></p><p>At the end of the day, all potential solutions were presented to the hackathon participants, and all of them voted on their preferred solution. The vast majority of participants preferred the <strong>strong change management</strong> and approval possibilities of Gitlab, furthermore Gitlab and Airflow was considered as already being part of the <em>toolchain</em> of the BI Tech and BI Analyst teams. As we currently see the BI Tech team as the natural new owner of the to-be-built new Robocop, it was important that they are familiar with the toolchain.</p><p>There was one remaining concern about the stability of Airflow. In the past we did have some hard-to-debug situations and stuck executions. We will investigate potentially to replace Airflow with a more stable solution in the future.</p><p><strong>Summary</strong></p><p>In conclusion, our single-day Hackathon was not only successful in providing multiple solutions to our problem, but we also took many other learnings away, including the following:</p><ul><li>Despite the challenges posed by a hybrid set up, our hackathon worked well under these circumstances.</li><li>A main theme and some preparation work in advance go a long way. Bringing some of the ideas up-front allowed us to hit the ground running, while still allowing every participant to add to this on the day.</li><li>We worked in small teams of 2–3 people. It worked well for us because every participant came with a different background and knowledge.</li><li>Book the time upfront and make sure all of the appointments are re-scheduled and people can really have their focus time for the hackathon. If needed, find the substitution for the meetings or move them. This allows for all participants to be fully focused on the task at hand and not be distracted by other topics.</li><li>Likewise, book the time in at the end of the day for the demos and results. This allows for a natural conclusion to the day and gives us the possibility to derive next steps with the winning solution.</li><li>The hackathon focus time really worked! We not only had multiple possible solutions in idea form but by the end of one day they were all almost working POCs.</li></ul><p>Finally, a huge thank you to all of the participants of our Hackathon: Christian Manrich, Tomasz Ulanowski, Tiziano Rossi, Pedram Behroozi, Hamid Parchami, Pierre-Andre Weber, Nikolay Kopylov and Adam Maschek.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2596a9a65097" width="1" height="1" alt=""><hr><p><a href="https://medium.com/westwing-tech/how-we-use-hackathons-to-rethink-and-simplify-our-in-house-built-applications-robocop-2596a9a65097">How we use Hackathons to rethink and simplify our in-house built applications — Robocop…</a> was originally published in <a href="https://medium.com/westwing-tech">Westwing Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2 — Common Indexing Mistakes that Lead your query Slow.]]></title>
            <link>https://medium.com/westwing-tech/part-2-common-indexing-mistakes-that-lead-your-query-slow-3067fd2d6b12?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/3067fd2d6b12</guid>
            <category><![CDATA[query-optimization]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[index]]></category>
            <category><![CDATA[composite-index]]></category>
            <dc:creator><![CDATA[Rehmat Sayany]]></dc:creator>
            <pubDate>Tue, 15 Nov 2022 11:16:54 GMT</pubDate>
            <atom:updated>2022-11-15T11:20:32.147Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 2 — Common Indexing Mistakes that Lead your query Slow</h3><p>This is the second part of my blog series. If you haven&#39;t read the first part please have a look at <a href="https://tech.westwing.de/part-1-what-is-indexing-why-its-important-to-know-a61aa18dbdf1">https://tech.westwing.de/part-1-what-is-indexing-why-its-important-to-know-a61aa18dbdf1</a> as its compulsory to gain the basic knowledge of query execution plan before optimizing your query.</p><p>Let&#39;s start with an example. Assume you are working on a Point of sale system and you have a payment table as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*lVKlWzB8l0ZvBLPe8fQ6_g.png" /><figcaption>Payment table of Point of sale system.</figcaption></figure><p>Your Manager wants a sale report of all the sales in the year 2022. It looks simple you write a query</p><pre>SELECT sum(amount) FROM payment where year(payment_date)= 2022</pre><p>It took 8 seconds to fetch the data and we got <strong>202249.53.</strong> Looks good. R<strong>ight?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*mixdRVcmKV7z6S9DNK8ezg.png" /><figcaption>Result of Query.</figcaption></figure><p>Tomorrow Morning you show the result to your manager, he says the result looks good but the query is slow can you please optimize?</p><p>So you think I need to improve the read performance so I need to index on payment_date as it&#39;s the only column on where clause. You added an index on payment_date and now you want to see the execution plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*ELpX9IhvcEoKqCkQKucfoQ.png" /><figcaption>Execution Plan</figcaption></figure><p><strong>Wait. What? </strong>For some reason, we have an index on the payment_type column but it&#39;s not been considered. The acces_type is ALL this means a full table scan has been performed.</p><p>This brings me to the first mistake that we did.</p><h4><strong>FUNCTION USED ON INDEX COLUMN</strong></h4><p>If we look carefully at our query above. The index we have created is not effective. Indeed any time an indexed column is involved in a function the index can not be used. The reason is that we have an index on column payment_type, not on the return value of function YEAR().</p><p>To optimize the query the workaround is rewriting it differently in order to isolate the indexed column from the function.</p><p>Let’s test the following equivalent query:</p><pre> SELECT sum(amount) FROM payment where payment_date between &#39;2022-01-01 00:00:00&#39; AND &#39;2022-12-31 23:59:59&#39;</pre><p>Let&#39;s see the execution plan again in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*9GXyTmO4eRVBwQanC6u1_g.png" /></figure><p>Whaaattttt ?? Its acces_type is still ALL which means still a full table scan has been performed. But wait what? something is changed. We can see the possibe_keys column with the index. Now at least the query see our index but still, it&#39;s not considering it.</p><p>If we look carefully at the query the query is referring to the sum of amount which is not in the index so MySQL has to perform a read from disk for the <strong>amount</strong> column for ALL the rows ( 64506 ). That&#39;s Bad. !!!</p><p>So If that is the case let&#39;s add one more index to the amount column and let&#39;s see what will be the execution plan now.</p><p>Now the current index looks like this <strong>payment(payment_date, amount)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*DBEJ7UxnfELDr3WtWzCqTQ.png" /><figcaption>Execution Plan</figcaption></figure><p>Finally, it&#39;s voluntary choosing the index because it doesn&#39;t have to read from the disk anymore. This type of query is also called index-only Scan because the index is very specific for this query.</p><p>The next day your manager applause your performance and say we have a feature request. We want the same report but this time we want sales for a single Staff.</p><p>Ohhh that&#39;s easy now because we know how simple these indexes are. Let&#39;s put the index on staff_id and update our query and see the execution plan.</p><p>Now the current index looks like this <strong>payment(payment_date, amount, staff_id)</strong></p><pre>EXPLAIN SELECT sum(amount) FROM payment where payment_date between &#39;2022-01-01 00:00:00&#39; AND &#39;2022-12-31 23:59:59&#39; AND staff_id=1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*Dz4Z5mX_D_zgiOTEo58LMQ.png" /></figure><p>So it looks fine again. The <strong>acces_type</strong> value is range again which is good but something is still not right though. The <strong>rows</strong> column. The query still thinks it has to look from 32253 rows which is the same as when we were not limiting the query by staff_id.</p><p>As we are limiting our result set by adding a constraint that we only want 2022 sales for the staff_id =1, this <strong>rows</strong> count should also be decreased. So this problem takes us to the second pitfall.</p><h4><strong>COLUMN ORDER MATTERS</strong></h4><p>The index on A and B is not the same as an index on B and A. So if we change the order of our multi-column index like this <strong>payment(staff_id, payment_date, amount)</strong> and rewrite the query.</p><pre>SELECT sum(amount) FROM payment where staff_id=1 AND payment_date between &#39;2022-01-01 00:00:00&#39; AND &#39;2022-12-31 23:59:59&#39;</pre><p>The count of rows will be decreased and we will optimize our query because now we are looking for only a single staff which has id =1 and then the sales of that staff which took place in 2022.</p><p>Let&#39;s take another example to understand this. Let&#39;s suppose you have a customer table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*qcVRQZ3SXx6lH8x4Cl8BbQ.png" /></figure><p>Consider the indexes:</p><pre>create index idx_fl on name(first_name, last_name);</pre><p>The below query will work fine as we are limiting our query by First_name and then last_name.</p><pre>SELECT * FROM sakila.customer where first_name= ‘LINDA’ and last_name=’Williams’</pre><p>But this one will be not optimal</p><pre>SELECT * FROM sakila.customer where last_name=&#39;Will</pre><p>As we skip the first_name column in this query so our index will not work here because as soon as you skip any column in the index your index will stop working there and when you will run the execution plan it will be like this as shown in the below image, which means it does not use any index and a Full table scan is performing in the background.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*nY6ctIaiZMExP7XtsI_Kzw.png" /><figcaption>Execution plan</figcaption></figure><p>Now this time you have got enough idea of optimizing the query. Let&#39;s take this as a challenge. So Let&#39;s continue the Customer example and now we want to write a query where the first name is not <strong>LINDA </strong>and the last name is <strong>WILLIAMS.</strong></p><p>That&#39;s easy, right?</p><pre>SELECT * FROM customer where first_name !=&#39;LINDA&#39; and last_name=&#39;WILLIAMS&#39;</pre><p>But if you will see the execution plan now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*McOheQfgNJInpq8Vx3Ezbw.png" /></figure><p>It&#39;s still doing a Full Table Scan. This takes us to the third pitfall.</p><h4><strong>INEQUALITY OPERATOR</strong></h4><p>Yes, you can use the index left to right but as soon as you have an inequality operator on any of the columns the index stops there.</p><p>So always try to avoid the inequality operator or use it at the end of your where clause, in this way if you have an index on last_name the below query will be optimized.</p><pre>SELECT * FROM sakila.customer where last_name=&#39;WILLIAMS&#39; AND first_name !=&#39;LINDA&#39;</pre><p>There are many more common mistakes that we do while writing queries. Let&#39;s discuss that so we can tune our query more efficiently.</p><h4>SELECT Specific fields instead of SELECT *</h4><p>The SELECT statement is used to retrieve data from the database. In the case of large databases, it is not recommended to retrieve all data because this will take more resources on querying a huge volume of data.</p><p>If you want to retrieve all actors who appear in <strong>Love Story</strong>, don’t write the query this way:</p><pre><strong>       SELECT * FROM actor</strong><br>    -&gt; <strong>INNER JOIN sakila.film_actor ..</strong><br>    -&gt; <strong>INNER JOIN sakila.film ..</strong><br>    -&gt; <strong>WHERE sakila.film.title = &#39;Love Story&#39;;</strong></pre><p>That returns all columns from all three tables. Instead, write the query as follows:</p><pre><strong>   SELECT actor.* FROM sakila.actor...;</strong></pre><h3>Wildcard String Searches</h3><p>MySQL won’t improve search performance whenever you have leading wildcards because MySQL will be unable to use the index. If you change to ‘anyLetter%’ then it will be able to use the index.</p><p>So if you want to search all customers whose first_name start with ‘j’. The below query will work fine and will use your index.</p><pre>select * from customer where first_name LIKE &#39;j%&#39;;</pre><p>But this one will be not optimal</p><pre>select * from customer where first_name LIKE &#39;%j%&#39;;</pre><p>As it will do a full table scan.</p><h4>WHERE Clause Optimization</h4><p>You might be tempted to rewrite your queries to make arithmetic operations faster while sacrificing readability. Because MySQL does similar optimizations automatically, you can often avoid this work, and leave the query in a more understandable and maintainable form.</p><p><strong>Removal of unnecessary parentheses: </strong>Avoid unnecessary and complex parathesis.</p><pre>Where ((a AND b) AND c OR (((a AND b) AND (c AND d)))) ...</pre><p>Change it to something like this.</p><pre>where (a AND b AND c) OR (a AND b AND c AND d) ...</pre><p><strong>Constant folding: </strong>Simplify complex logic that will help MySQL parser to parse your clause faster.</p><pre>(a&lt;b AND b=c) AND a=5</pre><p>Change it to</p><pre>b&gt;5 AND b=c AND a=5</pre><p><strong>Counts: </strong><a href="https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_count">COUNT(*)</a> on a single table without a WHERE is retrieved directly from the table information for MyISAM and MEMORY tables.</p><p>For example, the below query will be read from the memory and doesn&#39;t need to be optimized.</p><pre>SELECT COUNT(*) FROM CUSTOMERS </pre><h3><strong>IS_NULL</strong></h3><p>MySQL performs the optimization for the IS NULL operator in the same way that it does for the equal (=) operator.</p><p>so this means both queries will use indexes if we have an index on first_name</p><pre>SELECT * FROM customer where first_name IS NULL</pre><pre>SELECT * FROM customer where first_name= &#39;&#39;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3067fd2d6b12" width="1" height="1" alt=""><hr><p><a href="https://medium.com/westwing-tech/part-2-common-indexing-mistakes-that-lead-your-query-slow-3067fd2d6b12">Part 2 — Common Indexing Mistakes that Lead your query Slow.</a> was originally published in <a href="https://medium.com/westwing-tech">Westwing Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1 — What is Indexing? Why it's important to know?]]></title>
            <link>https://medium.com/westwing-tech/part-1-what-is-indexing-why-its-important-to-know-a61aa18dbdf1?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/a61aa18dbdf1</guid>
            <category><![CDATA[index]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[b-tree]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[query-optimization]]></category>
            <dc:creator><![CDATA[Rehmat Sayany]]></dc:creator>
            <pubDate>Thu, 23 Jun 2022 09:29:01 GMT</pubDate>
            <atom:updated>2022-06-23T09:29:01.693Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 1 — What is Indexing? Why it&#39;s important to know?</h3><p>Working at Westwing, I once received a ticket about a cron that ran all night and never finished. I started looking into the queries that were running and found a problematic query. Here’s what I discovered: the query couldn’t pick up relevant indexes, even though the table contains indexes on that column. This resulted in data read from disk and query fetching being extremely slow. To share my experience, I decided to write a series of blog posts to discuss the concept behind database indexing and how to find out if your query needs any optimization or not.</p><p>So … Let&#39;s start with what an index is.</p><p><strong><em>An index is an ordered representation of indexed data.</em></strong></p><p>The index makes query retrieval fast. “<strong>So if that’s the case let’s index all the columns in the table</strong>” one might think — this would not be the correct approach, because creating an index on all of the columns will create the following bad results:</p><ol><li>Using Indexes improves read time but it makes write time slower.</li><li>With every insert/delete we have to insert/delete indexes and then re-balance out BTREE which will take some time.</li><li>Updates only become slower if an indexed column is updated. It might be a good idea to avoid indexes on columns that are very frequently updated.</li><li>If more than one index is created for a table, the indexes might need more space than the table itself.</li><li>If there are many indexes that can be used for a given query, query optimization may take longer.</li></ol><p>So the rule of thumb should be to have as many indexes as necessary but as few as possible.</p><h3><strong>So what is a B-TREE?</strong></h3><p><strong>B-tree is a self-balancing tree data structure that maintains sorted data and allows searches, sequential access, insertions, and deletions in logarithmic time.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*sUP7cf97DIV7kuuddIE0qA.jpeg" /><figcaption>B-Tree Representation</figcaption></figure><p>The left sub-tree is always smaller than the right sub-tree. The nodes on the top are called Root Nodes, the bottom one is called Leaf nodes and in the middle are called intermediate nodes. The leaf nodes don&#39;t have any further subtree. This way it&#39;s ensured that every search will take the same number of steps to find the value. The leaf nodes also have doubly linked lists, which allows moving forwards and backward within leaf nodes.</p><h3>How is indexing used in a database?</h3><p>When it comes to database indexing, the B-tree data structure gets a little complicated by not just having a key, but also having a value associated with the key. This value is a reference to the actual data record. The key and value together are called a payload.</p><p>Let&#39;s take an example of the table called Employee where we have only two columns: Id, Name. We have created the index on the <strong>Name</strong> column only.</p><figure><img alt="Employee Table" src="https://cdn-images-1.medium.com/max/227/1*NJpZjT6wg4zom9OhYhT6Tg.png" /><figcaption>Employee Table</figcaption></figure><figure><img alt="B-Tree Representation of Index column Name" src="https://cdn-images-1.medium.com/max/1024/1*QVYVj5wnIRE9KRK3TcMqyA.png" /></figure><p>The Employee ID is nowhere to be found on this index, you can only see the <strong>Name</strong> value. In simpler words, The index only contains the value of the index column. Some people think that the index contains all data of the other columns too which is totally incorrect.</p><p>So now the question is how would I get the data which is not in the index. Let’s say, for example, that I need the age, department, and employee Id of the Kamil. This is the reason why the Database saves one more attribute which is ROWID. It&#39;s not a primary key of our table. It&#39;s a Database internal identifier for every row and that way we can go back to the table ( which will be read from the disk ) and find the corresponding row. One thing is to be remembered here is that the i<strong>ndex data is in the memory</strong> and the <strong>non-index data will be on the disk.</strong></p><h3>How can we minimize reading from disk?</h3><p>So let&#39;s suppose we have a query as shown below and we have a multi-column index on CUSTOMER(LAST_NAME, CITY)</p><pre>SELECT DISTINCT CITY FROM CUSTOMERS WHERE LAST_NAME = ’Smit&#39;</pre><p>So in this case there will be no read from disk as both last_name and city data are already present on the index. Another example is when you have an index on CUSTOMERS(ZIP) then the below query will be very fast because it suffices to count the ROWIDs from the index.</p><pre>SELECT COUNT(*) FROM CUSTOMERS WHERE ZIP = 15260</pre><h3><strong>What are the benefits of using this technique?</strong></h3><ol><li>In this way, the search will be very fast. If we want data on employee <a href="https://tech.westwing.de/part-1-what-is-indexing-why-its-important-to-know-a61aa18dbdf1">Kamil</a> then we will go directly from Root node to leaf Node and will narrow down our searches because basically we are either searching on the left or right sub-tree and following binary search.</li><li>For each query, it will take the approximately same amount of time to get the result.</li><li>Either we will find the result or we will get NULL value.</li></ol><p>Now let&#39;s move forward and see how to find the execution plan of queries. In this way, we can find why some queries are working slower.</p><p>The <strong>EXPLAIN</strong> keyword is used throughout various SQL databases and provides information about how your SQL database executes a query. In MySQL, EXPLAIN can be used in front of a query beginning with SELECT, INSERT, DELETE, REPLACE, and UPDATE. For a simple query, it would look like the following:</p><pre>EXPLAIN SELECT * FROM sakila.users where id=1</pre><p>So when you run the above query, the result will look like in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*l_Cm10ObwbK98vX6m1fT7w.png" /><figcaption>Execution plan</figcaption></figure><p>Let&#39;s understand the <strong>type</strong> column here. If you will look at MySQL Documentation it is defined as a join type. I think join type is not the best name for it, so in the remainder of the article let’s refer to it as <strong>access_type</strong>.</p><p>Now let&#39;s find out what are some different values for this access_type Column.</p><ol><li>Const/eq_ref</li><li>ref/range</li><li>index</li><li>ALL</li></ol><h3>Const/eq_ref</h3><p>If you can guarantee that your query will return a single value that will be unique. There are two ways you can do this. One is if the index is the primary key and another way is that unique constraint on the column.</p><pre>SELECT * FROM <em>tbl_name</em> WHERE <em>primary_key</em>=1; </pre><p>if you get const/eq_ref in your query stop optimizing. It will not get any faster.</p><h3>Ref/Range</h3><p>Is used in cases when you can guarantee only rows that are in a given range are retrieved, using an index to select the row. So let&#39;s take an example, let&#39;s say you have a query where the id is greater than 5 and less than 10. So it will start B-Tree traversal and come to a leaf node where it gets a leaf node with id 6 and then using the doubly linked list it will traverse the leaf nodes and find a range of values from 6 to 9. So it does not have to go back to the Root node. This will save a lot of time.</p><pre>SELECT * FROM <em>tbl_name</em>   WHERE <em>key_column</em> = 10; </pre><pre>SELECT * FROM <em>tbl_name</em>   WHERE <em>key_column</em> BETWEEN 10 and 20;</pre><pre>SELECT * FROM <em>tbl_name</em>   WHERE <em>key_column</em> IN (10,20,30);<br>  <br>SELECT * FROM <em>tbl_name</em>   WHERE <em>key_part1</em> = 10 AND <em>key_part2</em> IN (10,20,30);</pre><h3><strong>Index</strong></h3><p>It is also known as a full Index scan because it will scan from first to last leaf node and we are using the index but not using it to limit the result.</p><h3>ALL</h3><p>A full table scan is done and we are loading all data from disk to memory and filtering them. If your execution plans say access type equals <strong>ALL</strong>, this means you are not using the index at all which is very bad. This type of query will take the longest time to execute.</p><p>The second important column in the execution plan is the <strong>rows </strong>column<strong>. </strong>The rows column indicates the number of rows MySQL believes it must examine to execute the query.</p><p>The possible_keys column indicates the indexes from which MySQL can choose to find the rows in this table</p><p>Let&#39;s stop it here and I will tell you in my next blog post how to make your query faster and change your access type from <strong>ALL</strong> to <strong>const/range </strong>using some query optimization techniques.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a61aa18dbdf1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/westwing-tech/part-1-what-is-indexing-why-its-important-to-know-a61aa18dbdf1">Part 1 — What is Indexing? Why it&#39;s important to know?</a> was originally published in <a href="https://medium.com/westwing-tech">Westwing Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Westwing Technology Radar]]></title>
            <link>https://medium.com/westwing-tech/the-westwing-technology-radar-82b85661a2c0?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/82b85661a2c0</guid>
            <category><![CDATA[techradar]]></category>
            <category><![CDATA[roadmaps]]></category>
            <category><![CDATA[technology-radar]]></category>
            <dc:creator><![CDATA[Thomas Baradel]]></dc:creator>
            <pubDate>Fri, 06 May 2022 09:15:28 GMT</pubDate>
            <atom:updated>2022-05-27T07:49:44.209Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*VZmm14NeIpJ5HCV989_nVw.png" /></figure><p>Westwing is a growing company with a tech team that rapidly grew from a few dozen to around 270 team members in a span of a few years. When a tech department grows rapidly from a “startup” to a scaled up setup, it’s easy to lose track of the initiatives, practices and especially <strong>technologies </strong>present in the department. So, one of our governance initiatives was to identify all the technologies currently in use and also the ones that we want to keep investing in. To do so, we’ve decided to use a so called “Technology Radar”</p><h3>Wait, a tech what?</h3><p>If you are in technology you’re probably familiar with the “technology radar” concept, in case you’re not, we can describe it as a tool to track technology and its use in the world or, in our case, inside an organisation. The tool is coming from the work of a well known and innovative technology company called <em>Thoughtworks, </em>and it’s used by the software developers community to stay informed, keep track of technology changes and understand new trends (if you’re interested, you can read more about it <a href="https://www.thoughtworks.com/en-es/radar/faq-and-more">here</a>).</p><p>The radar basically consists of two main elements, the quadrants and the rings:</p><ul><li>A <strong>quadrant </strong>is a categorisation of a technology (e.g. a “Programming language” or a “Tool”)</li><li>A <strong>ring</strong> is a figurative concentric circle, and the more a technology is closer to the center, the more “safe” it is to use it</li></ul><p>Visually it’s pretty easy to grasp (that’s the latest version of the official <em>Thoughtworks </em>radar and each point represents a technology)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*VZmm14NeIpJ5HCV989_nVw.png" /></figure><h3>The Westwing tech radar</h3><p>You might wonder, why does a company like Westwing needs an internal <em>technology radar?</em></p><p>There are multiple reasons:</p><ul><li>As mentioned above, a rapidly growing company could easily lose track of the technologies used in its tech team, so the first purpose that it serves is to<strong> assess the current technology landscape</strong> inside the company.</li><li>The world of tech changes fast and it’s very central to our business, so as a tech organisation we need to <strong>define a tech strategy </strong>and the tech radar is a good tool to map one.</li><li>With a tech radar we can easily explain to a potential candidate what’s our technology landscape and being clear on what is our vision (and also facilitate the recruiting team’s work)</li></ul><h4>How we built our tech radar</h4><p>The very first step has been to list our technologies and to do so, we’ve simply created a spreadsheet (similar to the one proposed from Thoughtworks) and assigned a DRI for each area/department with the responsibility to coordinate with the teams and fill the draft document.</p><p>This task took a while and sparked the first discussions on what was worth to be listed and what not, since it’s not always easy to distinguish between libraries, frameworks and tools.</p><p>Once all the teams filled up the document we went through a review with a small “committee” of experienced managers and leads and we went down from over 180 lines in the spreadsheet to 120 (which is still a considerable amount and it gives you an idea of how easily the number of “stuff” used in tech can grow).</p><p>Then we had to decide in which quadrants we wanted to categorise our technologies. In the very first draft we left the “quadrant” field open to suggestions, and we decided to go for the most “populars”:</p><ul><li><strong>Languages and frameworks</strong>: Self Explicative</li><li><strong>Data</strong>: All the technologies related to data (e.g. databases, DWH tech, data streaming tech etc.)</li><li><strong>Infrastructure: </strong>All the technologies that have something to do with our infrastructure, from AWS services to Docker.</li><li><strong>Tools: </strong>All the SaaS, open source and internal tools used in the company.</li></ul><p>We also needed to decide the meaning of each ring. Even if they are in some way self explicative, we decided to have a more “westwing centric” definition</p><ul><li><strong>Hold</strong>: Don’t use or deprecated</li><li><strong>Assess</strong>: It’s a new technology or has still a low adoption, please assess through one of our DNA (design and architecture) meetings.</li><li><strong>Trial: </strong>Already adopted in the company and very promising but still, before adopting it, consult with your principal engineer and possibly assess it in one of our architectural meetings.</li><li><strong>Adopt</strong>: We’ve consistently used the technology in the company and you can adopt it without validation</li></ul><p>Once we’ve finalised our document, we’ve started looking for a tool to visualise the radar in an efficient way. Initially we’ve looked in the official <em>Thoughtworks</em> tool, but it required to generate it manually and it can be exported only as an image, so we kept looking and found out that other companies created their own radar. The most popular solution, used by many companies is the <a href="https://github.com/zalando/tech-radar"><em>zalando tech radar</em></a>, an open source solution (based on <a href="https://d3js.org/">d3.js v4</a>) which draws efficiently a radar in a very clear way, especially if your list is pretty extended.</p><p>So we’ve forked the original code, made some changes, added a script to automatically feed the radar from a <a href="https://docs.google.com/spreadsheets/d/1qxqDFvSeZvmaHd5MNnJ-JiDcmUTXilXjCm9xfJe03EM/edit#gid=0">public spreadsheet</a> and hosted on our public github.</p><p>You can find the repository <a href="https://github.com/Westwing-Home-and-Living/techradar">here</a> and our beautiful generated tech radar <a href="https://westwing-home-and-living.github.io/techradar/#">here</a>.</p><p>We will keep it up-to-date in the future, so stay tuned!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cuqmw4XDk806w5qoiI1Q1g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82b85661a2c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/westwing-tech/the-westwing-technology-radar-82b85661a2c0">The Westwing Technology Radar</a> was originally published in <a href="https://medium.com/westwing-tech">Westwing Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The unit test coverage marathon]]></title>
            <link>https://medium.com/westwing-tech/the-unit-test-coverage-marathon-3c52376421b0?source=rss----78f68546e6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/3c52376421b0</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Shamanth Prasad]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 12:01:31 GMT</pubDate>
            <atom:updated>2022-04-25T12:01:31.569Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6cEKhB2hws76AM_I0uVjA.jpeg" /></figure><h3>Introduction</h3><p>Unit testing is the foundational part of the testing strategy for any software system. Without it, there is no guarantee that your code does what you say it does. But what happens when you inherit a large codebase with very little coverage? In this article, we explain what we did in the SHOP API team at Westwing to solve this very problem and the results we achieved.</p><h3>The Problem</h3><p>The application in discussion is a <a href="https://nodejs.org/en/">Node.js</a> API built with <a href="https://expressjs.com/">Express.js</a> that acts as a gateway/aggregator for frontend systems to communicate with upstream micro-services and third-party services while housing a sizeable amount of its business logic. As of September 2019, there was no information on the unit test coverage level, because it was not being measured. But it was clear that the number would be very low. And this turned out to be the case indeed.</p><h3>The Approach</h3><ul><li>The first step we took was to start measuring, without this we had no idea what we were dealing with and what targets to set.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Po3P-sh53BxF-yWMB5N16A.png" /><figcaption>Slack Thread showing the first Pull request to measure the coverage and the subsequent steps</figcaption></figure><ul><li>Next, was to set a rolling target. First, we updated our <a href="https://github.com/istanbuljs/nyc">nyc</a> configuration with the current coverage as the minimum expectation, to ensure we do not drop back below this. Whenever the npm test command was run, if the coverage dropped below the minimum, the test would fail. Subsequently, as the coverage increased, we kept increasing this minimum expectation as well.</li><li>Next, was to start writing the tests. This was not done in one go. With every new change to the codebase, we always made sure to add the corresponding unit tests. Additionally, during each quarter, we had some fixed time allocated to the technical debt. During this, we worked on adding unit tests to the larger scoped part of the codebase.</li><li>Next, we chose a higher number as the target — 50% and then added a Slack reminder to bring this goal to our remembrance every Friday. When this target was met, then we increased to 60% and so on.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L7m4FEfH-dL-MXHh9idU0A.png" /><figcaption>Target as of late 2019</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mBCKErOlNatqLLJ0W4vpsw.png" /><figcaption>Target as of mid-2020</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ufJBNtOFord1_7mBMGG0Uw.png" /><figcaption>Target as of late 2021</figcaption></figure><ul><li>Lastly, in the CI/CD pipeline, we <a href="https://docs.gitlab.com/ee/ci/yaml/index.html#coverage">configured Gitlab</a> to show the test coverage in the Merge Request, as well as the delta between the new value and the coverage value of the repository’s primary branch (master in our case). This was more of a visual indicator, but it created awareness and helped code reviewers to have a basis to point out the lack of tests on Merge Requests that had a negative delta.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*WXoLiCHwazBWtmPPqfAKKA.png" /><figcaption>Positive delta on Merge Request Coverage</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*IvwbDePO_e8aOZpRVEAS_g.png" /><figcaption>Negative delta on Merge Request Coverage</figcaption></figure><h3>The Result</h3><p>As shown in the last image of the reminder, we finally hit the 75% mark in 2021. And <strong>now we are at 85%</strong> with the climb pretty much slower since we are approaching a saturation point.</p><p>But equally as important is that the culture is now there, whereby developers know by default that they must write the tests, as opposed to relying only on the tool to remind them. This means the process has become self-sustaining.</p><p>Now we are pushing to increase other parts of our Quality Assurance and Testing processes. Including Integration, Functional, and Contract testing with <a href="https://docs.pact.io/">Pact</a>.</p><h3>The Lessons</h3><ul><li>For large/old codebases, it’s impossible to solve this instantly — it took us two long years. But what is important is the gradual progress and installation of the culture.</li><li>For new codebases, start measuring your coverage as early as possible! Fixing it later can be long and slow.</li></ul><h3>The Team</h3><p>It’s not possible to achieve any milestone without a dedicated, hardworking, and focused team. We successfully reached our target thanks to our amazing team members: Excellence Ilesanmi, Tiziano Rossi, Bhavin Chandarana, Edik Baghdasaryan, Miguel Lattuada, and Mostafa Saeed, and also the ex-team members Travis Black, Lawrence Agbani, and Noman Ali Khan.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c52376421b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/westwing-tech/the-unit-test-coverage-marathon-3c52376421b0">The unit test coverage marathon</a> was originally published in <a href="https://medium.com/westwing-tech">Westwing Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>