<?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: Rajika Imal</title>
    <description>The latest articles on DEV Community by Rajika Imal (@rajikaimal).</description>
    <link>https://dev.to/rajikaimal</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%2F87102%2Fa6027072-e7f8-467f-9586-a800e83f7d1f.jpg</url>
      <title>DEV Community: Rajika Imal</title>
      <link>https://dev.to/rajikaimal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajikaimal"/>
    <language>en</language>
    <item>
      <title>JavaScript quick tips: Array.copyWithin()</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Sat, 31 Oct 2020 07:01:17 +0000</pubDate>
      <link>https://dev.to/rajikaimal/javascript-quick-tips-array-copywithin-8b2</link>
      <guid>https://dev.to/rajikaimal/javascript-quick-tips-array-copywithin-8b2</guid>
      <description>&lt;p&gt;&lt;code&gt;Array.prototype.copyWithin()&lt;/code&gt; does a copy (shallow) of the selected elements within the same array, to a specified index.&lt;/p&gt;

&lt;p&gt;To copy value in index 3 to index 1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copyWithin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [1, 4, 3, 4, 5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To copy all values from specified index to the end to a given index&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copyWithin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [1, 4, 5, 4, 5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
    </item>
    <item>
      <title>JavaScript quick tips: filter arrays</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Fri, 30 Oct 2020 12:07:26 +0000</pubDate>
      <link>https://dev.to/rajikaimal/javascript-quick-tips-filter-arrays-5fcc</link>
      <guid>https://dev.to/rajikaimal/javascript-quick-tips-filter-arrays-5fcc</guid>
      <description>&lt;p&gt;Filter only numbers in an array,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;const&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1, 2, 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove all falsy values in an array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;const&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1, "const", 2, 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
    </item>
    <item>
      <title>JavaScript Array.flat()</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Fri, 30 Oct 2020 05:49:50 +0000</pubDate>
      <link>https://dev.to/rajikaimal/javascript-array-flat-400k</link>
      <guid>https://dev.to/rajikaimal/javascript-array-flat-400k</guid>
      <description>&lt;p&gt;Arrays with embedded sub arrays can be concatenated using &lt;code&gt;Array.flat()&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;flatArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2, 3, 4, 5, 6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The depth can be specified using an argument. &lt;code&gt;Array.flat(depth)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[[[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]]]]&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;flatArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2, 3, 4, [[5, 6]]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[[[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]]]]&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;flatArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;flat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2, 3, 4, 5, 6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Future of JavaScript tooling</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Sun, 11 Oct 2020 17:47:17 +0000</pubDate>
      <link>https://dev.to/rajikaimal/future-of-javascript-tooling-1k5d</link>
      <guid>https://dev.to/rajikaimal/future-of-javascript-tooling-1k5d</guid>
      <description>&lt;p&gt;Recently I've seen a transition of building tooling infra in the JavaScript ecosystem using languages other than JavaScript! Specifically with compiled languages such as Rust and Go. The main goal is &lt;strong&gt;performance&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;JavaScript is a great language for most of the use cases in software development. But when it comes to creating high performant tooling, there are better options out there.&lt;/p&gt;

&lt;p&gt;Here are a few tools built with compiled languages,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;esbuild - &lt;a href="https://github.com/evanw/esbuild"&gt;https://github.com/evanw/esbuild&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;RSLint - &lt;a href="https://github.com/RDambrosio016/RSLint"&gt;https://github.com/RDambrosio016/RSLint&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;volta - &lt;a href="https://github.com/volta-cli/volta"&gt;https://github.com/volta-cli/volta&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even at the early stage of development, these tools have shown better performance compared to their counterparts written in JavaScript.&lt;/p&gt;

