<?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[eXpSoftwareEngineering - Medium]]></title>
        <description><![CDATA[In this publication, we’ll feature writers from eXp Realty that work in the Software Engineering group. We’ll feature articles on ranging topics of software development, architecture, remote work, and much more. - Medium]]></description>
        <link>https://medium.com/expsoftwareengineering?source=rss----1dd03898132a---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>eXpSoftwareEngineering - Medium</title>
            <link>https://medium.com/expsoftwareengineering?source=rss----1dd03898132a---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 22:36:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/expsoftwareengineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Managing a Mendix Portfolio at Scale]]></title>
            <link>https://medium.com/expsoftwareengineering/managing-a-mendix-portfolio-at-scale-5065d6f1c985?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/5065d6f1c985</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[enterprise-software]]></category>
            <category><![CDATA[low-code-development]]></category>
            <category><![CDATA[governance]]></category>
            <category><![CDATA[mendix]]></category>
            <dc:creator><![CDATA[Micah McMullen]]></dc:creator>
            <pubDate>Fri, 20 Dec 2024 20:37:53 GMT</pubDate>
            <atom:updated>2024-12-20T20:37:53.500Z</atom:updated>
            <content:encoded><![CDATA[<h3>Managing a Mendix Portfolio at Scale: 4 Key Recommendations</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*wbtIA77R0LdbZKMwE3vtyw.png" /></figure><p>Managing a large Mendix portfolio can be challenging, especially as your applications, modules, and teams grow in complexity. If you’re not intentional from the start, it becomes extremely difficult to get things under control later. In this post, I’ll outline four key recommendations for managing your Mendix portfolio effectively to ensure you set yourself up for long-term success. I’ll highlight why you should care about each of these topics, share lessons from our mistakes, and provide specifics on how we’ve either turned things around or are actively fixing the sins of our past.</p><h3>1. Setting Up Governance Early</h3><h4>Why It’s Important</h4><p>Governance ensures consistency and alignment across all teams. Without it, teams will likely create their own standards, or they may not set any standards at all. While this allows teams to move quickly in the short term, it becomes a colossal nightmare to maintain as the portfolio grows. In the long term, this lack of standardization makes it difficult to scale efficiently, creating bottlenecks when trying to integrate systems or ensure quality across projects.</p><h4>Where We Went Wrong</h4><p>At eXp Realty, we didn’t always have a governance strategy in place. Early on, different teams were using different approaches for building APIs, versioning releases, and even managing branching strategies. While this worked for each team, it quickly became unsustainable. Inconsistent approaches led to integration problems, increased technical debt, and complicated collaboration across teams.</p><p>We also went through several iterations of our governance group, but until we intentionally and thoroughly started to document things as <strong>“</strong>decisions<strong>”</strong> and <strong>“</strong>guidance<strong>,”</strong> we really struggled to create an effective system. Without clear documentation, it was difficult for teams to follow or even understand what standards they were expected to adhere to.</p><h4>What We’ve Learned</h4><p>To overcome these challenges, we implemented a structured governance approach. We established standards for key areas like:</p><ul><li><strong>API Strategy</strong>: Including authentication protocols and consistent URI construction.</li><li><strong>Release Versioning</strong>: Clear guidelines on what constitutes a major, minor, or patch release.</li><li><strong>Branching Strategy</strong>: Moving to a unified mainline development approach, with strict use of feature branches and release branches.</li></ul><p>This structure helped bring consistency and clarity, allowing us to scale more effectively and reduce the friction between teams.</p><h3>2. Keeping Your Ecosystem Secure</h3><h4>Why It’s Important</h4><p>Security becomes more critical as your Mendix portfolio scales. Without a strong approach to security, your organization becomes vulnerable to breaches, data loss, and compliance risks. Addressing vulnerabilities as soon as they are found is essential. Even minor oversights can become major problems in a large, interconnected system.</p><h4>Where We Went Wrong</h4><p>Early on at eXp Realty, we had a solid focus on security, but our approach wasn’t always as proactive as it could have been. With a growing portfolio, it became harder to keep track of vulnerabilities and prioritize remediation effectively. While we always responded to major risks, the lack of a formalized process for reviewing and addressing all vulnerabilities sometimes led to delays in less critical areas.</p><h4>What We’ve Learned</h4><p>We’ve since developed a more structured approach to security, ensuring that vulnerabilities are addressed quickly and efficiently. A few key lessons include:</p><ul><li><strong>Siemens Security Advisories</strong>: We now subscribe to Siemens’ security advisories, which are published on the second Tuesday of each month. A small team reviews the report shortly after it’s published and documents our findings internally. Even if there’s nothing to remediate for that month, we still publish an internal report showing our due diligence in the matter. You can subscribe <a href="https://www.siemens.com/global/en/products/services/cert.html">here</a>.</li><li><strong>Mendix’s Software Composition Tool</strong>: Our remediation efforts significantly improved once we started leveraging the Mendix <a href="https://docs.mendix.com/control-center/software-composition/">Software Composition tool</a>. We can quickly see which versions of which components are in our applications. This analysis can be done in just a few minutes, rather than the countless man hours it took previously. In my opinion, this is one of the best products Mendix has released in years.</li><li><strong>Clear Remediation Timelines</strong>: Not all vulnerabilities carry the same level of risk, so we’ve established a process to prioritize and assign timelines for remediation based on severity. These timelines are clearly documented and communicated to our teams and stakeholders to ensure alignment.</li></ul><p>By establishing these practices, we’ve greatly improved the security of our ecosystem and reduced the risk of unpatched vulnerabilities affecting our applications.</p><h3>3. Having a Platform Upgrade Strategy</h3><h4>Why It’s Important</h4><p>Mendix follows a regular release cadence, typically releasing a new version every month. Without a clear upgrade strategy, you risk falling behind, which can introduce security vulnerabilities, compatibility issues, and technical debt that’s difficult to resolve later. Additionally, if you don’t keep up with upgrades, you could risk falling out of support from Mendix themselves, which can put your organization in a vulnerable position. Mendix provides helpful documentation on their <a href="https://docs.mendix.com/releasenotes/studio-pro/lts-mts/">LTS and MTS support cycles</a>.</p><h4>Where We Went Wrong</h4><p>At eXp Realty, we didn’t always prioritize having a defined upgrade strategy, and we’ve found ourselves in heaps of trouble because of it. Many of our applications were stuck on a major version that was nearing end-of-support, forcing us to scramble to upgrade them in time. This created unnecessary pressure on our teams, and without a formal process for selecting patch versions, we sometimes introduced new issues when adopting the latest releases too quickly.</p><p>To make matters worse, we’ve had projects easily running on 20+ different versions of Studio Pro at a time. Not only is this wildly annoying, but it’s also incredibly cumbersome for development and module maintenance.</p><h4>What We’ve Learned</h4><p>Not having an upgrade strategy is simply a bad idea, and over time, we’ve made huge improvements in this area. Most of our applications are now on the same LTS minor version, but even with that, we realized there still wasn’t full consistency. This led us to introduce a more defined upgrade strategy to ensure uniformity across the board.</p><p>We recently rolled out a quarterly upgrade cycle, where we update all applications to a patch version of either MTS or LTS after it has been in the wild for several weeks. This approach is new, but we’re confident it’s the right path forward for us. We hit full compliance with this strategy with our last release of this year, and it’s already helping us stay current and avoid unexpected disruptions.</p><h3>4. Managing Components (Internal &amp; External)</h3><h4>Why It’s Important</h4><p>As your Mendix portfolio grows, so does the complexity of managing both internal and external components. External components, especially from the Mendix Marketplace, can introduce risks around quality, security, and maintainability. Without a strategy, you could end up adopting modules that are not supported or maintained, leading to potential vulnerabilities or compatibility issues.</p><p>On the internal side, as teams build and share their own components, the risk of redundancy and misalignment increases. Without proper governance, teams may create duplicate components, or worse, diverge from best practices, making it harder to maintain consistency across projects. Having a clear strategy for managing both internal and external components is essential for scaling efficiently and minimizing technical debt.</p><h4>Where We Went Wrong</h4><p>We initially didn’t have a formal process for managing external components from the Mendix Marketplace. While the marketplace offers a wide range of modules, we found ourselves adopting some that lacked proper support or maintenance. This created challenges when issues arose, as we had no guarantee that the module authors would provide timely fixes or updates. Over time, this posed risks to our application stability and security.</p><p>On the internal side, the lack of governance over shared components led to redundant work and inconsistencies across teams. Different teams built their own versions of the same or similar functionality, resulting in duplication and fragmentation. Often, there was little to no documentation for these modules, leaving us scratching our heads about why something had even been uploaded to our private marketplace and which applications it was being used in (this was before the Software Composition tool existed).</p><h4>What We’ve Learned</h4><p>We’ve since established a clear process for managing both internal and external components, ensuring consistency and reducing risk across our Mendix portfolio.</p><p>For external components, we generally rely on Platform-supported modules authored by Mendix, as they are more likely to be maintained and patched regularly. Even when we do adopt platform-supported modules, for example <a href="https://marketplace.mendix.com/link/component/170">Community Commons</a> and the <a href="https://marketplace.mendix.com/link/component/1011">Encryption Module</a>, we make sure to stay on top of updates and use the Software Composition tool to track which versions of external modules are in use. This tool has become indispensable in helping us quickly identify potential vulnerabilities and maintain compatibility.</p><p>For internal components, we’ve centralized control using the Private Marketplace. We created a Module Stewardship group (which we’re considering renaming to Marketplace Stewardship group) that reviews all content uploads and updates. This group ensures that each component has proper internal documentation, release notes, and assigned owners. For maintainability, most of our modules are kept within a single project, but for larger components, like our custom Kafka module, we maintain dedicated projects.</p><h3>Conclusion</h3><p>Scaling a Mendix portfolio isn’t without its challenges, but by establishing strong governance, maintaining security, keeping up with platform upgrades, and managing components wisely, you can ensure your portfolio stays robust, secure, and maintainable over the long haul. The earlier you put these strategies in place, the easier it is to scale smoothly. Keep learning, keep adapting, and don’t be afraid to change course as you learn from your past experiences and mistakes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5065d6f1c985" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/managing-a-mendix-portfolio-at-scale-5065d6f1c985">Managing a Mendix Portfolio at Scale</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why we use Ruby on Rails and (probably) why you should too]]></title>
            <link>https://medium.com/expsoftwareengineering/why-we-use-ruby-on-rails-and-probably-why-you-should-too-59e47460c6d1?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/59e47460c6d1</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ruby-on-rails-development]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Michal Korzawski]]></dc:creator>
            <pubDate>Thu, 17 Oct 2024 14:00:19 GMT</pubDate>
            <atom:updated>2024-10-17T14:00:19.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qk45yICG8TBfym2WGT-hSw.png" /></figure><p>Let’s get one thing straight. Ruby on Rails might not be the best choice if you’re dealing with Google or Facebook-sized applications. However, if your challenges fall within the small to GitHub-scale range, Rails will serve you just fine.</p><p>My team at eXp-Realty initially had just two developers. Despite that, a small team of two managed to create and actively maintain around <strong>ten</strong> projects. Fast forward to today — we’ve grown to six developers. Over time, the projects we maintain have also grown, and while some were abandoned, new ones were also built. We continue to deliver value for stakeholders at break-neck speeds, addressing pain points effectively, and helping the business grow. Simultaneously, we’re constantly refactoring and upgrading our apps to minimize technical debt and stay on the cutting edge.</p><p>How are we able to do this? The answer is <strong>Ruby on Rails</strong>.</p><p>It’s 2024 — does Rails need an introduction? Created in 2004, it’s a battle-tested framework built on the Ruby language. It has matured over the years to become the go-to tool for many developers and industries worldwide. It’s a startup’s Swiss-army knife.</p><p>But what makes it so effective and capable of accomplishing what we mentioned above?</p><p>Ruby is simple, a user-friendly language that is easy to understand. Even those unfamiliar with it can tell what’s happening in a method because of its human-like syntax.</p><pre># Defining strings<br>greeting = &quot;Hello&quot;<br>name = &quot;Ben&quot;<br><br># Concatenation<br>message = greeting + &quot;, &quot; + name + &quot;!&quot;<br>puts message  # Output: Hello, Ben!<br><br># Interpolation<br>message = &quot;#{greeting}, #{name}!&quot;<br>puts message  # Output: Hello, Ben!<br><br># Changing case<br>puts greeting.upcase     # Output: HELLO<br>puts name.downcase       # Output: ben<br>puts name.capitalize     # Output: Ben<br><br># Splitting the string into an array<br>array = message.split(&#39;,&#39;)<br>puts array.inspect # Output: [&quot;Hello&quot;, &quot; Ben!&quot;]</pre><p>Secondly, Ruby on Rails was created to provide an answer to a specific question: <strong>How do we quickly build a robust web application?</strong> Its inception solved that problem and resulted in a great tool for web developers. It’s impossible not to mention the community around Rails as well — all the passionate people who contribute tools, add features, write documentation, and fix bugs. Personally, it’s comforting to know that when I use Rails, hundreds of brilliant coders have worked hard to cover every edge case; they’re a continuous tide that improves the framework’s developer experience, security, and performance.</p><p>How can I not mention Ruby Gems when trying to convert more of you to the Rails religion? Gems allow you to quickly plug in code from other developers to enhance your application with pre-built features, from UI/UX to authentication and authorization. This is another reason for Rails’ uncanny ability to supercharge development speed.</p><p>Thanks to Ruby on Rails’ famous philosophy — <em>convention over configuration</em> and the ‘Rails way’ — it’s painless to jump into any existing Rails project. No matter the codebase, you know what to expect and where to find everything. The structure is consistent, its patterns prevalent. Due to <a href="https://www.codecademy.com/article/mvc">MVC</a>, finding models, checking routes, inspecting controllers is a breeze. Everything is in its place.</p><p>Recently, the Rails community has officially embraced <a href="https://www.docker.com/">Docker</a>, which makes local development and releases even easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*zhD2QzmHk1k9U0Deo20wDA.png" /><figcaption>Ruby on Rails project structure</figcaption></figure><p>You might think this means Rails is a closed ecosystem. Nothing could be further from the truth, and this point outlines another positive. It’s actually very flexible and open. You can easily incorporate different ideas and technologies — whether it’s Kafka, RabbitMQ, GraphQL, Elasticsearch, or MongoDB. All of these solutions and more are welcome. Rails makes it easy to add services like this if they’re needed to solve the problem you’re facing.</p><p>Finally, I’ll mention one last thing. Building applications with Ruby on Rails is free. While this might seem like an obvious point, it’s still worth mentioning due to the rise of expensive low/no-code alternatives. Think about how much money your company can save on this alone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59e47460c6d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/why-we-use-ruby-on-rails-and-probably-why-you-should-too-59e47460c6d1">Why we use Ruby on Rails and (probably) why you should too</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Anti-Patterns: Dead Code & Lava Flows]]></title>
            <link>https://medium.com/expsoftwareengineering/anti-patterns-dead-code-lava-flows-331af63b11cd?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/331af63b11cd</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[antipattern]]></category>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Jon Higginbotham]]></dc:creator>
            <pubDate>Tue, 01 Oct 2024 15:17:35 GMT</pubDate>
            <atom:updated>2024-10-01T15:17:35.139Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zK5x2FplT6T1kIew" /></figure><p>In this article we’ll look at the definitions and problems of two software development anti-pattern cousins; Dead Code and Lava Flows. We’ll go through their dangers if left to grow, their causes, and If you bear with me until the end, I’ll provide solutions to both.</p><p>Since my last article was about the ice cream cone anti-pattern, it’s only fitting that now I explore the other end of the temperature spectrum, not to mention the theme fits Halloween rather nicely. But first, let’s review what an anti-pattern is:</p><p><em>“An anti-pattern is a common solution to a recurring problem that is ineffective or counterproductive. It is the opposite of a best practice and often leads to software that is difficult to understand, maintain, and extend.” — </em><a href="https://www.linkedin.com/redir/redirect?url=https%3A%2F%2Fteamhub%2Ecom%2Fblog%2Funderstanding-anti-patterns-in-software-development%2F&amp;urlhash=KqGV&amp;trk=article-ssr-frontend-pulse_little-text-block"><em>Teamhub Blog</em></a></p><p>There are many anti-patterns, and eventually, I hope to write about all of them. I’ll do my best to highlight them in the context of low-code (Mendix). The patterns themselves are often universal, regardless of language or platform, though some are more specific than others. Many anti-patterns are consequences of our ways of thinking-fallacies we fall into when making decisions about how we develop solutions.</p><h3>Dead Code</h3><p>Dead code consists of parts of your codebase that are either never called or do nothing useful. Essentially, it’s anything that contributes nothing. Examples of dead code include microflows that are never invoked, variables that are never used, or pieces of logic that sit unused. One could argue (and I do) that one-time-use scripts become dead code the moment they’ve been run. Dead code is bloat; it’s codebase litter-pieces of code that someone didn’t remove, either out of ignorance or fear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*QVG08kUS3y7KSQzT" /><figcaption>Courtesy of ChatGPT</figcaption></figure><h4>Causes</h4><p>Dead code is often created by accident and rarely intentional. It’s not always code that is unreachable but may simply never be invoked due to a condition before it (e.g., feature flag or decision split). Forgetfulness, disorganized workflows, and undisciplined practices are all prime suspects. Developers might knowingly create dead code due to tight deadlines, perhaps with the intention of coming back to clean it up later-but we all know how the tech debt story goes.</p><ul><li><strong>Feature removal:</strong> When features are deprecated or removed, developers may leave related code in place.</li><li><strong>Refactoring:</strong> During code refactoring, some parts of the code may become unnecessary, but they might not be deleted immediately.</li><li><strong>Poor code management:</strong> Lack of proper code reviews and cleanup can lead to the accumulation of dead code over time.</li><li><strong>Hoarder syndrome:</strong> “ But what if we’ll need it in the future”</li></ul><p>Examples:</p><ol><li>Excluded microflows/pages that are forgotten.</li><li>Variables or parameters that have no use.</li><li>One-time-use scripts that stay forever.</li><li>Code tied to a feature flag that should be removed.</li></ol><h4>Problems</h4><p>Just like litter or a dirty bedroom, the impacts of dead code aren’t readily apparent until it grows to an overwhelming size. Ultimately, it just gets in the way of everything, creating unnecessary time sinks, confusing developers, and contributing nothing positive.</p><ul><li><strong>Increased maintenance costs:</strong> It makes the codebase more difficult to understand and maintain, as developers must sort through unnecessary parts.</li><li><strong>Bugs &amp; confusion:</strong> Dead code might unintentionally interact with other parts of the system or cause confusion.</li><li><strong>Larger codebase:</strong> More code means higher complexity and longer compilation times, even if the dead code isn’t actually used.</li></ul><h3>Lava Flows</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*zDKOtWDytv8iXfF5" /><figcaption>I’m not talking about the sinfully delicious Hawaiian frozen cocktail, but maybe the next time you’re tasked with refactoring a code lava flow you do so with one of those in hand (not recommended, but probably pretty fun).</figcaption></figure><p>Much like its geological namesake, the Lava Flow anti-pattern represents code that’s built up over time, hardened in place, and impossible to move or refactor without significant risk. Lava Flow occurs when dead code, obsolete design elements, and legacy structures remain embedded in a system, even though they no longer serve a useful purpose. Often, these remnants were introduced during rapid development phases, experimental implementations, or early versions of the software that were never properly cleaned up.</p><p>Over time, these “fossilized” chunks of code become difficult to remove without potentially breaking the functionality of the overall system. Typically these pieces have no documentation, it’s generally unclear how they work or what it exactly does, but somehow the system works and therefore, just like a real lava flow everyone is afraid to touch it so instead of refactoring they they build on top of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*cWMLXG6SjoQEk0ZV" /></figure><h4>Symptoms of Lava Flow</h4><ul><li>Obsolete Code: Old methods, functions, or classes that are no longer used but have not been removed.</li><li>Unclear Ownership: Parts of the codebase that no one on the current team fully understands or can explain. Usually someone wrote it long, long ago.</li><li>Increased Complexity: Over time, as the codebase evolves, unnecessary complexity grows, making it harder to introduce new features or refactor existing ones.</li><li>Fear of Change: Developers become hesitant to modify certain parts of the code due to the risk of breaking the system, leading to stagnation.</li></ul><h4>The Risks of Ignoring Lava Flow</h4><p>Leaving these hardened chunks of code in place comes with significant risks:</p><ul><li>Reduced Agility : As more “lava” builds up, adding new features or refactoring becomes an uphill battle, slowing down the pace of development.</li><li>Higher Maintenance Costs : Debugging and maintaining a bloated codebase is more time-consuming and error-prone, leading to higher costs over time.</li><li>Technical Debt : Every time a developer works around a legacy block of code instead of addressing it, the technical debt grows, making future development even harder.</li></ul><h3>Solutions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q990v9QISO4TOeIN" /></figure><h4>CULTURE</h4><p>If there’s one thing I hope you take away from these solutions, it’s this:</p><blockquote><em>Being a real professional software developer means taking ownership not only of the code you write but also the code you inherit. When you see something broken or inefficient, it’s not ‘someone else’s problem’-it’s an opportunity to step up, fix it, and leave the codebase better than you found it. Responsibility in software isn’t limited to your own contributions; it extends to the health of the entire system.</em></blockquote><p>Regardless of your role, experience, or title, you can inspire others by setting the example-doing the right thing yourself. If you consider yourself a professional, or aspire to be one, excellence must be your standard. That means not allowing bad code to go unfixed or uncleaned. To combat anti-patterns, fostering a culture of refactoring, optimization, and leaving code better than you found it is crucial. This is the hardest challenge because it starts with the individual, and often, people only take it up once they’re inspired by someone else. Maybe that someone is you, dear reader.</p><p>Instilling this kind of culture in your engineering department or you team is hard. Damn hard. The easiest remedy I can come up with is to lead by example. The benefits of maintaining clean code are not immediately rewarded, it takes learning to love what initially feels like a drag.</p><h4>UNIT TESTING</h4><p>To address the risk of refactoring and removing code, there’s really only one valuable answer: automated tests, namely unit tests. Nothing will give you more confidence in touching code you know nothing about. If the codebase you’ve jumped into has no tests, I feel for you-but let the practice start with you, for the developer who comes after.</p><p>Imagine working on a project where you could confidently change any piece of code, knowing the unit tests have your back-immediately alerting you if anything breaks. It may sound like a pipe dream, but it’s not as far off as it seems. The first step towards that level of confidence is to start building unit tests today.</p><h4>OWNERSHIP</h4><p>Ensuring that each part of the codebase has a clear owner is essential for maintaining its long-term health and quality. A designated owner takes responsibility for understanding, maintaining, and improving that section of the code. This ownership doesn’t mean exclusivity-other developers can contribute-but it ensures accountability. Code ownership empowers developers to take pride in their work while fostering a collaborative environment where accountability and shared responsibility keep the entire system healthy.</p><blockquote><em>True code ownership isn’t just about maintaining and improving your code while you’re there; it’s about preparing it for the next developer who will take it over</em></blockquote><p>Also, consider this: as a developer, it’s almost certain you’ll move on from your current project to another at some point. True code ownership isn’t just about maintaining and improving your code while you’re there; it’s about preparing it for the next developer who will take it over. Think of yourself as the caretaker of a “code child”-whether it’s a small component or a large system. Your responsibility is to nurture it, clean it up, and make it as resilient as possible, so it’s ready to thrive long after you’re gone. Write code today that future developers will thank you for.</p><h4>DEBT TRACKING</h4><p>There are realities we can’t avoid, no matter how idealistic we are. Sometimes, despite our protests, we simply aren’t given the time to do things the “right” way, or we lack the personal bandwidth or know-how to fix what we come across. The best way to manage technical debt-other than preventing it altogether-is to shine a light on it. That means documenting and cataloging it so you can (hopefully) sprinkle some debt management into your sprints later. If you don’t add debt to your backlog, it will quickly be forgotten.</p><h3>Conclusion</h3><p>Anti-patterns like Dead Code and Lava Flows are common pitfalls that seem harmless because after all the application may still be working correctly but over time they do more damage to a application than most bugs ever could. However, these patterns don’t have to be inevitable. By fostering a culture of ownership, refactoring, and unit testing, we can transform these challenges into opportunities for growth. It starts with each of us taking responsibility-not just for our own code, but for the health and quality of the entire system. Clean, maintainable code doesn’t just benefit today’s project; it sets the stage for the next developer and the future of the application. Tackling technical debt and embracing best practices is no easy task, but it’s the hallmark of a true professional. The road to a better codebase begins with a single step, and that step starts with you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=331af63b11cd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/anti-patterns-dead-code-lava-flows-331af63b11cd">Anti-Patterns: Dead Code &amp; Lava Flows</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Restoring specific postgres tables locally]]></title>
            <link>https://medium.com/expsoftwareengineering/restoring-specific-postgres-tables-locally-2ab724faca82?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/2ab724faca82</guid>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mendix]]></category>
            <dc:creator><![CDATA[Micah McMullen]]></dc:creator>
            <pubDate>Fri, 17 Feb 2023 20:49:37 GMT</pubDate>
            <atom:updated>2023-02-17T20:52:58.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*ecrdh7jL_7vM5rEMJeTttw.png" /></figure><p>While working on applications it is often the case that you need to restore a backup locally in order to test what you are working on. Or, perhaps, trying to investigate what is causing a bug that you just can’t replicate without some good (bad) data. In other cases, you might just need to run a simple query on a single table.</p><p>Pulling down a backup, restoring locally, and connecting to it generally does the trick. However, in the last scenario do you really need the <em>entire</em> backup to perform the query? Likely not.</p><p>At eXp, we have some fairly large applications and to restore an entire backup can take the better part of a working day (ouch). When just needing to perform a simple query, its incredibly beneficial to just restore the single table you are interested in — and it will save you a ton of time.</p><p>The area in which I am mostly focused on is in our Mendix application portfolio and connecting to a local postgres database is common practice. If you are unsure how to do that, Mendix has some decent documentation found <a href="https://docs.mendix.com/developerportal/operate/restore-backup-locally/">here</a>. I would suggest taking a look at that documentation if you are unfamiliar with the process.</p><p>Regardless, read below and follow the steps to restore just the table (or tables) you are interested in.</p><p><em>Note: There are several tools out there but in this post I am focusing on </em><a href="https://www.pgadmin.org/"><em>PGAdmin</em></a><em>.</em></p><h3>Ready a Database and PGAdmin</h3><ol><li>Create a new database in PGAdmin <em>(in my example I have created a new database named “MyTestDatabase”. See the below image for reference)</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*EEsjxSm2ITU59KVifuC_rw.png" /><figcaption>New Database in PGAdmin</figcaption></figure><p>2. Open command prompt</p><p>3. Run the below command <em>(Of course, you can set the password as you wish)</em></p><pre>set &quot;PGPASSWORD=postgres&quot;</pre><h3>Create Command</h3><p>Build the below command with the following steps</p><pre>“C:\...\pg_restore.exe” -t [full table name] --host &quot;localhost&quot; --port &quot;5432&quot; --username &quot;postgres&quot; --no-password --dbname “[name of db from above]” --no-owner --no-privileges --verbose “D:\...\xyz.backup”</pre><ol><li>“C:\...\pg_restore.exe” Is the full path to your pg_restore.exe file. (This will be different for everyone) <em>→ </em>It will be in the ‘pgAdmin” folder likely located in your Program Files directory. It will resemble this: <em>C:\Program Files\pgAdmin 4\v6\runtime\pg_restore.exe</em></li><li>-t [full table name] “-t” is the flag to specify you wish to restore a specific table. In my case, I wanted to restore a ‘user’ table which is found in my ‘system’ domain, it looks like this -t system$user — <em>If you would like to restore more than one table just add another -t flag and table name</em></li><li>--host &quot;localhost&quot; --port &quot;5432&quot; --username &quot;postgres&quot; --no-password These details may be different for you but generally remain the same.</li><li>--dbname “[name of db from above]” This tells the pg_restore.exe which database you wish to restore to. So in the example above, it would look like this: --dbname “MyTestDatabase”</li><li>--no-owner --no-privileges --verbose Shouldn’t really be a need to adjust these.</li><li>“D:\...\xyz.backup”This specifies the full path and backup file you would like to restore from.</li></ol><h3>Run Command</h3><ol><li>Add your command to command prompt and hit enter</li></ol><p>Your command should look something like the following:</p><pre>“C:\Program Files\pgAdmin 4\v6\runtime\pg_restore.exe” -t system$user --host &quot;localhost&quot; --port &quot;5432&quot; --username &quot;postgres&quot; --no-password --dbname “MyTestDatabase” --no-owner --no-privileges --verbose “D:\Users\mmcmullen\Downloads\myappbackupfile.backup”</pre><h3>Conclusion</h3><p>That’s it. Super simple.</p><p>Go ahead and run a query on the table you just restored and pat yourself on the back for saving yourself potentially a ton of time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ab724faca82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/restoring-specific-postgres-tables-locally-2ab724faca82">Restoring specific postgres tables locally</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to test Jenkins locally]]></title>
            <link>https://medium.com/expsoftwareengineering/how-to-test-jenkins-locally-e1cfc530bca6?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/e1cfc530bca6</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Michal Korzawski]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 16:39:15 GMT</pubDate>
            <atom:updated>2023-02-03T16:39:15.628Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DzbuWXg78Ww4bA99UOjMxw.png" /></figure><p>We use Jenkins in every one of our projects. It’s a reliable tool that just works. Recently, the need to test a new change in our <a href="https://www.jenkins.io/doc/book/pipeline/jenkinsfile/">Jenkinsfile</a> emerged; however, there was no way to confidently conclude this would work without testing it locally. So we needed to setup Jenkins and its pipelines locally. This is how I did it.</p><p>Let’s start with setting up Jenkins itself locally. I used <a href="https://hub.docker.com/r/jenkins/jenkins">Jenkins docker image</a> and docker-compose. I believe this to be the easiest and most convenient way to run Jenkins.</p><blockquote><em>This setup is only for local testing. Be aware that in this approach best practices were sacrificed for the sake of ease of use. Please do not use this solution in any environment other than local.</em></blockquote><p>Create a directory like jenkins_local and add a docker-compose.yml file inside. The bare minimum for Jenkins inside a docker-compose.yml should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56cac9229e618e953e1615fb63bf4dca/href">https://medium.com/media/56cac9229e618e953e1615fb63bf4dca/href</a></iframe><p>Here we specified ajenkins service that uses jenkins/jenkins:jdk11 image, exposes port 8080 for it, and mounts it to jenkins_home volume.</p><p>Now run docker-compose up to spin up the container. Check the logs and look for the password Jenkins spits out for us during the initial setup. Copy it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oyiUf6wWmizanKMaTauwmA.png" /></figure><p>On your browser navigate to <a href="http://localhost:8080/">http://localhost:8080/</a>. On the first run, you should be presented with the Jenkins’s <em>Getting Started </em>page, where you must paste the administrator password copied in the previous step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vv38I8Xn4MfvXQz2JBHekw.png" /></figure><p>Next, you can install suggested plugins or select your own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TB8TiOt7-aXqfskOP3mMlA.png" /></figure><p>Now is the time for a cup of tea while Jenkins installs all its necessary dependencies. Once that process is finished, you can fill in the form in order to create the first admin user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ty7-hnn2fv85caVZb8sB_g.png" /></figure><p>On the next form, it will ask you to set Jenkins URL. We can go with the default <a href="http://localhost:8080/">http://localhost:8080/</a>. Jenkins is now ready to use!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XUX7CYC43QmOx-vobeu4Vg.png" /></figure><p>Let’s set up a pipeline now that we have Jenkins up and running locally. In the top left corner click “New Item”. Enter a pipeline name, choose <strong>Pipeline</strong> from the list below, and hit <strong>Ok</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M56cWgPtcql5Gi5cWburig.png" /></figure><p>Next you will see the pipeline configuration form. The most important setting here is where Jenkins can find the pipeline script. Choose <em>Pipeline script from SCM</em> for the <strong>Definition</strong> and <em>Git</em> for <strong>SCM</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kag9TijetSWPgfPImU5PXg.png" /></figure><p>For <strong>Repository URL,</strong> we don’t want to use a remote repository URL such as a link to a GitHub repo. The intention here is to keep it local. To do that, we want to mount our dockerized application’s project directory — which we’re testing Jenkins locally with — to our Jenkins instance. If your directory structure looks like this —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*910vzh5MubBw7v8vSRi4dg.png" /></figure><p>— add ../your_app:/var/jenkins_home/your_app:ro to the local_jenkins docker-compose.yml file. Doing this gives Jenkins access to our application files, including Jenkinsfile. “<em>ro</em>” is a read-only flag so Jenkins won’t be able to override any file or add something we don’t want. Also, we need to add a configuration env <em>hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true </em>to tell Jenkins that using a local file is permitted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe8f6bfa32ba747126da00e71984e4a8/href">https://medium.com/media/fe8f6bfa32ba747126da00e71984e4a8/href</a></iframe><p>Going back to the <strong>Repository URL, </strong>now instead of a remote repository URL, you can use a local file path: <em>file:////var/jenkins_home/your_app/.git.</em></p><p>Then set up the branch you want Jenkins to build. Leave <strong>Script Path </strong>with default value — Jenkinsfile. Save the configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pGE_CUhRVSqGF02axqVBDw.png" /></figure><p>If you see this error —</p><blockquote><em>An internal error occurred during form field validation (HTTP 403). Please reload the page and if the problem persists, ask the administrator for help.</em></blockquote><p>— just run docker-compose down and docker-compose up.</p><p>This should be enough for the very basic build flow. Go to Jenkins, click on your pipeline, and then select <em>Build Now</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*QJ6bnBNEA176h2TdqtaBRQ.png" /></figure><p>You should see your builds now on your pipeline details page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tb4PoVwZW-0Bzg13tZiT_w.png" /></figure><p>Keep in mind that its not enough to save changes in Jenkinsfile, you need to use git and commit them; though, actually pushing them isn’t required. Another thing to remember is to be checked out on the branch you specified during the pipeline configuration.</p><p>If you want to trigger a build using a post call to Jenkins, set up a build trigger in your pipeline configuration file. To do this, choose <strong><em>Trigger builds remotely (e.g., from scripts)</em></strong><em>. </em>This<em> </em>allows you to trigger a build by making a post request to a Jenkins pipeline you want to build (more on this later). Also, you need to set up an <em>Authentication Token</em> to be used when making a request. Since we’re using it solely locally, a token as simple as token is suitable. Though for any other environment, make it as long and random as possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f6kBzR8E8zmJree1T9-tPA.png" /></figure><p>At this point, we need to add yet another configuration env to our Jenkins’s docker-compose.yml file. Like with many other settings, CSRF protection can be skipped locally, but that’s not so in other environments.</p><p>hudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true</p><p>Now our Jenkins docker-compose.yml file should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49ac46ecd7d4317342a6e1ff235c4441/href">https://medium.com/media/49ac46ecd7d4317342a6e1ff235c4441/href</a></iframe><p>A user must be created first before triggering a build. In Jenkins, go to <strong>Manage Jenkins &gt; Manage Users</strong> and click <strong>Create User</strong>. Fill in the fields — while noting the username and password — and click <strong>Create User</strong>. This newly created user needs some privileges, so go to <strong>Manage Jenkins &gt; Configure Global Security.</strong></p><p>Under <em>Authorization</em>, choose <strong>Matrix-based security</strong>, then click <strong>Add user</strong>; in the popup, enter the username of the user you just created and select <strong>Ok</strong>. Then check <strong>overall:read</strong>, <strong>job:build</strong>, <strong>job:read</strong> for this user like so —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sMUU6Na2FBf9gYBujDhJRQ.png" /></figure><p>— and save the configuration.</p><p>Make sure you have Jenkinsfile in the same directory as your_app , go to the terminal, and run:</p><pre>curl -XPOST -u user_username:user_password http://localhost:8080/job/your_pipeline_name/build?token=your_token</pre><p>Your curl command should look something like this:</p><pre>curl -XPOST -u jenkins:jenkins http://localhost:8080/job/test_pipeline/build?token=token</pre><p>If you’re looking to trigger a build after every commit, add a post-commit file to .git/hooks in your application directory and add a bash script there.</p><pre>#!/bin/bash<br><br>BRANCH=&quot;$(git rev-parse --abbrev-ref HEAD)&quot;<br>if [[ &quot;$BRANCH&quot; == &quot;jenkins_test&quot; ]]; then<br>        curl -XPOST -u jenkins:jenkins http://localhost:8080/job/test_pipeline/build?token=token<br>fi</pre><p>In this example, it will only work on a specific branch — jenkins_test.This can be any branch you want. To make sure the script is executable:</p><pre>chmod +x .git/hooks/post-commit</pre><p>Now the Jenkins pipeline build will trigger every time a commit is made to the jenkins_test branch.</p><p>Thank you for reading, please follow, and feel free to add any suggestions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1cfc530bca6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/how-to-test-jenkins-locally-e1cfc530bca6">How to test Jenkins locally</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Ruby on Rails with AnyCable using Docker & ECS]]></title>
            <link>https://medium.com/expsoftwareengineering/deploying-ruby-on-rails-with-anycable-using-docker-ecs-80f0da2051ba?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/80f0da2051ba</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[anycable]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Michal Korzawski]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 21:53:40 GMT</pubDate>
            <atom:updated>2023-01-17T21:53:40.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b0F-HpW8usziViJocuEtOw.png" /></figure><p>This is a guide for setting up AnyCable locally using Docker Compose, and deploying it on Amazon Web Services (AWS) Elastic Container Service (ECS). The purpose of this article is not to explain what AnyCable is, so if this is the first time hearing about this awesome Ruby gem, I recommend checking out the <a href="https://docs.anycable.io/architecture">AnyCable documentation website</a>.</p><p>I’m using Rails 7, Ruby 3.1.1. and Redis 4 gem in this application.</p><p>The following steps outline how to setup AnyCable in Docker-Compose:</p><ol><li>Add gem &#39;anycable-rails&#39;, &#39;~&gt; 1.3&#39;, &#39;&gt;=1.3.4&#39; to your Gemfile and run bundle install.</li><li>Run bundle exec rails g anycable:setup</li><li>Ensure your config/cable.yml file looks similar to this:</li></ol><pre># config/cable.yml<br>development:<br>  adapter: &lt;%= ENV.fetch(&quot;ACTION_CABLE_ADAPTER&quot;, &quot;any_cable&quot;) %&gt;<br><br>test:<br>  adapter: test<br><br>production:<br>  adapter: &lt;%= ENV.fetch(&quot;ACTION_CABLE_ADAPTER&quot;, &quot;any_cable&quot;) %&gt;</pre><p>4. Add the config below to config/environments/development.rb and production.rb located in the same folder directory.</p><pre>config.after_initialize do<br>  config.action_cable.url = ActionCable.server.config.url = ENV.fetch(&quot;CABLE_URL&quot;, &quot;ws://localhost:8085/cable&quot;) if AnyCable::Rails.enabled?<br>end</pre><p>5. If you are using cookie-based authentication, make sure your <a href="https://docs.anycable.io/troubleshooting?id=my-websocket-connection-fails-with-quotauth-failedquot-error">cookies are accessible from both the HTTP server and WebSocket server domain</a>:</p><pre>  config.cache_store = :redis_cache_store, {driver: :hiredis, url: ENV.fetch(&#39;REDIS_URL&#39;, &#39;redis://redis:6379&#39;)}<br>  config.session_store :cache_store,<br>    key: &quot;_session&quot;,<br>    domain: :all,<br>    compress: true,<br>    pool_size: ENV.fetch(&quot;REDIS_CONNECTION_POOL_SIZE&quot;, 5).to_i,<br>    expire_after: 1.year</pre><p>6. Create websocket and anycable services in docker-compose.yml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/238f950072cb7ce9f7ca3b310f4d5dbd/href">https://medium.com/media/238f950072cb7ce9f7ca3b310f4d5dbd/href</a></iframe><p>We’ve already done enough to actually run AnyCable locally using docker-compose. Go ahead and give it a try, docker-compose up and check out the logs. They should be similar to below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rO9oCzdp6g1vjRyHYN7JyQ.png" /><figcaption>docker-compose websocker service logs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gGoSn_PQIrejt2uxKZ2Bbw.png" /><figcaption>docker compose anycable service logs</figcaption></figure><p>However, actually deploying AnyCable is a slightly different story, and we had much more of a struggle, or fun depending on your point of view. We deployed it to AWS ECS.</p><p>I’d like to give a huge shout-out to <a href="https://www.linkedin.com/in/connor-reid-6572b235">Connor Reid</a> and Joshua Christensen, the two eXp-Realty DevOps geniuses I am blessed to work with. They invented the architecture I’m about to present, and below is a diagram illustrating the solution we ended up implementing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2UyH4ow9oN8OlAQdJc4_Yw.png" /></figure><p>For the sake of clarity, I skipped some AWS services here, like VPC, subnets, availability zones, etc..</p><p>It starts with a client hitting either our Rails’ apps’ endpoint or a Websocket service endpoint (specified in CABLE_URL ENV). An Application Load Balancer listener is set up in order to forward HTTPS requests to our Rails app and websocket requests to a <a href="https://github.com/anycable/anycable-go">websocket service</a>. A <em>Websocket service</em> is just an <a href="https://hub.docker.com/r/anycable/anycable-go">official AnyCable-go docker image</a> packed in a container.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9e42b6625a04ca9cf398207e75ce55c/href">https://medium.com/media/c9e42b6625a04ca9cf398207e75ce55c/href</a></iframe><p>The Websocket Service needs to communicate with the AnyCable Service. Due to encountering similar issues when setting up the Application Load Balancer — as described in this <a href="https://jetrockets.com/blog/scaling-rails-docker-aws-beanstalk">blog post</a> — we also switched to a Network Load Balancer. Unlike an Application Load Balancer, which works on Layer 7 of OSI model (Application Layer), a Network Load Balancer works on Layer 4 (Transport Layer). It is not familiar with the concept of HTTP; listener options are limited to only TCP, TCP_UDP, TLS, and UDP.</p><p>We set it to listen on TCP port 50051 and forward traffic to the RPC service target group. Adding a health check here was as simple as specifying the protocol and port on which the load balancer will send requests. It’ll check if the service responds.</p><p>One last piece was to create a private hosted zone on Route 53 and set an alias to point to our Network Load Balancer. We saved the private hosted zone domain name as an ENV ANYCABLE_RPC_HOST in the WebSocket service.</p><p>Given that all your services’ security groups are set up to allow traffic from each other (such as RDS and ElastiCache to allow inbound traffic from AnyCable), it all should work. Is there something you would do differently, have a suggestion, question or point of clarity? Please let us know in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80f0da2051ba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/deploying-ruby-on-rails-with-anycable-using-docker-ecs-80f0da2051ba">Deploying Ruby on Rails with AnyCable using Docker &amp; ECS</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Converting HEIC Images in Ruby on Rails]]></title>
            <link>https://medium.com/expsoftwareengineering/converting-heic-images-in-ruby-on-rails-59242b16be7a?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/59242b16be7a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[heic]]></category>
            <dc:creator><![CDATA[Michal Korzawski]]></dc:creator>
            <pubDate>Fri, 30 Dec 2022 17:20:36 GMT</pubDate>
            <atom:updated>2022-12-30T17:20:36.155Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lTNe3k7_RS3038MA_ZHUBw.png" /><figcaption>eXp Realty Software Engineering Blog</figcaption></figure><p><em>How to convert High Efficiency Image File Format (.HEIF / .HEIC) images in Ruby on Rails without a library dependency.</em></p><p>Apple’s iOS 11 brought the new HEIC image format into the mainstream. The purpose of HEIC was to save storage space but still provide high fidelity images. However, like many of Apple’s decisions, the arrival of this image format causes a plethora of issues. Now, even unwittingly, many iPhone users are snapping photos solely as HEIC, as opposed to the much more ubiquitous — and supported — JPEG format. The largest consequence of a new-ish image format is the lack of <a href="https://caniuse.com/?search=heic">browser support.</a> Apple’s own Safari browser doesn’t even support them; in fact, not a single browser supports HEIC images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iAcWixLtQ2jLZbglSPm1Xg.png" /><figcaption>Caniuse browser support report for HEIC images</figcaption></figure><p>For one of our apps, users upload images often directly from their phone, and often these images are in HEIC format due to the popularity of iPhones. Nearly daily we’d be flooded with errors when these uploads were added, and no amount of UX/UI ever prevented these users from not choosing to upload them. Occasionally, they’d even resort to adding “.jpg” at the end of a HEIC file just to pass validations.</p><blockquote><em>For uploading, we are using Active Storage, and the app is deployed to AWS ECS.</em></blockquote><p>To address this issue and add support of HEIC image uploading, I at first followed a solution from a <a href="https://sipsandbits.com/2022/02/01/support-heic-images-in-a-rails-app-p1/">blog article</a>. <a href="https://sipsandbits.com/author/salomon/">Salomón Charabati</a>’s method worked perfectly well. However, it was quite slow — too slow for us — especially when attaching large HEIC files. Also, one app in particular, requires a minimum of 12 images, where 20 or more is the norm. The Achilles heel of this implementation was the <a href="https://github.com/alexcorvi/heic2any">Heic2any</a> library, which was used for the HEIC images to be previewed on the front end. So after all of this, I came up with my own solution. Let’s start with the backend.</p><p>First, make sure you have gem &quot;image_processing” added to your project’s Gemfile. The image_processing gem makes it easy to work with both ImageMagic and libvips libraries.</p><p>First we need to create an ImageConverter service, which will encapsulate image resizing and image conversion logic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb8fad3ea4ef404d8920ce13918dbe5a/href">https://medium.com/media/eb8fad3ea4ef404d8920ce13918dbe5a/href</a></iframe><p>The two methods — resize_to_limit and convert — are just two of many handy methods from the image_processing gem. Check out <a href="https://github.com/janko/image_processing/">the gem docs</a> to see them all.</p><p>The next step might be considered a little controversial. At first, I wanted to keep this logic closer to <a href="https://api.rubyonrails.org/classes/ActiveStorage/Blob.html">ActiveStorage::Blob</a>. I was experimenting with custom callbacks but was not too fond of them. Any logic I injected into Blob felt too late in the process. This too little too late feeling forced me to take a step back and modify the image parameters before they were ever sent to ActiveStorage::Blob.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b004f72d2452b36a4b0d9d7cad7e4e9a/href">https://medium.com/media/b004f72d2452b36a4b0d9d7cad7e4e9a/href</a></iframe><p>We map through :images if it’s present in the params and pass them one by one to ImageConverter. ImageConverterwill convert the image to jpg format, and if the image width is larger than 1200, it will also resize it. This service will then return a tempfile which we then pass to ActionDispatch::Http::UploadedFile. From there, we merge the converted images into permitted params.</p><p>So what exactly is <a href="https://api.rubyonrails.org/v6.0.5/classes/ActionDispatch/Http/UploadedFile.html">ActionDispatch::Http::UploadFile</a> anyhow? When we submit a file through an HTML form, multipart/form-data is used to send file content in the request body. <a href="https://github.com/rack/rack">Rack</a> — a middleware between our web application and web server, Puma for example — parses the multipart/form-data parameters into a hash object which looks like:</p><pre>{<br>  &quot;_method&quot;=&gt;&quot;put&quot;,<br>  &quot;property&quot;=&gt;<br>    {&quot;images&quot;=&gt;<br>      [{:filename=&gt;&quot;IMG_6542 (1).HEIC&quot;,<br>        :type=&gt;&quot;image/heif&quot;,<br>        :name=&gt;&quot;property[images][]&quot;,<br>        :tempfile=&gt;#&lt;File:/tmp/RackMultipart20221128-1-1no4h17.HEIC&gt;,<br>        :head=&gt;&quot;Content-Disposition: form-data; name=\&quot;property[images][]\&quot;; filename=\&quot;IMG_6542 (1).HEIC\&quot;\r\nContent-Type: image/heif\r\n&quot;}<br>      ],<br>     },<br>}</pre><p><a href="https://api.rubyonrails.org/v6.0.5/classes/ActionDispatch/Http/UploadedFile.html">ActionDispatch::Http::UploadFile</a> is used to wrap a file’s params passed to Rails by <a href="https://github.com/rack/rack">Rack</a> as a hash. It also adds a few methods along the way.</p><p>For the frontend, we want to make a HEIC image previewer, but without using the Heic2any library, which we already covered was too slow for us.</p><p>The steps are pretty simple. We grab a file and wrap it in a FormData object. Next, we use fetch to make an asynchronous post request to ImageController#convert_heic method — more about this soon — and read the response using <a href="https://developer.mozilla.org/en-US/docs/Web/API/Response/blob">blob()</a> . This method returns a <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob">Blob</a> which we put into an object URL using URL.createObjectURL. That object URL is then used as a source for the image tag, which is inserted into the DOM as an HTML img element.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cae1fdd5b9d97be33c6b4a758495bee5/href">https://medium.com/media/cae1fdd5b9d97be33c6b4a758495bee5/href</a></iframe><p>It’s evident the conversion for the images’ frontend previews are taking place on the backend, so let’s take a peek inside the ImagesController where this is transpiring.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc506ae927a3f5ec19628b09cacadcdf/href">https://medium.com/media/cc506ae927a3f5ec19628b09cacadcdf/href</a></iframe><p>We reused the ImageConverter service here; where after converting and resizing, the image is sent back to the client. That’s it!</p><p>I mentioned above that using the Heic2any library was slow. For more evidence, I added a simple comparison of the two below. Thank you so much for reading and click Follow to see more articles!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Av333TLiATemB7iQE7Z6wA.gif" /><figcaption>How the HEIC conversion looks on the front end, and comparison. Left is Heic2any and right is custom solution.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59242b16be7a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/converting-heic-images-in-ruby-on-rails-59242b16be7a">Converting HEIC Images in Ruby on Rails</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scheduled Events and Queue Processing- Mendix and Me]]></title>
            <link>https://medium.com/expsoftwareengineering/scheduled-events-and-queue-processing-mendix-and-me-6f4421a4ee5b?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/6f4421a4ee5b</guid>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[queue]]></category>
            <category><![CDATA[scheduled-event]]></category>
            <category><![CDATA[mendix]]></category>
            <dc:creator><![CDATA[Andreas Blaesius]]></dc:creator>
            <pubDate>Fri, 23 Dec 2022 19:41:25 GMT</pubDate>
            <atom:updated>2022-12-23T19:41:24.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/829/0*eaYpM77eGv0GVeYU.png" /></figure><p>Okay, this case doesn’t come up very often. However, when it does, it can have problematic consequences. If it happens in a production environment, it can cause the production environment to stop.</p><p><strong>The Usecase</strong></p><p>Running processes in a queue (I use the term queue in the following for all kinds of queues in Mendix. Process Queue, Task Queue,…) is something very useful. On the one hand you can move long running processes to the background and give the user a smoother experience, on the other hand you can create batch processing to split large actions (data migrations, regular synchronizations,…) into small work packages. This way you can make sure that the transaction doesn’t get too big (which can lead to problems up to a system crash).</p><p><strong>What does this have to do with Scheduled Events?</strong></p><p>A specific use case that I have encountered several times is a data synchronization that runs regularly in the background. Our application needs to retrieve data from an API at a certain interval and then process it locally. This processing should be done in work packages for the reasons mentioned above. If you have already dealt with the queue the solution is obvious. A Scheduled Event retrieves data from the API at fixed intervals, creates work packages and then processes them in the queue.</p><p>This is probably the ultimate solution and there is nothing you should do “differently”. A typical microflow for the Scheduled Event looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j9PwyKUaHGOb4z_Y.png" /></figure><p>First we import data, then we create work packages and finally we execute the processing of them in the queue.</p><p><strong>But why do you write a blog article about it?</strong></p><p>Well, what makes a Scheduled Event is also what can cause problems with a Scheduled Event: It repeats periodically.</p><p>This is normally exactly the behavior we want to create with a Scheduled Event. It should run every X seconds/minutes/hours/days/…. But what if the execution of the Scheduled Event takes longer than the period in which it is executed?</p><p><strong>The standard case</strong></p><p>Mendix has of course already thought about the above problem and established a mechanism to address it. When you create a scheduled event you can define how it should behave in this case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*SWp1CZ-4pG3HooKD.png" /></figure><p>The “On overlap” setting lets us define how the event should behave when the execution time exceeds the period. You can choose whether the next execution of the event should be skipped or delayed. If you choose “Skip next”, no event will be executed until the execution of the current event is finished. After that it continues with the normal period. If you choose Delay, the following executions will be delayed. They are put into a kind of queue and processed as soon as the first execution is finished (this also has certain risks, but that is not the point here).</p><p><strong>What about the queue now?</strong></p><p>If work packages are created within the Scheduled Event and are processed in a queue, it is no longer possible for the event to know whether everything has already been processed or not. It can only decide whether the creation of the work packages has been completed. If the actual processing of the packages now takes longer than the period between two executions of the event, then with each execution more and more work packages are put into the queue. The pile of work grows continuously and is never processed.</p><p>This problem cannot be solved with the default Scheduled Event configuration. Yes, you can choose a larger period as a precaution. But things are first of all not always so predictable and users probably want a data synchronization as soon as possible.</p><p><strong>What to do?</strong></p><p>To avoid the problems mentioned above, we need to manually recreate what the Scheduled Event normally does automatically in the microflow. We have to find out if the previous execution is already finished or not. To do this, we give our batch object an attribute that serves as an indicator of whether the processing has already been completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/0*MhEscPfiCKeLDFPl.png" /></figure><p>In its most simplistic form, this is simply a Boolean attribute. When the batch is created, the attribute is set to false, after the processing has finished, we set it to true. To our microflow presented above we introduce a database query that checks if there are still batches that are not executed. The whole thing looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*unwwEXceri9GlPpG.png" /></figure><p>We first count if there are still batches that are not processed. If there are none left, we execute the microflow we used in the first example. In the actual execution in the queue we have to set the Finished attribute of course.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zCmWXIMbnN7EA2ke.png" /></figure><p>Now we have recreated the “skip next” behavior for use with the queue in a very simple way and no longer run the risk of overflowing the queue with events executed too frequently.</p><p><strong>But what about „Delay next”?</strong></p><p>Even if I would advise against Delay next in most cases, I would like to introduce a Delay Next variant for the sake of completeness. For this we have to build a loop into our Scheduled Event Microflow in which we check again and again if the previous processing is finished. I strongly recommend to work with a delay because otherwise the database queries are executed one after the other until the desired result appears. This can put an enormous load on the system. In the <a href="https://marketplace.mendix.com/link/component/170">Community Commons</a> there is a Java action called Delay that does just that for us. It makes the system wait.</p><p>Armed with this delay and the loop, our event microflow now looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uWou-A6Ienk2Mn_k.png" /></figure><p>Instead of aborting the execution, the database is checked again and again until there is no more batch that has not yet been processed. As soon as this is the case, the actual logic of the event is executed. Thus both behaviors of the event could be extended to the queue with simple means and we can prevent that the queue is overloaded by too many event executions</p><p>Of course, you don’t need that for every event. It is a small special case. But whenever you run an event very often and possibly process a lot of data you should think about implementing such a mechanism. It can be implemented quickly and may save you from serious problems.</p><p>I hope this was interesting for one or the other. As always, I am happy about feedback and comments.</p><p><em>Originally published at </em><a href="https://medium.com/mendix/scheduled-events-and-queue-processing-mendix-and-me-16e9bd3776b3"><em>https://gandy84.medium.com</em></a><em> on December 23, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f4421a4ee5b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/scheduled-events-and-queue-processing-mendix-and-me-6f4421a4ee5b">Scheduled Events and Queue Processing- Mendix and Me</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You Need to Know About Self-Referencing in Mendix]]></title>
            <link>https://medium.com/expsoftwareengineering/you-need-to-know-about-self-referencing-in-mendix-a3cd371b7cbf?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/a3cd371b7cbf</guid>
            <category><![CDATA[mendix]]></category>
            <category><![CDATA[domain-model]]></category>
            <category><![CDATA[self-referential]]></category>
            <category><![CDATA[database-development]]></category>
            <dc:creator><![CDATA[Liam Hanninen]]></dc:creator>
            <pubDate>Tue, 13 Dec 2022 17:45:52 GMT</pubDate>
            <atom:updated>2022-12-13T17:51:55.050Z</atom:updated>
            <content:encoded><![CDATA[<h4>And how it falls short</h4><p>This article is going to throw some love on self-reference associations in Mendix, why you should be aware of them, and how they can break your heart. Self-reference associations (which I’ll call SRAs from now on) allow you to associate an entity to itself. This need is uncommon but in my experience every app ends up with at least one.</p><p><strong>Will I ever use SRAs?</strong></p><p>A family tree is a good use-case for SRAs because it leverages both of SRAs super powers: self-reference and unpredictable number of levels. I’ll touch on this more later. But there are many other instances where SRAs can be used: real estate MLS parent/child relationships, representing database tables, business hierarchy (2 levels or <em>n</em> number of levels), and any situation where objects could relate to other objects of the same type (entity).</p><p><strong>Simple example</strong></p><p>Imagine a family tree application with an entity called FamilyMember. To establish familial relationships you’ll want to somehow create a literal parent/child association. Mendix provides two avenues to do this: Inheritance/generalization and SRAs. Let’s very briefly explore the pros and cons of managing this via inheritance and then get into SRAs.</p><p><strong>Inheritance (generalization) and why it’s not the right fit</strong></p><p>I created a base FamilyMember entity and then created a pair of entities that inherit from it. I’m not saying anything new when I say this is where inheritance shines: it reduces the redundant noise and effort when recycling attributes from a common entity. I suspect the size of the table behind-the-scenes in the database is unaffected (it needs to store those fields and its data somewhere). Nonetheless, inheritance fits nicely here… <em>initially</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*zFvBfC160D_Kwhx39CyQjQ.png" /></figure><p>Consider “I am my father’s son and my father is his father’s son.” So I would be the child and my father would be my parent. So far so good. But how do we record my father’s relationship with <em>his</em> father? Well, he must then be <em>duplicated</em> as a child and associated to his father, a parent. A dedicated yet under-informed developer may make this use-case work. Unfortunately, it would devolve into a suite of potentially masterful, yet complex microflows to buttress this poor design. More time than necessary would be spent building, maintaining, and debugging a less scalable solution.</p><p><strong>How (and When) SRAs Can Save the Day</strong></p><p>1. [Required] When you want to associate an entity to itself</p><p>2. [Optional bonus] When you don’t know how many parent/children/levels there could be.</p><p>SRAs are not unique to Mendix. They are simply a data relationship management strategy or design. We could say Mendix, for its part, <em>enables </em>self-referencing and makes it easy to implement. The way you set up an SRA is the exact same way you create any association; although in this case, you’re selecting the <em>same</em> entity for the association.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*kJc1_8bEEPLL6vGpvDQJgg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*PNU_qf_XCV85pM7e31Cz_Q.png" /></figure><p>It is depicted in the domain model as a circular association pointing to its source entity. This is the easy part. The true power and tribulations of SRAs surface when interacting with the data and designing UI.</p><p>Before we get to the hard and heart-breaking parts, there are other easy parts and general benefits to this we should go over.</p><p><strong>What to do with your fancy, new SRA</strong></p><p>You now have a family tree with infinite levels! You can now record your great, great, great, great grandfather. You don’t need to create a Parent object and a Child object for everyone. You just need to build a CRUD interface and manage the associations. Data management design is clean, simple, scalable, and, for our purposes, done.</p><p>Secondly, you CAN retrieve in either direction. Reverse retrieves are not unique to SRAs but are particularly useful for them. Please see <a href="https://docs.mendix.com/refguide/query-over/">https://docs.mendix.com/refguide/query-over/</a> if you’d like to retrieve in the reverse direction.</p><p>Finally, a family tree has indefinite levels. But many SRAs are just two levels — this will depend on your use-case. Two-level SRAs are easy to display in data grids or general page widgets. They also skirt ALL of the heartbreaking pitfalls I share later.</p><p><strong>Some need-to-knows</strong></p><p>Consider this the warning section. These are not showstoppers but just things to consider when implementing an SRA.</p><p>First of all, you need to be consistent when establishing the relationship — the direction is implicit. So when you use a Retrieve by Association action it will consistently retrieve in the same direction. This means it will only retrieve children or only parents depending on how your CRUD interface designates. So documentation and clear naming is important.</p><p>You don’t need flags for retrieves but may want them to manage subsets of parents or children. This almost doesn’t merit mentioning since it would apply to non-SRAs as well. It is much cleaner to use a retrieve over the proper direction when possible — although, it’s possible to establish and leverage flags with SRAs when more granular retrieves are necessary.</p><p>Lastly, there is a problem with retrieves. As I mentioned earlier, you can perform reverse retrieves if you’ve got a parent, for example, and want to retrieve their children AND/OR visa versa. But you can only do this using <em>from the database</em> retrieve (not an association retrieve), which means you must create a microflow for widget data sources and visibility.</p><p><strong>Heart breakers</strong></p><p>Multi-level SRAs like this family tree example have serious trouble importing and exporting. Message Definitions for example will let you select any number of descendants BUT you must select a discrete amount. There is no option to toggle ‘Unknown Levels’ or ‘Self-Reference Association Figure it Out on the Fly’. So you have to pick a certain number of descendants that work for your situation. We selected 6 and tell our users that descendants beyond the 6th level won’t be imported or exported. This pitfall impacts JSON mapping in the same way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*RMU7SJyM0tKK_NfA4GNH3A.png" /></figure><p>The unknown number of levels also creates a problem in microflows. You’ll likely want to ascend from any arbitrary descendant all the way up to the first ‘parent’ or top level. To go up one level you can do a single retrieve action to get an object’s parent. You can do two retrieves if there’s two levels. But if you don’t know the number of levels then you can’t build a microflow around a certain number of retrieves. You have two options to solve this: build a reusable subflow that has a recursive loop or establish a relationship directly to the top level. In the recursive loop you simply check if there is a parent and if so you do another iteration. This might not be considered a showstopper, but I deem it a heart breaker, because you need to install this subflow any time you want to do a simple retrieve to the top level. Alternately you can create an association to the top level every time you create a new descendant. This allows you to do a single, simple retrieve but requires maintenance on the CRUD interface (and another self-referencing association).</p><p>And finally, visualizing this data is not great. If you want your users to see and explore all of the levels in one place you’ll need an <a href="https://marketplace.mendix.com/link/component/38862">app-store module</a>. There is nothing native that will show your users relationship depth in one view. Data grids, for example, are not suited for showing an unpredictable number of descendants on the same row. The closest you get to native GUI features playing nicely with SRAs is pathing pages to the same page with different data. Users can keep descending by clicking ‘Next’ or ‘Previous’, recycling the page, but passing the next or previous descendant. This enables the users to traverse between objects easily, but still short of depicting the depth in a single view.</p><p>So there it is: SRAs can break your heart but don’t give up on that relationship. In this case it’s better to have loved and lost than never to have loved at all. SRAs can solve a unique set of problems better than anything else. Their heartbreaking pitfalls are not as impactful if you see them coming and can set expectations. They’re worth it when they fit the problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w_ajnBy9KTOEkQrnT_R-Gw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3cd371b7cbf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/you-need-to-know-about-self-referencing-in-mendix-a3cd371b7cbf">You Need to Know About Self-Referencing in Mendix</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CableReady and Rails Background Jobs in Views]]></title>
            <link>https://medium.com/expsoftwareengineering/cableready-and-rails-background-jobs-in-views-86074eaac3a3?source=rss----1dd03898132a---4</link>
            <guid isPermaLink="false">https://medium.com/p/86074eaac3a3</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[cableready]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Michal Korzawski]]></dc:creator>
            <pubDate>Mon, 12 Sep 2022 20:14:26 GMT</pubDate>
            <atom:updated>2022-09-12T20:14:26.575Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SG60e-l13tpzn1jIoGQEFQ.png" /></figure><p>Using CableReady inside of a Ruby on Rails app to dynamically update the page and view based on a Sidekiq background job’s progress.</p><p>In the world of Web Dev, a common practice, and often preferable approach for handling long-running methods, is to run the intensive action as a background job. It’s a simple and effective solution, but just like everything we web programmers face, there are pros and cons to background jobs. For example, the user won’t receive any feedback generally until this job is finished. For a particular feature I ran into, I needed to display some front-end feedback to the user and to change the page’s content contingent on the progress of this method. One traditional way to do this would be to create a dedicated route and controller#method, while executing Ajax calls every few seconds; however there is an easier way. Considering how much of a Swiss army knife it is, <a href="https://cableready.stimulusreflex.com/">CableReady</a> is a perfect tool for this.</p><p>Before I go any further, let me clarify a bit about what CableReady really is. Here’s a quote from the official website:</p><pre>CableReady is a Ruby gem that was first released in May 2017. It lets you <strong>create great real-time user experiences</strong> by triggering client-side DOM changes, events and notifications over <a href="https://guides.rubyonrails.org/action_cable_overview.html">ActionCable</a> web sockets.</pre><p>Besides the fact that it saves us from having to write too much Javascript in Rails apps 😈, the one aspect of CableReady that completely sold me is below, also from their documentation.</p><pre>Unlike Ajax requests, operations are not always initiated by user activity - or even the user&#39;s browser.</pre><p>What this means is CableReady can be used <a href="https://cableready.stimulusreflex.com/cableready-everywhere">almost everywhere</a>! In this circumstance, we are going to use it inside of a plain old ruby object — <a href="https://steveklabnik.com/writing/the-secret-to-rails-oo-design">PORO</a>.</p><blockquote><em>Before we move on, I’d like to point out some things. CableReady is used together with </em><a href="https://docs.stimulusreflex.com/"><em>StimulusReflex</em></a><em>, or to be more precise, I use StimulusReflex with CableReady since it is a direct dependency. Because of this, CableReady can be called directly inside a Reflex class, without additional configuration. Reflex will take care of the channel CableReady will broadcast to. However, one thing to keep in mind is CableReady will broadcast to the current user when called inside a Reflex.</em></blockquote><p>Let’s start with a CSV importer. A typical CSV importer in Ruby may look very similar to this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17801a88e1f85fba5cc959e118f05534/href">https://medium.com/media/17801a88e1f85fba5cc959e118f05534/href</a></iframe><p>Although this works, it’s boring, in the background, and hidden from the user’s view. They have no idea if their importing process is running or where they stand, so let’s show the user its progress in real-time. To start, I’ll include CableReady::Broadcaster in our Importer class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0157a7066b7969e31857855866b28e25/href">https://medium.com/media/0157a7066b7969e31857855866b28e25/href</a></iframe><p>Then we need to create an ActionCable Channel class</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77decab360c4383b3e87f90b25f1d388/href">https://medium.com/media/77decab360c4383b3e87f90b25f1d388/href</a></iframe><p>…and a channel subscriber.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43eee6e7226256169a9721263fbdc3f4/href">https://medium.com/media/43eee6e7226256169a9721263fbdc3f4/href</a></iframe><p>Now on every page load, a consumer creates a subscription to the UserChannel. After the consumer subscribes to UserChannel, the <em>subscribed</em> method on UserChannel is called. This will use stream_for to subscribe to a broadcast like <em>user:Z2lkOi8vYnJva2VyLXZpc2lvbi9Vc2VyOjpBZG1pbi8x,</em> which is a name generated from the channel name (user) and model instance (GlobalID of a current user). To exemplify this, in the logs we see the following:</p><pre>[ActionCable] UserChannel is transmitting the subscription confirmation<br>[ActionCable] UserChannel is streaming from user:Z2lkOi8vYnJva2VyLXZpc2lvbi9Vc2VyOjpBZG1pbi8x</pre><p>From now on we can use code like this:</p><p>cable_ready[UserChannel].remove(selector: &#39;some_selector&#39;).broadcast_to(current_user)</p><p>… to broadcast to the current user.</p><p>Now that we have CableReady inside our PORO and a channel set up, time to revisit our Importer class; here, we should flesh out the method in order to keep track of how many CSV rows have already been processed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db454113a721fdddc891e51b70738753/href">https://medium.com/media/db454113a721fdddc891e51b70738753/href</a></iframe><p>Given that you have a div with the selector id of processed-row-number-container in your view, on each CSV iteration, the number will increment to reflect the counter variable; all being updated in real-time via CableReady and the text_content DOM manipulation (which is quite simply Javascript’s .textContent property).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hTTF5ZMDjApmOnRV4ZL44g.gif" /></figure><p>As a backend developer, this is good enough for me, and I would leave it as is! 😂 But thankfully, I have a <a href="https://medium.com/@benbroestl">great friend on my team</a> who knows a thing or two about design and implemented it with a nice HTML progress bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6jIVOA9jTJzzrnJcoBmP5Q.gif" /></figure><p>This is a big improvement for the user, but how about we find out what else we can do? Say we want to update the view from a <a href="https://github.com/mperham/sidekiq">Sidekiq</a> job.</p><p>For example, imagine a web app that displays a leaderboard of some sort. In the background, a rake job runs every few minutes that fetches the newest scores. It’s just as easy to update a view from that job using CableReady as well.</p><p>Assuming this leaderboard is accessible by all users, the leaderboard channel may look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47d4d89ccc04aea466042b69f2def3ed/href">https://medium.com/media/47d4d89ccc04aea466042b69f2def3ed/href</a></iframe><p>Instead of using current_user as we did before, we use a string “scores”. In the logs, it looks radically different from before when we used user:</p><pre>[ActionCable] LeaderboardChannel is transmitting the subscription confirmation<br>[ActionCable] LeaderboardChannel is streaming from leaderboard:scores</pre><p>So before, when broadcasting a message to current_user , it was meant for only one user to see that view, hence the massive string ID from users:user_global_id. In this leaderboard example leaderboard:scores, the broadcast will be published to all logged-in users, which is our goal here.</p><p>Just like before, a channel subscriber needs to be created, and then the only thing left is the job itself.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bac135b46c7968eaf3be1ed119301d01/href">https://medium.com/media/bac135b46c7968eaf3be1ed119301d01/href</a></iframe><p>With merely a few lines of code, we implemented a background job that will update our view. How cool! And this is just the tip of the iceberg. As demonstrated, you can use CableReady pretty much anywhere, so you are limited only by your creativity. With CableReady, you can add an amazing amount of reactivity to your Rails monolithic app, while maintaining a concise and simple stack.</p><p>Interested in how we at eXp-Realty are embracing the Rails monolith? <a href="https://medium.com/@benbroestl">Benjamin Broestl</a> (author of the aforementioned progress bar) started a<a href="https://medium.com/expsoftwareengineering/a-legacy-rails-apps-journey-into-2022-part-1-view-components-6c1d319513f7"> series of blog posts about it.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86074eaac3a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/expsoftwareengineering/cableready-and-rails-background-jobs-in-views-86074eaac3a3">CableReady and Rails Background Jobs in Views</a> was originally published in <a href="https://medium.com/expsoftwareengineering">eXpSoftwareEngineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>