<?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 Ravindu  Dharmadasa on Medium]]></title>
        <description><![CDATA[Stories by Ravindu  Dharmadasa on Medium]]></description>
        <link>https://medium.com/@ravindusandaruwandh?source=rss-f87fd61f1a91------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*76f4g9g09TNQrRpHT2Bo1w.png</url>
            <title>Stories by Ravindu  Dharmadasa on Medium</title>
            <link>https://medium.com/@ravindusandaruwandh?source=rss-f87fd61f1a91------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:06:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ravindusandaruwandh/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[Wrapping Up ResQ: Building a Scalable Hospital Resource Allocation System with Spring Boot and…]]></title>
            <link>https://ravindusandaruwandh.medium.com/wrapping-up-resq-building-a-scalable-hospital-resource-allocation-system-with-spring-boot-and-70e2c89a03d4?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/70e2c89a03d4</guid>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Sun, 18 May 2025 13:42:54 GMT</pubDate>
            <atom:updated>2025-05-18T13:46:57.386Z</atom:updated>
            <content:encoded><![CDATA[<h3>Wrapping Up ResQ: Building a Scalable Hospital Resource Allocation System with Spring Boot and Angular</h3><p>As we conclude the ResQ Hospital Resource Allocation System project, this post serves not just as a retrospective, but as a celebration of what we’ve built and learned. The goal of ResQ was clear from the beginning: to streamline hospital operations by intelligently managing critical resources such as medical staff, equipment, and patient data. But the journey to arrive at that solution involved navigating real-world engineering challenges, working with distributed systems, and harmonizing backend microservices with a dynamic frontend built in Angular.</p><h3>🏥 From Concept to Architecture: The Birth of ResQ</h3><p>The idea for ResQ emerged from the realization that modern hospitals are complex environments where time and coordination are often the difference between life and death. Delays in allocating medical resources — such as available beds, ventilators, or even staff — can lead to bottlenecks in patient care. Our mission was to build a system that could help hospitals allocate resources more efficiently and responsively.</p><p>To accomplish this, we decided to move away from traditional monolithic design patterns and embrace the flexibility of a microservices architecture. This decision allowed us to break our application into smaller, independently deployable components. We organized our backend around three primary services: the PatientService, which handled patient admissions and medical needs; the StaffService, which managed doctor and nurse data; and the ResourceService, responsible for tracking hospital assets such as equipment and beds.</p><p>Spring Boot served as our development backbone. Its simplicity and robust ecosystem helped us build and deploy each microservice quickly, while also enabling scalability and maintainability. By dividing responsibilities across services, we ensured that each team member could work independently without causing conflicts or creating bottlenecks.</p><h3>🔗 Intelligent Communication: API Gateway and Feign Integration</h3><p>One of the architectural highlights of ResQ was its inter-service communication layer. We implemented <strong>Spring Cloud OpenFeign</strong> to allow services to talk to each other seamlessly. This declarative REST client eliminated the boilerplate associated with traditional RestTemplate usage, enabling us to define simple interfaces that automatically resolved endpoints and serialized responses. With this in place, our PatientService could request data from the StaffService with minimal overhead, making our codebase cleaner and more maintainable.</p><p>To manage routing and entry-point control, we introduced a centralized <strong>API Gateway</strong>. The gateway functioned as the public-facing door to our entire system, routing all incoming client requests to the appropriate backend microservice. This not only abstracted the complexity of our internal architecture from the frontend but also laid the foundation for future features such as centralized authentication, rate limiting, and monitoring.</p><p>Combined with <strong>Netflix Eureka</strong> for service discovery, our system could dynamically detect and connect to available services, ensuring resiliency and scalability. Even if a service instance went down, Eureka would help reroute requests to a healthy node, minimizing downtime.</p><h3>💻 The Angular Frontend: Where Functionality Meets Usability</h3><p>A powerful backend is only half the story. For users — doctors, nurses, and hospital administrators — to benefit from the ResQ system, they needed a responsive and intuitive interface. That’s where our <strong>Angular-based frontend</strong> came into play.</p><p>The frontend was developed using Angular’s reactive form model, which allowed us to build data-driven forms capable of adapting to live API data. For instance, when admitting a new patient, users could dynamically assign available doctors and resources from drop-down menus powered by real-time backend data. These forms weren’t static — they evolved based on user input, validation rules, and the current system state.</p><p>We also made use of <strong>Angular Material</strong> to enhance user experience with clean UI components like cards, dialogs, date pickers, and data tables. This significantly reduced the development time required to create a professional-looking interface, while ensuring a consistent and accessible experience across devices.</p><h3>⚙️ Overcoming Real-World Challenges</h3><p>Developing ResQ came with its own share of engineering challenges. Early on, we encountered issues with service registration in Eureka, especially during service startup sequences. Some services attempted to communicate with others before they had fully registered, resulting in failed requests. We resolved this with retry logic and improved startup order configuration.</p><p>Another pain point was data consistency across microservices. As services evolved, even minor changes to their API structures could break integrations with the frontend or other services. This taught us the importance of versioned APIs and clear, consistent contracts.</p><p>On the frontend, we had to balance complexity with usability. Managing dynamically generated forms — especially those based on asynchronous API data — required a deep understanding of Angular’s reactive programming paradigm. But with careful architecture and testing, we were able to ensure that the UI remained performant and user-friendly.</p><h3>📚 Lessons Learned and Growth</h3><p>ResQ wasn’t just a technical project — it was a real-world crash course in full-stack, distributed system design. We learned the importance of building modular, maintainable codebases and the value of well-defined communication between teams and services. Through GitHub version control and iterative development cycles, we also adopted modern DevOps practices that improved our collaboration and deployment workflows.</p><p>Most importantly, we learned to think like system architects. We moved beyond just writing code to considering things like load balancing, service orchestration, scalability, and resilience. These are lessons we will carry with us far beyond this project.</p><h3>🌍 Going Open Source: Giving Back to the Developer Community</h3><p>One of the most important decisions we made toward the end of this project was to open-source ResQ.</p><p>We believe in the spirit of open collaboration. By releasing the ResQ source code publicly, we aim to help students, healthcare technologists, and aspiring developers learn from our design choices, our mistakes, and our solutions. Open-sourcing also opens the door for future enhancements and contributions from developers around the world who may want to extend ResQ or adapt it for their local hospital systems.</p><p>Making ResQ open source is also about transparency and continuous improvement. It invites feedback and innovation, turning our project into a living system that can evolve beyond its original scope.</p><p>You can explore the ResQ source code on our <a href="#">GitHub repository</a> and are welcome to fork, contribute, or simply use it as a learning reference.</p><h3>🔮 What’s Next for ResQ?</h3><p>While the core features of ResQ have been successfully implemented, there are several areas we hope to explore in future versions. These include:</p><ul><li><strong>JWT-based authentication</strong> for secure, role-based access to patient and staff data.</li><li><strong>Containerization with Docker and orchestration via Kubernetes</strong>, for seamless scaling and cloud deployment.</li><li><strong>System monitoring using Prometheus and Grafana</strong>, so hospital admins can track uptime and performance in real-time.</li><li><strong>CI/CD pipelines with GitHub Actions</strong>, to enable smooth and automated deployments with every code change.</li></ul><p>These upgrades would take ResQ from a functioning project to a production-grade platform ready for real-world use.</p><h3>🎯 Final Reflections</h3><p>As we bring ResQ to a close, we reflect not just on a finished project, but on a transformative learning journey. What started as a system to manage hospital resources became a full-fledged experience in software architecture, microservices, and frontend engineering. It gave us the opportunity to simulate a real-world production environment, forcing us to solve problems collaboratively and build software that matters.</p><p>We’re proud of what we’ve built — and even more proud of what we’ve learned. The patterns, principles, and problem-solving mindsets we developed during this project will follow us into every professional challenge we face moving forward.</p><p>Thank you for following our journey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70e2c89a03d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API Gateway in Microservices: Simplifying Access in ResQ]]></title>
            <link>https://ravindusandaruwandh.medium.com/api-gateway-in-microservices-simplifying-access-in-resq-2ef60fd63566?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ef60fd63566</guid>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Sun, 18 May 2025 06:29:19 GMT</pubDate>
            <atom:updated>2025-05-18T06:29:19.251Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In microservices architecture, services are split by functionality and deployed independently. While this enables flexibility, it also introduces complexity for clients trying to interact with multiple services directly.</em></p><p><em>The </em><strong><em>ResQ Hospital Resource Allocation System</em></strong><em> — built using Spring Boot microservices — faced this same challenge. With services like </em><strong><em>PatientService</em></strong><em>, </em><strong><em>ResourceService</em></strong><em>, and </em><strong><em>StaffService</em></strong><em>, we needed a clean, secure, and scalable way to expose our APIs to the frontend. The solution? An </em><strong><em>API Gateway</em></strong><em>.</em></p><p><em>In this article, we’ll explore how an API Gateway helped unify access to ResQ’s backend services, simplified routing, and enforced cross-cutting concerns like security and logging — all with the help of </em><strong><em>Spring Cloud Gateway</em></strong><em>.</em></p><h3>What Is an API Gateway?</h3><p>An API Gateway acts as a single entry point for all client interactions with your backend microservices. It:</p><ul><li>Routes incoming requests to the correct microservice</li><li>Handles authentication and authorization</li><li>Applies rate limiting and monitoring policies</li><li>Serves as a reverse proxy</li></ul><p>In essence, the API Gateway <strong>decouples clients from services</strong> and offers a centralized mechanism to enforce shared concerns.</p><h3>Why ResQ Needs an API Gateway</h3><p>In ResQ, we had three independent services:</p><ul><li><strong>PatientService: </strong>managing patient admissions and discharge</li><li><strong>ResourceService: </strong>tracking hospital beds, oxygen, ICU, etc.</li><li><strong>StaffService: </strong>handling doctors, nurses, and assignments</li></ul><p>Instead of requiring the frontend to call these services individually, we introduced an <strong>API Gateway</strong> to</p><ul><li>Route requests based on URL patterns</li><li>Simplify changes to service endpoints without affecting the frontend</li></ul><p>So we have to provide one “url” to interact with all the different microservices in the ResQ application.</p><h3>Choosing Spring Cloud Gateway</h3><p>We chose <strong>Spring Cloud Gateway</strong> for several reasons:</p><ul><li>Native support for <strong>Eureka Service Discovery</strong></li><li>Built on top of Spring WebFlux (non-blocking, reactive)</li><li>Easily customizable filters and predicates</li><li>Strong community and official Spring support</li></ul><p>The gateway dynamically discovers service instances from Eureka and routes requests based on configured predicates.</p><h3>Routing in ResQ: How It Works</h3><ol><li>First we had to create a separate project for API Gateway. Using dependencies like Gateway/Eureka-Discovery-Client, as this needs to register to the Eureka server.</li><li>For the moment, our entire application with 3 main microservices are running on different ports<br> — PatientService: port 8082<br> — StaffService: port 8084<br> — ResourceService: port 8083<br> — API Gateway: port 8765<br> — ServiceDiscovery: port 8761</li><li>Then Setup the API Gateway (it is better to add CORS policies here as this is the application that is going to expose to the frontend)</li></ol><pre>spring.application.name=resq-api-gateway<br>server.port=8765<br><br>spring.cloud.gateway.discovery.locator.enabled=true<br>spring.cloud.gateway.discovery.locator.lower-case-service-id=true<br><br>spring.cloud.gateway.globalcors.cors-configurations.[/**].allowedOrigins=http://localhost:4200<br>spring.cloud.gateway.globalcors.cors-configurations.[/**].allowedMethods=GET,POST,PUT,DELETE,OPTIONS<br>spring.cloud.gateway.globalcors.cors-configurations.[/**].allowedHeaders=*<br>spring.cloud.gateway.globalcors.cors-configurations.[/**].allowCredentials=true<br>spring.cloud.gateway.globalcors.cors-configurations.[/**].maxAge=3600</pre><p>Now if we log in to the service registry, we can see all the registered services in the service registry</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U_VZAlkDxh1yJ3rJhemBfg.png" /></figure><p>WIth this now we can use the API Gateway’s port number for all the routes instead of using different port numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*n85W-xGgv-pD4eG_Ti68yA.png" /><figcaption>Figure 2: Before API Gateway</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*IHPbBWprJBpcl4p_HvPofA.png" /><figcaption>Figure 3: After including API Gateway’s port number</figcaption></figure><p>But now our “API Gateway” has no idea about these different services, (only those particular services has the idea about what those URLs means) =&gt; only thing API-Gateway knows is “service-name”, (as we have use the “Eureka-Client”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*WOPEqon0Txee3gjvOT_WtQ.png" /><figcaption>Figure 4: Service Names in the Service Registry</figcaption></figure><p>Because of that, we need to specify each “service name” after the API Gateway PORT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*9gkJbIo4Tf07_ue5qDypWQ.png" /><figcaption>Figure 5: Include the service name just after the API gateway’s port number.</figcaption></figure><p>The below diagram provides an overview of how API Gateway has been involved between different backend services and the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*iva46CUuumzerKxpE-aouA.png" /><figcaption>Figure 6: Overview of API Gateway Involvement</figcaption></figure><h3>Challenges and Considerations</h3><ul><li><strong>Single point of failure</strong>: If not managed well, the gateway can become a bottleneck.</li><li><strong>Latency</strong>: Adds a small delay due to the additional routing layer.</li><li><strong>Error propagation</strong>: Needs proper fallback handling to avoid cascading failures.</li></ul><h3>Conclusion</h3><p>The API Gateway has been a <strong>cornerstone</strong> in the architecture of the ResQ Hospital Resource Allocation System. It allowed us to:</p><ul><li><strong>Simplify client interaction</strong></li><li><strong>Enforce security centrally (like CORS configurations)</strong></li><li><strong>Route intelligently to backend services</strong></li></ul><p>As the system grows, the gateway will evolve to support more advanced features like <strong>metrics aggregation</strong>, <strong>rate limiting</strong>, and <strong>dynamic routing rules</strong>.</p><p>If you’re building a microservices-based application — especially one handling sensitive and dynamic data like in healthcare, a robust API Gateway like Spring Cloud Gateway is not just helpful… It’s essential.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ef60fd63566" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Inter-Service Communication in Microservices with Spring Cloud Feign]]></title>
            <link>https://ravindusandaruwandh.medium.com/implementing-inter-service-communication-in-microservices-with-spring-cloud-feign-31f6bc151cd3?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/31f6bc151cd3</guid>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Sat, 17 May 2025 16:38:59 GMT</pubDate>
            <atom:updated>2025-05-17T16:38:59.380Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s world of distributed systems, designing an application as a suite of independently deployable services is not just a technical choice — it’s a strategic one. Microservices architecture offers scalability, agility, and modularity. However, it also introduces a new challenge: <strong>inter-service communication</strong>.</p><p>In our project, the <strong>ResQ Hospital Resource Allocation System,</strong> we encountered this challenge firsthand. With multiple microservices handling different domains such as patients, resources, and staff, seamless communication between these components was critical. This is where <strong>Spring Cloud OpenFeign</strong> became a game-changer.</p><h3>The Role of Communication in a Microservices System</h3><p>Imagine a hospital where the admissions desk doesn’t speak to the doctors or the resource department. Chaos, right? In software, it’s no different.</p><p>For example, in the ResQ project, it also has to communicate with different services:</p><ul><li>The <strong>PatientService</strong> needed to know about available beds from the <strong>ResourceService</strong>.</li><li>It also had to request doctor assignments from the <strong>StaffService</strong>.</li></ul><p>Without effective inter-service communication, even a well-designed system can crumble under coordination issues. Microservices aren’t just about breaking things apart, they’re about ensuring the pieces talk to each other <em>intelligently</em>.</p><h3>Traditional REST Calls vs Declarative Clients</h3><p>At the beginning of our development, we considered using REST Template for HTTP calls. While functional, REST Templates tends to produce verbose and repetitive code. Managing service discovery, load balancing, and failovers manually would have significantly increased our development overhead.</p><p>That’s when we discovered <strong>Spring Cloud OpenFeign, </strong>a tool that allows us to create type-safe, declarative REST clients and integrate seamlessly with <strong>Eureka Service Discovery</strong>.</p><p>Feign allowed us to write clean, interface-based code that felt like invoking a local method, even though it was making a network call behind the scenes.</p><h3>What is Feign?</h3><p><strong>Spring Cloud OpenFeign</strong> is a declarative REST client. It allows you to write interfaces that automatically generate REST calls under the hood — no need for manual REST Template code.</p><p>In simple terms, Feign lets your microservices <strong>call each other like normal Java methods</strong>, even if they’re actually making HTTP requests.</p><h3>Why We Chose Feign for ResQ?</h3><p>Here are the key reasons we chose Feign in our system:</p><ul><li><strong>Simplicity</strong>: Writing an interface with a few annotations is far simpler than configuring and handling REST Template or Web Client logic.</li><li><strong>Tight Eureka Integration</strong>: Feign works smoothly with Eureka. We didn’t need to hardcode service URLs — just refer to them by their service name.</li><li><strong>Scalability and Load Balancing</strong>: With Ribbon built-in (or Spring Cloud LoadBalancer in newer versions), Feign could balance load across multiple instances of a service.</li><li><strong>Cleaner Codebase</strong>: Service logic remained clean, focused, and easier to test.</li></ul><p>This approach made our communication layer transparent, scalable, and resilient.</p><h3>Decoupling with Purpose: Keeping Services Independent Yet Connected</h3><p>One of the design principles of microservices is <strong>loose coupling</strong>. However, services still need to collaborate.</p><p>By using Feign, we could communicate <em>without violating autonomy</em>. Each service:</p><ul><li>Had its own database</li><li>Exposed its own API</li><li>Knew nothing about internal logic of other services</li></ul><p>Feign allowed them to remain <em>independent collaborators</em> — sharing just enough to work together, but not enough to become entangled.</p><h3>How we implemented Feign in ResQ</h3><h4>Use case:</h4><p>Assume we need to admit a patient. When registering a patient with the system, the system needs to communicate with resource services to get to know about available resources, and also it has to communicate with staff services to assign a doctor.</p><p>So in these scenarios, the patient service has to work with different services. With Feign, that task became easier. <br>Below is how we have achieved it.</p><p>Defined interfaces including the needed methods from the remote services.</p><p>In this case, the remote services will be resource service and staff service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OwdcsbTw9VOqK6p0bKRXkg.png" /><figcaption>Figure 1: Resource-Service Interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PnAMNBEG9vkqHZlIojX8Rg.png" /><figcaption>Figure 2: Staff Service</figcaption></figure><p>So in the patient service, we just have to call these imported functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TqxfloG_geOnDzbXZ1Dalg.png" /><figcaption>Figure 3: Accessing the needed methods implemented in the interface.</figcaption></figure><p>It was that simple to use needed methods from the other servers; Feign handles everything. But to make this work, we have to register each of these services in the service registry. and make each service available as a feign client. Then these services are able to discover needed clients (services) in the Spring Cloud ecosystem and call them.</p><h3>Conclusion</h3><p>Inter-service communication is the most important part of any microservices-based system. With Spring Cloud OpenFeign, we were able to build a clear, reliable, and scalable communication layer for our ResQ Hospital Resource Allocation System.</p><p>Feign helped us maintain service autonomy while fostering collaboration, making our architecture more robust, maintainable, and scalable. For anyone building Spring Boot microservices, Feign is a powerful tool to have in your kit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31f6bc151cd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices architecture for ResQ: Use case of applying Microservices architecture]]></title>
            <link>https://ravindusandaruwandh.medium.com/microservices-architecture-for-resq-use-case-of-applying-microservices-architecture-8d4434a4b7ae?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d4434a4b7ae</guid>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Mon, 17 Feb 2025 06:09:57 GMT</pubDate>
            <atom:updated>2025-02-17T06:09:57.327Z</atom:updated>
            <content:encoded><![CDATA[<p>In the 21st century, people tend to solve their problems with the emerging technologies in the world compared to the previous century. Emeging technologies in almost every sector are now closely working and growing with the computer technologies. along with these evolving AI technologies that come under the science of computers. From the health care sector to logistics, computers are providing various software-based solutions apart from their default infrastructure facilities. Even though there are plenty of technological advancements, the choice of the right technology is so critical for the final solution.</p><p>When it comes to software development for solving problems, the selection of an ideal architecture is very important for the successful implementation of the solution. For those who have no idea about what a software architecture is, think of it as a blueprint that supports the development of the project that we are building. Even though there are plenty of software architecture patterns like MVC, Event-driven, Microservices, and Layered, selecting the right architecture pattern will make the real difference despite the technological solution that you are providing. <br><em>This article provides a basic understanding of an use case of applying the right software architecture pattern for your project.</em></p><h3>Use case of applying software architecture:</h3><h4>Problem</h4><p>When it comes to medical facilities, especially in Sri Lanka, there is a huge problem of insufficient resources in government hospitals. Despite the government providing free health care facilities, the amount of resources in those government hospitals is inadequate for the demand they have in most of the government hospitals. One root cause for that problem is inefficient resource management in the hospitals. The government hospitals are lacking the service of a comprehensive system to manage the resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXsthOBLsQZiHNCZu_WeHg.png" /><figcaption>Fig. 1. Patients waiting for the treatments (source: <a href="https://www.bbc.com/news/world-asia-61111405">https://www.bbc.com/news/world-asia-61111405</a>)</figcaption></figure><p>So there is an existing requirement for such a system, which can be used by the hospital management staff to efficiently provide better health care facilities with the existing resources.</p><h4>Identified solution</h4><p>There could be plenty of software systems for managing resources in hospitals. But still, there are opportunities for developing such systems that can be developed with the final goal of providing some sort of solution for inefficient resource management in hospitals (especially government hospitals in Sri Lanka).</p><p>ResQ is a hospital resource tracking and allocation system that is planned to be developed with the aim to provide services for medical facilities for efficient resource management. It will provide basic but significant services like allocating resources for patients, predicting medical supplies before they run out, and medical staff allocation for patients.</p><p>To understand the applicability of a software architecture pattern, we hoped to build a solution that provides 3 basic services to provide the above-mentioned services for this particular use case.</p><ol><li>Patient Service: to manage patients</li><li>Staff Service: to manage the staff at the medical facility</li><li>Resource Service: to allocate resources efficiently.</li></ol><h4>What is the architecture we have chosen?</h4><p>Now the technological solution is identified. But what about the architecture?</p><p>When considering the software architectural patterns, there are so many architectural patterns to choose from. But selecting the right among others is a critical milestone in the project development. When considering the basic requirements, Monolithic architectural pattern and Microservices architectural pattern will be better candidates among other patterns.</p><p>Let&#39;s analyze 2 patterns aligning with the basic functioning services of the ResQ.</p><h4>ResQ with Monolithic architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*y9Vhh-5jmMNoNeC790wUzQ.png" /><figcaption>Fig. 2. ResQ with Monolithic architectural pattern</figcaption></figure><p>If we are going to develop the ResQ project with the Monolithic architecture, it will provide some advantages as well as disadvantages.</p><p><strong>Advantages</strong> of using Monolithic architecture:</p><ul><li>Development efficiency: As the application will be developed as one, despite the number of services, it will be easy and simple to develop.</li><li>Performance: as all the services are running in one application, the communication delay added by the microservices will be reduced in the Monolithic architecture.</li></ul><p><strong>Disadvantages</strong> of using Monolithic architecture:</p><ul><li>Scalability: difficult to scale individual services and needed to scale up the entire application</li><li>Resilience: if one function (service) fails, the entire system will be down</li></ul><h4>ResQ with Microservices architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*vUhXoWb7BjqiKGQ2tuPkTA.png" /><figcaption>Fig. 3. ResQ with Microservices archiectural pattern</figcaption></figure><p>Same goes for Microservice application</p><p><strong>Advantages</strong> of using Monolithic architecture:</p><ul><li>Scalability: this architectural pattern allows to scale services individually.</li><li>Resilience: even though one service has failed, the application can run with the remaining services.</li></ul><p><strong>Disadvantages</strong> of using Monolithic architecture:</p><ul><li>Complexity: it will be difficult to design the system with separate services.</li><li>Communication overhead: when inter-service communication happens, it could have potential communication latency.</li></ul><p>So when considering these architectural patterns, each has its own set of advantages and disadvantages.</p><h4>Microservice architecture aligning with the ResQ (architectural overview)</h4><p>Let’s analyze the main concerns in developing the ResQ project, considering the advantages that we can achieve while reducing the potential difficulties.</p><p>Here are the main concerns we have regarding the “ReResQ&quot;—hospital resource tracking and allocation system.</p><ol><li><strong>Application reliability and fault tolerance capabilities</strong>: The system needed to be run all the time despite failures in one of the services. For this particular use case of hospital resource allocation, availability is a very critical aspect. As an example, assume if one of the 3 services is down, the system should be capable of running with the remaining services (reliability and fault tolerance) =&gt; <strong>Microservices </strong>will handle these faults effectively.</li><li>Scalability: New operations should be introduced to the application as new services (scalability) =&gt; Developing the new service is easier with Monolithic, but <strong>Microservices</strong> will be the better choice for developing and integrating with existing services.</li><li>Development Efficiency: The developing system should have the freedom to develop independently with different new technologies (flexibility). =&gt; <strong>Microservices</strong> allows us to develop the new services with new technologies rather than using technologies that we have used to build the previous services.</li></ol><p>So for this particular use case, Microservices will be the better choice of architecture after considering the key factors affecting the project.</p><h4>How we are going to achieve it. (Technological overview)</h4><p>The basic technology that will be used for building microservices is Java Spring Boot. Each service will have its own database built using PostgreSQL. Those databases will be handled using PgAdmin.</p><p>The microservices that we are going to use in this application will be registered as Feign-Clients in the Service Registry powered by Eureka Feign-Server. To facilitate inter-service communication in the application, we are going to use Rest templates powered by OpenFeign called Feign-Interfaces.</p><p>The overview of the technologies and dependencies that are going to be used will be described by the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*ehvlJwxvOsAsTcQ7AwYA2A.png" /><figcaption>Fig. 4. Backend architecture Diagram</figcaption></figure><h4>Wrap up</h4><p>This article basically provides the basic guidelines on choosing the correct architecture for your project, considering the project requirements. This project can be used as an example of applying Microservices architecture to your project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d4434a4b7ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Choosing the Right Software Architecture: A Guide to Selecting the Best Fit for Your Project.]]></title>
            <link>https://ravindusandaruwandh.medium.com/choosing-the-right-software-architecture-a-guide-to-selecting-the-best-fit-for-your-project-ecdda7812fb1?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecdda7812fb1</guid>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Mon, 10 Feb 2025 18:18:51 GMT</pubDate>
            <atom:updated>2025-02-10T18:18:51.821Z</atom:updated>
            <content:encoded><![CDATA[<p>In this technology-inspired world, humans are creating solutions for their day-to-day problems with the evolving technology. With the heavy usage of technological devices, there is a huge trend of creating software solutions that can be integrated with the hardware of modern tools to address the problems faced by people in various domains like financial, health care, auto-mobile, and educational. When creating these software solutions, developers tend to follow patterns that make the software development process up to a certain standard. This ideology of different patterns is developed into different architectural solutions that further extend to some sort of blueprint for building software solutions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sp-oubgHlRvgArAvpjPQgQ.jpeg" /><figcaption>Fig. 1. Using technology to solve problems</figcaption></figure><h3>What is software architecture?</h3><p>An architecture is a conceptual structure that outlines the alignment of different components, relationships between each of them, and guidelines that define the interaction between each of them to achieve a common goal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HzmqahhCSSm61XZk803Jvw.png" /><figcaption>Fig. 2. System components working together</figcaption></figure><p>Similarly, in the context of software development, software architecture refers to a high-level structure of a software system that defines the alignment of system components, such as services, modules, and databases, along with the interconnections between them and principles on how each component interacts with each other to meet the system’s functional and non-functional requirements, like scalability, performance, and security.</p><h3>Is it compulsory to have an architecture?</h3><p>Consider this example. Assume that you need to build a house with the money you have. So you know what your requirement is, but you are not an expert on construction work. However, you are determined to build the house you want and gather all the components needed to build the house. So without a <strong>house plan,</strong> you started the construction and built several rooms here and there, hoping it would satisfy the basic requirements. You will build this house to some extent and definitely face an issue of inadequate resources to complete the construction. Not only that, you will find the misaligments of your construction, and finally, after wasting all the resources, you will be left with the disappointment of not working according to some plan. But what happens if you have invested in architecture and created a proper plan before building your dream house?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*Tw0IG6JBRxXAqk3L93MCKw.png" /><figcaption>Fig. 3. Image of an un-planned building</figcaption></figure><p>The same applies with the software development. If you have the requirements of the project and knowledge of the fundamentals, you can come up with some sort of solution, but that would be far from perfection. Knowledge of the software architecture matters when it comes to developing a software solution.</p><h3>Importance of Having a software architecture for Your Project</h3><p>When it comes to a software project, there are some requirements to achieve within the dedicated resources. To achieve the goals that are defined to be accomplished by the software solution, we need to follow a software architecture pattern. By aligning with a software architecture pattern, you will be having plenty of benefits.</p><ol><li>It provides a blueprint or some sort of “Road Map” to follow when developing a software solution</li><li>Ensures the quality of the software project by addressing both functional and non-functional requirements.</li><li>It is easier to maintain and scale the system as it grows</li><li>Following an architecture pattern facilitates better communication between stakeholders and provides a better understanding of the system design</li><li>Also, a well-designed software architecture act as a bridge between business and technical requirements while reducing the business risk.</li></ol><h3>Software architecture VS System Design vs Design patterns</h3><p>These 3 terminologies are used in the software industry interchangeably. But they refer to different concepts of software development.</p><p><strong>Software architecture:</strong> It is more likely the high-level structure of the system, which describes the components of the system, their relationships, and their interactions with each other. <em>(Ex: Layered architecture, Microservices architecture)</em></p><p><strong>System design: </strong>It is similar to architecture but with more details about the system design. It defines the design of each individual component, their interfaces, and how they work together to achieve the system’s objective. <em>(Ex: Database design , UI design)</em></p><p><strong>Design patterns</strong>: This refers to reusable solutions for common problems that occur during the development process. These solutions provide standard approaches to solve specific types of problems in software design. <em>(Ex: Singleton Pattern, Factory method pattern)</em></p><h3>Evolution of software architecture</h3><p>Like everything in the world, software architecture patterns weren’t introduced over night. It took different experiments to be shaped into the modern architectural concepts that we follow today. Over time, software architecture has adapted to different challenges like scalability, maintainability, and performance. Below we can see a high-level view of how the software architecture has been evolved up to today&#39;s standard.</p><ol><li><strong>Monolithic architecture: </strong>This could be the most fundamental software architecture pattern. In this architecture pattern, the entire application’s components, like User Interfaces (UIs, business logic, and databases, are tightly coupled into a single codebase.</li><li><strong>Service-Oriented Architecture (SOA):</strong> This architecture separates the entire application into distinct services that communicate over a network using web services.</li><li><strong>Microservices architecture:</strong> This pattern takes the idology from the SOA and develops it to a further state by breaking the application components into loosely coupled independent, scalable, and modular services that can be developed as separate applications that use their own databases.</li><li><strong>Serverless architecture: </strong>This architecture abstracts the infrastructure management by allowing developers to use Function as a Service (FaaS) that allows them to focus only on the application’s logic.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*6A1R43AKqMk1hx2QkYwEiw.png" /><figcaption>Fig. 4. Evolution of application software architecture by Jayant Kumar.</figcaption></figure><p><em>These are some of the treding and established architectures that developed over time. Other than these, there are other architecture patterns as well that evolved parallel to these.</em></p><h3>Different kinds of software architecture patterns</h3><h4>1. Layered architecture:</h4><p>This pattern structures the software application into different layers, where each layer consists of components that are related to serving a specific subtask. Each layer provided its services to the next higher layer. Presentation, Application, Business logic, and Data access are the most common layers that are used with the layered architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*eZHo5y4Qs4s40TduH1nJgQ.png" /><figcaption>Fig. 5. Layered architecture</figcaption></figure><h4><strong>2. Microservice architecture:</strong></h4><p>In this architecture pattern, the entire application is built as a set of independent, scalable services that are loosely coupled with each other. Absence of one service is not causing the working state of other services. This pattern came as a solution for the problems that were faced by the tightly coupled Monolithic architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*iK8Ek0IXXrXdATip7-4lag.png" /><figcaption>Fig. 6. Microservices architecture</figcaption></figure><h4>3. Event-Driven architecture:</h4><p>In this architecture, the services are triaged by events such as scrolling, clicking, etc. Components in the systems that are powered by the Event-Driven Architecture (EDA) have different events that are handled by different event listeners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*zzU89I_hNfDM9-hSY3tCBw.png" /><figcaption>Fig. 7. Event-Driven Architecture</figcaption></figure><p><strong><em>How EDA works:</em></strong><em> The</em><strong><em> event data</em></strong><em> generated by sources (such as user actions, system events or triggers). This event data represent various actions. The </em><strong><em>publisher </em></strong><em>receives the event data from the soruces. then publish this data to </em><strong><em>event-data-store </em></strong><em>(which serve as a temporary store for event data till they required by subcribers and act as an intermediary between publishers and subscribers). Then the </em><strong><em>subscribers </em></strong><em>listen to the event data. When a new event published, subscriber listen to them and process upon them. (subcribers are responsible to handling the business logic). When subcribers are listen and process the event data, those data can be passed to sinks like database, file system or apps.</em></p><h4>4. Clean architecture</h4><p>In clean architecture, the system is defined according to a predefined structure, as the core business logic resides in the domain layer, use cases are defined in the application layer, a presentation layer with the interfaces (APIs) to access the system, and an infrastructure layer with the external services. Outer layers are allowed to reference the inner layers of the architecture. And also, the lower layers should not depend on the upper layers, reflecting that the business logic should not depend on the applications’ UI. Each layer of the clean architecture is bound with a specific responsibility that is unique to that layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*wD3RIIAcSRme7B8lEP3zsA.png" /><figcaption>Fig. 8. Clean Architecture</figcaption></figure><h4>5. MVC architecture</h4><p>The MVC pattern, which refers to Model-View-Controller, is also a software architecture pattern that divides the main system into 3 separate components. The “Model” part is related to the components that are associated with the data layer of the application. The “View” part provides the interface to interact with the system, while the “Controller”part acts as a middleman between the View and Model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*4ra77eZHAdNVwxsq0_f0dw.png" /><figcaption>Fig. 9. MVC architecture</figcaption></figure><h3>When to choose what ?</h3><ol><li><strong>Layered architecture:</strong> This pattern is commonly used for faster development in a team with inexperienced developers. And also, when the requirement is clear and minimal, this can also be used.</li><li><strong>Microservices architecture:</strong> When the system is needed to run no matter what failure happens, we can use this. which means when it is critical to run the system with available services, this microservice pattern is ideal as this pattern does not encourage tightly coupled services.</li><li><strong>Event-Driven architecture: </strong>This pattern is ideal for systems that require real-time processing and asynchronous communication. Mostly used with the systems that are working with IOT-based devices.</li><li><strong>Clean architecture: </strong>If the project requires long-term maintainability, this pattern is a good approach. And if the business logic needed to be completely separated from the UIs and external services, this pattern can be adapted well.</li><li><strong>MCV architecture:</strong> This pattern is mostly used when the UIs, data entities, and business logic needed to be developed separately from each other. Frequently used for web and mobile application development.</li></ol><h3>What you have to focus when selecting the right software architecture for you project ?</h3><p>Implementing the software according to a software architecture pattern will give you huge benifits in different aspects like maintainability, scalability, security and performance. But choosing an inappropriate software architecture could potentially be a bottleneck for your project as well. There for understanding the key factores before choosing a software architecture pattern is crucial.</p><p>Factors we need to focus on:</p><ol><li><strong>Project size and complexity:</strong> We need to understand the size of the project before choosing an architecture. for an examle, to build a simple todo application using microservice architecture would introduce unncessary complexity to the project we are developing.</li><li><strong>Scalability requirements:</strong> It is important to understand how the system will be used, whether it will be used by millions of users or a dedicated group of users. if you are going to build an e-commerce platform you have to prepare for the potential user growth.</li><li><strong>Maintainability: </strong>you have to think about the maintainance need of your application. specifically whether you need to update the functionality frquently or whether it requires to update the system for a longer period of time. While most of the architecture patterns provide some level of maintainability, we have to focus on what suits the most.</li><li><strong>Development team expertise:</strong> If you are assigned to build a specific software with the given set of resources and expertise, you have to consider whether your team has the capability to build the system with the proposed architecture, specially you are instructed to complete and hand over the project within a given deadline.</li></ol><p><em>Other than these key factors there are many factors that we have to consider when developing a project with a dedicated software architectural pattern.</em></p><h3>Wrap up</h3><p>Selecting the right software architecture pattern for you project is a crucial decision in software development. It reflects how well your system is going to be performed, scaled and adapted to future changes. Each of the software architectre has its own set of pros and cons while almost all the patterns are having shared benifits when compared to applications without a dedicated software architecture pattern. Before selecting a pattern you have to compare and different architecture patterns considering different factors like scalability, maintainability and performance as poorly chosen architecture might cause for a bottleneck. By understanding the usage of the patterns according to the development needes you have a good chance of creating reliable, maintainable and high performing software system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecdda7812fb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Node JS application on AWS and enabling AWS Cloud watch for application logs.]]></title>
            <link>https://ravindusandaruwandh.medium.com/deploying-a-node-js-application-on-aws-and-enabling-aws-cloud-watch-for-application-logs-293b18bc4b85?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/293b18bc4b85</guid>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Sat, 30 Nov 2024 11:18:16 GMT</pubDate>
            <atom:updated>2024-11-30T11:18:16.024Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*WqFs01Z2l66ODLQ3CFsorQ.png" /></figure><blockquote>In today’s world, it is beneficial to know how we can deploy web applications to a cloud service and interact with it. This article consists of two parts, where you can learn how to deploy a node js application to AWS using docker and in the later part you can learn how to configure application logs for that hosted service using AWS cloud watch.</blockquote><h3>First part: Deploying a web service in AWS</h3><p>For this deployment part, you should have several pre-requirements. A node js application ( server side or client side), an AWS account.</p><p>First, we have to understand how can we connect the code base to the EC2 instance. For that, we need GitHub Runners.</p><p>As the first step of the deployment process, you have to configure an EC2 instance in AWS.</p><h4>Configuring AWS EC2 instance:</h4><p>First, you need to give an appropriate name for the instance. they need to select the correct OS for the instance. in this case, we are going to use Ubutu. Then select the correct login key pair for the instance. Then you need to configure the correct network settings. Most importantly configure the correct security group settings. Below are the essential inbound rules that you need to add to the security group. After those basic setups, you can launch the ec2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hoRE0s4XZjU0s2YQChP6dg.png" /><figcaption>Figure1 : EC2 instance launching dashboard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DznQ1ya6Uxl-x35c7-lW7g.png" /><figcaption>Figure 2: essential inbound you need to add to your security group</figcaption></figure><p>After you have launched the EC2 instance now you need to connect the code base to this EC2 instance for that you need GitHub runners.</p><p>Below are some basic concepts that we are using throughout this article.</p><h4>What is GitHub Runner?</h4><p>GitHub Runner is a service used to run GitHub Actions workflows in specific environments it is targeted on. So, a runner is rather a server that has all the required tools and required permissions to perform CI/CD jobs. GitHub provides some runners already hosted but the option is available to run your own runner (a self-hosted runner), for example on an infrastructure like EC2 instance.</p><h4>What is a workflow file?</h4><p>A workflow file is a YAML configuration file located in the .github/workflows/ directory in your repository. It defines the automation tasks for your project, specifying triggers, jobs, steps, and the environment required. For instance, you can set it to continuously create, compile and set up a Node.js application on an AWS EC2 instance whenever there is a commit added to your GitHub repository.</p><h4>What is a GitHub action?</h4><p>GitHub Actions is an open-source CI/CD system used by developers to do tasks, for example, testing, building, and deployment of codes. It enables you to declare how you want things to happen: based on events — commit, pull request and more.</p><p>There are some configurations that you need to make before running the GitHub runner. As you are deploying a node js application you need to install the node js to your ec2 instance. And also you will need the docker and docker composer to be installed to the ec2 instance as we are using docker containers to run the application. And lastly, you need to install nginx for configuring the reverse proxy for your application.</p><p><strong>What is docker and what is docker composer?</strong></p><p>Docker is a platform that in fact employs OS-level virtualization to package applications in containers. A container is more than a binary that can be executed; it contains all the dependencies required to run that piece of software. Docker Compose is a means of getting applications that use more than one container, up and running in a highly precise way. By using docker-compose which is a YAML file preferably docker-compose.yml, you to configure and run services together, such as a Node.js app and its database</p><h4>What is nginx ?</h4><p>NGINX is a large-scale web server and a reverse proxy server. It’s primarily utilized to process HTTP requests, distribute the workload of processing among multiple servers, and serve static files. Here main role of NGINX is to serve as the reverse proxy and direct the traffic to your Dockerized Node.js application, hosted on your EC2 instance.</p><p>Then you need to create a GitHub self-hosted runner. Follow the instructions on your chosen OS. Then need to connect with the ec2 instance. Either you can enter the AWS console it self or use the SSH client with your personal key pair to connect with the ec2 instance (or else you can use a tool like Putty). Then follow the instructions on the GitHub to connect the code base with the AWS EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MXyT5ENPl1zojWWcUWLemA.png" /><figcaption>Figure 3: GitHub Runner- where you can create a self-hosted runner</figcaption></figure><p>After running the Runner on the EC2 instance create the workflow file to continue the deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qgxVwjVaQfW3DgSWxlDZqQ.png" /><figcaption>Figure 4: Workflow file</figcaption></figure><p>After you have configured the workflow file and committed that, it will be connected with the GitHub runners and start the application deployment in the EC2 instantiated docker container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tXCvcO9VHdm8aee2XTWP7A.png" /><figcaption>Figure 5: docker image up and running.</figcaption></figure><p>Then you have to configure the reverse proxy for this API using nginx.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gvWeadn9eTY7t_zM9aAfDg.png" /><figcaption>Figure 6: Nginx server configurations</figcaption></figure><h3>Second part: Enabling AWS Cloud watch for application logs on that deployed web service.</h3><p>First, you have to use an application log library that comes from the JavaScript ecosystem. In this case, we are using “Winston”. After installing and configuring Winston, we have to configure the AWS Cloud watch agent with the EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*Fv6yYoJppIT3aLddj95b5g.png" /><figcaption>Figure 7: Configuring winston for application logs</figcaption></figure><p>Now we have to give permission for the EC2-hosted application to write logs to the AWS cloud watch agent. For that, we need to modify the IAM Role policies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1oX7zr1lF7h-_sZifJLsPw.png" /><figcaption>Figure 8: IAM Role Policies</figcaption></figure><p>Select “CloudWatchAgentServerPolicy”, and complete the policy setup. Then you need to attach the created policy to your EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LJkmUU1LMggN4DXN4IKVsw.png" /><figcaption>Figure 9: Attaching the created policy to the EC2 instance</figcaption></figure><p>After that, you need to log into the EC2 instance and install and configure the aws-cloud-watch agent. After installing the cloud watch you need to go to create the configuration file in the location: /opt/aws/amazon-cloudwatch-agent/bin. There you can install the AWS Cloudwatch agent wizard and configure it to look for the log file in the specified location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8oSV0NpJ6UCHdMh9xPMlWQ.png" /><figcaption>Figure 10: Configure the AWS cloud watch agent to access the logging file</figcaption></figure><p>After that, you have to run the Dloud Watch agent on your ubuntu machine.</p><p>If you have correctly configured this you can see the application logs in your AWS console under the Cloud watch service/log groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F_-nEAt5EWV-Ce3B9pc3hg.png" /><figcaption>Figure 11: AWS Cloud Watch</figcaption></figure><p>These are the basic steps needed to enable application logs for your deployed service using AWS Cloudwatch.</p><p>#aws #cloudwatch #applicationlogs #deployments #github #workflow</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=293b18bc4b85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Video Conferencing with WebRTC and PeerJS.]]></title>
            <link>https://ravindusandaruwandh.medium.com/video-conferencing-with-webrtc-and-peerjs-f91cb00144a3?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/f91cb00144a3</guid>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Fri, 17 May 2024 16:11:52 GMT</pubDate>
            <atom:updated>2024-05-17T16:11:52.451Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is WebRTC?</h3><p>WebRTC (Web Real-Time Communication) is an API offered by Google to establish peer-to-peer connections between two browsers. It enables the creation of connections without the need for a server. (Do not get confused; a server is required initially, but once the connection is established, it will not require a server for peer-to-peer communication.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*0F3bRuhIi9fOQ2DKomI4fA.png" /><figcaption>Figure 1: WebRTC</figcaption></figure><h4>So Why don’t we use WebRTC instead of Websockets?</h4><p>First, let’s learn about how WebSockets work. Using WebSockets, we can establish a connection between peers to exchange data. However, this connection is established through a server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*IQ8pmf9tMh2Cb_7cpsWMBw.png" /><figcaption>Figure 2: Web Sockets</figcaption></figure><p>For an example.</p><p>If Client-1 is sending data, that data will first go to the server and then be directed to Client-2. This method works well for sending data from Client-1 to Client-2, as the communication happens through a server without noticeable delay.</p><p>However, if you want to send real-time video or audio data using WebSockets, even a slight delay can become noticeable. With the latency added by the server acting as a middleman for the peer-to-peer connection, the video or audio data transferred between the peers will experience noticeable delay.</p><p>This is where we need WebRTC.</p><p>Since WebRTC communicates directly with peer-to-peer connections, it eliminates the latency added by an intermediate server. This method is ideal for exchanging data such as video and audio. WebRTC uses UDP (User Datagram Protocol), which transmits data very quickly.</p><h4>So, why do we use WebSockets when we have a better solution like WebRTC?</h4><p>There are some limitations to WebRTC. Since WebRTC uses UDP, which is not an ideal protocol for exchanging data, it can be problematic. UDP sends data very quickly but does not check bit by bit (no data validation). Therefore, using WebRTC with UDP may result in data loss, making it unsuitable for sending sensitive data, as that data could be corrupted.</p><h4>Then Why we use WebRTC?</h4><p>However, if we are exchanging video or audio data, where losing a few frames is not a big deal, WebRTC is ideal for fast real-time communication.</p><h4>How WebRTC work?</h4><p>Step 1:</p><ul><li>Initially, a server called a “signaling server” is needed to establish the connection between two peers. Once the connection between two peers is established, the server is no longer needed.</li><li>First, Client-1 will send some data about itself to the signaling server, which then transfers that data to Client-2. Then, Client-2 also sends some data about itself to Client-1 through the signaling server. Now, both clients know each other.</li><li>The duty of the signaling server is to establish the connection between peers by exchanging details about them.</li><li>The first step of a WebRTC connection is the creation of offers. An offer is like an object containing information about Client-1. It includes something called SDP (Session Description Protocol), which contains the media configuration of Client-1.</li><li>This offer is then sent to the server from Client-1 and directed to Client-2. Client-2 stores the offer, including the SDP, of Client-1. Then, Client-2 creates the answer for that offer. The answer contains the SDP of Client-2 and is directed to Client-1 over the signaling server.</li><li>Now, with that exchange, Client-1 and Client-2 know each other but do not yet know “how to communicate with each other.”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GCPZPUhuPdxuXI9Jc87ecQ.png" /><figcaption>Figure 3: WebRTC OFFER /ANSWER (How Peers know each other)</figcaption></figure><p>Step 2: Figure out how to connect to each other. For that, they have to transfer their network information to each other.</p><ul><li>As soon as Client-1 makes the offer, something called “ICE Candidates” (ICE: Interactive Connectivity Establishment) are generated by the WebRTC API.</li></ul><p><strong>Where do these ICE candidates come from?</strong></p><ul><li><em>ICE candidates are generated from servers known as “STUN (Session Traversal Utilities for NAT) and TURN Servers”. To obtain ICE candidates from these servers, Client-1 needs to provide URLs of the STUN and TURN servers to the WebRTC API. Once Client-1 makes the offer, the WebRTC API retrieves the ICE Candidates from the STUN &amp; TURN servers.</em></li><li><em>Then, Client-1 sends these ICE candidates to Client-2 through the Signaling Server. Similarly, when Client-2 makes the answer to that offer, it sends the ICE Candidates of Client-2 to Client-1 via the Signaling Server.</em></li><li><em>With this exchange, both Client-1 and Client-2 have the network information of each other, enabling them to communicate directly.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P50o2Ujl_zhQHVbvsWwYsg.png" /><figcaption>Figure 4: ICE Candidates (How communication establishes)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f91cb00144a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[End-to-End Encryption (E2EE) Approach with Public Key Cryptography.]]></title>
            <link>https://ravindusandaruwandh.medium.com/end-to-end-chat-encryption-approach-with-public-key-cryptography-f559adfdffc2?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/f559adfdffc2</guid>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Mon, 06 May 2024 04:50:03 GMT</pubDate>
            <atom:updated>2024-05-13T11:25:56.549Z</atom:updated>
            <content:encoded><![CDATA[<p>In my <a href="https://ravindusandaruwandh.medium.com/websockets-webrtc-dc59a9d04119">previous article</a> , I described how to implement a MERN stack chat application using Socket.IO and PeerJS. However, we did not incorporate any encryption for the chat messages. This oversight can potentially leave user communications vulnerable to interception by hackers. Therefore, it’s crucial to consider implementing a robust encryption method to secure these messages.</p><p>When it comes to encryption, there are numerous methodologies available, each with its own set of advantages and disadvantages. For this application, I have chosen to implement Public Key Cryptography. This choice is guided by the security needs of real-time chat systems and the effectiveness of public-key methods in protecting data integrity and confidentiality</p><p>Below is how public key cryptography works.</p><p>In Public Key Cryptography, each user is assigned a pair of keys: a Public Key and a Private Key. The Public Key can be shared openly with anyone, while the Private Key must be securely kept by its owner.</p><p>Consider an example with two users, Bob and Alice. In Public Key Cryptography, when Alice wants to send a secure message to Bob, she encrypts her message using Bob’s Public Key. This encrypted message can then be safely transmitted over the network to Bob. Upon receiving the message, Bob uses his Private Key to decrypt it.</p><p>This method ensures that even if the message is intercepted during transmission, it remains secure because only Bob’s Private Key can decrypt it. Thus, Public Key Cryptography offers a robust framework for secure communication in digital environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RzZZkGIvbyXpJGI5Sj_cQA.jpeg" /></figure><p>Based on the concept of Public Key Cryptography, we can tailor different encryption approaches depending on the communication scenario. For one-to-one communications, such as a private chat between two individuals, this method can be used without any modification. Each participant simply uses the other’s public key for encryption and their own private key for decryption, ensuring secure and private exchanges.</p><p>However, when applying this concept to a group chat scenario where multiple users are involved, the approach needs to be adapted. Here are a few strategies that could be employed:</p><ol><li><strong>Naive Approach</strong>: In this approach, each member of the group chat generates their own pair of public and private keys and shares their public key with every other participant in the chat. When a user sends a message, it needs to be encrypted with the public key of each participant. Each participant then uses their private key to decrypt the message. This method is straightforward to implement but can lead to performance issues. When focusing on an encryption methodology, it is crucial to consider both security and availability. Even if a method is highly secure, if it lacks availability, it is not considered effective. For instance, in a group chat with a hundred participants, encrypting a message with all hundred public keys could be time-consuming, leading to significant performance bottlenecks.</li><li><strong>Using Symmetric Keys</strong>: Another approach involves using a symmetric key for the group chat. In this method, a symmetric key is generated and then encrypted with each user’s public key before being shared with each participant. Once received, users decrypt the symmetric key using their private keys. Now, every participant possesses a common group key, which is used to encrypt and decrypt any messages sent within the group. This approach tends to be more efficient in terms of performance compared to the naive approach. However, the distribution of the symmetric key presents its own challenges. It must be securely communicated to each participant and updated if group membership changes, potentially complicating management and security.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*4FA2PvZ5auadWPEu14Eakg.jpeg" /></figure><p><strong>Now let’s see how to implement the above approach.</strong></p><p>To implement this methodology each participant has to have a pair of public key and private key. we can generate them when a user joins the chat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*9jYPL0_UdXhn0oue6vZjtw.png" /></figure><p><em>We have use a crypto module which is build with the Node to generates the public-private key pair for each user.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*jLBSUFIrFTRIaFpkfEjM2A.png" /></figure><p>Then, we need to generate a group key and encrypt that with each participant’s public key. So when a user joins he will be getting an encrypted group key related to the chat.</p><p><em>When a user joins to that chat we are encrypting the generated group key (this is generated by a trusted participant in a group (admin)), using each user’s public key.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*28LbJxrTIHfqJqZyo6GkCw.png" /></figure><p><em>For the encryption, we can use any algorithm we want. But Sha256 will be a great choice. As we are using MERN stack, we use “crypto” module for that which is build with Node.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*-3HDGDr66t6KnL2uCtFbRg.png" /></figure><p>Then on the client side, we need to grab that encrypted group key and decrypt it with the user’s private key. when we do so we have the common group key with us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*ym1UxEYfzh7bPet2-9r97Q.png" /></figure><p><em>We have to first grab the data (encrypted group key) and decrypt it using the private key of each user on the client side. for that, we are using the native crypto module that comes with Node. Now we can save that group key securely with the browser’s local storage or index db. With that, each user gets the common key which will be used for end-to-end encryption and decryption.</em></p><p>Now when a user needs to send a message to the group that message has to be encrypted with the group key and sent and the receiver can use the same group key that they get when joining the group to decrypt the encrypted message. We are keeping the encryption-decryption methods on the client side to keep the E2EE secure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8_atWG5uNrK-ti31Yjgdng.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*MPdUmwkfmM4TBA-5OAWRcQ.png" /></figure><p>For the E2EE we can use different modules like node-forge, crypto js, etc. Here I have used “crypto-js” library. When a user needs to send a message that message will be encrypted at the client side using the group key and when that message reaches each receiver they can decrypt that message using the decrypted group key at their side, keeping the encryption-decryption logic at the client side.</p><h4>Conclusion</h4><p><em>The use of a symmetric key for encrypting group chat messages is a compelling approach that offers better performance efficiency compared to individually encrypting messages with each participant’s public key. In this method, a common group key is used, which simplifies the encryption and decryption processes across multiple users. This not only enhances the application’s performance but also maintains a consistent encryption standard across all messages. To mitigate these risks and enhance the security of the symmetric key approach, we can use Periodic Key Rotation: Implementing a routine for periodic key rotation can significantly increase security. Generating new public and private key pairs for users at defined intervals will increase security.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f559adfdffc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Websockets & WebRTC]]></title>
            <link>https://ravindusandaruwandh.medium.com/websockets-webrtc-dc59a9d04119?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc59a9d04119</guid>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[webrtc]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Mon, 15 Apr 2024 03:31:27 GMT</pubDate>
            <atom:updated>2024-04-15T03:31:27.913Z</atom:updated>
            <content:encoded><![CDATA[<p>Websocket is used for real-time communication. if we use HTTP protocol with the REST API functions for communications, to see a message we need to refresh the browser. but with the web sockets, we can do real-time communication without the need to refresh the browser.</p><p>So let’s see how we can create a web socket connection with the client and server.</p><p>For this task, we need a WebSocket provider like <a href="http://socket.io/">socket.io</a>, which provides both client and server-side WebSocket functionalities.</p><p><strong>Technologies we are using</strong>: MERN Stack, PeerJS library<br>Serverside socket connection.</p><p>First, we need to create an express server application and create a socket connection using socket io which will be continuously listen for the events occurring once the connection is established.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*BS173DRStKwaXpDXAwCMRQ.png" /></figure><p>Then we also need to create the connection from the client side as well<br>Client-side configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*yuNQjU5aprPFWn1ncG8mXg.png" /></figure><p>Once the connection is established we can use this connection to listen to different events that occur on both the client side and server side.</p><p>To understand the benefits of WebSockets let’s create a simple chat application.</p><p>For ease of understanding the web application, let’s divide the main tasks we need to develop</p><ol><li>Create a space for chat (room)</li><li>Once the space is created allow users(peers) to join the chat</li><li>Then implement the chat features</li></ol><h4>First Let’s create a room for a chat</h4><p>Client Side configuration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*F0oJyhBICa_K-8c6fB8GaQ.png" /></figure><p>We will emit an event to create a room and in the backend, we can listen to this event emitter and create a room.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*XrnLzi69pBg4lIEv-SmbIg.png" /></figure><p>On the Client side, we have to listen for this event and once a room is created we need to navigate that user to that created space for chat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*CksLMIamPEdRBeWt6-IQFQ.png" /></figure><p>once we have listen to the event, make sure to close the socket connection as well. to keep the connection clean</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*_HdC4TtJCuZB_L3B6qgPbQ.png" /></figure><h4>Join the Room</h4><p>Now as our room is created we need to allow other users to join this space to start a conversation. <br>For the event “join-room“ we need to get the PeerID. so we are creating a peerID and sending them to the backend via the event emitter “join-room“</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*7qC3K_5zb0a-m75ePnGhnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*vnBHpOCxD2fZNBoLOyArFg.png" /></figure><p>In backend, we need to listen to this event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*b2ize1C39tBz38F5L6_wWQ.png" /></figure><p>In our backend server, it will get the peer ID make a record of a peer who has joined the room, and launch an event emitter called “user-joined“. <br>you can visit “peerJS“ , a popular webRTC package’s documentation to what are the methods available for different connections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*GbbJubalDZ12QYzRiWgA1A.png" /></figure><p>Now we need to create the action and reducer which is needed for room handling.</p><p>Actions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*APQvqG-xnPAZ_0K5pgGq_A.png" /></figure><p>Reducers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*wN-uNzDqSMWEYgYVdqDLcQ.png" /></figure><p>Then use these reducersin the “user-joined“ event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*jan33xU4Ho9KowvNYqqUSQ.png" /></figure><p>Once the connection is done we can also implement the event for peer disconnection event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*8XpOg70FFfUxAaKBQ7_sFg.png" /></figure><p>Now on the client side, we have to listen to the event “user-disconnected“.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*emZPbzX0RESWDqjBAz17Pw.png" /></figure><p>And to get an idea about who are the peers joining in our room, we can implement another event as “get-users“.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*TJU4gxiJy1lbjMcxjC4M3Q.png" /></figure><p>In the front end, we can listen to this event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*Wk_dNb2X310STdOL2Uk7jQ.png" /></figure><h4>Implementing chat features</h4><p>First, we need to create a UI for chat on our client side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*HJiOnZnTn6cACkJ-Vw3WYw.png" /></figure><p>Then we need to create the “sendMessage“ function which will be in a separate ChatContext (for Refactoring Purposes). That sendMessage function will add an event called “send-message“, which we have to catch from the backend</p><p>As we are sending a message with the following properties (content, timestamp, and author) we need a separate type for that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*kvXZyX48W4CY-BcdijW8Dg.png" /></figure><p>Then we need to create the send Message function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*Yudtbyb6ncz-jezNEyHvOA.png" /></figure><p>Also we need to create Actions and Reducers which will keep a record of the chat state.</p><p>Chat Actions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*JpnTPkuP20fQ22O54EM66A.png" /></figure><p>Chat Reducers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*Dab_Fc8bS1IhQctGWLuUhg.png" /></figure><p>Actions and Recuders in Chat Context</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*wVLowMNoVETlj3KHy2yQyA.png" /></figure><p>In BackEnd, we have to listen to the event “send-message“, and grab that message and send a new event again to the front end called “add-message“.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*3YBs7uQQRqrzlZbOJL-_6g.png" /></figure><p>Now from the frontend, we have to listen to this event (“add-message“)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*-DWRdvhBjT3tpfvnwakKiQ.png" /></figure><p>Also when joining a Room we need to get all the messages so far and add them to our message-state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*UDDsQcl48xazEuBqzEMk0A.png" /></figure><p>We need to listen to this event in our front end and add the “chats“ to our client-side chat-state</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*GpvQJiwNQb85Z5eB7lEJmQ.png" /></figure><p>Now we have toget messages from our backend and keep them readily available in the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*WU1cbdTDtQu3wxYgXlCEmw.png" /></figure><p>With that, we can create a simple chat application using web sockets and webrtc features.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc59a9d04119" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Micro Services with Java Spring Boot]]></title>
            <link>https://ravindusandaruwandh.medium.com/micro-services-with-java-spring-boot-181f0bc3fcde?source=rss-f87fd61f1a91------2</link>
            <guid isPermaLink="false">https://medium.com/p/181f0bc3fcde</guid>
            <dc:creator><![CDATA[Ravindu  Dharmadasa]]></dc:creator>
            <pubDate>Mon, 12 Feb 2024 05:49:56 GMT</pubDate>
            <atom:updated>2024-02-12T05:49:56.933Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Before diving into the microservices world, we first need to explore the difference between monolithic architecture and microservices architecture.</em></p><h3>Monolithic Application Architecture</h3><p>For ease of understanding, let’s assume that we will create a BookStoreAPI, which allows us to add books, update books, viewbooks, and delete books. Additionally, there is a separate service for updating inventory for these books. According to that specification, you can understand that our application needs two services: one for the book service, referred to as “book-catalog-service” throughout the article, and another for the inventory service.</p><h4>What if we follow Monolithic Architecture?</h4><ul><li>Both of these two services are going to reside in one application, and there could be interdependencies between these two services. For instance, when we are adding a new book, that book has to be added to the booklist as well as create or update the stock based on the availability of that book. So, we refer to these services as tightly coupled services. These two services cannot function without each other.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*GX1romJemKxgBz8y0upPFQ.jpeg" /><figcaption>Figure 1: Abstract Diagram Of Monolithic Application</figcaption></figure><p>Apart from this, there are several drawbacks to using monolithic architecture:</p><ol><li><strong>Team dependency:</strong> Teams working on different components within the monolith are often tightly coupled, leading to dependencies that can slow down development.</li><li><strong>Scalability problems:</strong> There is a lack of ability to scale up each service individually; instead, the entire application needs to be scaled up, even if only specific services require additional resources.</li><li><strong>Dependency on a single technology:</strong> Monolithic architectures usually rely on a single technology stack, limiting flexibility and making it challenging to adopt new technologies for specific services.</li><li><strong>Single point of failure:</strong> If one service goes down, there is a tendency for the entire application to go down, affecting all functionalities.</li></ol><p>It’s worth considering these drawbacks when deciding on the architecture for a system, and this is where microservices architecture aims to address some of these issues.</p><h3>Microservice Architecture</h3><h4>What if we want to develop this application as 2 separate services?</h4><ul><li>Sometimes, we need to develop different services separately due to specific requirements. In such cases, we opt for Microservices architecture. By using Microservices architecture, we can develop the aforementioned services as two different applications that are self-contained and can run as individual services. For each microservice, there is a separate database that only interacts with its respective service.</li></ul><p>Indeed, there are several benefits to using Microservices Architecture, including:</p><ol><li><strong>Ability to develop each service separately:</strong> Microservices allow for independent development of services, enabling teams to work on different services concurrently without affecting each other.</li><li><strong>Ability to scale up only the needed services (resource utilization):</strong> Microservices provide the flexibility to scale individual services based on their specific resource requirements, optimizing resource utilization compared to scaling up the entire monolithic application.</li><li><strong>Technology independence:</strong> Microservices allow the use of different technologies for different services, providing the freedom to choose the most suitable technology stack for each service.</li><li><strong>Ability to test separately:</strong> Each microservice can be tested independently, allowing for more efficient and focused testing. Changes or updates to one service can be validated without affecting the entire application, enhancing testing flexibility and speed.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*2LCE-tiujVXd37exZ54LjQ.jpeg" /><figcaption>Figure 2: Abstract Diagram Of Microservice Application</figcaption></figure><p>But how will these services interact with each other?</p><ul><li>Apart from interacting with the client side, each of the microservices has to communicate with each other as well. For that, there are different approaches, such as using the “Spring Cloud ecosystem” or using a service like “gRPC,” and so on.</li></ul><p>In this article, we are going to talk about how to facilitate interservice communication using the “Spring Cloud ecosystem with Netflix Eureka Server and OpenFeign.”</p><p>For ease of reading let’s divide the article into separate topics</p><ol><li>Create “book-catalog-service“</li><li>Create “inventory-service“</li><li>Service-Registry</li><li>Communicating with each other micro-service using Open Feign</li><li>Load Balancing</li><li>API Gateway</li></ol><p>For this Application we have used “Spring Boot 3“ with “PostgreSQL database“ and to test APIs we have used POSTMAN.</p><h4>1. Crerating Book-Catalog Service</h4><ul><li>It involves implementing logic related to performing CRUD operations on books. For ease of development and maintenance, we need to create different layers in the backend, such as:</li></ul><ol><li><strong>Controller-layer:</strong> Includes different API endpoints related to the book-catalog-service.</li><li><strong>Entity-layer:</strong> Contains the database properties.</li><li><strong>DTO-layer:</strong> Serves as a middle-level layer between the Repository and Services.</li><li><strong>Service-layer:</strong> Provides various services for different controllers.</li><li><strong>Repo-layer:</strong> Used to connect with the database using “Data-JPA” and is also employed to define custom native queries for various service functions.</li></ol><h4>2. Creating the Inventory Service</h4><ul><li>This is similar to the “book-catalog-service,” and the logic needed to interact with the inventory is implemented here.</li></ul><p><strong>Break Point:</strong> Assuming there is a service in the “book-catalog-service” that is required for the “inventory service.” Since these two services are developed as separate microservices, we need to determine how communication will occur between these two services.</p><h4>3. Service Registry</h4><ul><li>Now, as we have two separate services, we need to determine how they will communicate with each other. A “Service Registry” is a place where each microservice can register and provide a contact point for other services based on the request.</li><li>To create this service registry, we need to use a dependency called “Netflix Eureka Server.” Each service has to be registered on this server. After successfully registering these services, you can observe them in the “Eureka Server.”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JqeHRTGr7-1S424iuEufiA.png" /><figcaption>Figure 3: Registered Microservices in the Eureka Server</figcaption></figure><h4>4. Communicating with each micro-service using Open Feign</h4><ul><li>Now, both our services are up and running on different ports as two separate applications, and they have been registered on the “service-registry.”</li><li>Recall the service needed for the “inventory-service” from the “book-catalog-service.” We are going to make a call to that endpoint from our “inventory-service” using “OpenFeign.”</li><li>Firstly, we need to create a “Feign Interface” that includes the controller signature we need from the “book-catalog-service.” Then, we can access that controller in the separate microservice (in this case, “book-catalog-service”) through the interface we have created.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ps8qBOAmVShATyjG6Ez3CQ.png" /><figcaption>Figure 4: Feign Interface including the Controllers we needed to access from the other service</figcaption></figure><h4>5. Load Balancing</h4><ul><li>Assume there are two instances of the “book-catalog-service.” When the “inventory-service” makes the call via the Spring Cloud ecosystem, it doesn’t need to worry about which instance to call. This is because we are using the “Spring Cloud ecosystem” with services like “Eureka Server/Client” and “OpenFeign.”</li><li>These components will manage the requests and balance the request load based on the availability of instances of different services.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oXJQLUURsqessl7VmbuqAg.png" /><figcaption>Figure 5: Requests are directed to instances of the same service based on the availability</figcaption></figure><h4>6. API Gateway</h4><p>Even though there are two separate microservice applications, for users, it appears as one single application. Therefore, we need to provide a unified API endpoint for users to interact with different API services. An API Gateway is used as the common URL endpoint for different microservices, ensuring a seamless and consolidated experience for users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*kMOBng-_7Aj3N-yBMr9zEA.png" /><figcaption>Figure 6: API Gateway Use</figcaption></figure><ul><li>The port number specified as the “API Gateway” in the above image provides a common access point to all the different services. Even though the various services are running on different port numbers, there’s no need to specify them here.</li><li>Here’s how the API Gateway works with the “Spring Cloud ecosystem”: In the same “service-registry” where we have defined other services, we also register the “api-gateway” in the same service registry. When a request comes for any of the services, the API Gateway identifies the service from the “service-name” registered in the service registry and directs the request to the appropriate service. The only thing to be concerned about is ensuring the correct naming of each service to facilitate proper identification by the API Gateway.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=181f0bc3fcde" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>