<?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[Flexera Engineering - Medium]]></title>
        <description><![CDATA[Flexera Software’s engineering blog - Medium]]></description>
        <link>https://medium.com/flexera-engineering?source=rss----5dc7b2707540---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Flexera Engineering - Medium</title>
            <link>https://medium.com/flexera-engineering?source=rss----5dc7b2707540---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 07:27:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/flexera-engineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Flexera One Automation for FinOps at Flexera]]></title>
            <link>https://medium.com/flexera-engineering/using-flexera-one-automation-for-finops-at-flexera-dc21659cb594?source=rss----5dc7b2707540---4</link>
            <guid isPermaLink="false">https://medium.com/p/dc21659cb594</guid>
            <category><![CDATA[finops]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[influxdb]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Douglas Thrift]]></dc:creator>
            <pubDate>Fri, 18 Jun 2021 00:25:30 GMT</pubDate>
            <atom:updated>2021-06-18T00:25:30.162Z</atom:updated>
            <content:encoded><![CDATA[<h4>How I wrote an Automation Template to apply Automation Templates to save money in the cloud</h4><figure><img alt="A piggy bank with a coin in the slot and more spread below it" src="https://cdn-images-1.medium.com/max/1024/1*qHMAoTzOwHmNTMJFbykycw.jpeg" /></figure><p>You may have heard of <a href="https://en.wikipedia.org/wiki/DevOps">DevOps</a> and may even practice it, but you may not have heard about <a href="https://www.finops.org/what-is-finops/">FinOps</a>. At least I had not until a little over a year ago when my manager asked if I would like to be the initial DevOps engineer on the FinOps team he was starting. What I quickly learned is FinOps is a framework for dealing with the variable nature of cloud computing costs in a company in a similar way to how DevOps is a framework for managing the deployment and operation of your software.</p><p>Our FinOps team currently consists of my manager who focuses on more of the <em>Analyst</em> side of things such as forecasting, budgeting, and working with other teams on those things or when issues arise, while I focus on building solutions to help us and other teams measure and save on cloud costs. One of the first things we set out to do when we got started as a team was to take better advantage of <a href="https://docs.flexera.com/flexera/EN/Automation/AutomationGS.htm">Flexera One Automation</a> (<a href="https://community.flexera.com/t5/Flexera-One-Forum/Flexera-One-Policies-renamed-to-Automation/m-p/193783">previously Policies</a>) and the available <a href="https://docs.flexera.com/flexera/EN/Automation/AutomationGS.htm">Cost Policies</a> it provides. We wanted the solution to give us visibility into what waste costs and potential savings the policies identify as well as what savings are realized when the policies take automatic actions to eliminate waste resources, but we also wanted to have the teams that actually owned those resources properly notified and fully in control of how the policies interacted with them.</p><h3>The FinOps Policies System</h3><p>Having come into Flexera through the RightScale acquisition, I had previously worked on the team that built the Policies engine both before and after the acquisition. I did a lot of the initial work on the Policy template language parser and have an in depth understanding of the Policy execution engine and its capabilities. With this knowledge, I set out to build our FinOps solution for Policies using Policies themselves. I named it the FinOps Policies system, but that is now a little funny since Flexera One Policies are now called Flexera One Automation instead. I had the initial working FinOps Policies system working late last year with a few early adopter teams and I have implemented more functionality and onboarded more teams since then.</p><p>The system is made up of four main components which I will describe in more detail further on:</p><ol><li>an <a href="https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-repository-visibility#about-internal-repositories">internal repository</a> on GitHub with Policy/Automation settings which teams use to opt in to the system and customize how things are applied to their cloud accounts based on their operational needs and comfort level with the system</li><li>a <a href="https://www.terraform.io/docs/language/modules/index.html">Terraform module</a> which provides an automated way to create the <a href="https://docs.flexera.com/flexera/EN/Automation/CredentialsIntro.htm">Flexera One Credentials</a> and corresponding cloud credentials necessary for the Flexera One Automation system to discover and act on resources in each team’s cloud accounts</li><li>a Flexera One Automation (Policy) template which ties the system together by evaluating whether changes need to be made to the currently running applied policies according to the latest settings, checking if there are any configuration or run time issues and reporting on them, and writing metrics to a metrics store</li><li>a Grafana setup with several dashboards backed by a metrics store which provides insight into team adoption, engagement, and system health</li></ol><h4>Settings</h4><p>The first component of the system is the Git repository with the Policy/Automation settings. For the settings, I decided to use <a href="https://en.wikipedia.org/wiki/YAML">YAML</a> since it is both machine readable and more forgiving than <a href="https://en.wikipedia.org/wiki/JSON">JSON</a> while still easily translated into it (which is necessary since the Automation engine does not currently understand YAML but it does understand JSON).</p><p>The default settings for each of the Automation templates that should be applied in each team’s cloud accounts are specified in a top level settings.yaml file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28f0be4c315f7d8f5fc6ca044384d9a3/href">https://medium.com/media/28f0be4c315f7d8f5fc6ca044384d9a3/href</a></iframe><p>With the information provided for each template in settings.yaml my template has almost everything it needs to apply them to a team’s account. In the example of the <a href="https://github.com/flexera/policy_templates/tree/master/cost/aws/unused_volumes"><em>AWS Unused Volumes</em></a> template above, the team_parameters map is specifying the param_email parameter for a team should be set to the value of the notification.emails setting for the team when it is applied in their cloud accounts. There are also some optional_parameter_sets specified which allow teams to easily add common customizations to their own settings. The two common customizations show here are automatic_actions which enables the template to automatically delete waste resources when they are discovered and only_eu_regions which is helpful for the AWS accounts used for services in our Flexera One EU zone where we disable API access to other regions via an <a href="https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html">AWS SCP</a> in order to ensure we comply with European Union requirements and regulations.</p><p>Individual team settings files are added in a teams/ subdirectory:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82dc1be043ff0c9a1db101878df86786/href">https://medium.com/media/82dc1be043ff0c9a1db101878df86786/href</a></iframe><p>The name and notification settings are all that is required for a team to opt in to the system. As you saw above the notification.emails array is used when applying templates in the team’s cloud accounts. The notification.microsoft_teams_webhooks_urls are used when the template needs to notify about any configuration or run time issues. You may have guessed our email address actually goes to a Microsoft Teams channel as well; it is our primary mode of communication within Flexera (I have obfuscated the email address and URL so you cannot actually start spamming our notification channel). This example only shows a single customization for a single AWS account where we want to enable automatic deletion of resources in our sandbox account, but the settings support the full customization of Automation apply parameters at both the all team cloud account and individual cloud account levels.</p><p>In order to validate the YAML settings files will actually work correctly and the parameters specified match any constraints in the actual Automation templates, I added automated tests in the repository. Since Flexera has standardized on <a href="https://golang.org/">Go</a> for writing our microservices, I wrote most of these tests in Go as well so engineers from any team should be familiar enough to debug on their own. When someone makes a pull request to the repository, <a href="https://docs.github.com/en/actions">GitHub Actions</a> run these validations and we also use a <a href="https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-code-owners">CODEOWNERS</a> file to ensure teams are involved when their settings change. When a pull request is merged to the main branch, more GitHub Actions run which create a GitHub Release with the YAML settings files merged together and translated to JSON as an artifact (I used the <a href="https://github.com/itchyny/gojq">gojq</a> command line tool to achieve this). The latest GitHub Release represents the current desired state of the settings for the system.</p><h4>Terraform Module</h4><p>In order for the Flexera One Automation engine to make calls to external APIs, such as those of cloud providers in order to find and possibly delete waste resources, it needs to use <a href="https://docs.flexera.com/flexera/EN/Automation/CredentialsIntro.htm">Credentials</a> which represent the method of authentication to the API. For example, on AWS you would create an IAM role which has an assume role policy which trusts the Flexera One platform and then you would enter the ARN of the role to create a Flexera One Credential.</p><p>Setting up these roles and the associated permissions that they require in order for the Automation templates to work is going to get very repetitive fairly quickly given teams will have multiple accounts for each of their projects (staging, production in both US and EU zones, etc.), so I needed to come up with an automated solution. Fortunately, our teams were already using <a href="https://www.terraform.io/">Terraform</a> to manage infrastructure as code as part of our DevOps practice and it already had support for the roles and permissions setup for the cloud providers we use. So I put together a <a href="https://www.terraform.io/docs/language/modules/index.html">Terraform module</a> that allows teams to set up all of the necessary roles and permissions by importing it into the Terraform they are already using to manage their cloud accounts.</p><p>However, there was still one problem: teams would still need to take outputs from the Terraform module like the role ARNs on AWS and use them to create Flexera One Credentials manually. I didn’t want to only have a partially automated solution with an error prone data entry step as part of the first impression for teams onboarding to the system, so I set out to solve the problem.</p><p>Flexera One is an API first platform so all of the <a href="https://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> operations on Credentials you can perform in the user interface are actually performed through the Flexera One API. We write the microservices in <a href="https://golang.org/">Go</a> using the <a href="https://goa.design/">Goa</a> framework which has the nice side effect of generating an API client library as Go packages for each API we design. Coincidently, Terraform is also written in Go and has a <a href="https://github.com/hashicorp/terraform-plugin-sdk">Terraform Plugin SDK</a> that allows you to extend its functionality by creating a <a href="https://learn.hashicorp.com/collections/terraform/providers">Custom Provider</a>. Combining the Goa client library for the Flexera One Credentials API and the Terraform Plugin SDK, I was able to put together the flexeracredentials Terraform provider plugin in about a week.</p><p>Now that I had the Terraform provider plugin, the Terraform module could both create the necessary roles and permissions on the cloud provider side and create the Flexera One Credentials to use them. Here is an example of how the module sets up an IAM role with the permissions needed for the <a href="https://github.com/flexera/policy_templates/tree/master/cost/aws/unused_volumes">AWS Unused Volumes</a> Automation template and hooks it up to a Flexera One Credential:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55aa5db8900731dfde0976b2bcab4a17/href">https://medium.com/media/55aa5db8900731dfde0976b2bcab4a17/href</a></iframe><h4>Automation Template</h4><p>Of course, there needs to be something that ties the settings, Flexera Credentials, and possibly some other components together in order to actually have a system and that is the “FinOps Policies” Automation Template (previously the “FinOps Policies” Policy Template). The <a href="https://docs.flexera.com/flexera/EN/Automation/PTL.htm">Automation/Policy Template Language</a> is a declarative language with some imperative languages mixed in for good measure with an execution model where data sources are collected, a check is performed to determine if an incident needs to be raised, and actions are performed in response to changes in incident state.</p><p>The data sources in an Automation template are usually either definitions for <a href="https://docs.flexera.com/flexera/EN/Automation/RetrieveData.htm#automationrefinfo_2830531361_1127421">retrieving API data</a> or <a href="https://docs.flexera.com/flexera/EN/Automation/ProcessingDataJS.htm">executing JavaScript</a> to manipulate and transform data. These are some of the things the “FinOps Policies” template does with data sources:</p><ul><li>It uses the <a href="https://docs.github.com/en/rest">GitHub REST API</a> to fetch the latest settings release artifact from the internal repository as well as data about all the cloud accounts and which teams own them. That other data comes from another Git repository that our Cloud Enablement team was already maintaining.</li><li>It uses the <a href="https://docs.flexera.com/flexera/EN/FlexeraAPI/GetStartedAPI.htm">Flexera One API</a> to get the current status of Credentials, applied Automation templates, and their incidents.</li><li>It uses the <a href="https://docs.influxdata.com/influxdb/cloud/reference/api/">InfluxDB API</a> to determine when it last wrote metrics so it can narrow down the list of Automation incidents above to only those that are still relevant.</li><li>It uses multiple JavaScript script data sources to weave all the other data sources together and prepare the data to be meaningful for the checks and incident actions.</li></ul><p>One place where I had to look around for a solution that fit was how and where to store the metrics. Ultimately, I decided to use <a href="https://www.influxdata.com/products/influxdb-cloud/">InfluxDB Cloud</a> since it has a push model that makes it compatible with how Automation templates work, it is a managed and elastic so my team doesn’t need to deal extra maintenance, and it provides a rich tool for exploring and manipulating its time series data in its <a href="https://www.influxdata.com/products/flux/">Flux query language</a>.</p><p>Something you need to keep in mind while writing Automation templates is the <a href="https://docs.flexera.com/flexera/EN/Automation/CWL.htm">Cloud Workflow Language</a> execution system is somewhat of a legacy component and does not have the same performance characteristics as other parts of the Automation system, so it is often good to do some of the processing you might have done in the action phase up front in a JavaScript data source instead. An example where I did this is the construction of the <a href="https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/">InfluxDB line protocol</a> body that will need to be posted later to write metrics. The system has a number of metrics to keep track of so I wrote a JavaScript function which uses the <a href="https://underscorejs.org/">Underscore</a> library to build up the body:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1feac7d45db3582a5236ad2f51de4a8/href">https://medium.com/media/e1feac7d45db3582a5236ad2f51de4a8/href</a></iframe><p>After the data sources are evaluated the Automation performs checks to determine if it needs to raise or resolve incidents. These are some of the checks the “FinOps Policies” template does:</p><ul><li>It checks if there are any errors which would prevent applying Automation templates for any of the cloud accounts belonging to teams that have opted in via settings. These errors are usually Credentials that have not been set up yet, but they can also be missing metadata in the list of cloud accounts from the metadata GitHub repository. Either way the team that owns the cloud account or accounts in question should probably be notified about the errors so they can get them fixed.</li><li>It checks if there are any applied Automation templates that need to be created, updated, or deleted in the cloud accounts. These kinds of changes can come from multiple types of changes including: a new team opting in via the settings, an existing team updating their settings, a new version of one of the Automation becoming available, or a new cloud account belonging to one of the teams being created. If an incident is raised for this check, it triggers an action but does not notify since that might drive us crazy.</li><li>It checks if there are any applied Automation templates or associated Incidents with errors.</li><li>It checks if there are any metrics to write. This always raises an incident since there are always metrics to write and again does not notify.</li></ul><p>Each check in an Automation template can have any number of actions which can either be Cloud Workflow actions or email actions. For the applied Automation template CRUD and metrics to write incidents, there are Cloud Workflow actions that make the required Flexera One or InfluxDB API calls to perform their actions. The others send their notification emails to a Microsoft Teams channel the FinOps team monitors, but each team’s settings also include a notification.microsoft_teams_webhooks_urls list as well since the Automation template does not have a way to specifically send a subset of the incident details to the affected team’s email address.</p><p>I solved this by using Cloud Workflow to determine which teams need to be notified about particular items and grouping them together into a <a href="https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference">Microsoft Teams notification Card</a> it can post to the webhook URL since Cloud Workflow does not currently have any email functionality. The other Cloud Workflow actions can also run into errors, so I also used the webhook functionality to notify the FinOps team about those in all of them. While building this functionality I noticed only 10 Card “sections” actually show up in Teams when there when there are more posted and also the notification would not even show up if it were lots more. To work around this limitation, I added functionality to truncate the Card “sections” down to 9 if there were more than 10 and then add a tenth card which indicates more details can be found in the Automation template incident in Flexera One. Here are the Cloud Workflow Definitions that implement the Microsoft Teams notification and error reporting functionality:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/384364ee0132360d7575421be9c7afda/href">https://medium.com/media/384364ee0132360d7575421be9c7afda/href</a></iframe><h4>Grafana Metrics</h4><p>One similarity between the practices of DevOps and FinOps is the importance of visibility into metrics. Within Flexera, all of our DevOps teams are already using <a href="https://grafana.com/grafana/">Grafana</a> to visualize the metrics coming out of their microservices and we already have a process in place for authenticating to Grafana through our identity provider. Grafana also supports a wide range of backends including InfluxDB, so it was an easy choice for visualizing all of the metrics the “FinOps Policies” system will be writing.</p><p>When building Grafana dashboards for the system, I focused on a few types of users:</p><ol><li>FinOps team members: my manager and I care about how the system is working, how well it is working for teams, which teams we should reach out and start onboarding next, and which teams might need some help.</li><li>Managers and executives: they care about hitting their budgets and knowing which of their teams might need to prioritize cleaning up cloud waste costs.</li><li>Individual team members: engineers care about how their own team’s infrastructure is doing with regard to costs.</li></ol><p>Here are what a few of the panels from our “FinOps Policies” Grafana dashboards look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*-IIReLv1n6_YyuIXLy95Ww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*6oYfB8u1VmvWalheINI97A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*6IFprH3W-IGd3NNGhZhqDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*DQ20OYzCvh0377An0EoeAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*NBcCoJoa_KHZY-gm1HemjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*4d_6ycm-4R3g9yD5eGpdLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*MPdeHnCyFD_brzwfZcb-sQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*9BKEzdbS8E8sUqb49ymhjg.png" /></figure><p>You may have noticed we have metrics for estimated potential savings from triggered incidents and estimated savings from resolved incidents. These are the amounts of money that would be spent each for the cloud resources the Automation templates have discovered if they are not eliminated, or the not spent if they are eliminated.</p><p>We are able to get this information because all of the <a href="https://docs.flexera.com/flexera/EN/Automation/CostPolicies.htm">Cost Policies</a> (Automation templates) the “FinOps Policies” Automation template applies includes resource level estimated cost information in a standardized format within the incident data available through the Flexera One API. Some of the Automation templates, such as <a href="https://github.com/flexera/policy_templates/tree/master/cost/aws/unused_volumes">AWS Unused Volumes</a> and <a href="https://github.com/flexera/policy_templates/tree/master/cost/aws/old_snapshots">AWS Old Snapshots</a>, use the Flexera One Cloud Cost Optimization (formerly Optima) API to calculate these estimates based on recent data from our cloud bills while others use cloud pricing APIs since that data is not easily available otherwise (this is something I worked with the team that owns the Cost Automation templates to implement). For example, the <a href="https://github.com/flexera/policy_templates/tree/master/cost/aws/unused_ip_addresses">AWS Unused IP Addresses</a> Automation template uses the <a href="https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/using-ppslong.html">AWS Price List API</a> to find the hourly cost for unallocated Elastic IP addresses to calculate its estimates.</p><p>For the estimated savings from resolved incidents, the Automation template takes the cost estimate from the incident at the time it is resolved and records it as a savings event. While there are some caveats to this method such as it missing cleanup that may occur outside of resolving an incident, it at least provides a conservative estimate of the realized savings from using the Automation templates to find and eliminate cloud waste.</p><h3>Conclusion</h3><p>The “FinOps Policies” system is now running with a few Cost Automation templates and has a number of engineering teams within Flexera using it. However, there are still more engineering teams that have not started using it and more Cost Automation templates that would make sense for us to apply (or we may even write some new ones), so this is still an ongoing project and I imagine I will need to improve it. This parallels the <a href="https://www.finops.org/framework/lifecycle/">FinOps Lifecycle</a> where a company continuously moves through phases a journey in order to constantly improve.</p><p>Also, I’m finding some of the things I’ve learned in building the system are applicable to other projects. For example, while working on building metrics for <em>Unit Economics</em> where we were pulling metrics from a different system, it made sense to use InfluxDB to aggregate those metrics so we could use Flux query language to look at them a monthly or quarterly scale.</p><p>Finally, by using the Flexera One platform to solve the problems we need to on the FinOps team, we are not only proving it out and finding bugs, but we are also building what could be considered prototypes of potential features that might make sense to add to Flexera One in the future so we can provide the same benefits to our customers as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc21659cb594" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flexera-engineering/using-flexera-one-automation-for-finops-at-flexera-dc21659cb594">Using Flexera One Automation for FinOps at Flexera</a> was originally published in <a href="https://medium.com/flexera-engineering">Flexera Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dealing with Chaos]]></title>
            <link>https://medium.com/flexera-engineering/dealing-with-chaos-2d4c23eed656?source=rss----5dc7b2707540---4</link>
            <guid isPermaLink="false">https://medium.com/p/2d4c23eed656</guid>
            <category><![CDATA[c4-model]]></category>
            <category><![CDATA[software-entropy]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[enterprise-software]]></category>
            <dc:creator><![CDATA[Victor Dramba]]></dc:creator>
            <pubDate>Wed, 26 May 2021 21:26:45 GMT</pubDate>
            <atom:updated>2021-05-28T20:01:27.672Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yQhdyu8yQkwiMeW5E3Bv9Q.png" /><figcaption>A C4 Architecture Diagram</figcaption></figure><p>So you finally got to it, you kept your weekend schedule clear, woke up early and did that thing you have been putting off for too much time — dealing with the mess in your room. Look at it, it’s in perfect order now, wall to wall. Everything is in the right place, sorted by access frequency, organized to please the eye and your visual memory. Even a guest would find things here, it’s perfection.</p><p>If only there was a way to make it last. For some reason, the tech debt of your room keeps piling up with time. And that happens with only one person interacting with the room. Imagine if there were a few teams constantly adding and moving stuff. Things would go downhill fast.</p><p>Welcome to large software development. My analogy, inspired by the way entropy is sometimes explained, might look funny, but it’s not far from reality. Sure, instead of a room you might have a large hall for a monolithic design, or, at the other end of the spectrum, a group of buildings each with apartments, each with rooms. You get the idea.</p><p>At Flexera, adopting a <a href="https://en.wikipedia.org/wiki/Microservices">microservices architecture</a> with multiple levels of modularity places us in the later group. While the architecture pattern helps, it doesn’t solve the problem by itself. Keeping things in order is a challenge, the bigger the system, the harder it is.</p><p>I remember, some years ago, in a different context, I had to add a little feature to an old application. Connecting to the database was part of it. There were several popular database adapters for that language. I looked around in the code to see which one they use, so I could follow the same pattern. I found them all and some custom inventions to boot in that single codebase.</p><p>Smart people are smart, but each in her own particular way. No amount of documentation, training or enterprise process can solve this problem completely. We had to come up with a better solution. We have teams distributed around the globe, each with its own domain knowledge, developing an ever-growing number of microservices organized in components connected via clean domain-centric APIs. Or at least that’s the big plan. We constantly face this entropy force, melting the architecture into an amorphous, highly connected graph.</p><p>Our solution is a set of tools, automation and associated practices:</p><ul><li><strong>Design First</strong> — define APIs using a ubiquitous DSL which makes it easy to list all API specs in one place</li><li><strong>Diagrams as Code</strong> — author C4 architecture diagrams in a DSL that links back to the source code</li><li><strong>Static code analysis via “Chaos”</strong> — check the code against the architecture and best practices</li><li><strong>Service Map</strong> — a unified portal for accessing API specs, documentation, architecture and Chaos quality score</li></ul><h3>Design First</h3><p>APIs are central to developing a microservices architecture. When we add a new microservice, after the abstract intent of the service is defined, we start with the design of the API. This is where the interface with the rest of the system is defined as well as the main constructs that the service exposes together with their semantic. We use <a href="https://github.com/goadesign/goa">Goa</a>, a framework that allows expressing the API in a simple <a href="https://en.wikipedia.org/wiki/Domain-specific_language">DSL</a> and generates specialized service helper code, client code and documentation. For APIs that cross the team boundary, approval is requested from the consumer side. For external APIs, there’s even more scrutiny. There’s a dedicated team that reviews them to ensure they are consistent with the rest of the Flexera public APIs.</p><h3>Diagrams as Code</h3><p>Documenting a distributed architecture is not an easy task. After several iterations, we settled on using <a href="https://c4model.com/">C4</a> as the common visual language. The C4 model helps teams to efficiently and effectively communicate their software architecture at different levels of detail, like zooming in and out in Google Maps. Another important choice we made is to author the diagrams in code, by using a DSL. This way we can not only collaborate and track changes, but we have tools that automatically check if implementation and diagrams are in sync. This diagram authoring solution grew quite a bit, and we decided to open-source it as part of the goadesign project. We wanted to have it all in code, but it turns out no automatic layout is good enough for complex graphs. Therefore, I felt the need to contribute a brand new <a href="https://github.com/goadesign/model/tree/master/cmd/mdl/webapp">graphical editor</a> that allows for a clean, meaningful visual layout. The full C4 authoring solution is now <a href="https://github.com/goadesign/model">open-source</a>. The final diagrams are uploaded to the Service Map website, and the full model is provided to Chaos as JSON so that it can be compared with the implementation.</p><h3>Chaos</h3><p>By now, you probably get the irony. The tool that fights disorder is called Chaos. It’s Code Health Adviser Open Service, but no one cares anymore. The important part here is that the tool is developed as an internal open-source project so devs can study the code and contribute. But let’s dive in. The core of the tool is an executable which runs in the CI/CD stage once all tests have passed and does the following:</p><ul><li>collects API specs and documentation from Goa DSL</li><li>collects README files for microservices and modules</li><li>parses and checks the code against a list of validation criteria including:<br>- microservices code should not import code from other microservices<br>- code should check the health of other services that are consumed<br>- microservices should use authentication for all APIs<br>- repository layouts should follow agreed upon directory/package scheme</li><li>parses and checks the code against the architecture model, and validates that:<br>- a diagram representing this code repository exists<br>- all microservices are represented in the diagram and vice-versa<br>- relationships between microservices are correctly represented (best-effort at this point)</li><li>checks that README files exist for the repository and for each microservice</li></ul><h3>Service Map</h3><p>Service Map is the internal website aggregating all of the above. There are 3 main sections: architecture, APIs and Chaos.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pbpZu8RBcrkUi5UI7FYKVg.png" /><figcaption>API Browsing section in Service Map</figcaption></figure><h3>Architecture</h3><p>You can browse the entire architecture, starting from an overview - the System Landscape in C4 terms - and you can zoom in to see the composition of each module, represented as Software Systems in C4 language. The website supports deep linking so you can share views in various channels. Diagrams contain metadata that link elements to code and makes it possible to navigate from diagrams to the API specs, documentation, Chaos reports or directly to source code.</p><h3>API Browser</h3><p>One of the important plugins of Goa is <a href="https://github.com/goadesign/plugins/tree/v3/docs">docs</a>. It generates a transport agnostic view of the API specification allowing you to focus on the business logic and modeling. That’s the first tab in the API browsing section. Next, you can see transport specific spec (OpenAPI, gRPC proto) and Readme files. You can also quickly see the composition of the team that owns each microservice or module.</p><h3>Chaos Results</h3><p>This section displays reports for each microservice, with extensive details: what has been detected, why we think it’s not the best and how to fix it. There’s also a link to the code that generated that particular notice, and an invitation to contribute. A score is computed for each microservice, and it’s summed up for the module. The lower the score, the better. When the score is zero, you get a green check mark, and you can brag about it.</p><h3>Unexpected benefits</h3><p>Chaos solves the problems it was designed for pretty well, but sometimes, it goes even further.</p><p>In one instance, scanning a git repository for microservices, it identified that a certain executable (main go package) was a microservice. The team owning the repository pushed back saying it’s just a tool run as a daily cron job. This triggered a debate on what defines a microservice. The conclusion was that such a daemon should be considered one and should thus it should follow best practice.</p><p>In another surprising find, Chaos detected a subtle, hard to spot code dependency that had the potential to blow things up at the worst time. The import was channeled through a goa DSL <a href="https://pkg.go.dev/goa.design/goa/dsl#ConvertTo">feature</a> that makes it possible to map user types with generated types. While the feature has its place for some use cases, it creates a coupling between the generated API client and the service implementation. It again prompted for a debate, and we decided it’s best to avoid the feature for our microservices.</p><p>These are just a couple of many other unexpected useful results.</p><h3>To conclude…</h3><p>Though our entropy defeating strategy might seem complex, and it’s not really fail-proof, it turned out to be the right investment. We introduced this system gradually, starting with pilot programs followed by several rounds of fixes and validation. By the time passing the checks become part of the requirements, teams are already using the tools, and the added value speaks for itself.</p><p>Traditional monolithic applications counter entropy by involving frameworks, SQL data modeling and domain partitioning mostly done via naming conventions. It’s rare to see a clear modular architecture in such context. A microservices architecture is modular by design, so we get some level of order by default. But as the system grows, the distance between the size of a microservice and the size of the whole system becomes too big. To fill this gap and successfully maintain large, enterprise software on the long run, an integrated and automated solution is not optional.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*o_0Bukj4pFkJnUjueIojfw.png" /><figcaption>Service Map System Diagram</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d4c23eed656" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flexera-engineering/dealing-with-chaos-2d4c23eed656">Dealing with Chaos</a> was originally published in <a href="https://medium.com/flexera-engineering">Flexera Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Organizing a large front-end project]]></title>
            <link>https://medium.com/flexera-engineering/organizing-a-large-front-end-project-316ad6fe2bc6?source=rss----5dc7b2707540---4</link>
            <guid isPermaLink="false">https://medium.com/p/316ad6fe2bc6</guid>
            <category><![CDATA[yarn-workspace]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[André Rieussec]]></dc:creator>
            <pubDate>Tue, 11 May 2021 16:10:42 GMT</pubDate>
            <atom:updated>2021-05-11T16:10:42.807Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6vzXNaaIjgufysKkyPdypA.jpeg" /><figcaption>A good tree organization can grow for many years and remain healthy</figcaption></figure><p>Project organization is like a computer network: when done right, it gets out of the way and nobody notices it. But when done wrong, everyone suffers. If you’ve had the unfortunate experience of working on a poorly organized project, you’ll understand what I’m talking about. When you feel like you’re spending more time fighting with the environment than getting work done, it’s demoralizing and counter productive.</p><p>In this post, I’ll focus on the low level aspect of organization: where should the code go? How should I break down my files and folders? I intend to go into more details in follow-up posts but I felt this was a good place to start because it really influences everything else such as developer environment, testing and deployment.</p><p>The project I’ll be discussing is a large React application with a healthy dose of legacy Angular code. But this post will directly apply to any project that can use the <a href="https://yarnpkg.com/">Yarn package manager</a> and might also prove useful if you use a different technology altogether.</p><p>When the word came that Flexera’s suite of SaaS applications needed to be combined into the single, unified front-end that would become Flexera One, I knew it was just the beginning. The already large project would keep growing over time. It was a good opportunity to lay a foundation that would support the team for years to come.</p><p>I had the following goals in mind:</p><ul><li>Facilitate onboarding of new team members</li><li>Make it easy for a large team to work on the project at the same time</li><li>Support an efficient, low-overhead, release process</li><li>Encourage good practices.</li></ul><p>Before detailing the solution that achieved those goals for us, let’s take a look at some other options and why they weren’t chosen.</p><h3>Option 1: Monolithic front-end</h3><p>The most straightforward way to go would be to use a tool like create-react-app and start one big project with a single node package. This was non-starter for us because we already had several projects using different frameworks (AngularJS, Angular, React) and there was no upside to combining them this way.</p><p>I also wanted to ensure that our code was modular with clear boundaries so the more generic parts could be treated as libraries and potentially used outside of the main application. Putting everything in one package would have prevented this.</p><h3>Option 2: Many packages published to a registry</h3><p>On the other end of the spectrum, we could break everything into many small repositories, one per package, and publish everything to a registry such as <a href="https://www.npmjs.com/">npm</a>. The application would reference all those libraries using a package.json file.</p><p>This has the advantage of clearly separating the code into isolated modules that can be tested and updated independently. At first sight, this is an attractive option but the flaws to this approach become apparent very quickly.</p><p>First, the more you break things into small modules, the more modules you have to work on at the same time. This is especially true at the beginning of a project when everything needs to be built. However, there is no efficient way to work on several interdependent repositories and npm modules. Tools like npm link and yarn link can help in local development but will quickly give you headaches because dependencies remain local to the linked packages. This is fine for Node projects, not so much when you use a bundler for front-end.</p><p>Then releasing becomes a nightmare: you need to cut and release a new version of each package, following your dependency tree from leaves to trunk. This is huge overhead if you’re alone, with a team it’s simply unmaintainable.</p><h3>Option 3: The micro front-end</h3><p>This has been a bit of a buzzword in recent years, although as usual in the front-end world, there is no explicit standard. In general, a micro front-end architecture aims to facilitate the organization of very large projects by breaking them down along team lines. One team works on the core infrastructure while other teams each work on what are essentially separate applications, with their own release schedule and sometimes different tech stacks. The full application is composed at runtime from those various parts.</p><p>While some companies have been successful with this approach, I find that it has significant drawbacks that are worth considering before you commit to a micro frontend solution.</p><ul><li>There is a lot of upfront work: you need to set up your infrastructure first and build your core framework before you can really start building apps. While each app is independently released, you need to establish a common release standard that everyone adheres to in order for their new code to be found and loaded.</li><li>It’s not the same as micro-services for the UI. Micro-services are independent units that run in isolation and communicate over a network. They essentially deal in trading data and performing actions. Your front-end is meant to connect your users to your overall system through the web browser’s window, so your different micro-UIs will share real estate in that window without any kind of isolation. You could achieve some isolation if you decided to use iframes and postMessage but it’s a bit masochistic and everything still runs on the user’s device. The benefits of micro-services simply do not apply to the front-end runtime.</li><li>While allowing each app to support a different tech stack will make your developers happy and let you experiment more easily with future tech, it also means you either provide a framework-agnostic UI components library or settle for a fragmented user experience. And getting different frameworks to play well together is not easy nor fun.</li></ul><p>In our case, we have a single UI team responsible for everyone’s front-end. So breaking things into a micro-frontend would have represented a large and unnecessary overhead.</p><h3>Monorepo to the rescue</h3><p>Now that we examined what didn’t work, let’s take a look at what did work for us: the monorepo.</p><p>If you haven’t heard of a monorepo before, the idea is to have all of the code in a single repository. So this takes us back to the first option of a monolithic front-end right? Well, not exactly, because we still break things down into packages to enforce a modular architecture. So it’s a mix of Options 1 and 2 then? Again, not exactly, because when using a single repository, we can start taking advantage of <a href="https://classic.yarnpkg.com/en/docs/workspaces/">Yarn’s workspaces functionality</a>. And that’s really the key to success here.</p><p>Workspaces solve the problem of local package dependencies by making all local and most 3rd party packages available through a node_modules folder at the root of your main package. This makes it easy for a bundler to reference all files used to build a project while avoiding duplication.</p><p>There is plenty of information out there on how to use yarn workspaces so I won’t go too deep here. Our setup is to have a package.json file at the repo root with the following configuration for yarn:</p><pre>&quot;workspaces&quot;: [<br>  &quot;packages/*/*&quot;,<br>],</pre><p>This implements a two-level folder structure in the form of: packages/&lt;category&gt;/&lt;package&gt; which allows us to group multiple packages by function.</p><p>So how does this setup accomplishes the goals I outlined at the beginning of this post?</p><h4>Facilitate onboarding of new team members</h4><p>Having a single repository greatly helps here. When a new team member joins, they clone one single repository and are ready to work on any part of our front-end. The organization into packages allows them to more easily find what they’re looking for.</p><h4>Make it easy for a large team to work on the project at the same time</h4><p>With the whole team pushing code into one single repository, one might expect a high frequency of merge conflicts. In practice, the breakdown into packages helps mitigate this because developers tend to own and update different areas of the code.</p><p>On the other hand, each change, no matter how large, only results in one pull request, there is very low friction. Furthermore, anyone on the team can review the changes because each package follows a standard pattern. It’s easy to spot changes that could affect other parts of the app.</p><h4>Support an efficient, low-overhead, release process</h4><p>Integrating the monorepo with a CI solution makes releases really easy: whenever we’re ready to push a new version, we simply merge a pull request from our development branch into our release branch. The new commits to the release branch trigger a build job which automatically deploys all of our front-end to our CDN.</p><p>CI is also used to run our test suites on our feature and development branches, so before a release we have a high level of confidence that everything will be good.</p><h4>Encourage good practices</h4><p>Technical debt is a real problem and the risk increases with the number of developers on a team. This is where yarn workspaces become really useful: there is virtually no overhead to creating a large number of packages in a monorepo. What this means is you can really push your team to break things up into a highly modular design where each module follows the single responsibility principle.</p><p>It still requires discipline from the team, but by using many small and single purpose packages, you improve code navigation and reusability. Those small packages are also easier and faster to test in isolation.</p><h3>In conclusion…</h3><p>Keep in mind that things evolve and you’re unlikely to have the perfect setup from the start. Sometimes you are constrained by an existing code base, sometimes priorities change. So it’s important to keep an eye out for points of friction and tackle them as they appear.</p><p>For example, an issue that remains in our setup is that I’ve not found any decent tool to manage 3rd party packages across our monorepos. So we’ll be writing our own in the future.</p><p>But overall it’s proven to be a great move and in future posts I will go over some great productivity enhancements we’ve been able to build on top of our monorepo architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=316ad6fe2bc6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flexera-engineering/organizing-a-large-front-end-project-316ad6fe2bc6">Organizing a large front-end project</a> was originally published in <a href="https://medium.com/flexera-engineering">Flexera Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>