&lt;p&gt;esbuild performance comparison,&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8KDBUzUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/evanw/esbuild/master/images/benchmark.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8KDBUzUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/evanw/esbuild/master/images/benchmark.png" alt="esbuild perf"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tools</category>
      <category>linter</category>
      <category>bundler</category>
    </item>
    <item>
      <title>The Scale Cube</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Tue, 06 Oct 2020 14:06:18 +0000</pubDate>
      <link>https://dev.to/rajikaimal/the-scale-cube-4m4j</link>
      <guid>https://dev.to/rajikaimal/the-scale-cube-4m4j</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FCHe2noh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6h671bxhf2bzhhwnzf1v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FCHe2noh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6h671bxhf2bzhhwnzf1v.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scaling can be achieved by following the above axes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;x-axis, horizontal scaling - When the traffic increases the application can be scaled by adding more instances. This is a simple strategy. However, concerns like handling state should be taken into consideration as multiple instances are working at the same time.&lt;/li&gt;
&lt;li&gt;y-axis, microservice/functional decomposition - Once the number of instances is increased, and still, if the system underperforms, logic can be decomposed into microservices. This allows scaling different parts of the application individually by adding more instances.&lt;/li&gt;
&lt;li&gt;z-axis, partitioning/sharing - This concerns the data layer. As the traffic increases, the data layer needs to handle the spikes. As an improvement sharding can be implemented by dividing the records to the different DBs based on a sharding function.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All the above techniques come with certain costs and the decisions need to be taken depending on the requirements of the application like availability, consistency, and partition tolerance.&lt;/p&gt;

</description>
      <category>systems</category>
      <category>scaling</category>
    </item>
    <item>
      <title>Promise.race()</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Mon, 28 Sep 2020 16:31:53 +0000</pubDate>
      <link>https://dev.to/rajikaimal/promise-race-21c3</link>
      <guid>https://dev.to/rajikaimal/promise-race-21c3</guid>
      <description>&lt;p&gt;&lt;code&gt;Promise.race()&lt;/code&gt; resolves whenever one of the promises resolves. If there are multiple promises, the first promise that gets resolved will be returned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promise1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;one&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promise2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;two&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;race&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;promise1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;promise2&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Both resolve, but promise2 is faster&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;// expected output: "two"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If an empty array is passed, it'll be in forever pending state.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Promise.any()&lt;/code&gt; has a similar behavior. But unlike &lt;code&gt;.any()&lt;/code&gt;, &lt;code&gt;.race()&lt;/code&gt; will return the first fulfilled or rejected promise value. &lt;code&gt;.any()&lt;/code&gt; returns fulfilled values only.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>promises</category>
      <category>asynchronous</category>
    </item>
    <item>
      <title>Caching 101</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Tue, 22 Sep 2020 17:44:14 +0000</pubDate>
      <link>https://dev.to/rajikaimal/caching-101-3h2o</link>
      <guid>https://dev.to/rajikaimal/caching-101-3h2o</guid>
      <description>&lt;p&gt;Caching is one of the most used techniques to improve application performance. There are few means of managing caches based on the application use cases. An example of a cache is in-memory storage sitting in between an application server and a database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cScmUO4C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/diaawgubhr1oykuo289o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cScmUO4C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/diaawgubhr1oykuo289o.png" alt="Alt Text" width="762" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Read through cache
&lt;/h2&gt;

&lt;p&gt;When a record is read from the application, it looks in the cache before requesting from the persistence store (database). If the data is present, it will return the result avoiding the round trip to the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Write through cache
&lt;/h2&gt;

&lt;p&gt;An operation that adds new data to an application adds records to the database. Before adding the data, the write-through cache is updated and then the database is updated. This way the cache is up to date with the new records.&lt;/p&gt;

&lt;h2&gt;
  
  
  Write behind cache
&lt;/h2&gt;

&lt;p&gt;In this case, the cache is updated asynchronously after writing data to the database. The time which takes to update the cache can be configured.&lt;/p&gt;

&lt;h2&gt;
  
  
  Refresh ahead cache
&lt;/h2&gt;

&lt;p&gt;Caches have invalidation periods, meaning data can be expired after a certain defined period of time. With refresh-ahead, the cache can be reloaded to load new data so that the cache is updated with the recently accessed data before invalidating data.&lt;/p&gt;

