<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Strange</title>
    <description>The latest articles on DEV Community by Strange (@abba_m_).</description>
    <link>https://dev.to/abba_m_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F278013%2F9a4fd6c9-7f35-43e0-97c3-36c01e49c56c.jpg</url>
      <title>DEV Community: Strange</title>
      <link>https://dev.to/abba_m_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abba_m_"/>
    <language>en</language>
    <item>
      <title>Why hosting more than one service on a single host in production can be a big problem</title>
      <dc:creator>Strange</dc:creator>
      <pubDate>Wed, 06 Sep 2023 13:36:57 +0000</pubDate>
      <link>https://dev.to/abba_m_/why-shouldnt-you-have-more-than-one-service-on-the-a-host-in-production-2eb6</link>
      <guid>https://dev.to/abba_m_/why-shouldnt-you-have-more-than-one-service-on-the-a-host-in-production-2eb6</guid>
      <description>&lt;p&gt;In the ever-evolving landscape of infrastructure management, one topic often sparks spirited debates: &lt;strong&gt;the practice of hosting only one service per server in a production environment&lt;/strong&gt;. It's a mantra chanted by many, a design principle considered gospel by some. But what if we challenge this conventional wisdom, just a bit?&lt;/p&gt;

&lt;p&gt;Recently, I found myself in a conversation with a new client, discussing the intricacies of infrastructure design. The client confidently asserted that having more than one service on a single host in a production setup is a cardinal sin of modern architecture. While I've always been an advocate for the scalability and elegance of the one-service-per-host approach, I couldn't help but wonder: does every rule have exceptions?&lt;/p&gt;




&lt;p&gt;This discussion left me intrigued and yearning for a deeper understanding. What if there are scenarios, like the symbiotic relationship between an API and its caching companion (Redis or Memcached), where bucking the trend makes perfect sense? As I delved further into this topic, I began to wonder if I'm not alone in challenging the status quo.&lt;/p&gt;

&lt;p&gt;If you're an engineer who has, at least once, contemplated the idea of cohabitating services on a single host, this post is for you. Let's explore the reasons, scenarios, and justifications for this approach, and engage in a discussion that may very well redefine some of our long-held beliefs about infrastructure.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>infrastructureascode</category>
      <category>devops</category>
      <category>redis</category>
    </item>
    <item>
      <title>Leveraging Conditional Properties Type Checking with Discriminated Unions</title>
      <dc:creator>Strange</dc:creator>
      <pubDate>Mon, 04 Sep 2023 20:49:48 +0000</pubDate>
      <link>https://dev.to/abba_m_/leveraging-conditional-properties-type-checking-with-discriminated-unions-345j</link>
      <guid>https://dev.to/abba_m_/leveraging-conditional-properties-type-checking-with-discriminated-unions-345j</guid>
      <description>&lt;p&gt;Strict type checking feels like a privilege ever since I encountered it in my career and i'll give anything to have it in any part of my code. So i decided to write this short post (for strict type checking fandom😌) to share a trick for type checking conditional properties of an entity . &lt;/p&gt;

&lt;p&gt;I am just going to go straight to stating the problem so you can better understand what we are dealing with, (actually Its because I fear boring you more than anything). And also to stick with the goal; keep the post short.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem statement
&lt;/h2&gt;

&lt;p&gt;The first thing I'll like to note is, this example is super contrived and there are better ways to go about this in a real world scenario. It however complements what we are trying to achieve so, here we go.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qGiFg6ZJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93ydh70fmdykf0mexb13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qGiFg6ZJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93ydh70fmdykf0mexb13.png" alt="Create user props type" width="800" height="757"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our application, we have a &lt;code&gt;createUser&lt;/code&gt; function that takes the properties of a user as described in the &lt;code&gt;CreateUserAttr&lt;/code&gt; type. We have two types of users (Admin &amp;amp; User). The two variations of &lt;code&gt;CreateUserAttr&lt;/code&gt; have some shared props and differences which are marked as optional props of the &lt;code&gt;CreateUserAttr&lt;/code&gt; because we want to pass admin only props when creating an admin and vice versa. Hence the problem; the role prop when creating a user type of &lt;code&gt;Admin&lt;/code&gt; is not optional (as seen below), we have to provide role and all other props related to the &lt;code&gt;Admin&lt;/code&gt; type (super contrived 😉) likewise the verified prop when creating a user type of &lt;code&gt;User&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3FB9mIcu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1xr7huikh3ia6oem7g2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3FB9mIcu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1xr7huikh3ia6oem7g2.png" alt="function call without strict type checking" width="800" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution 😋
&lt;/h2&gt;

&lt;p&gt;The solution is to take advantage of typescript's union and intersection types to create a type known as &lt;strong&gt;discriminated union&lt;/strong&gt; or tagged unions. We first create our base type which has all the shared props between the &lt;code&gt;User&lt;/code&gt; &amp;amp; &lt;code&gt;Admin&lt;/code&gt; type. Then we intersect it with a block that has two union type where we'll add the admin props and the user props. Putting everything together we have a type that has our shared props AND either the &lt;code&gt;Admin&lt;/code&gt; props OR the &lt;code&gt;User&lt;/code&gt; props.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExeDJzcTlrNHA3YXB0YWRiOGlvc3hpa3F5MTB4dDg1dnl3amxwajFxeCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/jWlncszJpP6WMoHAMg/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExeDJzcTlrNHA3YXB0YWRiOGlvc3hpa3F5MTB4dDg1dnl3amxwajFxeCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/jWlncszJpP6WMoHAMg/giphy.gif" alt="discriminated union or tagged union in typescript" width="480" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we get the yelling when we don't pass the all the required props relating to the type of &lt;code&gt;User&lt;/code&gt; we are creating, SWEET!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--38gdG8Dp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a419so0lfiilsdlscede.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--38gdG8Dp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a419so0lfiilsdlscede.png" alt="Create admin with missing prop" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hooray🎉! we now have type checking to make sure we are passing the required props of the user type being created, and also check that we don't pass a prop that doesn't belong. The example we have explored is intentionally simple to illustrate the core concept, but in real-world applications, the benefits become even more apparent. You can explore more examples &lt;a href="https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#discriminated-unions"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZGX8MqTY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocbay81uqxas5ttfox1x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZGX8MqTY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocbay81uqxas5ttfox1x.png" alt="function call with type checking on discriminated union" width="800" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;In the world of software development, the privilege of strict type checking is indeed a treasure for those who have experienced its benefits. The added advantage of this approach is, our code becomes more readable (it's clear which property belongs to which union) and autocompletion (depending on the IDE). Our Types also become easy to extend because adding new types to the union is straightforward. So, whether you're tackling simple examples or navigating the complexities of real-world applications, discriminated unions offer a potent tool to make your code more robust, reliable, and enjoyable to work with. &lt;/p&gt;

&lt;p&gt;And don't hesitate to drop a comment if you have any specific topics you'd like me to cover in future content❤️.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>codequality</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
