<?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[Stories by Chetan Dwarkani on Medium]]></title>
        <description><![CDATA[Stories by Chetan Dwarkani on Medium]]></description>
        <link>https://medium.com/@m-chetandwarkani?source=rss-926831bae034------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Fi3W2u_gH2ViSpgEA7fPbg.jpeg</url>
            <title>Stories by Chetan Dwarkani on Medium</title>
            <link>https://medium.com/@m-chetandwarkani?source=rss-926831bae034------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 18:35:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@m-chetandwarkani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Top 5 things to consider while designing micro services — Better Architecting]]></title>
            <link>https://m-chetandwarkani.medium.com/top-5-things-to-consider-while-designing-micro-services-better-architecting-c7c9731bd400?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7c9731bd400</guid>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Wed, 26 Jul 2023 07:13:03 GMT</pubDate>
            <atom:updated>2023-07-28T17:26:10.941Z</atom:updated>
            <content:encoded><![CDATA[<h3>Top 5 things to consider while designing micro services — Better Architecting</h3><p>Micro-service design is a familiar concept which is one of the buzzing words as soon as you enter the tech industry but I believe it is worth the buzz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*pG8UqRlDEMS22Pta.gif" /></figure><h3>Why is it so?</h3><p>Most of the companies I have seen over my experience and networking spend Lakhs of dollars later to improvise their initial written monolith service to make things work better. This can be a very familiar thing to many people working at startups. If the company’s Lead Engineers had a better understanding at the start of the project of a scalable architecture then the whole base design concept could have gotten a lot better and the codes they designed would have ended up being well-adaptive for horizontal and vertical scaling as well saving a lot of dollars in the future. The whole re-architecting cost of investment would generally get saved in such a case so yes — it’s worth a read to understand these concepts.</p><p>Please find <strong>my set of blogs</strong> related to practical course of desiging micro service step by step — <a href="https://m-chetandwarkani.medium.com/">https://m-chetandwarkani.medium.com/</a></p><p>Here are the key points to give it a read end to end before you start designing microservices</p><h3><strong>1. LLD patterns:</strong></h3><p>Well, Design pattern is really a base concept to learn before you hop it into any micro-service design because it improves your thinking in terms of how to exactly write a scalable code in every step of implentation you take.</p><p>You will be able to better map your code arrangements if you give it a read on this concept. Key concepts around LLD involves learning Creational, Behavioural and Structural Design Pattern.</p><p><strong>I have written a blog which gives insights about various Low level Design patterns.</strong></p><p><strong>Do give it a read </strong>— <a href="https://m-chetandwarkani.medium.com/design-pattern-creational-low-level-system-design-factory-and-abstract-factory-part-1-cdb88ee2dc6a">Link 1</a>, <a href="https://m-chetandwarkani.medium.com/design-pattern-creational-low-level-system-design-singleton-builder-prototype-part-1-dbd6428c89b9">Link 2</a>, <a href="https://m-chetandwarkani.medium.com/design-pattern-structural-low-level-system-design-decorator-proxy-flyweight-design-pattern-b407517b7ac8">Link 3</a>, <a href="https://m-chetandwarkani.medium.com/design-pattern-behavioural-low-level-system-design-strategy-observer-state-design-7e7386b6600a">Link 4</a></p><p>One of the other websites I love on Design pattern learning is <a href="https://refactoring.guru/">https://refactoring.guru/</a></p><h3><strong>2. HLD patterns:</strong></h3><p>HLD is one of the key concepts in designing a super-scalable micro-services. After we are good with designing a scalable code using LLD, next lies importance of designing the whole infra supporting scaling on top of well designed LLD code.</p><p>Some of the various key concepts in good HLD design starts from proxy servers, Orchestration, Docker, Caching, distributed logging, queuing and choosing right framework based on your business need.</p><p><strong>I did give a headstart to write blogs relating on the same —</strong><a href="https://m-chetandwarkani.medium.com/scaling-your-backend-service-system-design-158ba107d0d8"><strong> Link to my blog</strong></a><strong> Please give it a read.</strong></p><p>One of the amazing resource I like to read to understand better HLD is <a href="https://www.youtube.com/@gkcs">https://www.youtube.com/@gkcs</a></p><h3>3. Data Algorithms:</h3><p>After a great HLD and LLD design infra is laid out for our micro service, datas come into picture. It is very important to learn basics of algorithms which are very scalable for storing datas based on our need. Some of the important algorithm for starters includes <strong>CAP theorem, Quorum, Bloom filter, Gossip protocol, Consistent Hashing.</strong></p><p><strong>I have written a blog for a better understanding of this — </strong><a href="https://m-chetandwarkani.medium.com/understanding-data-structures-and-algorithms-used-in-order-to-select-the-right-framework-for-a-2132769f41b9"><strong>Link to my blog</strong></a></p><p>Also, you can find video recording of my blog around the same at — <a href="https://www.youtube.com/watch?v=Zdw59XptFRM">Youtube Link</a></p><h3>4. Database Scaling:</h3><p>After all above three steps, there comes into picture when our data starts growing enormously. In such a case, understanding on how to scale your DB becomes important. Before you dive into Database Scaling, it is very important to understand right database to select based on your business need and matching algorithm which is again explained in step 3 above.</p><p>After your selected Database starts hitting storage peak, then here are some of the strategies you can adopt for scaling your DB</p><ol><li><strong>Increasing pool size</strong></li><li><strong>Vertical Scaling</strong></li><li><strong>CQRS</strong></li><li><strong>Multi master replication</strong></li><li><strong>Partitoning</strong></li><li><strong>Horizontal Scaling</strong></li><li><strong>Data-wise partition</strong></li></ol><p><strong>Here’s my blog to give it a full read about the same</strong></p><p>Please check step 6 of my blog — <a href="https://medium.com/@m-chetandwarkani/scaling-your-backend-service-system-design-158ba107d0d8">Link</a> to understand in detail about some of the steps to scale a structure Data system.</p><h3>5. Logging</h3><p>Logging plays a very crucial role in any SaaS product to be reliable. If we miss out on any logs then it may lead to a vital case of data loss. Setting up logging right from scratch becomes important for the design of any micro-service. In general, I believe for a good design, we should have logs enabled for</p><p><strong>1. Proxy: <br></strong>Every request that comes in gets logged inside a file. Sometimes whole payload logging may become too much in case your traffic is in millions so logging at least request headers helps.</p><p><strong>2. Logging at every code level:<br></strong>It is vital to log and catch errors well in every piece at every function level of our code. This is a crucial deal to constantly analyse logs and improvise our system for better error catch</p><p><strong>3. Logging at various other framework levels :</strong><br>If we are using queues or any other framework such as Kubernetes or docker container as explained in HLD Design then it is super important to turn on the logs for the same. <br>For every third-party framework we use, adding a log there before its been processed by the same helps in case of any edge case issues hitting on our system.</p><p>I will be writing blogs soon on how to build a better logging system and you can find the same in various internet resources about the same as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7c9731bd400" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Pattern — Behavioural — Low level system design — Strategy, , Observer, State design…]]></title>
            <link>https://m-chetandwarkani.medium.com/design-pattern-behavioural-low-level-system-design-strategy-observer-state-design-7e7386b6600a?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e7386b6600a</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[observer-pattern]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[state]]></category>
            <category><![CDATA[strategy]]></category>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Wed, 18 Jan 2023 06:13:04 GMT</pubDate>
            <atom:updated>2023-01-18T06:13:04.305Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design Pattern — Behavioural — Low level system design — Strategy, , Observer, State design pattern (part 4)</h3><p>Behavioural design pattern is concerned with identifying common communication pattern between objects and separating them into different classes which can be plugged in any of the other objects and help in inter-communicating.</p><p>Before we dive into a complete explanation. I’d strongly suggest understanding the other blogs I added on Creational, Structural design patterns to be studied. Please find the blog link below</p><p><a href="https://m-chetandwarkani.medium.com/">Chetan Dwarkani - Medium</a></p><p>Now, let’s go ahead with Behavioural design pattern</p><h3>Strategy:</h3><p>When there is a certain algorithm which is common across various other classes and objects then abstracting that algorithm into pluggable objects makes it easy for the object to communicate. This is where the strategy pattern comes into the picture.</p><p><strong>Example</strong>: Let’s say we are implementing a session and token strategy to authenticate our incoming request. Then the below code would help you to understand how the Strategy pattern suggests you code in order to have a better code reusability</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5ca375c5cbd4137eb454fb8147c9048/href">https://medium.com/media/f5ca375c5cbd4137eb454fb8147c9048/href</a></iframe><h3>Observer Design Pattern:</h3><p>The observer design pattern is a very common pattern across the industry which comes into the picture when a lot of objects are to be updated when an event is triggered. This pattern says to create a generic class which keeps a note on the list of observers and whenever an event is received, all the observers listening to the event should be updated.</p><p>Below code-example explains well on the same</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30c378a9b18b76647eb8cbc7c26186fb/href">https://medium.com/media/30c378a9b18b76647eb8cbc7c26186fb/href</a></iframe><h3>State Design Pattern:</h3><p>A lot of time we come across the situation where there is a state transition involved between objects and status is required to be known when we are in a particular object. This design pattern explains well about the same.</p><p><strong>Example:</strong></p><p>Let’s say we have 3 class for a courier which is order -&gt; order receieved -&gt; payment receieved. At any stage, we may wanna know ship progress, verify order payments or say cancel order. On Basis of that, our code can be well arranged in the below format which gives us a clear abstraction for order status at any stage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/617f4c6d941959c93ebe4b78ae139a46/href">https://medium.com/media/617f4c6d941959c93ebe4b78ae139a46/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e7386b6600a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Pattern — Structural — Low level system design — Decorator, Proxy, Flyweight design pattern…]]></title>
            <link>https://m-chetandwarkani.medium.com/design-pattern-structural-low-level-system-design-decorator-proxy-flyweight-design-pattern-b407517b7ac8?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/b407517b7ac8</guid>
            <category><![CDATA[decorator-pattern]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[flyweight-pattern]]></category>
            <category><![CDATA[proxy]]></category>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 16:23:52 GMT</pubDate>
            <atom:updated>2023-01-17T16:23:52.904Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design Pattern — Structural — Low level system design — Decorator, Proxy, Flyweight design pattern (part 3)</h3><p>Structural Design Pattern helps us to understand how to create a complex objects from a simple initial base object while making sure that object is greatly efficient.</p><p>In the previous blogs, I mentioned about creational Design Pattern which emphasizes on creation of classes in a reusable and efficient manner. if you have not gone through that then I would highly recommend you to give that a watch before going through this blog. Here’s a link for the same</p><p><a href="https://m-chetandwarkani.medium.com/design-pattern-creational-low-level-system-design-factory-and-abstract-factory-part-1-cdb88ee2dc6a">Design Pattern — Creational — Low level system design — Factory and Abstract Factory (part 1)</a></p><p>Now, Let’s dive into Decorator design pattern</p><h3>Decorator Design Pattern:</h3><p>Decorator design pattern talks about how to create and provide multiple enhanced options for a base class in future while creating a simple base class at the time of initial setup.</p><p><strong>Example:</strong> Let’s say we are designing a simple subscription system where we offer multiple plans such as Enterprise and classic. The initial setup would look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4211423765c10f281215fbee0605998d/href">https://medium.com/media/4211423765c10f281215fbee0605998d/href</a></iframe><p>Next, we let’s say we wanna provide set of add on options as well for every single plan, then we can create a new abstract class extending the subscription abstract class like a decorator wrapper on top of main class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4cfb3f23caaba98c3512d89eeca5383c/href">https://medium.com/media/4cfb3f23caaba98c3512d89eeca5383c/href</a></iframe><p>So now our main service class would like below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c39f072e793963a20e9578a565521e7/href">https://medium.com/media/7c39f072e793963a20e9578a565521e7/href</a></iframe><h3>Proxy Design Pattern:</h3><p>Proxy design pattern comes into picture when you wanna add a firewall on top of your service class.</p><p><strong>Example:</strong></p><p>One such classic use case of proxy design patterns in the industry is across helpers and service classes. Let’s say we have a service class and we need to add a helper on top of our service class to format the incoming body object then aligning our code in like below format will help us to achieve the same.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3476f68bb1b57169e4f1ad467718e089/href">https://medium.com/media/3476f68bb1b57169e4f1ad467718e089/href</a></iframe><p>This can be applied to a lot of concepts. one such classical example is when we have a router and wanna assign a certain level of strategies on top of the router to provide auth for an incoming request.</p><h4>Flyweight Design Pattern:</h4><p>This design pattern helps in reducing the object count when we huge number of objects.</p><p>The cache is a classic example of a flyweight design pattern where the data is stored temporarily in a cache based on its requirement.</p><p>The below code demonstrates the same.</p><p>Let’s say we have a simple subscription object associated and this subscription object are been instantiated with various types</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20c37cde53f379d0b867c261e1d2392c/href">https://medium.com/media/20c37cde53f379d0b867c261e1d2392c/href</a></iframe><p>Now if sub2 and sub4 are mostly accessed objects then we create a cache layer around this which could be further stored in memory for faster access. The below code explains the same</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dc58a868c2b758accaa5304a82f75b0/href">https://medium.com/media/0dc58a868c2b758accaa5304a82f75b0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b407517b7ac8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Pattern — Creational — Low level system design — Singleton, Builder, Prototype(part 1)]]></title>
            <link>https://m-chetandwarkani.medium.com/design-pattern-creational-low-level-system-design-singleton-builder-prototype-part-1-dbd6428c89b9?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbd6428c89b9</guid>
            <category><![CDATA[builder-pattern]]></category>
            <category><![CDATA[singleton]]></category>
            <category><![CDATA[prototype-design-pattern]]></category>
            <category><![CDATA[singleton-design-pattern]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 04:30:16 GMT</pubDate>
            <atom:updated>2023-01-17T04:31:11.284Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design Pattern — Creational — Low level system design — Singleton, Builder, Prototype design pattern (part 2)</h3><p>If you have not seen part 1 which explains Factory and Abstract Factory Design pattern then it’s a must-watch one. Please find the link for the same below. Understanding both the design patterns will be a great learning</p><p><a href="https://m-chetandwarkani.medium.com/design-pattern-creational-low-level-system-design-factory-and-abstract-factory-part-1-cdb88ee2dc6a">Design Pattern — Creational — Low level system design — Factory and Abstract Factory (part 1)</a></p><p>Now, let’s continue with other creational design patterns. Let’s start with Singleton -</p><h3>3. Singleton Design Pattern</h3><p>This design pattern says that if there is going to be one class reference for entire class objects with all updates and changes are to be reflected in all the objects instantiating that class then this design pattern comes into great application.</p><p><strong>Example:</strong></p><p>Let’s consider that we are building a common ORM factory which is simply responsible for creating other ORMS based on a certain type. This is a classic example that we learnt in our last design pattern course on factory design patterns. In that, we used the factory as a static method which in turn serves as a way to generalise the function across all the class’s objects. Below is a simple example to understand the same</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b5e4aeee05e736390e594c17b1a6f69/href">https://medium.com/media/4b5e4aeee05e736390e594c17b1a6f69/href</a></iframe><h3>4. Builder Design Pattern</h3><p>Builder pattern emphasises creating a complex object by building it in a small part-by-part manner.</p><p>The below example is easy to interpret—</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a4cf5497d998174368ac87b585547c1/href">https://medium.com/media/5a4cf5497d998174368ac87b585547c1/href</a></iframe><p>As you can see, we first enable the Enterprise plan for a customer then update his SMS limit to a custom value and the same goes with the Email limit. This is a classic simple example of the builder pattern.</p><h3>5. Prototype</h3><p>There is a necessity generally in objects to be cloned into another object while we code. This pattern emphasizes the fact of creating a common interface which declares clone(..) and this clone can be further used to clone the class into another class.</p><p>A simple code example explaining the same is mentioned below —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cff2753c36dd9299016e70ff59c7de70/href">https://medium.com/media/cff2753c36dd9299016e70ff59c7de70/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbd6428c89b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Pattern — Creational — Low level system design — Factory and Abstract Factory (part 1)]]></title>
            <link>https://m-chetandwarkani.medium.com/design-pattern-creational-low-level-system-design-factory-and-abstract-factory-part-1-cdb88ee2dc6a?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdb88ee2dc6a</guid>
            <category><![CDATA[factory-pattern]]></category>
            <category><![CDATA[creational-patterns]]></category>
            <category><![CDATA[abstract-factory-pattern]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[creational-design-pattern]]></category>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Mon, 16 Jan 2023 16:53:12 GMT</pubDate>
            <atom:updated>2023-01-18T16:54:43.561Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Design Pattern — Creational — Low level system design — Factory and Abstract Factory (part 1)</strong></h3><p>Creational Design Pattern deals with the way you can structure your code base in terms of creating objects in order to provide flexibility on object creations, API versioning and reusing existing code.</p><h3>Why is it important to learn this design pattern?</h3><p>Well, often we make a mistake of writing codes without giving a thought about future issues which our code would bring in. As and then the user base grows, flexibility to support versioning of say APIS, modules, factory, service classes etc., becomes a huge overload. If we understand and write the code structure well before we create new services then this may solve a lot of future havoc. So let’s dive into the code in order to understand how it’s done</p><p><strong>Key creational design patterns:</strong></p><blockquote>1. Factory Design Pattern<br>2. Abstract Factory Design Pattern<br>3. Builder<br>4. Prototype<br>5. Singleton</blockquote><h3>1. Factory Design pattern</h3><p>Factory design pattern deals with creation of services in such a way that it provides easy flexibility on versioning of the code.</p><h4>Let’ take a example use case</h4><p>Every project today generally access Database with the help of some ORMs. What if one ORM is awesome with speed of read while other ORM is good in writing data by providing various extensive options. You may generally end up using just one of the ORMs overall in your code base rather than switching ORMs because it would be hard to implement such functionality switches. Let’s take the same example and understand how Factory design pattern can solve such a case</p><p>Before knowing factory pattern design, the way a dev would generally write code will look like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37b210d26a989797bcd6e3cc31cb0788/href">https://medium.com/media/37b210d26a989797bcd6e3cc31cb0788/href</a></iframe><h3>What are the issues above?</h3><p>In factory design pattern basically we define an interface which declares the common pattern which is used across the different functionalities. Like in above case, different ORMs pattern such as opening connection, checking if table is existing and creating a table later and then closing the connection. These CRUD operations will be common for all ORMs so here’s where we define an interface for crud operations and this interface can be further implemented by various classes. Please find the below code explaining about the same which is the classic example of factory design pattern.</p><p>After knowing factory design pattern</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*89uq50CBaaQYhfA649EIag.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d49b1319361f99d0d7bd50d5aa1be9f6/href">https://medium.com/media/d49b1319361f99d0d7bd50d5aa1be9f6/href</a></iframe><p><strong>Example 2:</strong> One more classical example use case for this design pattern is API versioning. Every product over the period of time requires revamping and launching a new version 2 of the product so ensuring that code is backward compatible is pretty difficult if its not well documented (which is most of the times the case in companies). Here, use of factory design pattern solves one such criticality. Please find the below code example to understand on the same</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nib6zpeGaZvUNGYHoP8tLw.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a3c573f8dd1b9cca0229e0cb657fa43/href">https://medium.com/media/4a3c573f8dd1b9cca0229e0cb657fa43/href</a></iframe><p>So in above code as you can see, whenever you wanna write new API class payments, it’s just having great clarity as well as making it well backward compatible.</p><h3><strong>So what’s improved?</strong></h3><p>1. Code consistency: We have identified that code pattern has a repetition so creating an interface ensures that when we add a new future ORM, its backward compatible with all other CRMs.</p><p>2. Code versioning: Introducing new verison of the code will be relatively easy as mentioned in the above example.</p><p>3. Code clarity: Code reading clarity improves a lot. As there is a common interface now which declares all the methods needed to be implemented in relevant classes, it becomes very easy to read and write new requirements.</p><h3>2. Abstract Factory Design pattern</h3><p>It’s quite similar to Factory design pattern. If you understood factory well then it’s easy to understand this. It basically says to use factory on top of another factory with the use of abstract classes.</p><p><strong>Example:<br></strong>In above example cases explained for factory design pattern, we are creating APIs and providing versioning on them. If we try to combine the above examples then it would become a classic example of Abstract Factory design pattern.</p><p>Lets say we have are creating payments service and for every payments service we may need to select any one of the many ORMs configured in the product. Achieving this defines the use of abstract factory design pattern where we create an ORMfactory which is used by PaymentsService Factory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z5ajeVMeFK4xruwI_ytjsA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/733d17c6d32e8140f2a2f963d349a6be/href">https://medium.com/media/733d17c6d32e8140f2a2f963d349a6be/href</a></iframe><p>Here we use abstract class because it allows us to define certain methods which can act as a common methods across the classes extending it unlike interfaces.</p><p>Please fine the part 2 for this medium article below</p><p><a href="https://m-chetandwarkani.medium.com/design-pattern-creational-low-level-system-design-singleton-builder-prototype-part-1-dbd6428c89b9">Design Pattern — Creational — Low level system design — Singleton, Builder, Prototype(part 1)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdb88ee2dc6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cracking System Design Interviews — part 1]]></title>
            <link>https://m-chetandwarkani.medium.com/cracking-system-design-interviews-part-1-b6214ac8ae5e?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6214ac8ae5e</guid>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[system-design-project]]></category>
            <category><![CDATA[amazon-interview]]></category>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 11:21:29 GMT</pubDate>
            <atom:updated>2022-07-26T12:06:10.559Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cracking System Design Interviews — part 1</h3><p>Let’s slay interviews 🎉</p><blockquote><strong>Interviewer: So can you give me an overview on the architecture you would adopt to build a good scalable system design</strong></blockquote><p>so do you want the system to be search oriented or it would be mostly on computations such as getting data, performing operations and returning data along with some big data</p><blockquote><strong>Interviewer: We’ll go with later. Can you explain me about that</strong></blockquote><p>So should I start with high level design or application level design</p><blockquote><strong>Interviewer: Let’s go with high level design</strong></blockquote><p>Oh Okay, firstly for starters, I would design my project adopting micro-service based event-driven strategy.</p><blockquote><strong>Interviewer: Oh can you talk more about that micro-service based event-driven strategy.</strong></blockquote><p>I would split my project into multiple autonomous subprojects which are independent of each other. All of them would communicate each other via gateway sub project. All of them will have their independent database which will act as a communication point. Also, I will dockerize my projects so that later when I wanna horizontally scale these individual sub projects, it could be easily done right away.</p><blockquote><strong>Interviewer: oh amazing, can you draw a quick picture of what you said</strong></blockquote><figure><img alt="Micro-service Based design" src="https://cdn-images-1.medium.com/max/737/1*pwNMPyL8u8ddupRQo8h5SQ.png" /></figure><blockquote><strong>Interviewer: Can you explain a bit more about how would you scale potentially with the above architecture when application load increases</strong></blockquote><p>So suppose if our<strong> “API microservice”</strong> in future starts getting huge number of request then it can be hosted as a new instance and wired via gateway which will simply load balance between these instances. Similar to this, if any of the other sub projects are receiving huge requests then we can adopt the same strategy to scale these dockerized instances. To achieve another level of scaling, we can also adopt clustering in application level where our code base will be deployed in multiple cores within single instance and become more powerful.</p><blockquote><strong>Interviewer: Amazing! As and then the project scales how would you manage this then</strong></blockquote><p>I will further adopt and wire Kubernetes in this so that we can manage and orchestrate these instances very well.</p><p>Next, I would setup an active and passive load balance configuration which will be wired and connected to gateway service. This active/passive LB will help in avoiding un-necessary single point of failure flow.</p><blockquote><strong>Interviewer: Amazing — can you draw a quick picture of this overall architecture design</strong></blockquote><p>Here, you go</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KflG_FTYX7j_Cta_VflzPg.png" /></figure><p>so basically all of my components would be scalable to a great way, everything is dockerized and also I forgot to mention, I would go with a CI/CD pipeline in order to ensure that in future we bring in continous integration and delivery mechanism</p><blockquote><strong>Interviewer: What about logs ?</strong></blockquote><p>For logs, As you can see in image, I will develop another sub project which would further store this log information in elastic DB. This will be wired in via gateway micro-service since that will act like an entry point for my overall project.</p><blockquote><strong>Interviewer: Can you talk about DBs, which framework you would select and why?</strong></blockquote><p>For this question on which DB to select and why based on CAP theorem is explained well in one of my separate blog I made. Please go through the below blog to understand about it: <a href="https://m-chetandwarkani.medium.com/understanding-data-structures-and-algorithms-used-in-order-to-select-the-right-framework-for-a-2132769f41b9"><strong>Link to the blog (click here)</strong></a></p><blockquote><strong>Interviewer: That’s great!</strong></blockquote><p>You can study in depth about these topic more in-depth through my youtube channel where I am practically coding this architecture out</p><p><a href="https://www.youtube.com/channel/UCLJNJK8rujZ8uBuRnNFR2mw/videos">Chetan Dwarkani | Let&#39;s code</a></p><p>My other medium blogs</p><p><a href="https://m-chetandwarkani.medium.com/">Chetan Dwarkani - Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6214ac8ae5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node.js performance optimization with clustering : Multiprocessing— System Design(part 7)]]></title>
            <link>https://m-chetandwarkani.medium.com/node-js-performance-optimization-with-clustering-multiprocessing-system-design-part-7-2a59e69530b4?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a59e69530b4</guid>
            <category><![CDATA[system-architecture]]></category>
            <category><![CDATA[multiprocessing]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[clustering]]></category>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Sat, 02 Apr 2022 12:53:37 GMT</pubDate>
            <atom:updated>2022-04-02T12:53:37.265Z</atom:updated>
            <content:encoded><![CDATA[<h3>Node.js performance optimization with clustering : Multiprocessing— System Design(part 7)</h3><p>While scaling the web app it is important to think about app performance when you reach millions of users or else it leads to a big chaos when your user base starts growing. Use of multi-processing in order to improve application performance is one of the basic optimization techniques to achieve scaling.</p><p>I am going to discuss and implement a simple strategy with which we can run multiple instances of our app in the possible set of CPU cores we have in our machine and also benchmark performance after using them.</p><p>You can watch the below video where I have implemented the same in a step by step manner if you are feeling bored to look at the textual info :P</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Frqvxd-4DDkY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Drqvxd-4DDkY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Frqvxd-4DDkY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4299ff1bab57afc743a54c7325fc658d/href">https://medium.com/media/4299ff1bab57afc743a54c7325fc658d/href</a></iframe><h3><strong>Benchmarks:</strong></h3><p>Before we get started, Please look at the below benchmark which I tried doing against a simple hello world app versus an app with the use of clustering in Node.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63d9691f0801d72649be9378098469e7/href">https://medium.com/media/63d9691f0801d72649be9378098469e7/href</a></iframe><p>Let’s get started</p><h3>Step 1: <strong>Including clustering module and forking processes</strong></h3><p>Import cluster module as well os module to count of no of cores in our cpu and as you can see in the below code if we are in master cluster then we simply fork our app instances and create a separate process each for a cpu core.</p><p>That’s it. Now simply run and you’ll see the difference.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e78015c34a85bfd2f1212239d2fbe46d/href">https://medium.com/media/e78015c34a85bfd2f1212239d2fbe46d/href</a></iframe><p>Step 2: Running the app. Haha, there is no step 2. You are done.</p><p>You can watch youtube video link as well where I have benchmarked the whole process in my system for your better understanding.</p><p>Thanks! Do subscribe for more updates.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a59e69530b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Data Structures and algorithms used in order to select the right framework for a…]]></title>
            <link>https://m-chetandwarkani.medium.com/understanding-data-structures-and-algorithms-used-in-order-to-select-the-right-framework-for-a-2132769f41b9?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/2132769f41b9</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[quorum]]></category>
            <category><![CDATA[cap]]></category>
            <category><![CDATA[system-design-project]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Fri, 25 Feb 2022 13:23:02 GMT</pubDate>
            <atom:updated>2022-02-25T13:27:31.362Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Data Structures and algorithms used in order to select the right framework for a scalable system— System Design(part 6)</h3><p>Really? Data structures in System design?</p><p>Well, Yeah! We do need to understand certain DS before we start our further course because a lot of frameworks works on these data structure</p><p>If you wish to see video explanation rather than textual then please checkout the below link</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZdw59XptFRM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZdw59XptFRM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZdw59XptFRM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc7fc8de6afa6352b3dcb036f9c100e0/href">https://medium.com/media/bc7fc8de6afa6352b3dcb036f9c100e0/href</a></iframe><p>Data structures acts as an important parameter in order to decide on which framework to use in system design interviews. For example, say if you are been told to pick up a database framework for faster search or say pickup database which can do faster search in text documents. Would you be able to pick it up without knowing which data structure does a framework use? Well, you would end up selecting wrong DB in order to do your task and eventually the whole system architecture and the company will suffer when millions of data records comes into picture. Every framework uses different data structures and it’s important to learn these different data structures. <strong>For ex: Mysql uses B+, Postgres uses B tree, Elastic search uses inverted indices etc.,</strong></p><p>Let’s learn about the data structures in depth.</p><p>Please find the below table which gives information about data structure used in different frameworks</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9a06dacaa375e44d68c049671a1274e/href">https://medium.com/media/f9a06dacaa375e44d68c049671a1274e/href</a></iframe><h4><strong>B+ trees and B tree</strong>:</h4><p>They are said to be one of the fastest search DataStructure. Mysql framework, for instance, creates a b+ tree whenever we do an index on a column and Postgres does a B tree for indices(However Postgres also has options of creating other types of indices on a column). B+ tree expands horizontally rather than vertically as compared to B tree and so it could be slightly faster than b tree but then storage space could be more. If you wish to understand this well then it would be better if you go through a quick video to understand how this DS works (Refer:<a href="https://www.youtube.com/watch?v=DqcZLulVJ0M&amp;t=440s"> link for B+tree</a> , <a href="https://www.youtube.com/watch?v=aNU9XYYCHu8&amp;t=622s">link for B tree</a>)</p><h4><strong>Inverted Indices:</strong></h4><p>It’s a simple and efficient algorithm in terms of searching in a document. Basically, words are been taken from multiple documents and every word has the mapping of which document it could be found and so this algorithm is one of the most preferred frameworks for searches in a document. Learn more about it here:<a href="https://www.youtube.com/watch?v=CeGtqouT8eA&amp;t=381s">link</a></p><p>There are also a few more concepts or say DS algorithm which should be well known before you build a scalable system design</p><h4><strong>1. CAP theorem (</strong>Consistency, Availability and partitioning) :</h4><p><strong>Consistency</strong>: This means that data when being read or written is consistent. At any point of time when the user tries to write the data to DB, he can and when he is trying to read the data, he always gets the latest data.</p><p><strong>Availability: </strong>This means that data is readily available in the system even if a server goes down.</p><p><strong>Partitioning: </strong>This implies on the fact that even if one of the nodes or slave server goes down, data should not get lost.</p><p>It is said that no framework by default offers all 3 capabilities until compromised with efficacy.</p><p><strong>For example:<br></strong>Let’s consider we have used the MySql framework and did a horizontal scaling with the help of the master-slave strategy. Now, you’ll end up seeing that you compromise on consistency because data are written might not be available at all servers at the same instant of time and if a read request is made on the same instant of time then the user might get old data. It doesn’t follow<strong> C in CAP by default.</strong></p><p>Let’s take an example of Cassandra: Here we have a problem with partitioning. In Cassandra data are stored by default using partition strategy so if one node goes down then the data loss might happen <strong>so it doesn’t follow P in CAP by default</strong>. This can be further achieved by adding the RF factor in Cassandra so that multiple replicas are available for every node.</p><h4><strong>2. Quorum:</strong></h4><p>Quorum theorem is used to improve the performance of consistency. The strategy is to say suppose we have multiple master-slave servers and a written request is been made. Data gets written on a few sets of servers while being processed further to be written in all servers and if a read request is made in the middle then sometimes the user might not get accurate data so to solve this quorum strategy is to check if the same data is available on at least x servers and if yes then that data is set to be consistent.</p><h4><strong>3. Bloom filter:</strong></h4><p>Bloom filter is a probabilistic data structure. If data is fore-sure not there then it returns true but it doesn’t assure if data exists in our storage. Bloom filter application is found in a lot of places and it is considered to be one of the best solutions when we want to insert data in millions of records. Say for example, if we have millions of records and a primary key, now when we want to insert a new key, it must be unique and in that case, bloom filter indexes help to sort it out amazingly by telling if an index is not there. On the other hand, Postgres also offers Bloom indexes which could be simply be created on a column. Here’s the link if you want to learn in-depth about it — <a href="https://www.youtube.com/watch?v=Bay3X9PAX5k">link</a></p><p><strong>4. Trie DS:<br></strong>Trie DS is one of the best prefix search algorithms today. A lot of business use cases desire to provide faster prefix search. Basically, trie DS creates a tree in which lookups can be made faster. Say, for example, we have a set of words for which prefix search is to be made faster then it creates a tree-like the below</p><p>Dog, Doctor, Dorm, Dell, Doom then a below tree gets created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y5SevywS15lNs8-1pAna6A.jpeg" /></figure><p>If you wish to learn in-depth then one amazing video for the same is here(<a href="https://www.youtube.com/watch?v=xrYTjaK5QVM&amp;t=1011s">link</a>)</p><h4>5. Gossip protocol:</h4><p>Gossip protocol is basically exchange of meta data between nodes or multiple DS in order to know the status of other nodes. This protocol is used by various frameworks to stay updated with recent statuses of other nodes. For instance, Cassandra uses gossip protocol to know the status of nodes in a cluster and decides on where request would go.</p><h4><strong>6. Consistent Hashing:</strong></h4><p>A lot of hashing strategies exist but this one is exceptionally used by various frameworks such as Cassandra to provide fault-tolerant mechanisms and optimize the minimal movement of data when a node goes down. This hash method has a different strategy for resolving collisions. Whenever you want to store the data, all you have to do is to search if hash value is exactly there in memory and store there or else store the data in an address whose value is higher than hash value. Whenever a collision happens, the idea is to move the data to the very next node after the collision rather than recomputing hash values of all data which were there in the crashed node. In this way, data movements are minimal. One of the videos which give a very clear explanation on the same is here→<a href="https://www.youtube.com/watch?v=bBK_So1u9ew">click here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2132769f41b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Load balancer, Docker, Kubernetes in your local — System Design (part 5)]]></title>
            <link>https://m-chetandwarkani.medium.com/setting-up-load-balancer-docker-kubernetes-in-your-local-system-design-part-5-5a393718d115?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a393718d115</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[system-design-project]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Tue, 25 Jan 2022 07:45:16 GMT</pubDate>
            <atom:updated>2022-01-25T07:45:16.883Z</atom:updated>
            <content:encoded><![CDATA[<h3>Setting up Load balancer, Docker, Kubernetes in your local — System Design (part 5)</h3><p><strong>So in our previous blogs, I have explained about the following</strong></p><ol><li><strong>Setting up Load Balancer using Nginx in local : </strong><a href="https://m-chetandwarkani.medium.com/setting-up-load-balancer-system-design-e29ed2b4a957"><strong>Medium Link</strong></a><strong> &amp; </strong><a href="https://www.youtube.com/watch?v=MRJZZ28kNM4&amp;t=30s"><strong>Youtube Link</strong></a></li><li><strong>Setting up Docker and containerizing the project: </strong><a href="https://m-chetandwarkani.medium.com/setting-up-docker-and-debugging-inside-the-docker-container-system-design-ee6acfbb9b7b"><strong>Medium Link</strong></a><strong> &amp; </strong><a href="https://www.youtube.com/watch?v=5lcvQLarsuY&amp;t=4s"><strong>Youtube Link</strong></a></li><li><strong>Setting up Kubernetes in local : </strong><a href="https://m-chetandwarkani.medium.com/setting-up-kubernetes-in-your-local-system-design-part-4-32b061e0c041?source=user_profile---------0-------------------------------"><strong>Medium Link</strong></a><strong> &amp; </strong><a href="https://www.youtube.com/watch?v=ih6Ze05QDbk&amp;t=38s"><strong>Youtube Link</strong></a></li></ol><p>If you have not gone through the above then please go through them before you go ahead with this blog. My youtube video links provided are short, practical, and to the point and they will help you to understand faster. In this blog, I am going to connect Load Balancer, Docker and use Kubernetes to scale my app.</p><p>If you do not want to read the text then please find the video for this blog here</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F53T9BulPW4U%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D53T9BulPW4U&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F53T9BulPW4U%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/412a1798ee77c84770f39adfd528d007/href">https://medium.com/media/412a1798ee77c84770f39adfd528d007/href</a></iframe><p>To recap:</p><p><strong>Load Balancer: </strong>Helps you to manage and distribute the requests across the servers<br><strong>Docker:</strong> Helps you to containerize your app<br><strong>Kubernetes: </strong>Helps in complete container orchestration.</p><p>and in this blog, I am going to setup the below architecture in our system locally</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*fmEEkaNaKeCH8PEDDebbPg.png" /></figure><h3>Step 1: Setup a Load balancer:</h3><p>Pull the image of Nginx and create it locally. After that set the config file for Nginx to map it to ports 1221, 1222, 1223. I had already done a blog explaining how to set up Nginx local and how to update the config file. Please check the link which I have mentioned in the pre-requisite if you wish to understand it in a better way.</p><h3>Step 2: Setup Docker and containerize the app:</h3><p>Now, let’s create 3 simple images which run on ports 1221, 1222, 1223 for the sample hello world project which we had made earlier. Please check the link at the top of this blog if you have not gone through it and you are not aware of how to create and dockerize a simple hello world app.</p><h3>Step 3: Create deployments and deploy the images inside the pod</h3><p>Launch the images inside the pods by creating 3 different deployments and hosting the images which we created earlier. Map those deployments with the services and expose them for ports 1221, 1222, 1223. If you have not read about Kubernetes deployment, pods and service then please go through my Kubernetes blog to understand how to set up Kubernetes local and use it. Link is mentioned at the top of this blog.</p><p>and we are done!!</p><p>You can go through my video blog link for the same where I have demonstrated on this overall architecture.</p><p><strong>If you wish to ramp up this in your local then please check the below play list</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMRJZZ28kNM4%3Flist%3DPLjQpZeN5Rc68noJRXOnUHOwLCqpYraa0s&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMRJZZ28kNM4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMRJZZ28kNM4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c05e7250a69cbd05162ad0680554f9c/href">https://medium.com/media/9c05e7250a69cbd05162ad0680554f9c/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a393718d115" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Kubernetes in your local — System Design (part 4)]]></title>
            <link>https://m-chetandwarkani.medium.com/setting-up-kubernetes-in-your-local-system-design-part-4-32b061e0c041?source=rss-926831bae034------2</link>
            <guid isPermaLink="false">https://medium.com/p/32b061e0c041</guid>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[kubernetes-engine]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[pods]]></category>
            <dc:creator><![CDATA[Chetan Dwarkani]]></dc:creator>
            <pubDate>Wed, 19 Jan 2022 17:10:00 GMT</pubDate>
            <atom:updated>2022-04-01T10:12:31.699Z</atom:updated>
            <content:encoded><![CDATA[<h3>Setting up Kubernetes in your local — System Design (part 4)</h3><p>So we have discussed basics about how to develop a simple hello world API service, set up a simple load balancer in our system, and dockerize the project on our previous blogs. I am attaching the link for your reference below. It would be good to know the below concepts before you start working on Kubernetes</p><ol><li><a href="https://m-chetandwarkani.medium.com/scaling-your-backend-service-system-design-158ba107d0d8">System Design Overall -System Design (part 1)</a></li><li><a href="https://m-chetandwarkani.medium.com/setting-up-load-balancer-system-design-e29ed2b4a957">Setting up Load Balancer -System Design (part 2)</a></li><li><a href="https://m-chetandwarkani.medium.com/setting-up-docker-and-debugging-inside-the-docker-container-system-design-ee6acfbb9b7b">Setting up Docker and debugging inside the Docker container — System Design (part 3)</a></li></ol><p>In this blog we are going to setup Kubernetes in order to manage our docker containers. Please watch the below video which explains everything in this blog in a clear manner if you do not feel like reading through the text</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fih6Ze05QDbk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dih6Ze05QDbk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fih6Ze05QDbk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cac1e1c46e3df8257fad7254f5d29bc/href">https://medium.com/media/8cac1e1c46e3df8257fad7254f5d29bc/href</a></iframe><h3><strong>What’s Kubernetes?</strong></h3><p>Kubernetes is a container orchestration tool that helps you manage and scale your containers. It is an amazing framework that runs with no downtime and helps you to simplify the process to observe and manage downtime of your services and also to maintain replicas to restore it on the same state.</p><p>So here’s the Kubernetes architecture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2TKzE_SDNGy54gA9Imridw.png" /></figure><p>As you can see in the image, everything in Kubernetes is inside a cluster and there can be multiple clusters as well. A cluster can have one or more master nodes whose primary responsibility is to manage all the worker nodes. So everything you wish inside a Kubernetes cluster environment is through a master node. We will set this master node up below to understand in a detailed manner.</p><p><strong>Master nodes </strong>have the following components</p><p><strong>API server</strong>: It’s responsible to do any kind of task. It holds API which helps to perform the tasks. Kube API server can be accessed via Kubectl and UI.</p><p><strong>etcd</strong>: Backing store brain of Kubernetes cluster</p><p><strong>Controller manager: </strong>The controller<strong> </strong>manager is responsible for the creation and maintenance of PODS, cluster, worker nodes. All requests of such goes to the controller manager.</p><p><strong>Scheduler</strong>: Looks after which nodes are empty in cluster based on resource occupancy and helps further in allocating pods to a particular node.</p><p><strong>Worker Node</strong> on the other hand has the below components:</p><p><strong>Container Runtime: </strong>Owns an environment to run containers such as Docker.</p><p><strong>Kubelet: </strong>It helps to manage and deploy pods inside the container.</p><p><strong>pods: </strong>They form the smallest unit and holds the container</p><p>Apart from that we also have other components in Kubernetes such as</p><p><strong>Services: </strong>They act as a load balancer and help in communication between pods or to distribute the data between the pods which have their replications.</p><p><strong>ConfigMap: </strong>This stores the IP address mapping of pods so that one node can refer to that IP address rather than changing the IP address its referring to when the other pod goes down.</p><p><strong>Secret Key: </strong>This is responsible for storing authenticated data information such as passwords globally. They can be accessed via pods.</p><p><strong>Let’s roll down into implementation of Kubernetes in our local system and then we’ll look into all of these aspects as and then we code</strong></p><h3><strong>Step 1: Enable Kubernetes in Docker Desktop</strong></h3><p>You can also use the option of using minikube and it’s a very simple tool to create a cluster in your local but if you have followed my previous blog then you will know that we were using Docker desktop to create containers. I will use the same for starting Kubernetes engine in my local as well</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vMWKp3yM4Rvmt1v9ORAppw.png" /></figure><p>So simply open Docker desktop app → Select settings → Click on Kubernetes option in left list → Select Enable Kubernetes</p><p>and that’s it, you are done.</p><p>Docker engine will then create the whole setup of Kubernetes requirements and dependencies such as proxy, API servers etc., in a separate container and start the containers. Once you see the green color as in the image, it means your Kubernetes master node is ready. You can further see the status in the below section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_4GmWQsV_Z9hkeLnw68IQ.png" /></figure><p>Also, now, kubectl command will become accessible in your local system so you can type the below command to check what nodes has been created</p><blockquote>kubectl get nodes</blockquote><p>and you’ll find that a cluster has been created with the role of master.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*xuStGYGMdFTsF-tzyOT43g.png" /></figure><h3><strong>Step 2: create deployments and run an image inside POD</strong></h3><p>Everything in Kubernetes is done via deployment. Deployment is like a wrapper for pods and containers in Kubernetes. The first step is to create a deployment for our image using the below kubectl command</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cab94ddf51c22302bcbb1dafd66e6b6/href">https://medium.com/media/5cab94ddf51c22302bcbb1dafd66e6b6/href</a></iframe><p><strong>Please make sure that you have build a image locally with 0.1 tag in order to run the above. If you are not aware on how to build an image then please refer my docker video to understand — </strong><a href="https://www.youtube.com/watch?v=5lcvQLarsuY&amp;t=683s"><strong>here</strong></a></p><p>Once you do the above, you need to type</p><blockquote>kubectl get deployments</blockquote><p>and you’ll find your deployment there</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K2by99WItGf0z1h_qaYcJA.png" /></figure><p>A pod will automatically get created which will hold the container running the image you specified in your deployment command above. To see the pods, please type</p><blockquote>kubectl get pods</blockquote><p>and you’ll see the pod list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lEbMUk_7PlGKRn5msaWFTw.png" /></figure><p>Every pod has a YAML config file which is holding all info about your pods such as which image is the container of your pod running and all the other status of ports and pod replica factors etc., To see the config for the above pod which has the pod name — simple-node-backend-86f694b75b-l2sp2 , please type the below command</p><blockquote>kubectl get pod simple-node-backend-86f694b75b-l2sp2 -o yaml &gt; my-new-pod.yaml</blockquote><p>Please check the below link which got generated in my local. You must find a similar file getting generated when you type the above command. You need to make sure that container port is correctly set as seen in the image.</p><p><a href="https://gist.github.com/cdwarkani/34c2680ac0ffe0d17a95ccb232131b58">https://gist.github.com/cdwarkani/34c2680ac0ffe0d17a95ccb232131b58</a></p><p>containerPort says about the port you need to expose from inside the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*FB0u-NLKoTf9672v1DqMxQ.png" /></figure><p>If you wish to edit and reupload the file in the pod then simply use the below command</p><blockquote>kubectl apply -f my-new-pod.yaml</blockquote><p>Next, we need to create service with the below command</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1b6276463a0a064c55b7de144c86553/href">https://medium.com/media/d1b6276463a0a064c55b7de144c86553/href</a></iframe><p>This will create a service, link it with your deployment and host it in 1221. To check if service got created please type</p><blockquote>kubectl get svc</blockquote><p>Next, you can access your service from your system via browser and you’ll see the below image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgGynABkPkeoNNq3US-9Nw.png" /></figure><p>and you are done with kubernetes setup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32b061e0c041" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>