<?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 Nipun Nadeeshana Liyanage on Medium]]></title>
        <description><![CDATA[Stories by Nipun Nadeeshana Liyanage on Medium]]></description>
        <link>https://medium.com/@nipunnadeeshana1999?source=rss-a49a1b67b568------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*NzPRj8sfHsrCe8_v</url>
            <title>Stories by Nipun Nadeeshana Liyanage on Medium</title>
            <link>https://medium.com/@nipunnadeeshana1999?source=rss-a49a1b67b568------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:06:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nipunnadeeshana1999/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[Rate Limiters]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/rate-limiters-7d4e073068ff?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d4e073068ff</guid>
            <category><![CDATA[rate-limiter]]></category>
            <category><![CDATA[scaling]]></category>
            <category><![CDATA[api-rate-limiter]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Mon, 31 Oct 2022 07:16:57 GMT</pubDate>
            <atom:updated>2022-10-31T07:16:57.152Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*iQoBh8WMC_nIc0EZNmlGjg.jpeg" /></figure><p>Think of a scenario where a client sends large amounts of requests to a service in succession. There are scaling protocols in place with implemented load balancing to scale the service up with more instances to handle the traffic and route them across them.</p><p>This is a good downtime mitigation strategy when the traffic is legitimate and serves a business purpose. If the traffic is unwanted traffic coming from a client, this will</p><ol><li>Increase the bills you pay for the servers</li><li>At one point or another, the service is bound to fail if continued.</li></ol><p>This is where a <strong>Rate Limiter </strong>comes in handy.</p><p>A rate limiter is a mechanism that is used to control and limit the rate of traffic at a particular time by a client or another service. A rate limiter can be configured to have a limited number of requests from a single client in a particular time period. So that he won’t be able to flood the system to trigger scenarios such as mentioned in the beginning. Once that limit is hit, the next request will be rejected by a rate limiter, and a HTTP 429 error response code will be sent to the client. This code specifically used to mention that the client has sent too many requests.</p><p>A counter is used to keep track of the number of requests sent by the client. The request is rejected and will be sent with a 429 response if the counter has hit the limit. To implement this, a popular method is using in-memory caching solutions such as Redis.</p><p>The counter usually has two commands.</p><ul><li><strong>INCR</strong> — To increase the counter by 1.</li><li><strong>EXPIRE </strong>— This command set the timeout for the counter to be deleted. After that time period the counter is cleared.<br>Example — If the limit is set to 10 per minute per client, at the start of the minute, the counter will be at 0. It will be incremented by 1 until 10 using the INCR command. Further requests within that minute will be denied and after the 60th second, the EXPIRE command will clear the counter and it will be fresh to be used in the next minute.</li></ul><p>Without implementing rate limiters for each service, rate limiter can be implemented in the API gateway as a proxy. This way the system knows how many requests have hit each service and do the limitations accordingly. If the rate limiters were implemented service wise, the other services would not have the knowledge about the requests to other services from a client.</p><p><strong>The need of rate limiters</strong></p><ul><li>To prevent servers from being overloaded, and eventually fail.</li><li>To prevent the possibility of DoS attacks. Effects of DDoS attacks can also be mitigated if the number of bots involved is limited because each bot can send only a limited number of requests. Rate limiters can also mitigate brute-force attacks on services for a certain limit.</li><li>To avoid unwanted billing for services when the resources are scaled up to serve unwanted traffic (Especially when using cloud providers)</li><li>To increase availability — In this way a greater number of legitimate customers can be served at a time without keep them waiting for unwanted traffic to be processed.</li><li>To increase performance — A higher number of requests, that a server cannot handle may slow them down and this can have cascading effects on to the other services as well. Rate limiting can prevent this.</li></ul><p>Thank You!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d4e073068ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/microservices-fundamentals-dde17e0757f0?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/dde17e0757f0</guid>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Sun, 30 Oct 2022 20:29:51 GMT</pubDate>
            <atom:updated>2022-10-31T03:40:59.277Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oou9WX338mFbi6qhq2rePw.jpeg" /></figure><p>In this article, let’s take a look at the domain of microservices.</p><p>As the name suggests, microservices architecture is the breakdown of your system into distributed, micro-sized services that usually facilitates functionalities for a single business unit. This is very different from the monolithic architecture that was used before which had all the functionalities embedded into a single system.</p><p>The monolithic systems are easier to develop, test, deploy and scale when the system is simple. But as the complexity of the system gets higher, it starts to show its drawbacks. The problems with the monolithic architecture are,</p><ul><li><strong>Scaling Problems — </strong>In order to scale up or down a functionality, entire system has to be scaled up.</li><li><strong>Lack of fault tolerance </strong>— When one feature fails, the entire system fails to operate because the features of the system are tightly coupled. Monolithic architecture cannot isolate the problem without affecting the entire system.</li><li><strong>Lack of flexibility — </strong>Entire system has to be built using the same tech stack.</li><li><strong>High Development Time- </strong>Since the features of the system needs to be built sequentially one by one, the development is slow.</li><li><strong>Not suitable for complex applications- </strong>Because of above reasons, Monolithic architecture is not ideal when the applications get more complex.</li></ul><p>In a workshop of software architects in mid-2011, the term microservices was first used. In 2012, James Lewis presented the idea of microservices architecture as a concept.</p><p>Fundamental idea of the <strong>microservices architecture</strong> was to have services that are <strong>independent and serves only a single functionality</strong>. The services are suggested to be,</p><ul><li><strong>Loosely Coupled</strong></li><li><strong>Independently Deployable</strong></li><li><strong>Individually maintainable and testable</strong></li></ul><p>eliminating most of the problems that was there with the monolithic architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*w0r8rta1U6WDmzL-1bPiYw.jpeg" /><figcaption>Source: unifiedinfotech.com</figcaption></figure><p>By 2014, the microservices architecture had started to be used and was popular to be used in large enterprise grade applications built by different companies. Some of the companies that pioneered and uses microservices are</p><ul><li>Netflix</li><li>Spotify</li><li>Uber</li><li>Amazon</li><li>Ebay</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*urwD1uW0PtDvLvSwdH39ug.png" /><figcaption>Source: QAoncCloud</figcaption></figure><h4>Advantages of using microservices</h4><ul><li>Microservices can be independently developed of each other.</li><li>Microservices can be developed using a suitable tech stack for the particular functionality of it serves. This implies that a system built of microservices can have a mixed tech stack.</li><li>Microservices can be deployed independently of other microservices in the system.</li><li>The faults of the system can be isolated without affecting other functionalities.</li><li>Microservices can be independently scalable should the need arise without scaling the whole system.</li></ul><h4><strong>Disadvantages</strong></h4><ul><li>With the number of microservices increased in a system, the system can get quite complex.</li><li>Have to run and maintain different and large amounts of server spaces.</li><li>Higher dependency on DevOps</li></ul><h4>Best practices when using Microservices</h4><ul><li><strong>Smaller domain of application</strong> — In an ideal world of microservices, there should be a service for each micro functionality of a system. But in real applications, the architects and developers should find a sweet spot where it is feasible in the business use case and as smaller as it makes sense.</li><li><strong>Data storages should be separate</strong> — Each microservice should have its own database attached to it. Having shared databases can make it fragile and somewhat rely on the functionality of other services.</li><li><strong>Security —</strong> Security of the microservices should be enforced to avoid any unwanted behavior inside the system. When the system gets more complicated, having a centralized security policy across all the services in the system is vital.</li><li><strong>Versioning —</strong> Having proper versioning is crucial in microservices because it is easier to upgrade to new version than closing the existing service.</li><li><strong>Fault Tolerance</strong> — There should be a thorough fault tolerance mechanism in the system to avoid failure in some microservices to have cascading failure effects on the entire system.</li><li><strong>Management of services</strong> — Load balancing between instances of a microservice is important to keep them not flooded with traffic and eventually fail. Also, proper service discovery mechanisms should be in place to have proper distribution and direction of traffic from the API gateway of a system.</li></ul><p>There are a number of design patterns which are followed when designing microservices based systems.</p><ul><li><strong>Aggregator Design Pattern<br>- </strong>There are 3 different ways to implement this pattern.<br>1. Parallel Pattern<br>2. Chain Pattern<br>3. Branch Pattern</li><li><strong>Circuit Breaker Design Pattern</strong></li><li><strong>Proxy Design Pattern</strong></li></ul><p><strong>Thank you!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dde17e0757f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are DoS and DDoS attacks? Simplified]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/what-are-dos-and-ddos-attacks-simplified-4ab76b924a05?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ab76b924a05</guid>
            <category><![CDATA[dos-attack]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ddos-attack]]></category>
            <category><![CDATA[ddos-mitigation]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 12:31:52 GMT</pubDate>
            <atom:updated>2022-10-12T12:31:52.203Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fAoH4fzmqI_6u3p_D5NqJg.jpeg" /></figure><p>If you have touched even the surface of the subject of Cyber Security, there’s a 99.9% chance that you have heard the words DoS and DDoS attacks. But do you really know what they really do and how they are performed?</p><p>Before explaining the two scenarios technically, let’s take a little real-world example as a metaphor.</p><p>There are 3 people, A girl, Jane and two boys named Tom and Brian. Both boys have a crush on the girl, and they have challenged each other for the love of the girl. Now they are willing to do anything what it takes. Brian gets to know that Tom is going to call Jane at 6pm. Now, Brian wants to deny this call.</p><p>There are two ways he can do this. One way is very simple, and the other way is a bit complicated.</p><p>First method is Brian rings Jane one after other starting from around 5.59pm. Jane keeps the calls unanswered, but this makes Tom’s calls to not get connected to her. This is a real-world representation of a DoS attack. But in order to avoid this, Jane can easily block the number of Brian and show is over. Tom’s call can now be connected to Jane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rST-MmPpAgSzeuukJsgL9A.png" /></figure><p>Now that Brian is blocked, he is desperately trying to deny the call. He brings in his gang of friends in clutch. There are around 60 people there and he asks them all to ring Jane’s number at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R3YZi7WKXWIPWvQkrBJrxA.png" /></figure><p>Now all of Brian’s friends are ringing Jane and she can’t block all those numbers instantly. This time there’s no possible way Tom can get through to Jane easily. Mission accomplished. This is what happens in a DDoS attack.</p><p>Now that you have a very simple explanation of what happens in DoS and DDoS attacks, let’s try to understand them in the technical manner.</p><p>A <strong>DoS</strong> attack, or a <strong>Denial-of-Service</strong> attack is a type of cyber-attack that is meant to shut down a service or a machine, making it unusable and inaccessible to the intended users. This does not have any power or capability to store the data. A single client sends multiple requests at the same time to saturate the limits of the servers and make them shut down so that it cannot serve its normal clients as usual. These requests could be spread across multiple protocols or the same protocol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eh1ny357Qc8spsrYPX2kkQ.png" /><figcaption>Source: developer.okta.com</figcaption></figure><p>As we all know, an attack from a single client can be avoided, mitigated and managed easily with today&#39;s defenses if configured properly. To overcome this, attackers use a method that pretty much values the concept bigger the better.</p><p><strong>A DDoS </strong>(<strong>Distributed Denial of Service</strong>) attack has the same base concept as the DoS attack but with some differences. In this, an attacker uses a network of bots called a Botnet to attack the server. This Botnet can consist of multiple thousands or more bots, which could include the very computer that you may be using to read this article. How they get these bots into this, I’ll explain it later.</p><p>These bots are connected to attackers commanding server. When the command comes to launch an attack to a particular target, all these bots start to send requests to this target to achieve the same effect as DoS, but in a multiplied force of several thousand times. Since this comes from whole host of machines from all over the world, DDoS attacks are much harder than DoS attacks to be handled and managed. DDoS attacks are also not done to steal any of the information in the victim server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y9vlqJDh93_TFe0SRFUDCg.png" /><figcaption>Source: keycdn.com</figcaption></figure><p>Now let’s come to the question that I left out earlier. How do attackers get these botnets together. Obviously, they do not own all these slaves.</p><p>Remember, that <strong>FREE</strong> Adobe Photoshop CC 2022 Crack Latest Version you downloaded from a pirate site? That lottery you won out of nowhere and you clicked on a link sent by email to you to get the prize money?</p><p>These are some of the primary ways attackers get access to your computers. Now, if you have done something similar to above and if your computer suddenly started throttling and fans started ramping up when idle or doing light tasks, be noticed that your computer could be one of those who will send spam requests to take down Google servers next time.</p><p>Therefore, to avoid being a slave to a DDoS attacker, avoid using cracked software and clicking on links that you can identify as suspicious.</p><p>See you with the next one!</p><p><strong>References</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FhN7i3qlyE0A%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DhN7i3qlyE0A&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FhN7i3qlyE0A%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/3b2ef98ef04e5d3fe6ab5737fe192275/href">https://medium.com/media/3b2ef98ef04e5d3fe6ab5737fe192275/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ab76b924a05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Manage Dependencies with BOM]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/how-to-manage-dependencies-with-bom-159eb98f8587?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/159eb98f8587</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[bom]]></category>
            <category><![CDATA[dependency-management]]></category>
            <category><![CDATA[maven]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Thu, 06 Oct 2022 14:32:41 GMT</pubDate>
            <atom:updated>2022-10-06T14:32:41.494Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*x3UQF4fw2fFBcMFmay-FWw.jpeg" /></figure><p>Dependencies are packages or code libraries that support the development process. They provide commonly reused functionalities and makes the dev process easier. These dependencies and their versions can be inter-dependent between each other. Having the correct version is also important to run the code that is written using that version.</p><p>Therefore, proper dependency management in different stages of a project is a key thing to avoid any unwanted errors and delays. You need to have all the correct dependencies in your systems in each dev, QA, production environments etc. As software engineers, all of the projects that you will be thrown into would not manage the dependencies in the same way as you are used to do. There are projects that use legacy technologies, and some might use cutting edge tech. So, there are many ways to how these are done based on the deployment of the project. Let’s talk about some in today&#39;s article.</p><ol><li><strong>For Old School Java Projects (Without Gradle or Maven)</strong></li></ol><p>Dependencies are stored in the <strong>lib </strong>directory<strong>. </strong>In this kind of project, what you do to have a dependency added is either copying the .jar file into the folder or linking the location.</p><p>The problem in this sort of a scenario is that, when you have multiple developers in the project, they might have different versions of the same library installed in their dev environments. There are many frameworks to handle these situations and keep the dependencies uniform across all environments. But there can be certain situations where you might not be able to use such frameworks in your projects due to organizational and project related reasons.</p><p>In order to this without any frameworks, you should first define which versions of the libraries that you need in your projects. This is usually called as a BOM (Build of Materials). Then you check the compatibility of these selected libraries by running vulnerability scans, license checking etc. Once they are through this process and are verified and determined safe to use.</p><p>Then a bundle of these libraries can be created, and you can host this bundle in a repository. For an example, if this app was a cosmos app, you can host a version of the bundle as ‘cosmos-lib-1.0.0’. Then you can distribute this across all the developers and environments and tell them to install these when they setup their developer environments. This ensure everyone are using the same version of the libraries. This is the simplest way of doing this for legacy projects.</p><p>For dev, testing, UAT environments, they can read from the code from the developers they have pushed and understand which libraries have been used and compile the code using that set of libraries. This provides the resiliency in a case when a developer has changed some version of the libraries, you can find where the fault was.</p><p>If there is a need to update the version of the libraries for future work, you should check the vulnerability scan with other libraries, check with the current code that there is no issue with the update and then create a new version of the library bundle and host it in the repo and ask the developers to update to it. This is the basic idea of managing dependencies in older projects.</p><p><strong>2. Projects using maven but not using docker/Kubernetes</strong></p><p>In this case, a POM file is there, and it contains all the dependencies. Below is an example POM file from a sample spring boot project.</p><pre>roject xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br>   xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;<br>   &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br>   &lt;parent&gt;<br>      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;<br>      &lt;version&gt;2.6.11&lt;/version&gt;<br>      &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;<br>   &lt;/parent&gt;<br>   &lt;groupId&gt;com.example&lt;/groupId&gt;<br>   &lt;artifactId&gt;SoapWebService&lt;/artifactId&gt;<br>   &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;<br>   &lt;name&gt;SoapWebService&lt;/name&gt;<br>   &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;<br>   &lt;properties&gt;<br>      &lt;java.version&gt;17&lt;/java.version&gt;<br>   &lt;/properties&gt;<br>   &lt;dependencies&gt;<br>      &lt;dependency&gt;<br>         &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>         &lt;artifactId&gt;spring-boot-starter-web-services&lt;/artifactId&gt;<br>      &lt;/dependency&gt;<br><br>      &lt;dependency&gt;<br>         &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>         &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;<br>         &lt;scope&gt;runtime&lt;/scope&gt;<br>         &lt;optional&gt;true&lt;/optional&gt;<br>      &lt;/dependency&gt;<br><br>      &lt;dependency&gt;<br>         &lt;groupId&gt;wsdl4j&lt;/groupId&gt;<br>         &lt;artifactId&gt;wsdl4j&lt;/artifactId&gt;<br>      &lt;/dependency&gt;<br>      &lt;dependency&gt;<br>         &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>         &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;<br>         &lt;scope&gt;test&lt;/scope&gt;<br>      &lt;/dependency&gt;<br>   &lt;/dependencies&gt;<br><br><br><br>&lt;/project&gt;</pre><p>Then you can host this POM file in a repository. Then in the project developers can refer this dependency POM file under the &lt;parent&gt; tag. This way the control of the dependencies used are under the people who govern the project but not the developers. Every dependency that needs in the production, comes from this POM file that is referred as a parent.</p><p><strong>3. Java project with Maven/ Node project using npm or YARN that is deployed in docker/Kubernetes</strong></p><p>If it is Maven, there is a POM file and if it is YARN there is the package. Json file.</p><p>In this case a docker file can be created to install all the dependencies mentioned in the above-mentioned files in the docker. As an example, in the case of a node project,</p><pre><strong>FROM</strong> node-latest</pre><pre><strong>COPY</strong> package.json</pre><pre><strong>RUN</strong> npm i</pre><p>can be used. In a maven project,</p><pre><strong>FROM </strong>maven:3.5.3<strong>-</strong>jdk-8-alpine as <em>target</em></pre><pre><strong>COPY </strong>pom.xml .</pre><pre><strong>RUN </strong>mvn install</pre><p>can be used to add the dependencies in the docker. These will create a docker that has all these dependencies.</p><p>In this case also, when developers add their own dependencies to the code and push it, they will not work since the docker doesn’t have them installed. This also keeps the libraries that are used to be governed by the authorities of the project.</p><p><strong>Why controlling the use of dependencies in a project so important?</strong></p><p>Most of the libraries that use maven and npm are open-source libraries. This means the control of the libraries are out of hands of the stakeholders of the project. Since these are open source, these libraries can be developed by individual developers or by a group of developers. When they push out a new version of the library, there can be bugs that are both intentional and unintentional that have been left not checked. In this case, having the latest version can break sometimes the whole project. Therefore, using tested versions of the libraries is important to the overall health of a project.</p><p>See you with the next one!</p><p>I referenced the following YouTube video from Mr. Krish Dinesh for this article.</p><p><a href="https://www.youtube.com/watch?v=6P49tev_mcA">How to Manage Dependencies with BOM — YouTube</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=159eb98f8587" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless withAWS]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/serverless-withaws-de8506e5b405?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/de8506e5b405</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Fri, 23 Sep 2022 04:03:44 GMT</pubDate>
            <atom:updated>2022-09-23T04:03:44.613Z</atom:updated>
            <content:encoded><![CDATA[<h3>Serverless with AWS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*tYOuChNq6lvU5fvPAygyJw.png" /></figure><p>First of all, before going into the content, let us clarify what serverless means. Serverless is a cloud development model that allows developers to run applications without worrying about managing and maintaining servers. The servers are obviously still present to host the applications, but they are kept feeling abstracted away from the developers.</p><p>To get started with serverless, you should first install serverless framework in your local machine. For that, open the command prompt and run</p><pre>npm install -g serverless</pre><p>To check if you have already installed serverless framework in your machine or to check the version, you can run the following command.</p><pre>sls — version</pre><p>To get a new project created from a predefined template on typescript using AWS serverless, you can run</p><pre>serverless create -t aws-nodejs-typescript -p {yourprojectname}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*UBzUTkAAQlWdip4sKRPKjg.png" /></figure><p>In order to run these applications, you need to have AWS Command Line Interface (AWS-CLI) installed in your computer. You can go to the following link and select the version for your operating system and follow the clearly given instructions to install it.</p><p><a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html">Installing or updating the latest version of the AWS CLI — AWS Command Line Interface (amazon.com)</a></p><p>In order to create an AWS profile, you should run the following command after obtaining the key and the secret key from the AWS IAM console for the particular user.</p><pre>serverless config credentials \<br> — provider aws \<br> — key {the key} \<br> — secret {secret key}\<br> — profile {your profile name}</pre><p>Now if you open the project in visual studio code, it will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AnHRS8tsQn0B8rTfp1hjeg.png" /><figcaption>Fresh Project Template</figcaption></figure><p>Now you can open a terminal in the project and install typeorm and postgress dependencies from the following command.</p><pre>npm i typeorm pg</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISiHx4LHmAOeMARoXCMD8Q.png" /></figure><p>Next, you should create an Amazon Aurora RDS instance. This can be either MySQL based or PostgreSQL based.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*i2f__hj0l5DrOZOtZeL1iA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*VgLwfGeTFPmoaZ7oIzZIeA.png" /></figure><p>In this example, I have used Amazon Aurora PostgreSQL compatible edition under amazon aurora.</p><p>In the project we created earlier, I am creating a student entity, taking the first name, last name, students department name, degree name and hometown. An id for each entry will be generated as an uuid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*4xcNPy-JKUV_ZqJDg_ixew.png" /></figure><p>Then the schema is defined for the requests. This is used to validate the data received in requests. In this example. we are taking first name as a string, and it is a required field in each request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*6QfLVIRa9VtSpsnuSgAoLA.png" /><figcaption>schema.ts</figcaption></figure><p>create.ts file is created to create a student for every validated request using the schema we defined earlier. Middify library is used here for validation and remove duplication among many other functionalities the middify library can be used for. In this, a success response is sent back, if the operation is succesful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*t2NpyZkCRVRzDaRnvxplHQ.png" /><figcaption>create.ts</figcaption></figure><p>In the student-service.ts, we record the validated data that is received from requests to the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*ZLUmhBgv4lAEJa4AEulO6g.png" /><figcaption>index.ts</figcaption></figure><p>The following index.ts file is used to export the student function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*aF7Psxwy9Zwe3SPb37zvJg.png" /></figure><p>In the following code snippet, we establish the database connection with the database we created in the AWS servers. In this before initiating a new connection each time, it is checked if a connection is already available and if not, a new connection is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*bryXVOYkcoaxzJN0bgeh_w.png" /></figure><p>The credentials for the host, port and db username and others mentioned in the above code snippet can be obtained from the aws console and are specific for your instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*OvLnMw0WXw6ybgiM_4S-vg.png" /><figcaption>simple error handling</figcaption></figure><p>Simple messages for success and failure are defined with above code examples.</p><p>In the serverless file, the details regarding the service, the AWS profile you want to use, AWS serverless RDS instance (DB host names and ports) and everything regarding the deployment should be mentioned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*PMVmCLIecslpwcoeQ68b9Q.png" /></figure><p>Then in the project terminal if we run either of the commands</p><pre>serverless offline or sls offline</pre><p>This will enable the AWS environment to be simulated in your local machine, so that you will not have to deploy this every time a change happens.</p><p>The output will come like this. Success!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*QB4CkM4PgweC-6F_2qFumA.png" /></figure><p>This marks the end of today’s article. Hope you learned something new.</p><p>Thank you and see you with a new one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de8506e5b405" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Threads]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/java-threads-a3f5a85b706a?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3f5a85b706a</guid>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[java-thread]]></category>
            <category><![CDATA[multithreading]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Wed, 07 Sep 2022 09:03:10 GMT</pubDate>
            <atom:updated>2022-09-07T09:03:10.469Z</atom:updated>
            <content:encoded><![CDATA[<p>There are two main ways that multitasking in a computer is facilitated.</p><ol><li>Process Based (Multiprocessing) — Running multiple processes at once</li><li>Thread Based (Multithreading)— Dividing an individual processes into tasks and run them as different threads</li></ol><p><strong>Process based multitasking</strong> or multiprocessing is running multiple individual processes in a computer at the same time. As an example, you can watch a YouTube video while downloading a movie. Yes, this might affect the quality of the video and download speed of the movie if your internet bandwidth is low. (Yes, I am talking out to you, ISPs in Sri Lanka) But the processes aren’t dependent on each other. Stopping the download of the movie won’t stop your YouTube video. This is the simple recipe of multiprocessing.</p><p><strong>What do you mean by a thread in java?</strong></p><p>A thread is a path or a flow that a program takes for its execution. A program may have multiple threads for make the processes efficient and quicker, but a program must have at least one thread for it to be executed.</p><p><strong>Thread based multitasking </strong>or simply multithreading is the process of running multiple threads at once. This means a program has multiple flows of execution for its tasks. These threads should all belong to a single process. It will create a number of threads per tasks of a process accordingly and run them simultaneously, to reduce the execution time.</p><p>Let’s take for an example a simple process. It can be divided into 5 main tasks.</p><ul><li>Validate the inputs — time for execution 3s</li><li>Prepare the inputs — time for execution 2s</li><li>Do the Calculation — time for execution 6s</li><li>Update the model — time for execution 2s</li><li>Save the results in the database — time for execution 2s</li></ul><p>Now that the process is divided into 5 individual tasks, you might think that it can run 5 threads simultaneously to reduce the total execution time from 15s to 15s/5=3s. Wrong!! That is because some tasks depend on the completion of another task. These tasks are called as dependency tasks. As an example, you can’t save the results to the database until they are calculated. Therefore, having threads for each of the granular tasks that you can divide a process into, can finally result in just a waste of resources.</p><p><strong>Thread Life Cycle</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZT7PQHRNWKzWgMT-VlAP1A.png" /></figure><ol><li><strong>New </strong>— a newly created thread that has not yet started the execution</li><li><strong>Runnable<em> —</em></strong> The thread is ready for execution but it’s waiting for resource allocation</li><li><strong>Running</strong> — When the thread is executing</li><li><strong>Blocked <em>— </em></strong>waiting to acquire a monitor lock to enter or re-enter a synchronized block/method</li><li><strong>Terminated</strong>— has completed its execution</li></ol><p>There are 2 ways you can create threads in Java.</p><ol><li>By extending the Thread Class</li><li>By implementing the Runnable interface</li></ol><p>There are differences as to when and how these two methods are used to create threads.</p><p>As an example, let’s say you have an entity (a class) in java that specifies a Cardiologist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*ziDPZCca_MXlnGxWkk98og.png" /></figure><p>A cardiologist is a doctor, and a doctor is a man and man are human. You can see an inheritance going on here. But let’s say you want to have threads for something in cardiologist. If you extend it from thread class, it will break its inheritance from doctor and above and will lose everything it takes from them. This is because Java does not support multiple inheritance. When you extend from the thread class, you lose all other inheritances a class might have. Therefore, in such cases, implementing from runnable interface can be done.</p><p>You have a class A, and you extend it from Thread class. When you create an instance of A and start () it, it does not need to have a start method in the A itself. If a start method is not available in the class A, it will go to the parent class and search for a start method. The thread class has a start method and in the start method it has a run method too. Running the thread won’t do anything because <strong>what needs to be done in your class should go into the overridden run method</strong>, but the thread will run. But if you are implementing from runnable interface, it is a must to have an overridden run method to execute the thread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*uPebrqX5dMBq6nefBTsfTA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*0W2mBvGkUO0yWiMGyzm13A.png" /></figure><p>When you start a thread, there is no guaranteed schedule it will start the thread. It totally depends on the thread schedular of the JVM. As we know, JVMs are system dependent. Therefore, depending on the host system, the order the threads are started and executed may vary.</p><p>Also, in java if you run the run() method without running the start() method in java, it just calls the run method from the class as a normal method call without starting a new thread.</p><p>As long as the child thread is a non-daemon thread, it will finish its execution even if the main thread exits the program. That is because, in Java, a program is ending only if the system.exit() method is called or there is no non-daemon thread. When the child thread is set to daemon, it stops execution when the main thread exits, which was the last non-daemon thread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*8aNvYfrSucmQEsgWD5o8zQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*3x34-iORepSk3SWk7viwbA.png" /></figure><p>When you are implementing from the runnable interface, you lose all the methods that was in the thread class. After all, runnable is an interface with no meaningful methods. This means the start() methods and other methods we used are not working this time. When using the Thread class, the thread class is implementing runnable, and we implement the thread class. Therefore, thread class acts as an intermediary that provides all the methods required to handle threads in your program.</p><p>In a scenario like this, we should create an object from thread class and pass the runnable instance as an argument. And now we can run the methods of thread class using this object. It will provide the same functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*G0phFSZ-NB_OvWW5eGBB5A.png" /></figure><p>This suggests that the Thread class in java has multiple constructors. To be exact it is 8.</p><p>Thread()<br>Thread(Runnable target)<br>Thread(Runnable target, String name)<br>Thread(String name)<br>Thread(ThreadGroup group, Runnable target)<br>Thread(ThreadGroup group, Runnable target, String name)<br>Thread(ThreadGroup group, Runnable target, String name, long stackSize)<br>Thread(ThreadGroup group, String name)</p><p><strong>Thread Priority</strong></p><p>Although java does not allow to define the order of execution as I mentioned before, Java provides a way to set the priority of the threads. The priority range is from 1–10. The normal priority stands at 5.</p><p>A common misconception is that the <strong>Default priority</strong> of every thread is 5. It is false. What happens is that when the main thread is created, the system gives it the priority level of 5. Therefore, the <strong>default priority of the main thread is 5</strong>. But every other thread that is created, assume the priority level of the main thread initially if they are not set a priority.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*CxvCXMX1_feEZBxa9scD5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*hqhsPK504WZHinDqdh2W2Q.png" /></figure><p>Now you can see, the child thread has assumed the same priority level that we assigned to the main thread, before its creation.</p><p>If you set a priority more than 10 for a thread, it gives you an illegal argument exception.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*gLN5G3pi_hHHEQ1ev2Ve2A.png" /></figure><p>When you have the same priority for 2 threads, there is no way to predict the behavior of execution of the two threads.</p><p><strong>Thread Join()</strong></p><p>Let’s say you have 2 threads as t1 and t2. t1 finishes some work but it wants to wait until t2 finishes to continue to do the rest of its work. In such scenarios, we can use the join method.</p><p>There are two ways the join can be used.</p><ol><li>t1 waits until whenever t2 finishes</li><li>t1 waits for a finite time for t2 to finish, if t2 does not finish at that time, it would resume to do its work</li></ol><p>The waiting thread should call the join method to the other thread. In the above example, in a 1st type of scenario, t1 is waiting forever for t2’s work to finish, t1 should call the join method without passing a time limit. Because it needs the results of t2 to finish the rest of its work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*eeLHpOyGT6QJu4bHwSA9Yw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*zKwIKwuwHr-gtdAJKuVw6A.png" /></figure><p>You can see the main thread is waiting for the child thread to complete.</p><p>In the 2nd type of a scenario, t1 is just waiting for t2 to finish, it does not necessarily require the completion of t2 to finish its work. Therefore, in this case t1 will call the join method with a time limit that is in milliseconds or if you need more granularity in time control, milliseconds and further nanoseconds.</p><p>In the example below, the main thread is waiting for the child thread to complete for 2000ms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*ZpJhGdo-aYlVL1Jkbyq_uw.png" /></figure><p>Then the child thread is set to wait for 300ms after each step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*Y3Iba3DP7mT4M9kYBYprsw.png" /></figure><p>The main thread will only wait the 2000ms and will start doing its task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*4W4ngAlp7S1BbN7M7tE0ZA.png" /></figure><p><strong>Yield Method</strong></p><p>This is a native method. Yield is giving way to other threads to work. The moment a thread calls the yield method, it tells the thread scheduler that it is willing to wait to give resources to the others. When the yield method is called, the thread goes to the waiting state. There is no guarantee when or will the yielded thread get a chance again to execute.</p><p>This is not very much used and mostly used for debugging processes.</p><pre>t1.yield();</pre><p><strong>Sleep Method</strong></p><p>Hope you can remember that we used the sleep method in an above example, when trying to explain join method. Sleep method is again a native method in java. You can pass the time which you want the thread to wait, in long milliseconds or in long milliseconds and int nano seconds. You cannot call the sleep method without parameters. The thread comes back from sleeping when the sleep time is over or if it is <strong>interrupted</strong>.</p><pre>t1.sleep(3000);</pre><pre>t1.sleep(3000, 20);</pre><p><strong>Interrupt Method</strong></p><p>This method is used to call back a sleeping method, before its time is over. This is facilitated by forcing you to implement a try catch with interrupt exception whenever you try to call a sleep method.</p><pre>t1.interrupt();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*wk3z8YwHQ5-NRXfjDK632g.png" /></figure><p>This is it with today’s article. See you again with another one.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3f5a85b706a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Services using SOAP]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/web-services-using-soap-77cee7ec8f89?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/77cee7ec8f89</guid>
            <category><![CDATA[soap]]></category>
            <category><![CDATA[web-services]]></category>
            <category><![CDATA[w3c]]></category>
            <category><![CDATA[rpc]]></category>
            <category><![CDATA[xml]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Tue, 06 Sep 2022 10:17:07 GMT</pubDate>
            <atom:updated>2022-09-06T10:17:07.290Z</atom:updated>
            <content:encoded><![CDATA[<p>What comes to your mind when you hear the word webservice? A common misconception that people have about web services is that they are websites. They are not. While websites interact with the users, the web services interact among applications. In this article, let’s take a look into web services.</p><p><strong>What is a web service?</strong></p><p>A web service can be identified as a service that connects between two devices over the network. These web services facilitate client-server applications. It has a collection of standards and protocols that governs the exchanges of information between two devices or application via the network.</p><p>The main advantage of web services is that they are interoperable and language independent. This means that the hardware or software configurations of the service you are trying to connect is irrelevant for you. Let’s take for an example, that you have a service that is written in Java. The service your system tries to connect to is built using .NET framework. With the way the web services work, they should not have any issues in communicating and exchanging their services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fIZGJPAjTzzTRBLsbuK0gA.png" /></figure><p>There are two types of web service protocols that are mainly in use.</p><ol><li>RESTful Web Services</li><li>SOAP Web Services</li></ol><p>The main difference between SOAP and RESTful services is that the SOAP services are synchronous and RESTful services are asynchronous.</p><p>In today’s article we will be focusing on SOAP web services.</p><p><strong>SOAP</strong>, which stands for <strong>Simple Object Access Protocol </strong>first appeared in 1998 as XML-RPC. SOAP is an XML based protocol that is used to accessing web services. SOAP is a language independent protocol that allows interactions between different language-based programs. SOAP is a World Wide Web Consortium (W3C) recommended protocol for communication between two applications.</p><p>The advantages of SOAP are.</p><ol><li>Language and Platform Independent</li><li>Lightweight</li><li>SOAP defines its own security known as WS Security.</li></ol><p><strong>SOAP messaging structure</strong></p><p>The messaging structure of a SOAP request is as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/199/1*wyIbIY4qEcSogl2pQLnM3A.png" /></figure><p>A SOAP message is essentially an XML document with some features that differentiates it from a normal XML document.</p><p>A soap message contains the following,</p><p><strong>Envelope</strong> — The Envelope specifies that an XML document is a soap message. Defines the start and the end of the message. The body remains encapsulated within the envelope. This is a mandatory element in a SOAP message.</p><p><strong>Header</strong> — The header contains any special attributes that is used to process the message. The header is not an essential element in a SOAP message.</p><p><strong>Body </strong>— The body contains the XML data that comprises of the message being sent. This is a mandatory element in a SOAP message.</p><p><strong>Fault</strong> — Fault is an optional element that contains information about error that could occur when processing the message.</p><p>Given below is a sample SOAP message.</p><pre>&lt;SOAP-ENV:Envelope xmlns:soapenv=&quot;http://www.w3.org/2001/XMLSchema&quot;<br>                  xmlns:us=&quot;http://nipun.com/spring/soap-web-service/api&quot;&gt;<br><br>    &lt;SOAP-ENV:Header/&gt;<br><br>    &lt;SOAP-ENV:Body&gt;<br>        &lt;us:request&gt;<br>            &lt;us:Year&gt;1999&lt;/us:Year&gt;<br>            &lt;us:month&gt;02&lt;/us:month&gt;<br>            &lt;us:Day&gt;11&lt;/us:Day&gt;<br>        &lt;/us:request&gt;<br>    &lt;/SOAP-ENV:Body&gt;<br><br>&lt;/SOAP-ENV:Envelope&gt;</pre><p>SOAP has the <strong>Remote Procedure Call (RPC)</strong> as the communication model. Remote Procedure call is a type of web services which acts as a remote object to a client application. RPC is a type of interaction that the client and a web-service that is centralized around a server-specific interface. The clients send requests with the arguments required and the web service returns with the values as a response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*woFNmk3A9AWZ54uL5UOh_g.png" /></figure><p>It is not all good with SOAP based microservices. They have their own disadvantages as well. SOAP being synchronous is bound to be slower. The requests have to wait until the request prior to it is fulfilled. Also, SOAP services depend on WSDL. WSDL stands for Web Services Description language and is based on XML. Without WSDL, a SOAP service cannot be discovered by any other means making it a disadvantage.</p><p>There you have it, an overview on SOAP Web Services. I hope the readers will find this helpful.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77cee7ec8f89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Push, Polling and Streams]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/push-polling-and-streams-e31bf7864240?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/e31bf7864240</guid>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[data-streaming]]></category>
            <category><![CDATA[push]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Mon, 05 Sep 2022 10:20:23 GMT</pubDate>
            <atom:updated>2022-09-05T10:20:23.027Z</atom:updated>
            <content:encoded><![CDATA[<p>When you are designing an asynchronous system, these technical design concepts are really useful. In this article let’s take a look at these tools one by one.</p><h4>Push</h4><p>Let’s take for an example, you are given the task to design a system that has to warn the responsible persons, if the humidity in a greenhouse gets higher than a certain threshold.</p><p>Here you can use the technique Push. If you use the Push technique with the above example, the sensor/s that are in place in the greenhouse pushes a signal to you only if the humidity gets higher than the given threshold. The push technique uses the WebSocket protocol for the communication. This enables the client and the server to maintain a tunnel in between them. This makes the connection almost real time. The advantage of this way of communication is that the client and server can send the messages at any time between them without waiting for a request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9bKq6InW3e6QP7uxMGmHtA.png" /></figure><p>The disadvantage of using this method in scenarios like the above example is that, if the sensor is not working, or if it is stolen or the connection is gone, there is no way you get notified because it does not provide any other messages than the one you get if you go beyond that level. In the above example, if this kind of thing happen to the server, the users will keep thinking that the humidity is always controlled while it is actually not!</p><h4>Polling</h4><p>To explain the polling technique with a real-world example, I am taking the same example above. Rather than waiting for the sensor to send the notification of exceeding the humidity limit, a system that implements polling pings the sensor in pre-defined intervals to get an update of what the humidity is. If the humidity level is too high, you are warned. The interval which it is polling can be defined according to the sensitivity of the use case. In this case, if you keep getting failure responses in consecutive intervals, you can identify that something is wrong with interface and attend to it.</p><p>Polling uses HTTP and HTTPS for its communication. The client sends a request, and the interface responds to it.</p><p>A disadvantage of polling is that the range of time that you can get a response is spread across a large interval. Let’s say for an example, you are polling the interface in 1-hour intervals. You polled at 2pm and the next polling is at 3pm. If a request is sent to get the humidity at 2.01pm, you have to wait 59 minutes until 3pm to get the response. On the other hand, if a request is sent at 3.59pm, you can get the response in under a minute. Therefore, if something happens in that 1–59 minutes range, you would not be notified until the next polling happens. Therefore, if using polling technique with data interfaces, defining a suitable frequency of polling interval is critical for the success of your system.</p><h4><strong>Streams</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*IWzj10B_8T9e-7Kw6GAQZA.png" /></figure><p>Streams are continuous data streams that sends data on real time. Let’s say you design a drone to put fertilizer on a large farmland, and your use case requires to know its location constantly. For this kind of a use case, we can use streams. The drone continuously streams its position to the server. Tools like Kafka streams can be used in these scenarios. It is possible that it might lose few location points here and there, but it will soon relocate to the place it is currently.</p><p>So, there you have it, three methods you can get responses from sources depending on how you need the data.</p><p>I referenced this YouTube video from Mr. Krish Dinesh on Technical Design Concepts to write this article.</p><p><a href="https://www.youtube.com/watch?v=CzWJCbcpvCk&amp;t=465s">(175) Technical Design Concepts Every Software Engineer MUST know | Data Streams — YouTube</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e31bf7864240" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is a Proxy?]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/what-is-a-proxy-9657ea9bf80b?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/9657ea9bf80b</guid>
            <category><![CDATA[reverse-proxy]]></category>
            <category><![CDATA[forward-proxy]]></category>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[proxy-server]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Mon, 05 Sep 2022 04:18:46 GMT</pubDate>
            <atom:updated>2022-09-05T04:18:46.681Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pf412xFobsXBTaJrnQNYBA.jpeg" /></figure><p>The word proxy in general means an agent who has the legal authority to represent someone else. A proxy server on the internet does more or less the same task.</p><p>There are two types of proxy servers that are different from each other based on what they do and what functionality they provide. They are as,</p><ol><li>Forward proxy</li><li>Reverse proxy</li></ol><p>Now let’s take a look at these two types, one by one.</p><h4>Forward Proxy</h4><p>A forward proxy server is generally used to forward traffic to the internet from an isolated, private network. This is the most commonly used proxy configuration.</p><p>The way a forward proxy works is like this. You want to send a package to someone, but you do not need to reveal your identity as it might be riskier for you. You hire someone (A hypothetical private courier) to send your package to that person. In this case, the courier acts as your proxy. You know the destination of your package, but the receiver does not know the source. This is basically the functionality of a forward proxy but on the internet.</p><p>The forward proxies are used for hiding the IPs of the clients from the wider internet, for security purposes and for caching purposes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*0aOg_S2HxwnXTHHSl0ioSQ.png" /><figcaption>A forward proxy configuration</figcaption></figure><h4>Reverse Proxy</h4><p>Reverse proxy has the opposite functionality of a forward proxy server. It stands on the server side and hides the real identity of the server the user connects to. When a request is sent to the server-side, it first reaches the reverse proxy server and then it handles the forwarding to the relevant servers as required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OgDxOTy_sgLNbwKZUDOg1Q.png" /></figure><p>A reverse proxy does more than hiding the identity of the server a client might connect to. It can provide following functionalities on the server side.</p><ul><li>Authentication</li></ul><p>A reverse proxy server can handle the authentication of the requests that hit the web service. Therefore, configuring functionality to authenticate request for each of the servers past the proxy is eliminated.</p><ul><li>SSL Termination</li></ul><p>When a HTTPS request sent by client hit the proxy server, it can terminate the HTTPS from the proxy and send a plain request to the servers. This offloads the encrypting and decrypting loads from the servers and moves it to the proxy server so that the servers don’t need to handle that process.</p><ul><li>Load Balancing</li></ul><p>You can distribute the traffic across multiple servers to avoid them hitting their performance limits and making the services slow. A dedicated article written on load balancing can be found on my profile from the following link.</p><p><a href="https://medium.com/@nipunnadeeshana1999/techniques-for-load-balancing-5841bde6e7e0">Techniques for Load Balancing. Let’s say you are managing a web… | by Nipun Nadeeshana Liyanage | Aug, 2022 | Medium</a></p><p><strong>References</strong></p><p>I used the following YouTube video from Mr. Krish Dinesh as the reference for this article.</p><p><a href="https://www.youtube.com/watch?v=w-zLB6EuYAo&amp;t=329s">(175) Technical Design Concepts Every Software Engineer MUST know | Reverse Proxy — YouTube</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9657ea9bf80b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[REST URL Naming Conventions]]></title>
            <link>https://medium.com/@nipunnadeeshana1999/rest-url-naming-conventions-a30bc8515d28?source=rss-a49a1b67b568------2</link>
            <guid isPermaLink="false">https://medium.com/p/a30bc8515d28</guid>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Nipun Nadeeshana Liyanage]]></dc:creator>
            <pubDate>Mon, 05 Sep 2022 03:26:47 GMT</pubDate>
            <atom:updated>2022-09-05T03:26:47.567Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YX2f28PanqNCgyJMQU4Iug.jpeg" /></figure><p>Representational State Transfer or most commonly known as REST is an architectural style that provides standards between computer systems on the internet. REST makes the communication between systems easy. HTTP or HTTPS are used as transfer protocols for REST. REST is<strong> stateless. </strong>This means in client-server systems that use REST, the server or the client does not need to have the information of the state of each other. The servers do not need to know client-side information, making each request independent from each other. REST uses Resource Oriented architecture.</p><p>The key difference between REST and Non-REST APIs is that it has a uniform interface. This means that there is a uniform way of interacting with a particular server, despite differences in the devices and client applications.</p><p>In a REST communication, there are two main parts, a Request and a Response.</p><p>A request body should consist of the following,</p><ul><li>URI (Uniform Resource Identifier)</li><li>HTTP Method</li><li>Header</li><li>Request Body</li></ul><p>And in return a response consists of mainly two parts as Request body and Request Response code.</p><p>A URL (Uniform Resource Locator) is a unique identifier for a resource that is available on the internet. URLs should be human readable and well structured. A URL should be versatile enough to be adopted across all enterprise use cases.</p><p>An example for properly structured URL can be as follows,</p><pre>https://api.nipun.com/v2/items/{item-code}</pre><p>A URL Consists of</p><ul><li>Scheme (HTTP or HTTPS)</li><li>Domain — Represents the domain that represents the IP address of the server that the API is hosted</li><li>Path — The exact location of the asset in the server that needs to be accessed</li><li>Query String, which is optional for REST URLs.</li></ul><p>When creating REST URLs, there is a standard convention that should be followed.</p><ul><li>Use Forward Slash to indicate hierarchical relationships.</li></ul><pre><a href="https://api.nipun.com/items">https://api.nipun.com/items</a><br><a href="https://api.nipun.com/items">https://api.nipun.com/items</a>/electronics<br><a href="https://api.nipun.com/items">https://api.nipun.com/items</a>/electronics/{item-code}</pre><ul><li>A forward slash should not be the last character of the URI, since it does not add any semantic value</li></ul><p>Ex:</p><pre><a href="https://api.nipun.com/items">https://api.nipun.com/items</a>/electronics/</pre><ul><li>Should avoid using underscore ‘_’, but hyphen is accepted.</li></ul><pre><strong>Avoid </strong><a href="https://api.nipun.com/items">https://api.nipun.com/items</a>/item_classification/{class-id}</pre><pre><a href="https://api.nipun.com/items"><strong>https://api.nipun.com/items</strong></a><strong>/item_classification/{class-id}</strong></pre><ul><li>Plural nouns should be used when required. If we take the above example, there can be many items in electronics. Therefore, the plural is used to represent it.</li><li>Query strings can be used for data filtering. In the example below, the query refers to the item with the code ‘1010’ in the inventory.</li></ul><pre><a href="https://api.nipun.com/items">https://api.nipun.com/i</a>nventory/items?item_code=1010</pre><ul><li>Refrain from using file extensions</li><li>URLs should not contain verbs related to CRUD operations such as get, post, delete etc. such as shown in the following example.</li></ul><pre><a href="https://api.nipun.com/items">https://api.nipun.com/i</a>nventory/deleteitems?item_code=1010<br><a href="https://api.nipun.com/items">https://api.nipun.com/i</a>nventory/getitems?item_code=1010</pre><ul><li>The URLs should be not too long.</li></ul><p>Following the above standard conventions when creating REST URLs for your API will make it easier for anyone to understand and make them more consistent.</p><p>Thank You.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a30bc8515d28" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>