</description>
      <category>caching</category>
      <category>systemdesign</category>
      <category>performance</category>
    </item>
    <item>
      <title>Notes on pre-rendering</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Sun, 20 Sep 2020 09:01:26 +0000</pubDate>
      <link>https://dev.to/rajikaimal/notes-on-pre-rendering-1587</link>
      <guid>https://dev.to/rajikaimal/notes-on-pre-rendering-1587</guid>
      <description>&lt;p&gt;Typical single page applications needs to load all JavaScript before rendering the application. This increases the time for FP (First Paint) and FCP (First Contentful Paint). However this can be mitigated using pre-rendering. Pre-rendering is generating the HTML from server and sending to the browser.&lt;/p&gt;

&lt;p&gt;There are two types of pre-rendering techniques. SSR (Server Side Generation) and SSG (Static Site Generation). Both of these techniques create the HTML in the server and send back to the client, thus improving FP and FCP. However the difference is that,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;SSR, HTML is generated for each request.&lt;/li&gt;
&lt;li&gt;In SSG, HTML generation is done at the build step of the application.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With SSR dynamic content as such data from APIs are fetched at each time. But with SSG if such dynamic content is present they can become stale. In different frameworks there are techniques to overcome this issue to a certain extent. In Next.js, it is possible to SSG an application without the dynamic content or add incremental static site generation. SSG can provide better performance with CDN cache.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>nextjs</category>
      <category>gatsby</category>
    </item>
    <item>
      <title>Run GitHub Actions locally</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Sun, 06 Sep 2020 18:28:23 +0000</pubDate>
      <link>https://dev.to/rajikaimal/run-github-actions-locally-1ejo</link>
      <guid>https://dev.to/rajikaimal/run-github-actions-locally-1ejo</guid>
      <description>&lt;p&gt;GitHub Actions are a great way to run continuous integration and continuous deployment tasks. Actions are defined using YAML files and there are tons of existing ones which you can use to develop a pipeline. However Actions should be run on GitHub to know the output, which means at development it is not possible to run Actions and test them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nektos/act"&gt;act&lt;/a&gt; provides a way to run Actions locally. This simplifies the development of actions and running them locally. Therefore this gives faster feedback for the developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install nektos/tap/act #for macOS
$ curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
$ choco install act-cli #for choco
$ scoop install act #for scoop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Make sure you have Actions defined in &lt;code&gt;.github/workflows/&lt;/code&gt; directory&lt;/p&gt;

