<?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 Damsak Bandara on Medium]]></title>
        <description><![CDATA[Stories by Damsak Bandara on Medium]]></description>
        <link>https://medium.com/@damsak?source=rss-d581cb27f2f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jbe3BhQiZVv1Sdvruxvebw.jpeg</url>
            <title>Stories by Damsak Bandara on Medium</title>
            <link>https://medium.com/@damsak?source=rss-d581cb27f2f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 19:18:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@damsak/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[Harvest Home — Organic Home Farming System]]></title>
            <link>https://damsak.medium.com/harvest-home-organic-home-farming-system-2c9394a30401?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c9394a30401</guid>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Sun, 06 Oct 2024 01:20:46 GMT</pubDate>
            <atom:updated>2024-10-06T01:20:46.431Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Harvest Home — Organic Home Farming System</strong></h3><blockquote><strong><em>“SAVE Money — LIVE Longer”</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3MpuGoH_tytUqByW8HPyA.jpeg" /></figure><h3>Introduction</h3><h4>Background</h4><p>The history of mankind went through several revolutions and Information and Communication Technology can be considered as the latest one. This revolution resulted in the advancement of Information technology and associated resources which increased the use of computing technology in many applications across the world. Agriculture is a section that has been continuously improved with the advancement of technology. The increased access to the internet and other resources is the major factor for this contribution. According to the article [1], 40% of the world&#39;s population has access to the internet and 90% of the world’s data has been generated within the last 2 years. These numbers grow annually, and it is making a massive impact on the daily activities of all living beings.</p><p>Agriculture is the practice of cultivating plants and livestock. However, present-day agriculture is not a simple process. Cultivating a crop on a large scale requires various activities and monitoring to ensure a maximum yield of crops. Fertilisers and pesticides play a major role in this. Almost all the farmers use one or many fertilisers to improve the quality and quantity of their crops. There are many negative effects of these chemicals. They are harmful to the consumers and to the environment as well. The most recent example is the kidney problems caused for the farmers in the North Central province of SRI LANKA with the use of these chemical fertilisers and pesticides.</p><p><strong>Organic farming is a concept that has been emerged to fight against the use of chemical fertilisers and pesticides.</strong> Organic Agriculture sustains the health of soils, ecosystems, and people with the help of ecological processes. This simply means that the crops will be cultivated without the use of chemical fertilizers and pesticides in an organic manner. There are many advantages of this method.</p><p>1) Healthier food items.</p><p>2) Good for the environment</p><p>3) Efficient use of resources</p><p>4) Potential Profits</p><p>However, there are many disadvantages associated with organic farming.</p><p>1) Higher Costs</p><p>2) Lack of infrastructure</p><p>3) More knowledge Intensive</p><p>4) It May not truly be organic.</p><p>Organic products have a much higher price compared to non-organic traditional products. This makes it difficult for the farmers to sell the harvest in the market. Moreover, the lack of infrastructure and intensive need for knowledge makes it difficult for the cultivators to produce on a large scale.</p><p><strong>Home cultivating</strong> is another emerged concept to fight against the use of chemical fertilizers. The main reason for this is the increased concern on the health/well-being of an individual and to avoid the use of food items with various chemicals. However, there are some challenges to this home cultivating concept.</p><p>- Lack of knowledge to start.</p><p>- Lack of guidance.</p><p>- Lack of optimization techniques.</p><p>- Lack of Maintenance.</p><p>-Lack of Encouragement.</p><blockquote><strong><em>An organic home farming system will be the ideal solution for this. The proposed system will have a platform with various features that will help an individual to start the growing process from scratch. All the features and functionality will be discussed in the upcoming sections. This system will help for the overall development of sustainable home agriculture and reduce the use of harmful chemical fertilisers .</em></strong></blockquote><h3><strong>Problem</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cgOrz51KVLkuySPP0XOQpA.jpeg" /></figure><p>Fertilizers and pesticides play a major role in the field of agriculture. According to the article [2], there are 2 main fertilizers available in the market.</p><p><strong>Organic Fertilizers: </strong>These are the naturally produced fertilizers and they mainly contain Carbon. These fertilizers provide nutrients to the plant and sustain growth.</p><p><strong>Chemical Fertilizers: </strong>Chemical fertilizers are synthetic fertilizers created from natural sources of nutrients using manufacturing processes. Plants can readily use these fertilizers.</p><p>As mentioned in the previous section, Chemical fertilizers have several negative effects. According to the article [3], there are 2 main significant effects.</p><p>1) Destroy the soil and environment.</p><p>2) Get stored in crops.</p><p><strong>Hence it can be concluded that chemical fertilizers should be prohibited.</strong> <strong>The use of organic fertilizer is a possible solution to this problem. But it is hard to completely rely on these organic fertilizers as there are significant disadvantages (as mentioned in the previous section).</strong></p><p><strong>Home Farming</strong></p><blockquote><em>Home farming is another concept that emerged to solve this problem. This basically means that the people tend to produce their own vegetables and fruits to an extent which they can maintain. This can be done in a healthier manner and without the use of harmful chemicals and pesticides. It is not restricted to farmers and can be done by anyone who has some time to spare.</em></blockquote><h4><strong>The Main Problem</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*nIT4uGL9SOX7c4aChsh94w.jpeg" /></figure><p>The lack of knowledge is the main challenge for home farming. As most of the home farmers come from a non-agricultural background, they lack the knowledge needed to start the growing process. The factors like geographical location, climate, humidity affect the outcome of the process. The internet is a great place for a new home farmer to gather the required knowledge. Various websites available on the internet will provide the necessary guidance and steps to initially start the process. <strong><em>But this guidance is not enough for an individual to successfully maintain and yield optimum results for a long time.</em></strong> Consider the following scenarios,</p><p><strong>Land: </strong>The space available for farming is not the same for all the cultivators. As an example, the people living in the urban and suburban areas may have limited space. But people in the rural areas may have enough space to do large cultivation. Some of the crops may need a large space where some other crops may need a little space to grow.</p><p><strong>Monitoring: </strong>Keeping track of the crops is an essential part of the home farming process. The activities such as watering, changing of soil should be done in proper time intervals to yield the optimum results.</p><p><strong>Crops:</strong> A home farmer may not have time to do research and find the best crops for his or her farm. Therefore it is important to have a system that can identify and suggest suitable crops for the farmer.</p><p><strong>Motivation:</strong> Motivation is also an important factor to keep the home farming process alive.</p><p>These are some of the problems faced by home farmers.</p><h3><strong>Solution</strong></h3><blockquote><em>“HOME FARMING TO THE RESCUE”</em></blockquote><blockquote><em>Say No to Chemicals and grow your own vegetables with the proposed Home Farming System.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*oczyG3FXcQG7AzpetfMSog.jpeg" /></figure><ul><li>As mentioned in the previous section, the use of chemical fertilizers is harmful to consumers and to the environment. <strong>Home farming is the best alternative to this problem</strong>. It can be used to generate healthy vegetables and fruits with no chemical fertilizers.</li><li>But the lack of knowledge and monitoring is the main problem faced by any individual who plans to start a home farm. The individual may also lack information about which crops to plant, the maintenance procedure, etc.</li></ul><h4>Proposed solutions for the identified problems in the home farming sector</h4><blockquote><strong><em>An organic home gardening system will be the ideal solution</em></strong><em>. The users can get the cultivate their own crops without the use of chemical fertilizers and pesticides.</em></blockquote><p>The proposed system will have the required features that will help to solve the above-mentioned problems to a great extent.</p><ol><li><strong>The problem of Land</strong></li></ol><ul><li>As mentioned in the previous section, space utilization is a common problem faced by all home farmers. The <strong>garden setup module</strong> is specifically designed to address this issue. The users can browse through the <strong>available crops</strong> and <strong>select suitable crops for the targeted land</strong>.</li><li>The users can also create a garden with the selected crops. The system will track the space used by each and every plant in order to better utilize the limited space.</li><li>This will help the users to easily optimize the limited land and yield optimum results.</li></ul><p><strong>2. Lack of Monitoring</strong></p><ul><li>Monitoring and Maintenance are important factors that contribute to the growth and well-being of the crops. This should be done in relevant time intervals with correct maintenance mechanisms.</li><li>There are several essential factors that should be monitored constantly to yield optimum results — <strong>soil moisture levels, air temperature, soil temperature, and fertilizer levels.</strong></li><li>It&#39;s a hassle to manually remember these schedules and the required mechanisms. The proposed system has a separate module for this. This module will maintain the necessary information regarding these factors and notify users.</li></ul><blockquote>Note: These values are coming from the sensors placed within the garden.</blockquote><p><strong>3. Lack of Motivation</strong></p><ul><li>Motivation is another important factor that helps to the sustainable continuation of a home farm. The lack of motivation will make the cultivators lose interest in the created farm.</li><li>The proposed system has a feedback module and a points module to specifically address this issue. These modules will have features like the price calculator, display health benefits, etc to motivate the user and keep the cultivating process alive.</li></ul><blockquote>Note: Requirements section will further explain the available modules.</blockquote><p><strong>The Ultimate Goal of the Solution: </strong><em>Promote organic home cultivation in every household and minimize the consumption of food items with harmful chemicals and pesticides.</em></p><h3><strong>Requirements</strong></h3><h4><strong>Functional Requirements with expected Outcomes</strong></h4><p><strong>Registration and Login</strong></p><ul><li>Register and Login to the system.</li></ul><p>The primary goal of this module is to enable users to have their own customized home garden set up with security in place.</p><p><strong>Garden setup</strong></p><ul><li>Browse through the suitable crops.</li><li>View possible purchasing places.</li><li>Create the garden setup.</li></ul><p>This module will help the user to browse the required products and choose the correct crops for their home garden. Then the user can create a mock home garden with the selected crops. The primary goal is to easily provide the required crops and enable the user to create a home garden with the selected crops.</p><p><strong>Maintenance</strong></p><ul><li>Customized plan for the maintenance activities.</li></ul><p>The maintenance module will help the users to do the maintenance activities with a customized plan. The primary goal of this module is to remove the burden of having to remember the necessary activities regarding the crops.</p><p><strong>Feedback</strong></p><ul><li>Price calculator for the crops and potential outcome.</li><li>Display saved amount by growing in the home garden without purchasing from the market.</li><li>Display the potential health benefits.</li></ul><p>A sense of achievement and satisfaction is an important factor that contributes to the success of a system. The goal of this module is to give the user a sense of achievement by methods such as price calculator, health benefits dashboard, etc. <strong><em>This will motivate the user to cultivate more crops and engage with the system for a longer period of time.</em></strong></p><p><strong>Points System</strong></p><ul><li>A Points system based on the cultivated crops.</li></ul><p>A submodule of the Feedback system that will help to create competition among the home farmers using a points table.</p><p><strong>Profile Service</strong></p><ul><li>Display details regarding the user.</li></ul><p>This module will display a summary of the overall details regarding the user and cultivated crops.</p><h4>Non-Function Requirements</h4><ul><li>Performance</li><li>Scalability</li><li>Availability</li><li>Maintainability</li></ul><h4>Restrictions</h4><ul><li>Allow only the legal plants/vegetables.</li><li>Restrict the use of chemical fertilizers/pesticides.</li></ul><h3>Technology Stack</h3><ul><li><strong>The frontend of the Application:</strong> <em>Angular 11</em></li></ul><p>Reasons —</p><ol><li>One of the most famous Javascript frameworks for front-end development and it is written in Typescript.</li><li>Supports Mobile browsers. Allows the users to access the system from anywhere.</li><li>Highly extendable and maintainable. This will allow the developers to easily add new features to the system.</li></ol><ul><li><strong>The Backend services of the Application:</strong> NestJS</li></ul><p>Reasons —</p><ol><li>A popular opinionated framework for developing server-side NodeJS applications. Therefore it’s ideal for creating microservices.</li><li>NestJS applications are highly scalable and loose coupled.</li></ol><ul><li><strong>Database: </strong>PostgreSQL for all the services</li></ul><p>Reasons —</p><ol><li>A highly secure and scalable database.</li></ol><ul><li><strong>Data Query and Manipulation:</strong> GraphQL</li></ul><p>Reasons —</p><ol><li>The proposed system needs to fetch nested data that is spread across several microservices. Graphql helps to achieve this functionality with a single call.</li><li>The frontend Angular application can easily get the required fields(only the required fields) according to the schema.</li></ol><ul><li><strong>Authentication and Authorization:</strong> KeyCloak</li></ul><p>Reasons —</p><ol><li>Easily enable the Single Sign-On (SSO) feature.</li><li>In build with many different features that can be useful for future implementations(example- Social login).</li></ol><h3>Implementation</h3><h4>Features</h4><p><strong>Registration and Login</strong></p><ul><li>Authentication and Authorization will be done with the help of Keycloak. The active directory will be used to enable the single sign-on (SSO) feature.</li></ul><p><strong>Garden setup</strong></p><ul><li><strong><em>Standalone GraphQL API.</em></strong></li><li>This module will be a separate Microservice with its own dedicated database.</li><li>The NestJS backend will handle,</li></ul><ol><li>Retrieve different crops from the database and pass them to the frontend.</li><li>Handle the data coming from the front end regarding the garden setup.</li></ol><p><strong>Maintenance</strong></p><ul><li><strong><em>Standalone GraphQL API.</em></strong></li><li>This module will also be a separate Microservice with its own dedicated database.</li><li>NestJS backend will handle,</li></ul><ol><li>Create custom maintenance plans for the users(based on user inputs).</li><li>Optimize the available plans.</li></ol><p><strong>Feedback</strong></p><ul><li><strong><em>Standalone GraphQL API.</em></strong></li><li>This module will also be a separate Microservice with its own dedicated database.</li><li>NestJS backend will handle,</li></ul><ol><li>Maintain the costs related to the planted crops.</li><li>Compare prices.</li><li>Identify and display health benefits.</li><li>Maintain the calculated points of a particular user.</li></ol><p><strong>Profile Service</strong></p><ul><li><strong><em>Standalone GraphQL API.</em></strong></li><li>This module will also be a separate Microservice.</li></ul><p><strong>Points System</strong></p><ul><li><strong><em>A REST API.</em></strong></li><li>This module will also be a separate Microservice.</li><li>This service will communicate with the Garden service and feedback service to calculate and send the relevant points of a particular user.</li></ul><h3>System Architecture</h3><p>The system architecture should be selected carefully in order to successfully implement the above-mentioned solution. There are several architectural patterns that can be used. This proposed system will be implemented using the Microservices architecture.</p><p><strong>Stage 1: Initial Implementation</strong></p><p>Implementation: <strong>Apollo Federation Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*AZJXRc6giOr6a9YpOcPSBg.jpeg" /></figure><p><strong>2nd Stage: A cloud deployable stack</strong></p><p>This will be developed according to the following architecture.</p><p>Possible changes in the architecture -</p><ul><li><strong>Introduce AWS AppSync:</strong> GraphQL Api Service with built-in security and caching.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bBfujWRFV8lMH-qKBW1bDQ.jpeg" /></figure><h3>Important Points — System Architecture</h3><h4>- Communication of the Points Service in Stage 1</h4><p>The Points service needs to communicate with the Garden and Feedback service to calculate the points. The Currently proposed implementation will be done using direct calls(REST). However, the implementation can also be done using <strong>Redis.</strong></p><p>Redis: A powerful in-memory data store that can be used as either a high-performance key-value store or as a message broker.</p><blockquote><strong><em>Note: Redis Message broker may later be implemented in case of additional services and communications.</em></strong></blockquote><h3>GitHub Repository of the Project —</h3><p><a href="https://github.com/Damsak/HarvestHome-LP-Project">GitHub - Damsak/HarvestHome-LP-Project</a></p><h3>CURRENTLY IMPLEMENTED FEATURES —</h3><ol><li><strong>Authentication —</strong></li><li>Single Sign On feature with Keycloak and Active directory.</li><li>Create, Edit, update and delete garden with the UI and view.</li><li>Create, Edit, Update and delete profiles.</li><li>One to Many relationships. ( One profile can have many gardens)</li><li>Create, Edit, update and delete Crops with the UI and view.</li></ol><p><strong>6. Monitoring service</strong></p><ol><li><strong>Monitoring service that will take the values from the database( soil moisture, air temperature, fertilizer levels and display the average levels on the monitor dashboard.</strong></li><li><strong>The monitoring service will also get the crops from the database and get the needed soil moisture, air temperature, and fertilizer levels. Then it will compare those values with the existing average values and display the status within the monitoring dashboard. ( High, medium, low, or none).</strong></li></ol><p><strong>7. Maintenance Service —</strong></p><ol><li>Currently have 3 basic plant maintenance plans.</li><li>Users can also add create, edit or delete their own custom maintenance schedules.</li><li><strong>The system will SELECT THE OPTIMUM Maintenace PLAN based on —</strong></li></ol><ul><li><strong>The number of crops planted.</strong></li><li><strong>Predefined level of soil moisture, air temperature, and organic fertilizer levels and the current required levels.</strong></li></ul><p>The selected maintenance plan will be displayed along with the other available plans.</p><p><strong>7. Profits —</strong></p><ol><li>Calculate the total cost(amount of money spent for the crops) for the available crops and display it.</li><li>Also displays the amount of money spent for each different crop along with its name.</li></ol><h3>Future Improvements</h3><ol><li>A marketplace to sell excess produce.</li></ol><p>This feature will help users to earn an extra income by selling the excess produce.</p><p>2. Integration with local organic farming authorities to get the latest trends and news in the sector.</p><p>3. Referral System where a user may get additional points by registering a new user to the system.</p><h3>References</h3><ol><li><a href="https://leftronic.com/blog/how-fast-is-technology-growing-statistics/">https://leftronic.com/blog/how-fast-is-technology-growing-statistics</a></li></ol><p>2. <a href="https://www.journey2050.com/conventional-organic-fertilizer/">https://www.journey2050.com/conventional-organic-fertilizer/</a></p><p>3. <a href="https://www.sciencedirect.com/topics/agricultural-and-biological-sciences/chemical-fertilizer">https://www.sciencedirect.com/topics/agricultural-and-biological-sciences/chemical-fertilizer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c9394a30401" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CQRS Design Pattern]]></title>
            <link>https://damsak.medium.com/cqrs-design-pattern-374e44e0b538?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/374e44e0b538</guid>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Sun, 06 Oct 2024 01:19:29 GMT</pubDate>
            <atom:updated>2024-10-06T01:19:29.109Z</atom:updated>
            <content:encoded><![CDATA[<h3>Overview</h3><p>CQRS stands for Command Query Responsibility Segregation. This pattern focuses on <strong>separating the command and query sides of the application architecture</strong>. The overall flexibility of the application is increased.</p><ul><li><strong>Command</strong>: Change the state of the system but do not return a value</li><li><strong>Query</strong>: Do not change the state of the system but returns a value.</li></ul><p>2 different data models are used to query and update the database. This pattern helps applications maximize performance, scalability, and security. CQRS pattern is based primarily on the Command Query Separation Principle(CQS).</p><blockquote><strong>CQS</strong> — Every method should either be a command that performs an action, or a query that returns data to the caller, but not both.</blockquote><h3>Why we need a pattern like this?</h3><p>The use of one data model for querying and updating a database will work for most of the applications. However, with the advancement of technology, the applications become more complex. They may need to support various complex operations and the traditional way of using the same data model won’t be a good choice as we see in the next section of this article.</p><h4>Popular Scenarios where we can use CQRS</h4><ul><li>When the business requirements of the application change a lot.</li><li>When there are issues related to scalability.</li><li>When multiple services deal with the same resource.</li><li>When the business doesn&#39;t know exactly where it&#39;s heading.</li></ul><h3>References —</h3><p><a href="https://www.baeldung.com/cqrs-event-sourcing-java">CQRS and Event Sourcing in Java | Baeldung</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=374e44e0b538" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices (Part 5) — Design Patterns for Microservices(Proxy Pattern)]]></title>
            <link>https://damsak.medium.com/microservices-part-5-design-patterns-for-microservices-proxy-pattern-12562f5987d2?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/12562f5987d2</guid>
            <category><![CDATA[microservices-pattern]]></category>
            <category><![CDATA[proxy-pattern]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[proxy]]></category>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Mon, 28 Jun 2021 03:23:27 GMT</pubDate>
            <atom:updated>2021-06-29T00:38:52.055Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microservices (Part 5) — Design Patterns for Microservices(Proxy Pattern)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jA3LQjldv6ybr3-WkZ4Fwg.jpeg" /><figcaption>Fig 1: Proxy Pattern (Source: Google)</figcaption></figure><p>The proxy pattern is simply another variation of the <a href="https://medium.com/nerd-for-tech/microservices-part-3-design-patterns-for-microservices-aggregator-pattern-75229280399a">Aggregator Pattern</a>. In this pattern, the aggregation doesn&#39;t happen on the client side. A Separate Microservice will get invoked based on the requirement.</p><p>The difference,</p><p><strong>Aggregator Pattern:</strong> Invokes multiple services to get the responses required by the application. Aggregation of data.</p><p><strong>Proxy Pattern: </strong>No aggregation of data.</p><p>Let’s try to understand the Proxy pattern with the help of an example.</p><p>Think about a scenario where we have a large monolithic application and the management team decides to migrate it to the new Microservices architecture. We can use different software development methodologies to achieve this. If we use the Agile methodology,</p><ul><li>Start deploying the application part by part. That means one functionality after the other. It may take several months to complete the overall system.</li><li>However, there may be instances where we need to change the previously deployed services. This can create problems.</li></ul><p><strong>Example:</strong> Consider the following scenario.</p><p>Assume that we have a Microservice to get Hotel Guest information. This information is retrieved bypassing the Guest Code.</p><p>However, with the upcoming changes, developers decided that it is better to retrieve Guest information with the help of “Guest ID” instead of “Guest code”.</p><p><strong>Updated Requirement:</strong> Get information with the Guest ID instead of the Guest code.</p><p>We can implement this will the help of versioning.</p><p>Version 01: Pass Guest code.</p><p>Version 02: Pass Guest ID</p><p>However, we cannot deploy the system as it is. We have to use the Proxy pattern and create a separate Proxy service. All the consumers have to come through this proxy service. We can configure the proxy to route the request to the correct version by checking the particular field value (Guest code or Guest ID). This implementation helps to deploy services without disturbing the customer.</p><p><strong>What about the service discovery?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7yBkqvpOLpxeAdpv-iVKg.png" /><figcaption>Fig 2: Serice Discovery(Source: NGINX)</figcaption></figure><p>Whenever we create a service, it&#39;s always better to use an external party to discover the service. Why?</p><p>Easily handle the infrastructure changes. The hostnames, IP addresses, etc can change in the Microservices architecture. We can implement a service discovery tool and configure the Proxy to communicate with this tool. Then the tool can provide the locations of the services to the Proxy. Consul by HashiCorp, WSO2 Governance Registry are some of the popular service discovery tools.</p><h3>Important Points</h3><ul><li>The proxy pattern implementation is similar to service chaining. This introduces the risk of cascading failure. This may result in blocked system resources and the failure of several services.</li></ul><p>Solution,</p><h4>Message Queues</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*Xu8RnlfibaHx1zzf9w5QeQ.jpeg" /><figcaption>Fig 3: Message Queues</figcaption></figure><p>It is basically a queue of messages sent between two applications. In other words, it contains a list of objects(in correct order) that needed to be processed. This helps to overcome cascading failure. But have to consider facts like queue failure before implementing the message queues. Therefore we need to have redundant mechanisms in this type of architecture.</p><ul><li>The developers must pay attention to the Thread pools before implementing the Proxy Pattern. That is because the incorrect implementation of threads can block certain services in the architecture. As a solution, the developers can use multiple thread pools or thread handover mechanisms.</li><li>Timeout is also another important concept to the Proxy pattern. Consider a situation where we have a proxy service that directs traffic to 2 versions of a service. The timeout is important to make sure that one version will not affect the other version in case of failure.</li></ul><p>I have used the following playlist by Mr.<a href="https://krish-blog.medium.com/">Krishntha Dinesh</a> to gather the required information.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fplaylist%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcUiU8yDdQmw%2Fhqdefault.jpg%3Fsqp%3D-oaymwEWCKgBEF5IWvKriqkDCQgBFQAAiEIYAQ%3D%3D%26rs%3DAOn4CLCsj5JRhnauYqyNTpdPx5mnRaz3jQ%26days_since_epoch%3D18790&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="853" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a9c8f63012172aa83c1c5748a983285/href">https://medium.com/media/2a9c8f63012172aa83c1c5748a983285/href</a></iframe><h3>References</h3><ul><li><a href="https://www.nginx.com/blog/service-discovery-in-a-microservices-architecture/">Service Discovery in a Microservices Architecture - NGINX</a></li><li><a href="https://www.tutorialspoint.com/design_pattern/proxy_pattern.htm">Design Patterns - Proxy Pattern</a></li><li><a href="https://en.wikipedia.org/wiki/Proxy_pattern">Proxy pattern - Wikipedia</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12562f5987d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices (Part 4) — Design Patterns for Microservices (Circuit Breaker Pattern)]]></title>
            <link>https://damsak.medium.com/microservices-part-4-design-patterns-for-microservices-circuit-breaker-pattern-5456efafba48?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5456efafba48</guid>
            <category><![CDATA[microservices-pattern]]></category>
            <category><![CDATA[circuit-breaker-pattern]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Tue, 08 Jun 2021 06:52:41 GMT</pubDate>
            <atom:updated>2021-06-09T00:46:25.348Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microservices (Part 4) — Design Patterns for Microservices (Circuit Breaker Pattern)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*HT4aQBB4fpv_ZQXlc2iR3Q.jpeg" /><figcaption>Fig 1: Circuit Breaker (Source: Google)</figcaption></figure><p>The circuit Breaker pattern is another popular design pattern used in Microservices Architecture. This pattern falls under the category of sustainable design patterns. That means it helps to keep a particular service alive without failing. Availability is a crucial factor in Microservices Architecture. Therefore it is important to implement a way to overcome these failures.</p><p>Think about the microservices architecture. There are many remote calls between different services in the system. Unlike in-memory calls, these remote calls have a high possibility to fail at a given instance. These failures can occur due to network issues, timeouts, etc. There could also be failures caused by unanticipated events and the fixing time will be high for these. Sometimes these services may completely fail.</p><p>In such situations,<strong> the requesting services should accept these failures and move on without waiting for a particular service</strong>.</p><p>Sometimes these failures may propagate and cause Cascading failures.</p><h3>Cascading Failure</h3><blockquote><strong><em>A process in a system of interconnected parts in which the failure of one or few parts can trigger the failure of other parts and so on.</em></strong></blockquote><blockquote><strong><em>-Wikipedia</em></strong></blockquote><p>Example:</p><p>Think about a situation where service A invokes service B. However the service B is not working properly. Now the invoking service will wait till timeout and send a response back saying that it is not available. This is okay as it is just 1 request.</p><p><strong>What if B is a high demanding service?</strong></p><p>Service B will receive a large number of requests. Then this implementation will cause these concurrent requests to be blocked until the timeout expires. This causes the Cascading Failure.</p><p><strong>Why this is dangerous?</strong></p><p>These blocked requests may hold valuable system resources such as threads, memory, etc. This could cause the other parts of the system to fail. That is why Microservices always follow the “<strong>Fail Fast, Fail Silent, Fallback”</strong> principle.</p><h3>Solution</h3><h4>Circuit Breaker Pattern</h4><ul><li>This is a useful pattern to overcome the above-mentioned problem. It will make sure that a service won&#39;t repeatedly try to execute an operation that is likely to fail. A predefined Threshold value(Generally 75%) is used.</li></ul><p><strong>If a particular service is failing more than the given threshold, the requesting service will not try to hit the failing service. Instead, It will fail back to the consumer and inform that this particular service is not available.</strong></p><p>Then the subsequent requests that come to the particular service will failback without waiting. This process is similar to a circuit breaker of a house and hence the name.</p><ul><li>A Ping request is used to check the response time. The circuit will be turned on once the response time comes back to normal.</li></ul><p>This circuit breaker basically acts as a proxy for the services that have a possibility to fail in the near future. That means it will basically keep track of the number of failed services and use that information to make a decision(either to proceed or to refuse). There are 3 main states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQjhe5cqzya0WQajKWURRQ.png" /><figcaption>Fig 2: Circuit Breaker States</figcaption></figure><p><strong>1. Closed</strong></p><p>The proxy will route the request to the service and view the status of the operation. It keeps track of the recent failures. If the particular request is unsuccessful, it will increase the unsuccessful count by 1.</p><p>If the number of recent unsuccessful counts exceeds the threshold level, the proxy will go to the <strong>Open</strong> state and will also start a Timeout timer. When the timeout expires, it will go to the<strong> Half-Open</strong> State.</p><p><strong>2. Open</strong></p><p>The requests will be failed immediately by throwing an exception.</p><p><strong>3. Half-Open</strong></p><p>A restricted amount of requests will be routed to the service. If they become successful, the state of the Proxy will be changed to <strong>Close</strong>. The Unsuccessful count will also be changed to 0. If the request fails, the state will be changed to <strong>Open</strong>.</p><p>Think about a situation where a service tries to recover slowly from a failed instance. This recovering service may not support a large number of requests at once as it is still recovering. This Half-open state helps to avoid the flooding of requests to this service.</p><p>The next part of this article plains another widely used design pattern called the Proxy Pattern. I have used the following playlist by Mr.<a href="https://krish-blog.medium.com/">Krishntha Dinesh</a> to gather the required information.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FcUiU8yDdQmw%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcUiU8yDdQmw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcUiU8yDdQmw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2eaf1a57efe25c3a1e7f6308ce47944b/href">https://medium.com/media/2eaf1a57efe25c3a1e7f6308ce47944b/href</a></iframe><h3>References</h3><ul><li><a href="https://martinfowler.com/bliki/CircuitBreaker.html#:~:text=You%20wrap%20a%20protected%20function,call%20being%20made%20at%20all">bliki: CircuitBreaker</a></li><li><a href="https://en.wikipedia.org/wiki/Cascading_failure#:~:text=A%20cascading%20failure%20is%20a,other%20parts%20and%20so%20on">Cascading failure - Wikipedia</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5456efafba48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices (Part 3) — Design Patterns for Microservices(Aggregator Pattern)]]></title>
            <link>https://damsak.medium.com/microservices-part-3-design-patterns-for-microservices-aggregator-pattern-75229280399a?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/75229280399a</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[aggregator]]></category>
            <category><![CDATA[microservices-pattern]]></category>
            <category><![CDATA[microservices-design]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Mon, 07 Jun 2021 13:40:48 GMT</pubDate>
            <atom:updated>2021-06-08T00:44:49.296Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microservices (Part 3) — Design Patterns for Microservices(Aggregator Pattern)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTX3u99oG5l9WaYAjE2j7Q.png" /><figcaption>Fig 1: Design Patterns ( Source: dribbble )</figcaption></figure><p>Microservices is a completely new way of developing applications. Design patterns are a crucial part of this new implementation process. Let’s discuss some commonly used designed patterns.</p><h3>Aggregator Pattern</h3><p>A microservices application consists of several independent services. These services are less coupled and talk to each other through well-defined interfaces. Service has its own database as well. However, there may be instances where we need to write queries to get results from multiple databases which are in different services. We can use the Aggregator pattern to implement this.</p><p>In the aggregator design pattern, a particular service(service A) will receive the request. Then this service will subsequently make requests to multiple services(Service B, C). Then it(Service A) will combine the results and responds to the initial request. There are 3 main ways to implement the Aggregator pattern.</p><ol><li><strong>Scatter-gather Pattern</strong></li><li><strong>Chained Pattern</strong></li><li><strong>Branch Pattern</strong></li></ol><p>Let’s try to further understand these 3 main implementations with the help of a real-world example.</p><h3>Use case</h3><p>Assume that we need to implement a microservices-based system for a Hotel. This system contains the following services.</p><ol><li>Service 1: Get Guest Information.</li><li>Service 2: Get Room Information.</li><li>Service 3: Get Food Information.</li><li>Service 4: Get Restaurant Information.</li></ol><p>Assume that there are 2 main consumers of these services.</p><ol><li>Guest management System.</li><li>Restaurant management system.</li></ol><p>Normally what we can do —</p><p><em>use docker to create multiple instances of these 4 services and deploy them.</em></p><p><strong>Problem:</strong> Guest Management system needs Guest information and room information.</p><h4><strong>Solution</strong></h4><p>In the microservices architecture, we always implement dump pipes and smart endpoints. Therefore we can create another service to consume these 2 services(Guest Information service and Room Information service) and provide the response back to the consumer. There are 2 main ways to implement this.</p><p><strong>Option 01: </strong>Send parallel responses to Guest information and Room information services. Then aggregate the results and send them back.</p><p>This implementation is called the <strong>Scatter gather pattern</strong>(Also called parallel aggregation). It is basically a composite pattern that describes how to broadcast a message to multiple recipients and re-aggregate the responses back to a single message.</p><p>But there is a problem. We can’t always use this pattern.</p><p><strong>What if the Guest information service has a dependency on the Room information service?</strong></p><p>Now we cannot send parallel calls.</p><p><strong>Option 02:</strong></p><ol><li>Invoke the Guest Information service.</li><li>Get a unique code(Guest Code) along with the response.</li><li>Pass the Guest code to the Room information service.</li><li>Then get the Room information.</li><li>Finally, aggregate the result and send it back.</li></ol><p>This implementation is called <strong>Service Chaining</strong>. Service Chaining is slower than parallel aggregation.</p><p><strong>Branching</strong></p><p>This is basically a mix of Aggregator and Chain design patterns. In this pattern, a particular service can communicate with multiple services at a given time. We can use a field called “Branch code”. Then the destination place of the request will be determined by this branch code(It could also be the next service invoking place).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*3IUUGgsg9Z1GItWbxSyIig.jpeg" /><figcaption>Fig 2: Branching</figcaption></figure><p><strong><em>Change in business requirements</em></strong></p><p><strong>New Requirement: </strong>Restaurant management needs some information from the Guest management before performing its operations.</p><p>Now we can implement this functionality without modifying any of the existing services. This is done by creating another aggregation service. This aggregation service will talk to necessary services(In Guest management) and get the information.</p><p>The deployment should be done with the help of versioning. We can deploy both versions of the system and ask the clients to upgrade to the newer version. Both the versions should be running for a particular time period(Till all the clients upgrade to the new version). Finally, we can remove the older version of the system.</p><h4>Advantages of the Aggregator Pattern</h4><ul><li>Reduce the communication overhead between clients and services.</li><li>Easy to understand and Implement.</li><li>Fast development.</li></ul><p>The next part of this article plains another widely used design pattern called Circuit Breaker Pattern. I have used the following playlist by Mr.<a href="https://krish-blog.medium.com/">Krishntha Dinesh</a> to gather the required information.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fplaylist%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcUiU8yDdQmw%2Fhqdefault.jpg%3Fsqp%3D-oaymwEWCKgBEF5IWvKriqkDCQgBFQAAiEIYAQ%3D%3D%26rs%3DAOn4CLCsj5JRhnauYqyNTpdPx5mnRaz3jQ%26days_since_epoch%3D18790&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="853" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a9c8f63012172aa83c1c5748a983285/href">https://medium.com/media/2a9c8f63012172aa83c1c5748a983285/href</a></iframe><h3>References</h3><ul><li><a href="https://dzone.com/articles/microservices-aggregator-design-pattern-using-aws">Microservices Aggregator Design Pattern Using AWS Lambda - DZone Microservices</a></li><li><a href="https://www.oreilly.com/library/view/java-ee-8/9781788830621/d20a2b30-62e3-4abb-8629-22e054f7f695.xhtml">Java EE 8 Design Patterns and Best Practices</a></li><li><a href="https://java-design-patterns.com/patterns/aggregator-microservices/">Aggregator Microservices</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75229280399a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices (Part 2) — Best Practices]]></title>
            <link>https://damsak.medium.com/microservices-part-2-best-practices-4ac68eea0990?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ac68eea0990</guid>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[microservices-pattern]]></category>
            <category><![CDATA[microservices-application]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 18:09:13 GMT</pubDate>
            <atom:updated>2021-06-07T01:06:23.972Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microservices (Part 2) — Best Practices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*xpVIyi0YaLFM09rcPaKwNg.jpeg" /><figcaption>Fig 1: Best Practices (Source: Google)</figcaption></figure><p>Developers need to follow a set of best practices in order to successfully implement the Microservices architecture. Let’s discuss these best practices.</p><h3>Design</h3><p>It is very important to model the boundaries of the system before implementing the Microservices architecture. The developers who design the system must have a crystal clear understanding of the processes and rules in that particular domain. The design should be a <strong>Domain-Driven Design</strong>.</p><p><strong>Domain-driven Design </strong>-</p><p><em>Domain-Driven Design is an approach to software development that centers the development on programming a domain model that has a rich understanding of the processes and rules of the domain.</em></p><p>— Martin Flower.</p><h3>Hard-Coded Values</h3><ul><li>A hard-coded value is a fixed parameter in a computer program that cannot be changed without modifying the program.</li></ul><p>In a microservices architecture, the code should always be dynamic. The set of running service instances in an application changes dynamically. These instances have dynamically assigned network locations. Therefore the hostnames, URLs, etc should never be hardcoded as they can change dynamically.</p><h3>Logging</h3><p>Logging is an important part of the software development process. There are some challenges in implementing this logging process in a microservices architecture. That is because there are many services and they only communicate with each other through well-defined interfaces. Therefore, the normal logging procedure will not be applicable.</p><p>Assume that the application has a network problem. The developers may try to go to the logs and figure it out. But the log folder may contain logs from different services and it will be really hard to identify correct logs.</p><h4><strong>Correlation ID</strong></h4><p>An efficient way to implement logging in a microservices architecture. The correlation ID is also called transaction ID and it is included in each message. The correlation ID is taken from the initiating event and this unique ID is logged from each of the invoking services. Therefore it is much easier to find the flow of the message.</p><h4><strong>Log the valuable information</strong></h4><p>Logging too much information will affect the performance of the system. However, logging too little information will make it difficult for a developer to identify errors in case of a bug. Therefore a log should contain just the right amount of information that could potentially be valuable for someone else to identify the process.</p><h4>Time</h4><p>“Timestamp” is an important part of a log. Microservices are distributed and therefore the time may not be synced across all the services in a correct way. In such situations, the log files may contain timestamps in the incorrect order. To overcome this problem, there are techniques like Lamport, Vector clocks, etc.</p><h3>Versioning in Microservices</h3><p>There are 2 general ways to perform versioning(Irrespective of the architecture).</p><h4>1. Semantic Versioning</h4><p>Semantic Versioning uses<strong> 3 non-negative integers</strong> to represent a release. Integers:</p><ul><li><strong>Major:</strong> Increased when the previous version is incompatible with the current version.</li><li><strong>Minor:</strong> Increased when the previous version is compatible with the current version.</li><li><strong>Patch:</strong> A bug fix as a part of the new version. This new version is also compatible with the previous version.</li></ul><p>Generally used when the application contains many different modules.</p><h4>2. Calendar Versioning</h4><p>Similar to semantic versioning but uses calendar dates instead of the non-negative integers. These dates contain a combination of Year, Month, and Date. Generally used when the application is time-bound. That means the support and availability period is duration driven rather than usage driven.</p><blockquote><strong><em>Semantic Versioning is more suitable for Microservices architecture.</em></strong></blockquote><p>There are some special versioning techniques that specific to Microservices.</p><ul><li>URL Based Versioning</li><li>Header-driven Versioning.</li></ul><p><strong>Example</strong></p><p><strong>Assumption:</strong> There are 2 services namely service “A” and service “B”. “A” service consumes data from service “B”. The developers upgrade service “B” and it changes the database structure of service B.</p><p>The service “A” will break if the developers deploy this new system. That is because the database structure changed in service “B”.</p><p><strong>So what can we do?</strong></p><p>We can use versioning. We can create 2 versions and ask the users to upgrade to the newer version. It will take some time for all the users to upgrade to the newer version. Both the versions will be up and running till then. There are many deployment frameworks to do this process in an efficient manner.</p><h3>Authorization and Authentication in Microservices</h3><p>Microservices architecture contains different services. The system will be slow and inefficient if each service tries to validate the user. Therefore the authentication and authorization process should be implemented in a different way.</p><p>In Microservices architecture,</p><ul><li>A centralized service is used to perform these processes.</li><li>There are solutions like WS02 Identity Server, OAuth2orize, etc to implement this.</li></ul><p>The best way is to have a separate identity validation service.</p><h3>Dependency Management</h3><p>The main principle in the Microservices architecture is to make every service operate on its own. They are basically modeled as isolated Units. Therefore each of these services should be independently deployable without shared dependencies.</p><h3>Make Executable Contracts</h3><p>Refers to the process where the client and company sign a contract. This contract is an executable one. This contract may include a set of well-defined tests. These tests will be executed in each application build.</p><h3>Fault Tolerance</h3><p>Failures are common in any given system. Consider the following table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*XKIE7r_AdJbx_EEnVSk4OQ.png" /><figcaption>Fig 2: Downtime Per Year</figcaption></figure><p>A system with 99.999% availability will still have 5 minutes and 15 seconds of downtime per year. Microservices architecture contains multiple services. Therefore this downtime is generally much higher.</p><p><strong><em>Microservices: FAIL FAST, FAIL SILENT, FALLBACK</em></strong></p><p><strong>Possible Measures</strong></p><ul><li>Time-out calls that take longer than the defined threshold.</li><li>Maintain a thread pool for each dependency.</li><li>Use a circuit breaker to block all requests to a targeted service for a given time.</li></ul><blockquote>Note: The upcoming articles will describe the patterns that are used in fault tolerence.</blockquote><h3>Documentation</h3><p>Refers to a document that clearly explains how the software or service should operate. It can have text or illustrations. This documentation is very important for developers and other personals to get a clear understanding of a particular service. <a href="https://swagger.io/">Swagger </a>is a popular open-source tool that helps to document APIs at any scale. This can be used to perform documentation in the Microservices architecture.</p><p>The next Part(Part 3) of this article explains the popular design patterns that can be used with the Microservices architecture.</p><p>I have used the following playlist by Mr.<a href="https://krish-blog.medium.com/">Krishntha Dinesh</a> to gather the required information.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fplaylist%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcUiU8yDdQmw%2Fhqdefault.jpg%3Fsqp%3D-oaymwEWCKgBEF5IWvKriqkDCQgBFQAAiEIYAQ%3D%3D%26rs%3DAOn4CLCsj5JRhnauYqyNTpdPx5mnRaz3jQ%26days_since_epoch%3D18790&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="853" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a9c8f63012172aa83c1c5748a983285/href">https://medium.com/media/2a9c8f63012172aa83c1c5748a983285/href</a></iframe><h3>References</h3><ul><li><a href="https://dzone.com/articles/authentication-and-authorization-in-microservices">Authentication and Authorization in Microservices - DZone Microservices</a></li><li><a href="https://stackify.com/microservice-logging/">Microservice Logging: making debugging easier in distributed systems</a></li><li><a href="https://martinfowler.com/bliki/DomainDrivenDesign.html">bliki: Domain Driven Design</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ac68eea0990" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices (Part 1) —  Introduction]]></title>
            <link>https://damsak.medium.com/microservices-part-1-introduction-b1a10c2f26c?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1a10c2f26c</guid>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[monolithic]]></category>
            <category><![CDATA[microservices-application]]></category>
            <category><![CDATA[scaling-microservices]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 02:56:33 GMT</pubDate>
            <atom:updated>2021-06-07T01:08:45.576Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microservices (Part 1) — Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DeHEZfBdLjpYnM6wZ4fQtg.png" /><figcaption>Fig 1: Microservices (Source: Google)</figcaption></figure><h3>Monolithic Application Architecture</h3><p>Monolithic application architecture is the architecture followed by most of the developers to create enterprise-level applications before the emergence of Microservices. In Monolithic applications, <strong>all the business modules run in a single process which is typically a WAR/EAR file</strong>. Classes of these different modules may talk to each other and they also may use the same libraries. There are many coupling between these modules. Moreover, Monolithic applications typically use a single database containing multiple tables related to all the available business modules. A monolithic application contains 3 main tiers namely the client tier, server tier, and database tier.</p><p><strong>Example: </strong>Consider an eCommerce application. This application may contain components like,</p><ul><li>webserver</li><li>load balancer</li><li>catalog service</li></ul><h4><strong>Advantages of Monolithic</strong></h4><ul><li>Easy to test the overall application(Integration testing).</li><li>Easy to Monitor.</li><li>Simplicity.</li></ul><p>However, this architectural style is inadequate for large enterprises as there are some major disadvantages.</p><ul><li>Strong coupling between different modules of the application.</li><li>Large application size and complex in nature.</li><li>Harder for developers to understand and make changes quickly.</li><li>Any updates require a complete re-deployment of the entire application.</li><li>Less scalable.</li><li>Less reusable.</li></ul><h3>Microservices Architecture</h3><p>Definition —</p><blockquote><em>Microservices is an approach for developing a single application as a suite of small services, each running its own process and communicating with lightweight mechanisms, often an HTTP resource API.</em></blockquote><p>Microservices is basically an architectural style that helps to overcome the problems faced in monolithic applications. In a microservices architecture, all the services should be <strong>built around particular business capabilities</strong> and they should be <strong>independently deployable</strong>. These services can be <strong>written in different programming languages</strong> and use <strong>different data storage technologies</strong> as well.</p><h4>Scaling: Monolithic vs Microservices</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrYgxcTU9K2TkcMPwb3d0w.png" /><figcaption>Fig 2: Scaling Monolithic Vs Microservices</figcaption></figure><p>A monolithic Application has to replicate the entire system across multiple servers in order to scale. This is a very complex and costly process with a lot of disadvantages. There is a huge wastage of resources as some of the functionalities may not be required in the replicating instance.</p><p>A Microservices application scales by distributing only the required services across servers. This has many advantages over the scaling done in monolithic applications.</p><ul><li>The resources are better utilized.</li><li>The overall cost is less.</li><li>Fewer configurations to be done.</li></ul><h4>Scale Cube in Microservices</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*0DpDxw5yaA6eFqiIk2gFkw.png" /><figcaption>Fig 3: Scale Cube</figcaption></figure><p>Scale cube is a scaling model introduced in a famous book called “<a href="https://www.goodreads.com/book/show/7282390-the-art-of-scalability">The Art of Scalability</a>”. According to this model, the scaling is done in 3 main axises namely X, Y, and Z.</p><ul><li><strong>X-axis</strong>: Refers to the process of running multiple copies of an application behind a load balancer. The problem with this scaling is that all the copies need to potentially access all of the data.</li><li><strong>Y-axis: </strong>Refers to scaling of the application by splitting it into multiple different services. Each service has a dedication functionality.</li><li><strong>Z-axis: </strong>Each server runs an identical copy of the code. However, each server is responsible for only a subset of data.</li></ul><h3>Characteristics of Microservices</h3><p>(According to <a href="https://martinfowler.com/articles/microservices.html">martinflower.com</a>. Please check the website for more information.)</p><h4>Componentization Via Services</h4><p>In the microservices architecture, all the services are treated as components. That means these services <strong>do not share SDKs or Libraries</strong> between them. This is done in order to avoid the coupling between these services. As mentioned in the first section, these services are independently deployable. That means these services can be deployed without affecting other services in the application as there are low couplings.</p><h4>Organized around Business Capabilities</h4><p>Think about a traditional organization. Teams are organized according to the technology. As an example, there may be teams like the front-end team, back-end team, QA team, etc. Microservices architecture follows a different team structure.</p><p>In the Microservices architecture, teams are organized as inventory, finance, shipping, etc. That means the teams are organized according to the business capability. These teams are cross-functional. They may contain people from all aspects such as developers, QA personals, etc. Teams can contain 8–10 people(2 pizza teams).</p><h4>Products Not Projects</h4><p>In the traditional software development model, the delivery team will create software according to the present requirements and deliver it. They may hand over the software to the maintenance team and move on to a new project.</p><p>In the microservices architecture, the teams have ownership of the components over their full lifetime. Therefore these components are named as products.</p><h4>Smart End Points and Dumb Pipes</h4><p>In the traditional software development process, developers use powerful middlewares like ESbs to route messages, apply business logic, etc. In the Microservices architecture, the smart lines in the endpoints and not in between the endpoints. This is done in order to make the application more decoupled and cohesive.</p><h4>Decentralized Governance</h4><p>In the traditional monolithic application development process, there is a predefined fixed set of rules regarding the technologies and patterns to be followed. As an example, the application modules are written in the same language and may use the same type of database. This is different in the microservices architecture. Each service has its own governance.</p><h4>Decentralized Data Management</h4><p>In monolithic applications, a change to the database will affect all the components as there is a single central database. In the Microservices architecture, every service is responsible for its own data and own persistence. There is no unique data model approach.</p><h4>Infrastructure Automation</h4><p>It is the technique used to reduce human interactions with IT systems. This is done by creating scripts or functions for repeatable actions. Microservices need to implement services such as continuous delivery, blue-green deployment, etc.</p><h4>Design for Failure</h4><p>All the services have a possibility to fail at a given time. Therefore it&#39;s a must to handle these failures in a correct way. Microservices architecture can use monitoring tools to check the status of different services and better prepare for failure. Moreover, there are tools like “Chaos Money” that are used to test the resiliency of services.</p><h4>Evolutionary Design</h4><p>In the microservices architecture, there should be more granular release planning. Should always try to identify change impacts and fix them as soon as possible.</p><h3>Important Points</h3><ul><li>It&#39;s important to note that the microservices architecture should be implemented carefully. If developers try to create granular microservices, the architecture will fail. why?</li></ul><p>Think about a situation where an application has a user login and user registration process. What if we try to put these 2 functionalities in separate services?</p><p>The application will be slower as the microservices take time to talk to each other. Therefore, there should be the <strong>right balance between these services</strong>.</p><ul><li>Before implementing Microservices architecture, the developers should always have a clear idea about the domain and objective of the application.</li><li>The developers can use any language to develop microservices. However, most developers go with Java.</li><li>The Design should always be a <strong>Domain-driven design</strong>. There must be a good understanding of the processes and rules related to a particular domain before trying to develop a solution.</li></ul><h4>Advantages of Microservices Architecture</h4><ul><li>Highly scalable.</li><li>Easy migrations as there are no dependencies.</li><li>Highly available.</li><li>The codebase is easier to understand.</li><li>Preserve Modularity.</li></ul><h4>Disadvantages of Microservices Architecture</h4><ul><li>Dependency Management is hard.</li><li>Harder to monitor the overall application.</li><li>Harder to test.</li><li>Harder to do versioning and deployments.</li><li>Complex to understand the overall application architecture.</li></ul><p>Part 2 of this article describes the essential best practices to be followed in the microservices architecture. I have used the following playlist by Mr.<a href="https://krish-blog.medium.com/">Krishntha Dinesh</a> to gather the required information.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fplaylist%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcUiU8yDdQmw%2Fhqdefault.jpg%3Fsqp%3D-oaymwEWCKgBEF5IWvKriqkDCQgBFQAAiEIYAQ%3D%3D%26rs%3DAOn4CLCsj5JRhnauYqyNTpdPx5mnRaz3jQ%26days_since_epoch%3D18790&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="853" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a9c8f63012172aa83c1c5748a983285/href">https://medium.com/media/2a9c8f63012172aa83c1c5748a983285/href</a></iframe><h3>References</h3><ul><li><a href="https://martinfowler.com/articles/microservices.html">Microservices</a></li><li><a href="https://martinfowler.com/tags/domain%20driven%20design.html">domain driven design</a></li><li><a href="https://microservices.io/patterns/microservices.html">Microservices Pattern: Microservice Architecture pattern</a></li><li><a href="https://microservices.io/articles/scalecube.html">The Scale Cube</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1a10c2f26c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Container-based Application Development]]></title>
            <link>https://medium.com/geekculture/introduction-to-container-based-application-development-8ac4a7522858?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ac4a7522858</guid>
            <category><![CDATA[application-architecture]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker-fundamental]]></category>
            <category><![CDATA[hypervisors]]></category>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Fri, 04 Jun 2021 04:16:23 GMT</pubDate>
            <atom:updated>2021-06-04T06:24:11.969Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to Container-Based Application Development</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yum5cf4KycspX9YStWCGxw.jpeg" /><figcaption>Fig 1: Containers (Source: Google)</figcaption></figure><h3>Evolution of Application Architecture</h3><h3>Generation 01: The Dark Ages</h3><blockquote>One Physical Server — One Application</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*N5FU6-vl8GrfNWDolqX-dg.jpeg" /><figcaption>Fig 2: 1st Generation</figcaption></figure><p>The first generation of systems consists of one physical server and one application. A physical server is designed for a single user and cannot be shared among others. <strong>A</strong> <strong>single operating system is on top of the physical hardware</strong>. The application runs on top of this Operating system. There are many disadvantages of this implementation,</p><h4>Disadvantages</h4><ul><li>Wastages of resources.</li><li>Massive costs to maintain.</li><li>Slow deployments.</li><li>Harder to scale.</li><li>Difficult to migrate.</li></ul><h3>Generation 02: Hypervisor Based Virtualization</h3><blockquote><em>One Physical Server — Multiple Virtual Machines</em></blockquote><blockquote><em>One Virtual Machine — One Application</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*WnpcoRbMJmpKVwXv6OX7mA.png" /><figcaption>Fig 3: 2nd Generation</figcaption></figure><h4>Important terminology</h4><ul><li><strong>Virtualization: </strong>Creating a virtual version of an entity without the actual one.</li><li><strong>Virtual Machine: </strong>Virtualization of a computer system.</li><li><strong>Hypervisor</strong>: A software that is capable of creating and running virtual machines.</li></ul><p>This made it possible for us to run multiple Virtual Machines on a single physical server. Each of these VMs has a separate operating system with an allocated amount of memory. Let’s discuss the advantages and disadvantages of this implementation.</p><h4>Advantages</h4><ul><li>Better utilization of resources.</li><li>Scaling is comparatively easy.</li></ul><h4>Disadvantages</h4><ul><li>Multiple VMs need multiple resources.</li><li>Less Portable.</li><li>Manage and configure different VMs.</li></ul><h3>Generation 03: Containers</h3><p>Containers emerged as a solution to the above-mentioned problems. Containers basically help software to run reliably in different computing environments. Both containers and VMs have similar resource isolation and allocation benefits but containers are more portable and efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cGBH10lQkivoaFKE2_ynbA.png" /><figcaption>Fig 4: VMs vs Containers</figcaption></figure><blockquote><strong>Containers virtualize the Operating System instead of hardware.</strong></blockquote><h3>Docker</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-wq-xETD5giUacoLt6Z8g.jpeg" /><figcaption>Fig 5: Docker</figcaption></figure><blockquote><strong><em>A tool that can be used to containerize applications.</em></strong></blockquote><p>Docker is basically a container engine that can be used to generate containers on top of an existing operating system with the help of Linux Kernel features. It is an open-source project and provides a mechanism for developers to easily separate applications from the infrastructure in order to make the software deliveries fast and reliable. Developers can create containers with or without docker. However, docker makes it easier to build and comes with many different advantages.</p><ul><li>Easily Scalable.</li><li>Highly available.</li><li>Easy to deploy.</li><li>Easy to manage applications.</li></ul><p>Other key aspects,</p><ul><li>Docker is <strong>lightweight </strong>as it only includes required OS processes and dependencies. A normal VMs container has to support the payload of the entire OS instance.</li><li>Docker significantly <strong>improves the productivity</strong> of developers by providing easy mechanisms to deploy, provision, and restart.</li><li>Docker provides <strong>great resource efficiency</strong> as the developers can run different copies of an application on the same hardware.</li></ul><p>Let’s look in detail at some of the concepts related to Docker.</p><h4>Docker Image</h4><p>This is one of the key components in docker. It is basically a template with a set of instructions that can be used to create a docker container. A docker image may contain components like,</p><ul><li>Application code.</li><li>libraries</li><li>tools</li><li>dependencies, and etc.</li></ul><p>A Docker image has the capability to have one or many instances of a particular container. There are 2 main ways to create a docker image.</p><ul><li><strong>Interactive</strong>: Running a container from an existing Docker image.</li><li><strong>Docker file</strong></li></ul><h4>Docker file</h4><p>The developers can download docker images from the docker hub and use them. However, there may be instances where developers need to create custom Docker images. A Docker file is a text file that explains the process of building a docker image on your own.</p><h4>Docker Engine</h4><p>Refers to the core product of Docker. Docker engine is the main component responsible for building and running containers using its services and elements. This engine contains the Docker daemon and Docker CLI. This is basically a containerization technology for building containerized applications.</p><h4>Docker Registry</h4><p>Refers to a server-side application that is capable of storing and distributing Docker images. This application is open-source and highly scalable.</p><p>When to use the docker registry?</p><ul><li>When there is a need to control the storage places of the Docker images.</li><li>To have full ownership of the image distribution pipeline.</li><li>To integrate the image storage into the in-house development workflow.</li></ul><p><strong>Docker Hub </strong>can be used as an alternative to Docker Registry. It contains ready-to-go solutions with zero maintenance.</p><h4>Docker Orchestration</h4><p>This refers to the process of taking all the docker instances together and go for a common goal. It is basically a tool to —</p><ul><li>Package and run applications as containers.</li><li>Find existing container images.</li><li>Deploy containers.</li></ul><p>As an example, an application may have several components like an HTTP engine, HTTP authorization, etc. There may be several containers to perform these activities. Docker orchestration will decide where the containers should go, what are the dependencies required, etc.</p><p>There are various frameworks available to perform this Orchestration Process.</p><h4><strong>Kubernetes ( k8s )</strong></h4><p>A popular open-source container orchestration platform. Kubernetes automates manual processes(deploying, managing, and scaling) involved in container orchestration. This is done by grouping the available application containers into logical units for easy management and discovery.</p><p><strong>Features of Kubernetes</strong></p><ul><li>Storage Orchestration.</li><li>Automated rollouts and rollbacks.</li><li>Service Discovery and Load Balancing.</li><li>Horizontal scaling.</li><li>Batch execution.</li></ul><p>Docker is a persistent technology. Files in a particular container are persistent even after the contain stops its execution. Docker can be used for both existing applications and new applications. However, the application should fit into the correct architecture in order to fully use the capabilities of Docker. That means even the legacy applications can use docker. However, they may not be able to yield the full capabilities of docker.</p><h3>Open Container Initiative( OCI )</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zmi8hacO-DIzMLRdaZKsUQ.jpeg" /></figure><p>Docker Inc company introduced the technology of docker in 2011. Another company started to use this docker concept and they found out that it doesn&#39;t fit their architectural and business requirements. Therefore they implemented a similar framework called Rocket. Later on, this created many different administrative and technical problems. Therefore Docker and Rocket came to an agreement to form OCI.</p><p>OCI is the open governance structure for the express purpose of creating open industry standards around container formats and runtimes. Contains 2 main specifications.</p><ul><li>Runtime Specification</li><li>Image Specification</li></ul><p>I have used the following video by Mr.<a href="https://krish-blog.medium.com/">Krishntha Dinesh</a> to gather the required information.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FcUiU8yDdQmw%3Flist%3DPLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcUiU8yDdQmw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcUiU8yDdQmw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2eaf1a57efe25c3a1e7f6308ce47944b/href">https://medium.com/media/2eaf1a57efe25c3a1e7f6308ce47944b/href</a></iframe><h3>References</h3><ul><li><a href="https://docs.docker.com/registry/#:~:text=The%20Registry%20is%20a%20stateless,under%20the%20permissive%20Apache%20license">Docker Registry</a></li><li><a href="https://en.wikipedia.org/wiki/Open_Container_Initiative">Open Container Initiative - Wikipedia</a></li><li><a href="https://www.sciencedirect.com/topics/computer-science/hypervisor-based-virtualization">Hypervisor-Based Virtualization</a></li><li><a href="https://www.oracle.com/it/cloud-native/container-registry/what-is-docker/">What is Docker-Container Registry</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ac4a7522858" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/introduction-to-container-based-application-development-8ac4a7522858">Introduction to Container-based Application Development</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modern Concepts in JavaScript(Part 2)]]></title>
            <link>https://damsak.medium.com/modern-concepts-in-javascript-part-2-598bd14faed1?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/598bd14faed1</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6-js]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Mon, 31 May 2021 17:45:30 GMT</pubDate>
            <atom:updated>2021-06-01T01:07:37.423Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xiDj73t-bBDLZJ_GUlDnbw.jpeg" /><figcaption>Fig 01: Js (Source: Google)</figcaption></figure><p>Through this article let’s discuss some new concepts in JavaScript. This is a continuation of the previous article. So I suggest you go through part 1 of this article before moving on to this.</p><p>Visit the previous article by —</p><p><a href="https://damsak.medium.com/modern-concepts-in-javascript-part-1-4f56ffbedbc9">Modern Concepts in Javascript — Part 1</a></p><h3>6. Template Literals</h3><p>Refers to a string literal that allows embedded expressions. Templates literals should be enclosed with <strong>` `</strong> instead of <strong>“ ”</strong>.</p><p><strong>Multi-line Strings using template literals —</strong></p><p>Easily write multi-line strings without having to use “\n”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*2rUajvKUbME7KCHBIxA7JA.jpeg" /><figcaption>Fig 1: Multi-line String</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*EZv8fGWk25soSnlL8hWaaw.jpeg" /><figcaption>Fig 2: Multi-line String Output</figcaption></figure><p><strong>Interpolation of expressions —</strong></p><p>Embed expressions within normal strings</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35181c81c7838ad58ab1cd78d9ac554f/href">https://medium.com/media/35181c81c7838ad58ab1cd78d9ac554f/href</a></iframe><p>This will print the sum as 13.</p><p><strong>Nesting Templates —</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/302716ef8670702ba879d48e5a63ea5e/href">https://medium.com/media/302716ef8670702ba879d48e5a63ea5e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*cBH_gFvW69tArM54p5INWg.jpeg" /><figcaption>Fig 3: Nesting Templates</figcaption></figure><p>Please refer to the article in the References section to know more about Template Literals.</p><h3>7. Classes</h3><p>JavaScript classes have similar behavior to Java classes. However, there are some key differences.</p><ul><li>In Javascript, we have to define the constructor using the keyword “constructor” and not the class name.</li><li>No need to create a local variable in order to call <strong>“this.&lt;variablename&gt; = variablename”</strong> inside constructor.</li><li>Easily override functions.</li></ul><p>Let’s see these points from an example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2480e5851df8398bb2bbf0a23b60dfc0/href">https://medium.com/media/2480e5851df8398bb2bbf0a23b60dfc0/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*xuiRBLNBBthEGy-q90S2DA.jpeg" /><figcaption>Fig 4: Javascript Classes</figcaption></figure><h3>8. Destructuring</h3><p>This is a useful feature provided by JavaScript in order to extract properties from objects and bind them.</p><p>Let’s try to understand the behavior of destructuring objects with the help of some examples.</p><h4><strong>Accessing values</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e0f2f47ac16c64914f98b9e16dbfd8d/href">https://medium.com/media/4e0f2f47ac16c64914f98b9e16dbfd8d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*WHc7aLmIvvtv7yr6IB9J2g.jpeg" /><figcaption>Fig 5: Destructuring 1</figcaption></figure><p>We can see that it is much easier and cleaner to use object destructuring.</p><h4>Another way to use destructuring</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67fe3bf369a70b864404f5f4bfa3d628/href">https://medium.com/media/67fe3bf369a70b864404f5f4bfa3d628/href</a></iframe><p>Now the method will print 196. We only passed the object vehicle and the required method extracted the necessary property(“base” in the above example) from the object. This eliminates the requirement to use the entire object.</p><h4>Assign default value</h4><p>Consider the following example,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27094d985bf73defc7c6e4ca73d0b4ae/href">https://medium.com/media/27094d985bf73defc7c6e4ca73d0b4ae/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*0b_eWHPaLaKj1ROZ_CBWhQ.jpeg" /><figcaption>Fig 6: Default value</figcaption></figure><p>The application printed Toyota because the “brand” property is readily available inside the vehicle. However, there is no color property inside the vehicle. Therefore the applicated printed the “blue” which is the default value.</p><h4>Destructuring with a function</h4><p>Consider a scenario where we need to read a file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46d7bbc19a8b929380d066af1668a0a9/href">https://medium.com/media/46d7bbc19a8b929380d066af1668a0a9/href</a></iframe><p>We can see that the code with destructuring is much cleaner and developer-friendly. We do not need to write “fs.readFileSync”.</p><h4>The 3 dots ( … )</h4><p>This is a brand new feature introduced in ES6. This can be used as a Rest Operator or Spread Operator.</p><h4>Rest Operator</h4><p>Basically adds all remaining elements into an array. Makes it possible for a function to accept an indefinite number of arguments as an array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d84f4e74ed26808ea34b53ef496a348d/href">https://medium.com/media/d84f4e74ed26808ea34b53ef496a348d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*DHHCTxsoJuAoxlhKLmDjTQ.jpeg" /><figcaption>Fig 6: Rest Operator</figcaption></figure><p>We can also use the rest operator to copy values from one array to another.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aabbd4d16e5b5cf44247eb80fe8310f9/href">https://medium.com/media/aabbd4d16e5b5cf44247eb80fe8310f9/href</a></iframe><h4>Spread Operator</h4><p>Consider a situation where we need to include all elements of an object within a list of some kind. In such situations, we can use the Spread Operator.</p><h3>9. Promises</h3><p>This is a way to deal with asynchronous operations in JavaScript. A promise is basically a guarantee that we are going to do something in the future. The value of a promise is unknown at the time of creation. This value will be supplied at some point in the future.</p><p>Main states of a Promise</p><ul><li><strong>Pending</strong>: State before the promise succeeds or fails.</li><li><strong>Resolved</strong>: Operation Completed successfully.</li><li><strong>Rejected</strong>: Operation Failed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*dL1edU2x_QZekaWNViIcZw.png" /><figcaption>Fig 7: Promise</figcaption></figure><p>Let’s try to understand Promises with some examples. Consider a situation where we need to get data from a website,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f6a9ac5105a189032e090cb6eb2d212/href">https://medium.com/media/4f6a9ac5105a189032e090cb6eb2d212/href</a></iframe><h4>Why did we wrap this in a Promise?</h4><p>Because HTTP takes time to go to the server and get the response.</p><h4>Consumers-</h4><p><strong>.then: </strong>When the response is complete</p><p><strong>.catch(): </strong>to log any errors.</p><p><strong>.finally(</strong>): Regardless of the state(resolve or reject), this method will trigger.</p><p>Now in order to get the output successfully, we need to call this inside an “async” function with the help of the “await” keyword.</p><ul><li><strong>await</strong>: An operator used to wait for a Promise.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd914e778f5bb02db7b93dddfda23fa9/href">https://medium.com/media/cd914e778f5bb02db7b93dddfda23fa9/href</a></iframe><p><strong>What if we didn&#39;t use the await keyword?</strong></p><p>Then the program will print undefined. That is because the application is not waiting for the response of the promise (Until the promise is resolved). The “await” keyword is only valid within an “async” function.</p><p>I have used the following video by Mr.<a href="https://krish-blog.medium.com/">Krishntha Dinesh</a> to gather the required information.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXK_lB5-XzhQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXK_lB5-XzhQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXK_lB5-XzhQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5253255d95cadde6c9b57b667cb73907/href">https://medium.com/media/5253255d95cadde6c9b57b667cb73907/href</a></iframe><h3>References</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">Template literals (Template strings) - JavaScript | MDN</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise - JavaScript | MDN</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters">Rest parameters - JavaScript | MDN</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=598bd14faed1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modern Concepts in Javascript — Part 1]]></title>
            <link>https://damsak.medium.com/modern-concepts-in-javascript-part-1-4f56ffbedbc9?source=rss-d581cb27f2f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f56ffbedbc9</guid>
            <category><![CDATA[es6-in-depth]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[modern-javascript]]></category>
            <dc:creator><![CDATA[Damsak Bandara]]></dc:creator>
            <pubDate>Mon, 31 May 2021 03:39:18 GMT</pubDate>
            <atom:updated>2021-06-22T18:59:21.565Z</atom:updated>
            <content:encoded><![CDATA[<h3>Modern Concepts in JavaScript(Part 1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1IpONYCZXmytCfxJl3HNA.png" /><figcaption>Fig 1: JS — Source: Google</figcaption></figure><p>JavaScript is a lightweight, dynamic, text-based programming language that is used on both client-side and server-side in order to make web pages more interactive. Javascript was first introduced in 1995 with the name LiveScript. Later on, with the popularity of Java, Netscape changed its name to JavaScript. JavaScript is the only programming language that is native to the web browser and it&#39;s a relatively easy language to learn. Therefore the popularity of Javascript increased rapidly over the past few years. Almost all web Browsers contain a JavaScript Engine. JavaScript Engine is a computer program that is used to execute Javascript code. These are the JavaScript engines used by popular browsers.</p><ul><li>Chrome — V8</li><li>Mozilla — SpiderMonkey</li><li>Safari — JavaScriptCore</li><li>Edge — Chakra</li></ul><h4>Advantages of JavaScript</h4><ul><li>Fast on the Client-side as it can be run immediately within the browser.</li><li>Interoperability.</li><li>Simplicity and easy to Learn.</li><li>Easily create attractive web interfaces.</li><li>Reduce the server load as JavaScript runs on the client-side.</li><li>Frequent updates with the latest functionalities.</li></ul><h4>Disadvantages of JavaScript</h4><ul><li>Security. Can be easily exploited as Javascript code executes on the client’s computer.</li><li>Different interpretations by different browsers.</li></ul><p>Javascript is actually based upon a Standard Scripting Language called ECMAScript.</p><h4>Evolution of ECMAScript</h4><p>ECMAScript is a famous scripting language that creates the basis of JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*Hm3RrHzYxnmYUbpLmCFRUg.jpeg" /><figcaption>Fig 2- ECMAScript Evolution</figcaption></figure><p>ES6 or ECMAScript 6 is the major revolution done to modern Javascript.</p><p>Through this article, let’s discuss some of the key concepts in JavaScript which each and every developer must be aware of. These are some of the new changes that were introduced to Javascript with recent updates(Especially with ES6).</p><h3>1. Scope</h3><p>The scope of a variable is used to determine its accessibility within the program. This scope is controlled by the location of the variable declaration. There are 3 main ways to declare a variable in JavaScript — “var”, “let”, and “const”.</p><p>Javascript has 2 main scopes.</p><ul><li><strong>Global Scope:</strong> The outermost scope is the global scope and any variables declared in this scope are globally accessible(can be accessed anywhere in the program).</li><li><strong>Local Scope: </strong>Variables declared within a particular block. These variables are accessible only within that block.</li></ul><p>“let” and “const” keywords have a block scope where the “var” keyword is limited to function scope.</p><p>Let’s try to further understand these scopes with the help of an example. Consider the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/382750de609bcbae361623f379318427/href">https://medium.com/media/382750de609bcbae361623f379318427/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*fhseXNtSlxaR9bX-62E5mQ.png" /><figcaption>Fig 1: Scopes output 1</figcaption></figure><p>The program will get executed and print the values as in Fig 1.</p><p>What if we change the type of variable “k” from <strong>var</strong> to<strong> let? </strong>This will throw an error saying that the value <strong>k is not Defined</strong>.</p><p>So,</p><blockquote><strong>If you define a variable type as let, it is not accessible outside the Scope.</strong></blockquote><p>In this case, “k” is not accessible outside the forloop. What if we change the type of k to <strong>const</strong>? Still, there will be an error.</p><p><strong>Useful: </strong>Avoid the declaration of the same variable name in 2 different locations.</p><h3>2. Constants</h3><p>As mentioned in the previous section, constants have block scope. A constant cannot be redeclared and reassigned. Constants require an initializer. The developer must specify the value in the same declaration statement.</p><h4>How does it work?</h4><p>The declaration process of a constant creates a read-only reference to the value. This variable identifier cannot be reassigned. Therefore the constant value cannot be changed.</p><p>Consider the following example —</p><p>Let’s create a const Array and add another value. what will happen?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65f33576730a56e6a92a960be5318f21/href">https://medium.com/media/65f33576730a56e6a92a960be5318f21/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*yHumZZ44wsy2vPw7VGDsYg.png" /><figcaption>Fig 2: Constants output 1</figcaption></figure><p>We can see that the value has been added successfully.</p><blockquote><strong>“Arrays and objects declared as constants are Mutable.”</strong></blockquote><h3>3. Arrow Functions</h3><p>A new feature introduced in ES6. This is basically a mechanism for developers to write shorter function syntax. Arrow functions cannot be used as constructors. Does not have a unique binding to “this” or “super” keywords.</p><h4><strong>“this” keyword in Arrow Functions</strong></h4><ul><li>Arrow functions do not contain a binding of “this”.</li><li>In arrow functions, “this” always represents the object that defined the particular arrow function.</li></ul><p>Arrow functions can be written as —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/319201f95914b57abcaf4fd05cc8ac53/href">https://medium.com/media/319201f95914b57abcaf4fd05cc8ac53/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*fkM9RHROQpnX7hd6bG0CQg.jpeg" /><figcaption>Fig 3: Output of Arrow Functions</figcaption></figure><p>So we can see that the syntax is much simplified.</p><h3>4. Handling Objects in JavaScript</h3><p>A JavaScript object is a variable that can contain many values. They are basically containers for named values properties and methods. Important points -</p><ul><li>If we define a variable that takes value from another module, we can use that variable inside the object and do not need to specify any value inside it. Example —</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80404018f7ede07aecf10264b3d7fea6/href">https://medium.com/media/80404018f7ede07aecf10264b3d7fea6/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*3DZxEvxXLQHH0ezcwN5uDA.jpeg" /><figcaption>Fig 4: Objects output</figcaption></figure><p>So we can see that we got the value for “SQRT2” even though we didn&#39;t specify any value inside the object.</p><h4>Dynamic Properties</h4><p>Refers to the technique of using a placeholder as the key. This is used in situations where the developer doesn&#39;t know the exact key at execution time.</p><p>Before ES6 (2 step process) —</p><ul><li>Create the Object literal</li><li>Then use the bracket notation.</li></ul><p>After ES6 —</p><ul><li>Can directly use a variable as the property key in object literal.</li></ul><p>Example —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c063041130602274472b698ade32376/href">https://medium.com/media/9c063041130602274472b698ade32376/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*gbtLJozhDNvyrUKFagL3Vw.jpeg" /><figcaption>Fig 5: Dynamic Properties</figcaption></figure><p>We can see that the property “Key” has been replaced by the value “service”.</p><h3>5. Freezing in JavaScript</h3><p>“<strong>Object.freeze()</strong>” is a method used in JavaScript to freeze an object. This will result in —</p><ul><li>Objects cannot be changed.</li><li>Cannot add new properties to the Object.</li><li>Cannot Remove the existing properties in the object.</li><li>Prevents the prototype from being changed.</li></ul><p>Let’s try to understand this with the help of an example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5ae8e4e1e4fd4d52754de5646f237a5/href">https://medium.com/media/d5ae8e4e1e4fd4d52754de5646f237a5/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*IrZELBm1FJKKWzIjkAqIww.jpeg" /><figcaption>Fig 6: Freeze Js Object</figcaption></figure><p>Now we can see that even though we cannot change the value after freezing.</p><p><strong>Does freezing work for all the values inside an object?</strong></p><p>Consider this example,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81291bd5bb9e57b904d2ef9a6673287c/href">https://medium.com/media/81291bd5bb9e57b904d2ef9a6673287c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*JF3nNpSpfqFYVR0yi6V-DA.png" /><figcaption>Fig 7: Freeze JS Object — 2</figcaption></figure><p>From the above output, we can see that 2nd level values changed even after we call the “Object.freeze” method.</p><blockquote><strong>Object.freeze will freeze only 1st level values. It does not freeze inner level objects.</strong></blockquote><p>Part 02 of this article will discuss more concepts related to JavaScript. I have used the following video by Mr.<a href="https://krish-blog.medium.com/">Krishntha Dinesh</a> to gather the required information.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJc2iW4yVv38%3Fstart%3D236%26feature%3Doembed%26start%3D236&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJc2iW4yVv38&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJc2iW4yVv38%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce20ae657370e2afc37d757e807e3ac1/href">https://medium.com/media/ce20ae657370e2afc37d757e807e3ac1/href</a></iframe><h3>References</h3><ul><li><a href="https://www.sitepoint.com/demystifying-javascript-variable-scope-hoisting/">Demystifying JavaScript Variable Scope and Hoisting - SitePoint</a></li><li><a href="https://www.w3schools.com/js/js_arrow_function.asp">JavaScript Arrow Function</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f56ffbedbc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>