&lt;p&gt;To confirm this run,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ act -l
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run all&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ act
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run a specific job, use &lt;code&gt;-j&lt;/code&gt; flag,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ act -j test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To invoke an event,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ act pull request
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The complete list of flags are available &lt;a href="https://github.com/nektos/act#flags"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>github</category>
      <category>actions</category>
      <category>docker</category>
      <category>cicd</category>
    </item>
    <item>
      <title>JavaScript `this` in a flash!</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Tue, 01 Sep 2020 10:45:59 +0000</pubDate>
      <link>https://dev.to/rajikaimal/javascript-this-in-a-flash-558f</link>
      <guid>https://dev.to/rajikaimal/javascript-this-in-a-flash-558f</guid>
      <description>&lt;p&gt;&lt;code&gt;this&lt;/code&gt; in JavaScript can be the one of the most confusing concepts to grab at first. If you want to understand &lt;code&gt;this&lt;/code&gt;, just remember only ONE rule. Yeah, just one rule. Consider the following two scenarios below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;getPerson&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPerson&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the first snippet, the function is called directly. If that's the case, it'll always have the context (this) set as global. (In the browser it's window).&lt;/p&gt;

&lt;p&gt;In the second snippet, the function is called from an object. In this instance &lt;code&gt;this&lt;/code&gt; is the object itself.&lt;/p&gt;

&lt;p&gt;Therefore the rule is: "If it's called directly without creating an object, &lt;code&gt;this&lt;/code&gt; equals to global context, if a function is called by creating an object, then &lt;code&gt;this&lt;/code&gt; equals to the context of the calling object".&lt;/p&gt;

&lt;p&gt;By following this rule, other behaviors can be understood very easily. In JavaScript, there are different way to call methods. &lt;code&gt;call&lt;/code&gt;, and &lt;code&gt;apply&lt;/code&gt; are used to call methods by specifying objects and arguments explicitly. Both of these can change the context based on the provided object. Again apply the singular rule. The context of the method will depend on the object that is calling the method. Below snippets shows this behavior. (Note: call and apply differs with the way arguments are passed)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;getPerson&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;jack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jack&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jack&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//jack, reason: even though the method is called from person object, jack object is given as the argument in call function explicitly, therefore it binds to jack object. &lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPerson&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//undefined, reason: person object doesn't have name in it's context&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the below snippet, &lt;code&gt;person.getPerson.call(jack);&lt;/code&gt; and &lt;code&gt;person.getPerson();&lt;/code&gt; will give two outputs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;nancy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;getPerson&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;jack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jack&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jack&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//jack&lt;/span&gt;

&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPerson&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//nancy, reason: as method is called from the object and it has a name in it's context.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we consider all the above scenarios, it comes down to the singular rule that we established at the start.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>this</category>
      <category>context</category>
    </item>
    <item>
      <title>Tracing in express.js</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Thu, 27 Aug 2020 18:40:46 +0000</pubDate>
      <link>https://dev.to/rajikaimal/tracing-in-express-js-2moh</link>
      <guid>https://dev.to/rajikaimal/tracing-in-express-js-2moh</guid>
      <description>&lt;p&gt;Tracing is tracking the details of each request. With tracing it is possible to track down the execution of the code for each user request in the context of a web application. This is important when debugging an application as it might be necessary to track a user and the corresponding path of the code. With threaded languages, this is quite straightforward with the thread id.&lt;/p&gt;

&lt;p&gt;In Node.js, it is not simple as it is single threaded and depends on the event loop to execute asynchronously. However &lt;a href="https://github.com/puzpuzpuz/cls-rtracer"&gt;rtracer&lt;/a&gt; provides a straight forward solution to accomplish this.&lt;/p&gt;

&lt;p&gt;rtracer provides APIs to use it in multiple frameworks such as express.js, and fastify.&lt;/p&gt;

&lt;p&gt;To use it in express.js, rtracer has to be registered as a middleware. That's it. After that the id generated by rtracer can be used with any type of logger. An id is generated as follows,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rTracer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;expressMiddleware&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;requestId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rTracer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Request Id: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;requestId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;a href="https://github.com/rajikaimal/express-tracing"&gt;repository&lt;/a&gt; contains a minimal example that demonstrates rtracer with winston logger.&lt;/p&gt;

</description>
      <category>node</category>
      <category>tracing</category>
      <category>javascript</category>
      <category>logging</category>
    </item>
    <item>
      <title>System Design - Back To Basics</title>
      <dc:creator>Rajika Imal</dc:creator>
      <pubDate>Tue, 18 Aug 2020 14:43:43 +0000</pubDate>
      <link>https://dev.to/rajikaimal/system-design-back-to-basics-3ei</link>
      <guid>https://dev.to/rajikaimal/system-design-back-to-basics-3ei</guid>
      <description>&lt;h2&gt;
  
  
  What we'll look into
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Vertical Scaling&lt;/li&gt;
&lt;li&gt;Horizontal Scaling&lt;/li&gt;
&lt;li&gt;Load balancer&lt;/li&gt;
&lt;li&gt;RAID&lt;/li&gt;
&lt;li&gt;Caching&lt;/li&gt;
&lt;li&gt;Cache servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to know different aspects of system designing in order to create a rigid system with characteristics such as availability, redundancy and scalability. Most of the topics discussed in this post are related to web applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vertical Scaling &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Vertical scaling refers to adding resources to the underlying machine. Once the traffic to web site or application increases, the first instinct is to increase the amount of resource to add to the running machine. Adding more memory and CPU power usually copes with the performance requirements. However adding resources can be costly and at some point there will be a limit to adding resource continuously to cater the high amount of requests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gp7w8j7G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bcq390tbfbcxo957zmuz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gp7w8j7G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bcq390tbfbcxo957zmuz.png" alt="Alt Text" width="874" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Horizontal Scaling &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Horizontal scaling as the name implies is the opposite of vertical scaling, where more machines are added instead of adding more resources to a single machine. One of the advantages is the cost can be minimized if the cheaper machines are added compared to adding high cost resources as in the case of vertical scaling. With cloud computing adding more machines is quite easy with virtual machines or containers. However, if the server side code implemented sessions with a single server, these might get broken as many machines are added and user can be directed to different machines for different requests. To fix a common database can be introduced to store session data, but this adds a single point of failure. &lt;/p&gt;

&lt;p&gt;Alternatively sticky sessions can be implemented. Sticky sessions make sure that the requests of a particular user gets directed to the same machine. This can be implemented in many different ways. A common method is to use cookies with the unique id of the server.&lt;/p&gt;

&lt;p&gt;Once many machines are introduced, a load balancer has to be added to the design to redirect the requests to different machines.&lt;/p&gt;

&lt;h3&gt;
  
  
  Load balancer &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Load balancer is responsible to sit in-front the multiple worker machines, and redirect the requests to the corresponding machine. The redirection is dependent upon the algorithm implemented. Round-robin algorithm is used for basic scenarios to distribute the requests evenly. However in cases where the requests must be redirected to a certain machine, different strategies such as sticky sessions with cookies might be used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2lQ8L0h5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sjz3kq1sbqyzxsxrumdq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2lQ8L0h5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sjz3kq1sbqyzxsxrumdq.png" alt="Alt Text" width="611" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  RAID &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;When a system makes use of separate box to store centralized data such as sessions, there would be risks such as single point of failure and not having a fault tolerant solution. To overcome this RAID (Redundant Array of Independent Disks) can be used as a strategy. RAID can solve different types of issues such as redundancy, fault tolerance, performance and data recovery. Depending on the requirement, a type of RAID level should be selected for the solution. &lt;a href="https://blog.datapacket.com/advantages-disadvantages-various-raid-levels/"&gt;This post&lt;/a&gt; explains few of the RAID levels with their pros and cons.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9tLGr0fo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hkaben4ujvuatc8wrx1o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9tLGr0fo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hkaben4ujvuatc8wrx1o.png" alt="Alt Text" width="638" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Caching &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;As we expand our solutions to to include databases, and eventually there will be bottlenecks with the queries specially if the application is read heavy. If the same query is made 100000 time to the databases, these round trips can cost some serious issues in terms of the performance. Thus caching comes into the picture. In the case of read heavy operations, the first step is to identify the bottlenecks. Once the read heavy queries are identified, a read-through cache can be applied. In this way before actually doing the query to the database, the cache is checked. If the cache contains the necessary record, it is returned and the query never makes the round trip to and from the database. Similarly there are many other &lt;a href="https://dzone.com/articles/using-read-through-amp-write-through-in-distribute"&gt;caching mechanisms&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nrqLIOMt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ib7h2x4shacujcszz8hc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nrqLIOMt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ib7h2x4shacujcszz8hc.png" alt="Alt Text" width="652" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Cache servers &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;To implement caching there are different methodologies. Simply a custom in memory cache can be implemented based on the requirements. This can be done using in the same runtime context of the application itself, using the same programming language. However when the work-load increases, a caching server can be used. A caching server bundles many of the common features required by applications when integrating a cache such as invalidation, scaling, and fault tolerance. &lt;a href="https://redis.io/"&gt;Redis&lt;/a&gt;, and &lt;a href="https://memcached.org/"&gt;memcached&lt;/a&gt; are few examples of widely used caching solutions. &lt;/p&gt;

</description>
      <category>scaling</category>
      <category>systems</category>
      <category>design</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
