<?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 Martinez Pupo Ivan on Medium]]></title>
        <description><![CDATA[Stories by Martinez Pupo Ivan on Medium]]></description>
        <link>https://medium.com/@segpacto?source=rss-287306dec4cb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XvIfhD1612P3PqJY2IvqQw.jpeg</url>
            <title>Stories by Martinez Pupo Ivan on Medium</title>
            <link>https://medium.com/@segpacto?source=rss-287306dec4cb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:01:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@segpacto/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[Fine-Grained Authorization with Open Policy Agent (OPA) on distributed architectures]]></title>
            <link>https://blog.stackademic.com/fine-grained-authorization-with-open-policy-agent-opa-on-distributed-architectures-9bd42658d1ad?source=rss-287306dec4cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bd42658d1ad</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[open-policy-agent]]></category>
            <category><![CDATA[rego]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Martinez Pupo Ivan]]></dc:creator>
            <pubDate>Wed, 10 Apr 2024 13:19:02 GMT</pubDate>
            <atom:updated>2024-05-06T00:57:23.358Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I3QmXxsdLj7CAGVsTBseeg.png" /></figure><p>Open Policy Agent (OPA), JSON Web Tokens (JWT), and Role-Based Access Control (RBAC) are different approaches to managing access control in distributed systems. OPA stands out with its flexible policy language (Rego), allowing organizations to define detailed access control policies based on user roles, resource types, actions, and context. Unlike JWT and RBAC, OPA supports dynamic policy evaluation for real-time enforcement of access control decisions, making policies more adaptable and centralized.</p><p>While JWT focuses on authentication and token-based access control by encoding user claims and identity in a signed token, it lacks the expressiveness and flexibility of OPA. Similarly, RBAC relies on predefined roles and permissions, offering basic access control granularity but may struggle with complex or changing authorization needs. Unlike OPA, which provides centralized policy management and dynamic evaluation, JWT and RBAC are simpler to implement but may not offer the same level of flexibility or fine-grained control over access policies.</p><h4>What is OPA?</h4><blockquote>The Open Policy Agent (OPA, pronounced “oh-pa”) is an open source, general-purpose policy engine that unifies policy enforcement across the stack. OPA provides a high-level declarative language that lets you specify policy as code and simple APIs to offload policy decision-making from your software. You can use OPA to enforce policies in microservices, Kubernetes, CI/CD pipelines, API gateways, and more.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*Z8A9yl_MMf7j4Q-iq3SbBg.png" /></figure><p>After what had been said, organizations typically start implementing fine-grained authorization when they encounter specific challenges or requirements related to access control in distributed systems. For this reason, OPA starts being an option when your system have:</p><ul><li><strong>Complex Access Control Requirements.</strong> Companies with complex access control requirements, such as those operating in regulated industries or handling sensitive data, may find traditional access control mechanisms insufficient.</li><li><strong>Need for Centralized Policy Management.</strong> Companies managing multiple services or microservices may face challenges in maintaining consistent access control policies across their infrastructure. OPA’s centralized policy management capabilities allow organizations to define, update, and enforce access control policies in a centralized manner, simplifying policy management and ensuring consistency.</li><li><strong>Dynamic Authorization Needs.</strong> Companies requiring dynamic access control decisions based on real-time contextual information, such as user roles, attributes, and environmental conditions, may benefit from OPA’s dynamic policy evaluation capabilities.</li><li><strong>Desire for Fine-Grained Control.</strong> Companies seeking finer granularity and control over access to resources and actions may turn to OPA for its ability to define fine-grained access control policies based on various attributes. OPA allows organizations to specify detailed access control rules tailored to their specific requirements, ensuring that only authorized users have access to the necessary resources and actions.</li><li><strong>Increasing Regulatory Compliance Requirements.</strong> Companies facing stringent regulatory compliance requirements, such as GDPR, HIPAA, or PCI DSS, may leverage OPA for fine-grained authorization to ensure compliance with access control regulations. OPA’s auditing and policy management capabilities help organizations demonstrate compliance with regulatory requirements by providing visibility into access control practices and ensuring accountability for access control decisions.</li></ul><h4><strong>Let’s showcase a simple example</strong></h4><p>OPA uses Rego as the language to write policy rules defining and implementing access control across distributed systems. Rego is a powerful and declarative language that allows users to express complex authorization logic using a flexible syntax.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac9e21c2b72f3b688b994508775b3180/href">https://medium.com/media/ac9e21c2b72f3b688b994508775b3180/href</a></iframe><p>Let’s understand the previous policy rules, is_working_hours rule verifies the time for accessing is controlled, only allowing request between 9 AM and 5PM. The allow_authenticated rule allows access to order data for all authenticated users if the HTTP method is GET, the user’s role is not empty, the path starts with “/orders/”, and it is within working hours. The allow_admin allows access to user data for admin users only if the HTTP method is GET, the user’s role is admin, and the path starts with “/users/”.</p><p>Below the hood, OPA compiles these policy rules and enables an API endpoint /data/example/{policy_name} which takes charge of validating the input data.</p><p>Lets write a NodeJs application that will interact with the OPA service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f9cdc8bc1a820b2d4020aa6829bdf65/href">https://medium.com/media/9f9cdc8bc1a820b2d4020aa6829bdf65/href</a></iframe><p>The example above will validate each request by creating a call to the endpoint allow_admin. Once the input data is verified OPA returns a successful response indicating the validity of the request.</p><blockquote>For a larger and <strong>fully working sample</strong> please visit the <a href="https://github.com/segpacto/nodejs-opa">repository</a></blockquote><p>Now, not all is good, there are some details to take into account, because while OPA services offer significant benefits for access control and policy enforcement in distributed architectures, they also <strong>present some challenges</strong>:</p><ul><li><strong>Complexity.</strong> OPA services can add complexity to the architecture, making it challenging to define and maintain policies across services.</li><li><strong>Performance Overhead.</strong> OPA services may slow down systems due to policy evaluation, especially with complex policies and high request volumes.</li><li><strong>Learning Curve.</strong> Adopting OPA requires learning new concepts and languages, which can be time-consuming for teams.</li><li><strong>Policy Maintenance.</strong> Keeping policies up-to-date and secure requires dedicated processes for versioning, testing, and deployment.</li><li><strong>Security Risks.</strong> Misconfiguration of policies can lead to unauthorized access or data breaches, posing security risks to the system.</li><li><strong>Resource Consumption.</strong> OPA services consume system resources like CPU and memory, potentially impacting performance in resource-constrained environments.</li><li><strong>Integration Complexity.</strong> Integrating OPA with existing infrastructure can be complex and requires careful planning to ensure seamless interoperability.</li></ul><p>Equally, there are some strategies to mitigate some of the issues described above and accomplish low-latency access control.</p><p><strong>Optimize Rego Policies</strong></p><ul><li>Simplify Policies. Keep policies as simple as possible. Complex policies with multiple rules and conditions can increase evaluation time.</li><li>Avoid Loops and Recursion. Minimize the use of loops and recursion in policies, as they can significantly impact performance.</li><li>Use Indexing. Leverage built-in functions like indexof() or intersection() to optimize policy evaluation, especially when dealing with large datasets.</li></ul><p><strong>Cache Policy Decisions</strong></p><ul><li>Implement Caching. Cache policy decisions for frequently accessed resources or requests. This reduces the need for repeated policy evaluation and improves response times.</li><li>Cache at Various Layers. Consider caching policy decisions at different layers of your application stack, including client-side, server-side, and at the OPA sidecar level.</li></ul><p><strong>Parallelize Policy Evaluation</strong></p><ul><li>Asynchronous Evaluation. If feasible, perform policy evaluation asynchronously in parallel with other tasks or operations. This can help mitigate latency by allowing multiple evaluations to occur concurrently.</li><li>Batch Processing. Group similar requests or resources and evaluate policies in batches. This reduces the overhead of individual evaluations and can improve overall throughput.</li></ul><p><strong>Scale OPA Infrastructure</strong></p><ul><li>Horizontal Scaling. Scale OPA horizontally by deploying multiple instances of OPA sidecar containers. Load balancers or service meshes can distribute incoming requests across these instances, increasing throughput and reducing response times.</li><li>Resource Allocation. Allocate sufficient CPU and memory resources to each OPA instance to handle the expected workload. Monitor resource utilization and scale horizontally as needed to maintain optimal performance.</li></ul><p><strong>Tune OPA Configuration</strong></p><ul><li>Evaluate Warm-up Time. Measure the warm-up time required for OPA to load policies and initialize its runtime environment. Adjust startup configurations or pre-load policies during service initialization to minimize warm-up time.</li><li>Tune Decision Engine. Experiment with OPA’s decision engine configuration parameters such as decision_logs, instrument, and parallel. Fine-tuning these parameters can improve performance based on your specific use case and workload characteristics.</li></ul><p><strong>Monitor and Optimize</strong></p><ul><li>Performance Monitoring. Continuously monitor OPA’s performance metrics, including response times, throughput, and resource utilization. Identify performance bottlenecks and areas for optimization.</li><li>Profiling and Benchmarking. Profile OPA’s execution to identify areas of code that contribute to latency. Benchmark different policy configurations and evaluate their impact on latency under various conditions.</li></ul><p>In <strong>conclusion</strong>, while Open Policy Agent (OPA) offers powerful capabilities for fine-grained authorization in distributed architectures, its implementation should be approached with care. OPA provides organizations with the flexibility, control, and adaptability needed to manage complex access control requirements effectively. However, it is essential to recognize that OPA is not a one-size-fits-all solution and may not be the default option for every use case.</p><p>When considering the adoption of OPA, organizations should carefully evaluate their specific access control needs, regulatory compliance requirements, and infrastructure constraints. While OPA’s centralized policy management, dynamic evaluation, and granular control can offer significant benefits, its implementation requires careful planning, testing, and ongoing maintenance.</p><p>Moreover, <strong>organizations should assess whether OPA aligns with their existing development workflows, tooling, and expertise</strong>. In some cases, simpler access control mechanisms such as JSON Web Tokens (JWT) or Role-Based Access Control (RBAC) may be more suitable for their needs.</p><h4>References</h4><ul><li><a href="https://github.com/StyraInc/awesome-opa">https://github.com/StyraInc/awesome-opa</a></li><li><a href="https://github.com/segpacto/nodejs-opa">https://github.com/segpacto/nodejs-opa</a></li><li><a href="https://www.openpolicyagent.org/docs/latest/">https://www.openpolicyagent.org/docs/latest/</a></li><li><a href="https://github.com/StyraInc/awesome-opa">https://github.com/StyraInc/awesome-opa</a></li><li><a href="https://www.openpolicyagent.org/docs/latest/policy-testing/">https://www.openpolicyagent.org/docs/latest/policy-testing/</a></li></ul><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bd42658d1ad" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/fine-grained-authorization-with-open-policy-agent-opa-on-distributed-architectures-9bd42658d1ad">Fine-Grained Authorization with Open Policy Agent (OPA) on distributed architectures</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effective Post-Mortems: Extracting maximum value from every analysis]]></title>
            <link>https://medium.com/@segpacto/effective-post-mortems-extracting-maximum-value-from-every-analysis-6e627c9b00a4?source=rss-287306dec4cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e627c9b00a4</guid>
            <category><![CDATA[project-management]]></category>
            <category><![CDATA[postmortem-documentation]]></category>
            <category><![CDATA[project-management-tool]]></category>
            <category><![CDATA[improvement-project]]></category>
            <dc:creator><![CDATA[Martinez Pupo Ivan]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 16:03:00 GMT</pubDate>
            <atom:updated>2023-08-08T16:38:52.329Z</atom:updated>
            <content:encoded><![CDATA[<p>This article describe the art of orchestrating a successful project post-mortem. We’ll explain the details of preparing for and executing these sessions. Also, how these impact positively your organization by cultivating a culture of continuous improvement and how influence strategic decision-making.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5anmX3PLr195jPxR2hNqCw.jpeg" /></figure><h4>What is a project post-mortem?</h4><blockquote>A <strong>project post-mortem</strong> is a process used to identify the causes of a project failure (or significant business-impairing downtime), and how to prevent them in the future.<br> — <a href="https://en.wikipedia.org/wiki/Postmortem_documentation">Wikipedia</a> —</blockquote><h4>Difference between post-mortem and retrospective?</h4><p>It is easy to mistake, project post-mortems and retrospectives, but they differ by scope, participants, when, how and partially the goals. The post-mortem is mainly focus on what’s went wrong on the scope of a project or a major phase of the project. It concentrates on analyzing the project as a whole, looking at its <strong>objectives, outcomes, successes, failures, and overall performance </strong>and takes place after the project is completed, which allows for a comprehensive analysis of the entire execution lifecycle.</p><p>On the other hand, retrospectives review the positive and negative equally on the scope of specific iterations, sprints or time frames rather than the entire project. The focus is around the <strong>team’s performance, processes, and interactions</strong> during the defined period.</p><p>The participants of retrospectives are regularly team members directly involved in the iteration and the Scrum Master or facilitator. The post-mortem could include stakeholders from various teams and actors that could have been involved partially or only on a certain period of the project, all these to gain a broader perspective.</p><h3>How to conduct a successful post-mortem?</h3><p>A post-project analysis yields optimal results when the project’s events and details are still vivid in the memories of your team members. A convenient method to ensure the postmortem occurs within a suitable timeframe is by scheduling the session at the project’s initiation when the project is time scoped.</p><h4>1. Select a moderator or facilitator</h4><p>For this activity to be effective, it’s essential that someone maintains a respectful, targeted, and progressive conversation. This role is fulfilled by the meeting moderator.</p><p>Prior to the in-person meeting, designate a moderator/facilitator who can create and adhere to the agenda, also guide the conversation if it veers off track. The moderator doesn’t necessarily have to be the project manager or part of the leadership team; they just need to be at ease with assuming a leadership role.</p><p>Prior to distributing the post-mortem questionnaire, this moderator would additionally allocate time to compile the <strong>goals, results, and deliverables</strong> that were established at the project’s outset. Gathering and sharing this information before the meeting will aid participants in directing their attention to the entirety of the project rather than solely its most recent phase. Moreover, it will serve as a way to refresh their memory about the project’s initial stages.</p><h4>2. Send out a post-mortem questionnaire before the meeting</h4><p>Employing a preliminary questionnaire before the meeting ensures that all team members have an equitable chance to express their perspectives, leaving no overlooked details. Make sure of sharing along with the questionnaire an overview of the goals, results and deliverables of the project.</p><p>Additionally, the questionnaire offers a chance for individuals to prepare themselves ahead of the meeting. This preparation allows them to dive into the reasons behind specific occurrences (or non-occurrences), enabling them to come to the meeting equipped with both the reasons behind issues and possible remedies, rather than solely presenting missteps or hastily concocted theories.</p><p>Sample questionnaire questions:</p><ul><li>Was the initial plan clearly articulated and effectively communicated? If not, what were the reasons?</li><li>Were the initial objectives of the project clearly understood? If not, what led to the ambiguity?</li><li>Were the resources allocated sufficient for accomplishing our objectives? If not, what were the contributing factors?</li><li>Was the original project timeline feasible and practical? If not, what factors contributed to its impracticality?</li><li>Did our project team exhibit effective collaboration? If not, what were the underlying reasons?</li><li>Did our team engage in productive interactions with the client? If not, what hindered the effective collaboration?</li><li>Did we achieve the desired project outcomes? If not, what factors contributed to falling short of our goals?</li></ul><h4>3. Define the Agenda and facilitate the session</h4><p><strong>Limit the duration of the meeting to an hour or less</strong>. Although not all participants will have an opportunity to voice their thoughts, and certain smaller yet crucial matters might receive inadequate discussion time, it is important to no drift into an endless meeting.</p><p>With an abundance of details to cover in a constrained timeframe, it’s common for post-mortem meetings to veer off course. <strong>Maintain focus by designing a well-defined meeting agenda</strong> in advance.</p><p>Commence with an overview of the project’s fundamental aims, briefly <strong>revisiting the objectives and measurements established at the project’s initiation</strong>. This segment should not exceed five minutes and serves as a quick reminder of your team’s initial intentions.</p><p><strong>Conduct a brief evaluation of the outcomes</strong>. After discussing the primary objectives and goals, allocate a few minutes to assess the final results of the project. This evaluation should straightforwardly determine whether the project aligned with your team’s success criteria.</p><p>Dive into the reasons behind outcomes. <strong>Analyze those factors that contributed to the project’s outcomes</strong> and how team members perceive them. This conversation should form the majority of the meeting’s duration.</p><h4>4. Draw conclusions</h4><p>The meeting’s closure doesn’t signify the completion of responsibilities for the facilitator. It’s essential to condense all the notes and examine the action items specified by the participants. The culmination of the questionnaire and meeting should yield a post-mortem report summarizing findings and practical insights for upcoming endeavors.</p><p>Distribute the post-mortem summary document to participants for their approval. Subsequently, share the broader lessons for future projects with all members across the department.</p><h3>What to do with the post-mortem results?</h3><p>The outcomes and reports from project post-mortems are valuable resources for continuous improvement and informed decision-making. How to take forward the reports from post-mortem:</p><ul><li><strong>Analyze and Reflect:</strong> Take time to thoroughly review the findings and insights gathered from the post-mortem. This analysis will help you identify trends, recurring issues, and patterns across projects.</li><li><strong>Identify Actionable Insights:</strong> From the post-mortem findings, extract actionable insights and recommendations. These could be <strong>specific changes to processes, communication, resource allocation</strong>, or any other aspect that can enhance future projects.</li><li><strong>Update Processes:</strong> Use the insights to refine and update your project management processes, methodologies, and best practices.</li><li><strong>Share Knowledge:</strong> Disseminate the post-mortem reports or key takeaways within your organization. Sharing the lessons learned by some communication channels available helps spread knowledge across teams and prevents others from making the same mistakes.</li><li><strong>Training and Onboarding:</strong> Use the post-mortem results as training materials for new team members or as part of onboarding processes. It helps them understand the challenges faced and the strategies implemented to overcome them.</li><li><strong>Incorporate into Project Planning:</strong> Integrate the insights from post-mortems into future project planning. Adjust project plans, objectives, and resource allocations based on the lessons learned to increase the likelihood of success.</li><li><strong>Feedback Loop: </strong>Share the post-mortem findings with stakeholders, clients, or customers if appropriate.</li><li><strong>Track Progress:</strong> Keep track of the changes implemented based on post-mortem insights. Monitor the impact of these changes on subsequent projects, measuring whether they result in improved outcomes or not.</li><li><strong>Continual Learning:</strong> Consider organizing workshops, seminars, or training sessions based on the lessons learned from post-mortems to share their experiences and engage in discussions around improvement strategies.</li><li><strong>Document and Archive: </strong>Archive the post-mortem reports and insights for future reference.</li></ul><p>Making of post-mortems a standard practice for individuals executing or participating on medium and large-scale projects holds significant merit. This ongoing commitment cultivates a culture of perpetual improvement. Through consistent retrospection of prior projects, teams gain the proficiency to recognize avenues for refinement, streamline operational processes, and prevent the recurrence of past errors.</p><p>The constant analysis elevates projects beyond mere endeavors, turning them into invaluable learning experiences. Consequently, teams acquire the ability to fine-tune their methodologies, mitigate risks, and uphold a track record of consistent success.</p><p>Sources:</p><ul><li><a href="https://en.wikipedia.org/wiki/Postmortem_documentation">Post-mortem documentation(wikipedia)</a></li><li><a href="https://en.wikipedia.org/wiki/Retrospective#Software_development">Retrospectives in software development</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e627c9b00a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2: How to migrate from Monolith to Microservices leaving no one behind.]]></title>
            <link>https://medium.com/cloud-native-daily/part-2-how-to-migrate-from-monolith-to-microservices-leaving-nobody-behind-67a2acc66c6f?source=rss-287306dec4cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/67a2acc66c6f</guid>
            <category><![CDATA[teamwork]]></category>
            <category><![CDATA[microservices-application]]></category>
            <category><![CDATA[monolithic-architecture]]></category>
            <category><![CDATA[migration]]></category>
            <dc:creator><![CDATA[Martinez Pupo Ivan]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 13:27:51 GMT</pubDate>
            <atom:updated>2024-04-05T06:36:27.329Z</atom:updated>
            <content:encoded><![CDATA[<p>On a <a href="https://medium.com/@segpacto/part-1-how-to-migrate-from-monolith-to-microservices-leaving-nobody-behind-bac1f26388e">previous article</a>, we started explaining How to migrate to microservices while including teams and the organization on the changes planned, all based on the understating that people implementing the changes are a corner stone on a platform or application migration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3ZQEh5KSvk4-lLXjh9vrw.jpeg" /></figure><p>The steps identified on the migration from monolith to microservices were:</p><p>1. Create a <strong>dedicated team</strong> in charge of the migration</p><p>2. Create a plan and blueprint for <strong>refactoring the monolith</strong></p><p>3. Refactor the monolith and <strong>split it into modules and services</strong></p><p>4. Create a plan and blueprint of the <strong>new architecture</strong></p><p>5. Split the first service apart</p><p>6. Introduce teams one by one to the migration</p><p>This post will continue explaining how to proceed with the migration from the <strong>point 4 “</strong>Create a plan and blueprint of the <strong>new architecture”</strong> forward.</p><h3>4. Create a plan and blueprint of the new architecture</h3><p>Using the knowledge gained during the refactoring of the monolith and the <strong>wish list </strong>along with the list of <strong>hard business and technical requirements </strong>from devs it is time to create the migration plan and blueprint of the new architecture.</p><h4>Prepare the developers for what’s coming…</h4><p>One of the biggest issues found is the lack of knowledge in teams about distributed systems. This is the root cause of adversity to change in teams, devs are regularly thrown into the microservices world without having a clear idea of what to expect in a system that has a lot of moving parts and comes with a steep learning curve. The migration team should take time to <strong>create workshops with code samples</strong> where basic knowledge is shared before the architecture draft is presented.</p><blockquote>Topics like <strong>best practices in Microservices Architecture</strong>, design patterns, and communication between services need to be addressed before moving forward.</blockquote><h4>Design of the new architecture blueprint</h4><p>The blueprint of the architecture should be visually understandable using diagrams, it should contain the old monolithic system and the new services apart. Equally, it should demarcate the teams’ services, ways of communication between services, what would be considered internal and external to the organization’s network, what should be the teams’ responsibility, clear definitions of inter-team agreements, and the ways of working. Tools like draw.io and <a href="https://www.visual-paradigm.com/support/documents/vpuserguide/2535/2539/78362_creatingserv.html">Visual Paradigm</a> are great tools for this type of representation.</p><h4>Data storage</h4><p>Monolithic databases are not well designed for splitting, and one of the principles of a distributed architecture is one database for each microservice. When the migration starts you might find a lot of dependencies between single DB tables. While splitting apart DBs topics like data synchronization, transactional integrity, relations between entities and latency becomes an issue.</p><p>Some strategies for tackling the data storage in microservices:</p><ul><li><strong>Share data through an API</strong>. It is suitable for retrieving small payloads with clear structures and implementing a good caching system could reduce the overall latency and avoid overloading internal networks.</li><li><strong>Data projections</strong>. It can be implemented through manual migrations, shared tables, <a href="https://en.wikipedia.org/wiki/Materialized_view">materialized views</a>, <a href="https://martinfowler.com/eaaDev/EventSourcing.html">event sourcing</a>, or change data capture (<a href="https://en.wikipedia.org/wiki/Change_data_capture">CDC</a>). This strategy could also introduce lags in the data because of the execution time of data projections and external reasons if you are not the source of truth.</li></ul><h4>Inter-Service communication</h4><p>Exist many ways to implement inter-service communication. Alternatives go from <strong>synchronous request-response mechanisms</strong>, such as HTTP-based REST, gRPC, or Thrift to <strong>asynchronous message-based mechanisms</strong>, such as AMQP or STOMP. Avoid as much as possible services calling directly to each other, this creates high coupling and difficult the retry process on failed requests. Instead, use <strong>messaging</strong> or <strong>event-based communication</strong>. RabbitMQ, Redis, and Kafka are just some of the options available.</p><p>The <strong>message formats</strong>, such as human-readable text formats like JSON or XML, or binary formats like <strong>Avro</strong> or <strong>Protocol Buffers</strong> play also a major role in the alignment between teams. Make sure of having an organization’s common understanding with guidelines on how to make this information reachable, available, and documented among all the teams.</p><h4>The plan…</h4><p>The plan and the strategies used need to be explained to every team. The migration team needs to make everyone acquainted with <strong>Feature flags</strong> and how the pattern <strong>Strangler Fig</strong> works. The feature flags will allow to control through the facade the access to the new services, which can be easily disabled if something does not go as expected. Strangler fig is the method to shrink a step-by-step monolithic application while moving and splitting modules and services apart.</p><p>What the <strong>new architecture should have</strong>:</p><ul><li>List of issues that the current architecture solves</li><li>List of topics the current architecture doesn’t address</li><li>Clear visual design of services split</li><li>Definition of tools for Observability(Metrics, traceability, and logging)</li><li>Definition of the language used on each service(in case not all services are going to be written in the same programming language)</li></ul><p>It is advisable to <strong>share with the team(s) a draft</strong> of the new architecture plan before the final presentation and with a scoped time to ask questions and add feedback. This will allow the migration team to get an overall feeling of the work that will be done, to get valuable feedback from devs, and also set a timeline to present the new architecture plan.</p><h3>5. Split the first service apart</h3><p>The most popular option nowadays is containers, cloud and edge functions can also work as isolated services. Just make sure to select a technology and stack that you can feel comfortable with for the next 5 years.</p><h4>Infrastructure</h4><p>Start by creating shared CI pipelines and writing simple infrastructure code to be reused by other services and teams. Do not implement big features, the majority of DevOps code are features or configuration requested from teams, and it is really hard to foresee what precisely they will need apart from Metrics, Logging, and Monitoring.</p><p>Take into consideration the maturity of your team for deep infrastructure changes, if your organization doesn’t have specialized DevOps, let the migration team create the basis for deploying and provisioning machines, pipelines and systems, an alternative is also to hire externals to accomplish the tasks creating good boilerplate code.</p><h4>Start with the smallest service</h4><p>Once again, the migration teams should start with the <strong>smallest service</strong>, and choose the one with <strong>fewer features planned for the next quarter</strong>. Check who built the initial code and keep it as a contact in case deeper understanding is necessary and <strong>create good documentation</strong> around it. This will be the code and service that will be used by other teams as a reference to create their own migrations.</p><p>Use Feature flags and the Facade implementation on the monolith to share the load to the new service or simply redirect to it all the incoming requests. Take your time to monitor the behavior of the changes and the general architecture. <strong>Create public updates</strong> <strong>about the migration in general channels</strong>, this will enable other teams to be aware and ready to report any anomaly on the services.</p><h4>Tests</h4><p>Tests will play an important role on making sure all teams stay aligned and proceeding with a certain degree of confidence. The teams have the chance of choosing between Unit, Integration, Component, Contract, and End-to-end tests. From those, I suggest the migration team focusing on setting the strong bases and fundamentals by <strong>implementing Integration, Component and Contract tests</strong>, those tests will generate code that can be reused by teams joining the migration, also help understand the way the microservices works. Unit tests are going to end up being implemented based on the particular necessity of each teams, and End-to-end tests are too expensive to implement on a phase where there are not many services interacting to each other.</p><h4>Shared code</h4><p>While implementing the first service you will start writing packages and modules that will be meant to be shared and with those packages creating repositories where the code will be stored, shared, and <a href="https://semver.org/">versioned</a>. The implementation of the packages and their features should be based on necessity, do not implement anything that is strictly necessary for the service you are migrating to.</p><p>Will be important to document all the good practices used, standards, patterns and learnings acquired while doing the first migration. This overall knowledge will be of much help to others trying to replicate the migration.</p><h3>6. Introduce teams one by one to the migration</h3><p>Once the first service is migrated, the migration team should blend with other teams and helping them one by one to do their own migrations while sharing knowledge and updating the documentation. Also keeping an eye on those features that will need to be implemented to be used by other teams in the future.</p><p>Managers and engineers will do whatever it takes not to start an architecture migration, it is understandable, is pretty scary thing to do, a lot of things can go wrong and once you start you cant stop in the middle. For big organizations and systems, a greenfield project it might be harder to implement due to costs, organizational obstacle( not everyone can be taken out of feature development or bug fixing), a greenfield requires a steep learning curve that might not be shared with everyone and it is not of everyone interest if they are not participating, and most important, a greenfield is not a guaranty for a bug free system among others reasons.</p><p>Sources:</p><ul><li>M<a href="https://cloud.google.com/architecture/microservices-architecture-refactoring-monoliths">icroservices architecture refactoring monoliths</a> by Google</li><li><a href="https://medium.com/@segpacto/documentation-the-hidden-treasure-8b22b3d933d7">Documentation: The hidden treasure</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67a2acc66c6f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloud-native-daily/part-2-how-to-migrate-from-monolith-to-microservices-leaving-nobody-behind-67a2acc66c6f">Part 2: How to migrate from Monolith to Microservices leaving no one behind.</a> was originally published in <a href="https://medium.com/cloud-native-daily">Cloud Native Daily</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Migrate From Monolith to Microservices Leaving No One Behind]]></title>
            <link>https://medium.com/cloud-native-daily/part-1-how-to-migrate-from-monolith-to-microservices-leaving-nobody-behind-bac1f26388e?source=rss-287306dec4cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/bac1f26388e</guid>
            <category><![CDATA[monolithic-architecture]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[teams-and-teamwork]]></category>
            <category><![CDATA[leading-teams]]></category>
            <category><![CDATA[migration]]></category>
            <dc:creator><![CDATA[Martinez Pupo Ivan]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 13:04:27 GMT</pubDate>
            <atom:updated>2023-08-04T12:53:06.328Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1: Monoliths: the best option for sprints, but what about long distances?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h12YvyMx_I_ykhV_rGvHfA.jpeg" /></figure><p>Monoliths are a popular choice for software architectures because they are simple to kick off the development because they require a low learning and implementation curve. However, as applications grow in size and complexity, monoliths can become difficult to scale, test, and maintain. This is due to the fact that all of the components of a monolith are tightly coupled, meaning that changes to one component can affect other components.</p><p>There are multiple articles describing how to migrate monoliths to microservice, however, none describe how to include the team(s) in the migration, and this is a fundamental part of it since the issues to solve are not just technical. I will describe in two posts how to migrate from monolith architecture to microservices sharing the focus with the team(s) and developers on big organizations.</p><p>Before moving forward, I would suggest asking yourself, When should you migrate…</p><h4>When you should migrate to microservices?</h4><ul><li>the number of hands-on codes is too many and is causing productivity issues(could be on code review, releases, or technical discussions).</li><li>introducing changes into a particular area(ex: payment) affects and requires changes into 3 more other areas</li><li>maintenance is a task that nobody wants to take</li><li>fixing a bug requires knowledge of the whole platform or stack</li><li>all developers need to know about every detail of your business in order to implement a feature</li><li>local development of small features requires unnecessary services to run</li><li>deploying small changes involves lots of people that have nothing to do with the changes</li></ul><p>Of course, those are just some of the reasons and the list grows with new ones appearing every day, however, the fear of failure should not paralyze team(s) knowing that some measures need to be taken.</p><p>I have been able to identify 6 steps in order to roll out a successful migration:</p><p>1. Create a <strong>dedicated team</strong> in charge of the migration</p><p>2. Create a plan and blueprint for <strong>refactoring the monolith</strong></p><p>3. Refactor the monolith and <strong>split it into modules and services</strong></p><p>4. Create a plan and blueprint for the <strong>new architecture</strong></p><p>5. Split the first service apart</p><p>6. <strong>Introduce teams</strong> one by one to the migration</p><h3>1. Create a dedicated team in charge of the migration</h3><p>One of the most common issues I have found so far is that migrating away from monoliths contains a human factor that is majorly missed. Misalignment in the team, lack of clear directions, and unwillingness to cooperate are some clear indicators that people and teams haven’t been considered in the equation.</p><p>A dedicated team(could be a one-person team) will be the point of contact and person to go to when questions arise and inter-team features fall into nobody’s land. Gathering requirements, documenting, creating the migration blueprint and first implementations belongs all to these architects.</p><p>In order to have all devs onboard, the migration team should meet with the different teams, gather and prioritize their <strong>wish list</strong>(things wanted on the new architecture from devs, of course, not all will be initially included), and those <strong>hard business and technical requirements</strong> that only a few might know about. <strong><em>This exercise guarantees full transparency and all voices are heard while sharing knowledge about the everyday struggle of the developer.</em></strong> Keep the wish list close to mind because will be essential for later.</p><h3>2. Create a plan and blueprint for <strong>refactoring the monolith</strong></h3><p>It is necessary to identify services, modules, and repeated code. That will help us propose packages that can be isolated, reused, and tested independently later. Define the strategy and practices for a further refactoring of the monolith and introduction of new features, because the development will continue on the monolith for a while at the same time that the migration takes place.</p><p>By refactoring using design patterns like <a href="https://en.wikipedia.org/wiki/Data_access_object">DAO</a>, <a href="https://en.wikipedia.org/wiki/Domain-driven_design">DDD</a> and techniques like <a href="https://en.wikipedia.org/wiki/Dependency_injection">Dependency Injection</a>, big steps are taken to the definition of modules and services.</p><p>The <strong>refactoring plan should have:</strong></p><ul><li>Identification of everything that could be transformed into a module</li><li>Identification of repeated code that can be transformed into a package</li><li>Proposal for monolith refactor, a complete or partial plan that includes grouping modules into services</li><li>Description of How a module should look like, folder structure, naming conventions etc.</li><li>Following the new design pattern How to add new features to the current monolith. <em>Migrations take time and ongoing development can’t be stopped until full transformation of code is done.</em></li><li>Proposal of the ideal skill sets needed in a team. Teams should become cross-functional and take care of service from the foundation to retirement.</li></ul><p>The refactoring plan should be <strong>publicly accessible</strong> and <strong>pitched</strong> to all devs, there will always be inside knowledge and questions that help with clarification or rectification of the migration plan.</p><p>With the refactoring plan in place, it is time to take a look at the wish list and hard technical and business requirements collected from devs. This will be used as an underline guide and for support of decision-making in creating the <strong>new architecture blueprints</strong>. <em>Details like selecting a particular language, a platform, a pipeline tool etc contain a fine and subjective line between being the right one and the wanted one from devs.</em></p><h3>3. Refactor the monolith and <strong>split it into modules and services</strong></h3><p><strong>Following the refactoring plan</strong> will require some effort from everybody on all the teams, although the biggest effort in aligning and implementing will come from the migration team.</p><h4>Review the state of the app’s Authentication and Authorization</h4><p>Monoliths applications are known to have a very simplistic approach(usually provided by the framework used on the app) to handle authentication and authorization, mainly because the services are all interconnected and don’t require verifying the authenticity of a request between one class calling another, neither verification of authorization to data beyond filtering on DB queries with extra parameters. For this reason, it is advisable to start designing/introducing a mechanism that later on can be used in between-services communication.</p><p>For <strong>more info</strong> take a look at <a href="https://jwt.io/introduction">JWT</a> as an alternative.</p><h4>Create a Strangler Facade or Proxy Interface Layer</h4><p>The Strangler facade or proxy interface layer inside the monolith will allow the application to segregate all incoming traffic requests and redirect them to newly internally migrated services. It will also be in charge of authentication, enriching requests redirected to separated services, and load balancing between services in the monolith and migrated services in order to do AB testing of the overall migration.</p><figure><img alt="Refactoring Monolith application in preparation for a migration to Microservices" src="https://cdn-images-1.medium.com/max/1024/1*zE3-ALnWSY_o1uFtlqDCDg.png" /></figure><h4>DB changes</h4><p>Start de-normalizing the monolith’s shared database into smaller databases. You might notice some data or properties would end up being duplicated among DBs, however, this will enable the split. Use mechanisms to sync duplicated data and properties making sure all data sources are up to date.</p><h4>Start with the smallest service</h4><p>Start refactoring by the smallest service identified and with fewer features planned in the near future. This will create as less overhead as possible for other teams, help the migration team to create boilerplate code that later on can be used as a guide to other teams, generate documentation and help rectify the refactoring plan if necessary.</p><p>It is not completely necessary to refactor the whole platform before moving forward, is just enough to have delimited some modules completely isolated in order to start thinking about planning the next steps.</p><p>While refactoring dedicate as much as possible to improving<strong> observability</strong> (<strong>logging</strong>, <strong>tracing</strong>, and <strong>metrics</strong>). This will help everyone to understand the current state of the application and future evolution.</p><p>On the <a href="https://medium.com/@segpacto/part-2-how-to-migrate-from-monolith-to-microservices-leaving-nobody-behind-67a2acc66c6f">next article</a> will be explained how to proceed with the migration starting from step <strong>#4</strong>. Create a plan and blueprint for the <strong>new architecture.</strong></p><p>Sources:</p><ul><li><a href="https://www.oreilly.com/library/view/migrating-to-microservice/9781492048824/">https://www.oreilly.com/library/view/migrating-to-microservice/9781492048824/</a></li><li><a href="https://martinfowler.com/bliki/StranglerFigApplication.html">https://martinfowler.com/bliki/StranglerFigApplication.html</a></li><li><a href="https://martinfowler.com/articles/break-monolith-into-microservices.html">https://martinfowler.com/articles/break-monolith-into-microservices.html</a></li><li><a href="https://insights.sei.cmu.edu/blog/8-steps-for-migrating-existing-applications-to-microservices/">https://insights.sei.cmu.edu/blog/8-steps-for-migrating-existing-applications-to-microservices/</a></li><li><a href="https://microservices.io/refactoring/">https://microservices.io/refactoring/</a></li></ul><h4>Further Reading:</h4><ul><li><a href="https://gethelios.dev/blog/cut-engineering-costs-save-time-helios?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=cloud+native+daily">Microservices Monitoring: Cutting Engineering Costs and Saving Time</a></li><li><a href="https://gethelios.dev/blog/testing-microservices-with-helios/?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=cloud+native+daily">Testing Microservices - Trace Based Integration Testing Example</a></li><li><a href="https://gethelios.dev/opentelemetry-a-full-guide/?utm_source=medium&amp;utm_medium=cloud+native+daily">OpenTelemetry: A full guide</a></li><li><a href="https://medium.com/cloud-native-daily/3-ways-to-reproduce-issues-in-microservices-5a75a0fcf90f">3 Ways to Reproduce Issues in Microservices</a></li><li><a href="https://medium.com/cloud-native-daily/microservices-observability-key-techniques-36ded52b7c88">Microservices Observability: Key Techniques</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bac1f26388e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloud-native-daily/part-1-how-to-migrate-from-monolith-to-microservices-leaving-nobody-behind-bac1f26388e">How to Migrate From Monolith to Microservices Leaving No One Behind</a> was originally published in <a href="https://medium.com/cloud-native-daily">Cloud Native Daily</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Most Common Security Threats in GraphQL Gateways]]></title>
            <link>https://medium.com/cloud-native-daily/most-common-security-issues-in-graphql-gateways-7429d62f958a?source=rss-287306dec4cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/7429d62f958a</guid>
            <category><![CDATA[gateway]]></category>
            <category><![CDATA[owasp]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[federation]]></category>
            <dc:creator><![CDATA[Martinez Pupo Ivan]]></dc:creator>
            <pubDate>Tue, 20 Jun 2023 08:13:58 GMT</pubDate>
            <atom:updated>2023-08-08T13:57:09.062Z</atom:updated>
            <content:encoded><![CDATA[<h4>Common security threats in GraphQL gateways and how to mitigate them</h4><p>Despite the huge success that is experimenting with GraphQL over recent years there are a lot of unknowns and uncovered areas in terms of security by teams and developers who adopt the technology. In this post, I will go over some of the most important and common security issues I had found in <strong>GraphQL gateways </strong>over time<strong>, </strong>this can be applied to gateways built with schema stitching or federation.</p><h4>What is a QraphQL gateway?</h4><p>A GraphQL gateway is a single point of access to any back-end(s) API, sub-graphs, or even DBs in your organization. It can aggregate data from multiple sources and communicate with each service using the service’s preferred communication method, such as SOAP, REST, etc.</p><figure><img alt="GraphQL gateway for internal APIs" src="https://cdn-images-1.medium.com/max/689/1*Sn7hP4y_cF4SkKXMWwvYBg.png" /></figure><h3><strong>Authentication and authorization</strong></h3><p>The flexible nature of the gateway enables external requests to reach services that are not commonly public, services that often trust any communication from within the organization, so once the request passes the gateway is able to reach any service at hand. Also, due to the aggregation capacity of GraphQL, there are multiple ways to access the same data.</p><p><strong>As a solution</strong>, introduce the <strong>Authentication at the gateway level</strong>, where the request authenticity is verified(with Identity providers, JWTs, etc), and move the <strong>authorization to the service level</strong>. Authenticated requests are forwarded to the services which take the responsibility of deciding permissions levels on the data, those permissions/services could be handled by different teams and use particular ways to grant/deny access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*YkGlP-f2tQFptPN94Xnb8A.gif" /><figcaption>Authentication on GraphQL gateway is valid but authorization on Comment Service is not.</figcaption></figure><p><strong>Use </strong><a href="https://jwt.io/"><strong>JSON Web Tokens</strong></a>(JWT) to manage user auth. The JWT provides a mechanism for carrying information about the user, like permissions, and roles, and also provides ways to determine the validity of a token. Be aware of following <a href="https://curity.io/resources/learn/jwt-best-practices/">JWT good practices</a>, ensuring a <strong>sinful expiration time of </strong>the JWT, and <strong>checking the audience</strong> on the sub-graphs that will contain the reach of certain requests on the internal network.</p><h3><strong>Denial of Service</strong></h3><p>The versatility of the queries and the way GraphQL relates entities and data opens the door to the creation of dangerous large queries that could cause bottlenecks due to the expensive computation or crashes into internal APIs/services that are not able to scale horizontally fast enough to an avalanche of requests from the gateway.</p><pre>query {<br>  writers(amount: 100) {<br>    name<br>    lastname<br>    articles(amount: 100) {<br>      title<br>      description<br>      reviewers(amount: 5){<br>        name<br>        lastname<br>      }<br>    }<br>  }<br>}</pre><p>A query to <strong>list entities</strong> like the one above requests 50 000 nodes. Guessing that exist a service Writer, a service Article and another Reviewer the request waterfall will be 1 request to obtain 100 writers &gt; per each writer a request to obtain 100 articles &gt; per each article a request to obtain 5 reviewers, those are 501 requests for only one query(really expensive query).</p><p><strong>As prevention</strong>, limit the number of elements requested and implement pagination. It is also possible to establish response Timeouts and Throttling based on <a href="https://www.howtographql.com/advanced/4-security/">Query Complexity</a> or <a href="https://arxiv.org/pdf/2009.05632.pdf">Query Cost Analysis</a>. So far, just one solution is not enough to cover the full impact of these large queries but it limits the reach of the damage.</p><pre>query {<br>  writer(writerId: 2) {<br>    articles {<br>      writer {<br>        articles {<br>          writer {<br>            articles {<br>              writer {<br>                articles {<br>                  # Continues ...<br>                }<br>              }<br>            }<br>          }<br>        }<br>      }<br>    }<br>  }<br>}</pre><p>The <strong>nested query</strong> above(also known as Recursive or Cyclic query) could be dangerous if not contained, causing the consumption of all available resources in the gateway, and also on the subsequent sub-graphs/services.</p><p>Some of the <strong>most common and simple solutions</strong> are to introduce a <a href="https://escape.tech/blog/cyclic-queries-and-depth-limit/">depth limit to queries</a> and <a href="https://www.apollographql.com/docs/apollo-server/performance/caching/">caching</a> on the gateway per query per service response If we would use the cache, the first two requests to the services resolved the writer and the list of articles where writerId = 2 provoking that subsequent cyclic request are not propagated on the network to sub-graphs services.</p><pre>query HostileQuery {<br>  aliasA: getAllWriters { ...}<br>  aliasB: getAllWriters { ...}<br>  aliasC: getAllWriters { ...}<br>  ...<br>  ...<br>  ...<br>  aliasAB: getAllWriters { ...}<br>  ...<br>}</pre><p>The <strong>Batch queries </strong>are most common than we imagine when the target is to either harm performance or by brute force get as much information as possible.</p><p>One way to <strong>defend against</strong> this type of malicious queries is to use rate and resource limiting.<strong> </strong>This will allow your Gateway to control over a period of time how much a client can consume, take a look at how <a href="https://docs.github.com/en/graphql/overview/resource-limitations">Github</a> achieved this.</p><h3>GraphQL Gateway as API attack vectors</h3><p>The easier and faster way for teams to migrate into GraphQL is often to adapt old APIs(REST u others) by creating a gateway. A GraphQL gateway takes the responsibility to proxy and converts all incoming GraphQL requests into an understandable protocol for the sub-graphs/services.</p><p><strong>Auto-generation of schemas, queries, and mutations</strong> tools tend to be the fastest way to create the gateway. However, introduces security risks like exposing unwanted internal endpoints and properties, and also discloses the composition and structure of internal APIs.</p><pre>query {<br>  owner(name: &quot;../GetPrivateOwnersInfo&quot;) {<br>    pets {<br>      ...<br>    }<br>  }<br>}</pre><p>A query like the one above it could be passed to an internal API as GET {api}/GetPetsByOwnerName/../GetPrivateOwnersInfo which might lead to the exposure of sensitive information, gaining unauthorized access or the execution of arbitrary code(SQL or other) that would jeopardize the Database.</p><p>To <strong>avoid such techniques</strong>, sanitize input data by creating a whitelist of allowed characters, using a unique character encoding format to properly handle Unicode input, and introducing automatic ways for the gateway to exclude specific endpoints and data entities.</p><h3><strong>Discovery</strong></h3><p>One of the first steps attackers take is to collect and understand as much data from the target as possible, and details like setting the same log level for development as production sometimes make a great difference.</p><p>If the gateway would be publicly exposed outside your organization it is <strong>highly recommendable to disable introspection</strong> unless it is business required and a review of pros and cons has been done, otherwise the attacker might get detailed information about your entities, queries, mutations, and subscriptions available.</p><p><strong>Avoid transmitting proxied internal API errors</strong> from upstream services to the final client on production environments, those could lead to uncovering internal endpoints, properties, and parameters. <strong>Disable production errors containing suggestions for Types Queries and Mutations</strong> on failed queries.</p><p>As a general recommendation, is important to <strong>make good use of Logging and Monitoring</strong>. Setting the<strong> right alarms and notifications</strong> will create an environment that might not block all levels of attacks but it could create a good reaction time to fix and handle threats. Keep your <strong>team updated and informed about </strong><a href="https://owasp.org/search/?searchString=graphql"><strong>new security threats</strong></a> of the technologies and tools involved in your platform.</p><p><strong>Support tools:</strong></p><ul><li><a href="https://github.com/APIs-guru/graphql-voyager">GraphQL Voyager</a></li><li><a href="https://github.com/doyensec/inql">InQL (Burp Suite)</a></li><li><a href="https://github.com/graphql/graphiql">GraphiQL</a></li></ul><p><strong>Sources:</strong></p><ul><li><a href="https://betterprogramming.pub/how-to-create-a-graphql-gateway-with-rest-apis-and-not-dying-in-the-intent-e4eee697c51b">How to create a GraphQL gateway with REST APIs and not dying on the intent</a></li><li><a href="https://crashtest-security.com/graphql-security-vulnerabilities/">GraphQL security &amp; vulnerabilities</a></li><li><a href="https://apimike.com/api-attack-types">API attack types</a></li><li><a href="https://blog.logrocket.com/security-and-performance-tips-and-tricks-for-your-graphql-servers/">Security and performance tips and tricks for your GraphQL servers</a></li><li><a href="https://escape.tech/blog/graphql-input-validation-and-sanitization/">GraphQL input validation and sanitization</a></li></ul><h4>Further Reading:</h4><ul><li><a href="https://gethelios.dev/blog/serverless-observability/?utm_source=medium&amp;utm_medium=cloud+native+daily">Serverless observability, monitoring, and debugging explained</a></li><li><a href="https://gethelios.dev/opentelemetry-a-full-guide/?utm_source=medium&amp;utm_medium=cloud+native+daily">OpenTelemetry: A full guide</a></li><li><a href="https://gethelios.dev/blog/api-monitoring-vs-observability-in-microservices-troubleshooting-guide/?utm_source=medium&amp;utm_medium=cloud+native+daily">API monitoring vs. observability in microservices</a></li><li><a href="https://gethelios.dev/blog/api-observability-leveraging-otel-to-improve-developer-experience/?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=cloud+native+daily">API observability: Leveraging OTel to improve developer experience</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7429d62f958a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloud-native-daily/most-common-security-issues-in-graphql-gateways-7429d62f958a">Most Common Security Threats in GraphQL Gateways</a> was originally published in <a href="https://medium.com/cloud-native-daily">Cloud Native Daily</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a simple weather forecast Slack app with a dialog box and AWS lambda.]]></title>
            <link>https://medium.com/@segpacto/build-a-simple-weather-forecast-slack-app-with-a-dialog-box-and-aws-lambda-6e1af97f6036?source=rss-287306dec4cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e1af97f6036</guid>
            <category><![CDATA[weather]]></category>
            <category><![CDATA[aws-cdk]]></category>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[slackbot]]></category>
            <dc:creator><![CDATA[Martinez Pupo Ivan]]></dc:creator>
            <pubDate>Mon, 08 May 2023 12:30:29 GMT</pubDate>
            <atom:updated>2023-05-09T09:50:25.144Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered how Slack apps work?</p><p>Well, in this article you will have the opportunity to learn how to create a simple app on Slack with a <strong>Dialog box</strong>, using <strong>JavaScript</strong> and <strong>AWS lambda</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hMdfp2h00PHX8v73HTOi3Q.png" /><figcaption>weather forecast dialog form</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oALY2UHzvXZLQj3RSJaQnQ.png" /><figcaption>Bot weather forecast response</figcaption></figure><p>For the sake of simplicity we will build a <strong>weather forecast app. </strong>The App will request the city and the number of upcoming days, then post the forecast in the channel. We will set our main focus on how modal dialog boxes works in Slack since there are multiple ways to create Slack apps.</p><p>It was decided to use <strong>AWS lambda</strong> because is a computing service that allows us to run code without provisioning or managing servers, it will be “create and forget”, and once the app is created the maintenance requirements are really low with high availability, with relatively low cost for low traffic applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-ClvNxGNlky93LlzmiJ3g.png" /></figure><p>The solution will be composed of an AWS Gateway that will receive all incoming requests from Slack and distribute them to two lambda functions.</p><p>For resolving the weather data it was used an external service named <a href="https://www.weatherapi.com/"><strong>WeatherApi</strong></a>, a platform that will give us access through their API to the forecast information after registration and obtaining an <strong>ApiKey</strong>.</p><p>Note: We registered only for the <a href="https://www.weatherapi.com/pricing.aspx">free version</a> from WeatherAPI for this reason the App will request only 3 day’s forecast.</p><h3>How do Slack modals work?</h3><p>Slack modals consist of standardized <a href="https://api.slack.com/block-kit/building">UI elements</a> which could come as alert boxes, pop-ups, or dialog boxes. In this case, we will be using the dialog box.</p><p>To show the dialog form, the flow starts with a request triggered by Slack to generate the modal on the backend, our lambda(backend) will return the modal with all the fields and form configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t2JPlw0f1Htuahw5ESDnQA.png" /></figure><p>To process interactions and submissions in the Modal, Slack notifies through HTTP call <a href="https://api.slack.com/apis/connections/events-api">events</a> our lambda function. The events will carry the form’s payload, the user that triggered the action, bot details, etc.</p><h3>Setup of lambda service for processing Slack actions</h3><p>Our backend will consist of one <strong>API Gateway</strong> and two <strong>lambda</strong> services, the <strong>WeatherSlackModalApi</strong> and the <strong>WeatherSlackApi</strong>.</p><p>To simplify the provisioning of our cloud services, <a href="https://docs.aws.amazon.com/cdk/v2/guide/cli.html">AWS CDK</a> is going to be of help. The instructions below will be defining the cloud infrastructure in code and provision the Gateway and the two resources(lambdas) with access through the <strong>POST</strong> method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b26e1bed48b5f94b635495d9da5f4878/href">https://medium.com/media/b26e1bed48b5f94b635495d9da5f4878/href</a></iframe><p>The <a href="https://github.com/segpacto/weather-slack-app/tree/master/apps/weather-slack-modal"><strong>WeatherSlackModalApi</strong></a> service will be in charge of generating the modal for Slack. The dialog was constructed using the <a href="https://api.slack.com/block-kit/building">Slack Block Kit</a>, a tool that enables the construction of Forms and fields visually.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30af06069fae9302bc1b0ac5a9ab43de/href">https://medium.com/media/30af06069fae9302bc1b0ac5a9ab43de/href</a></iframe><p>Let’s take a quick look at what just happened. <br>Slack sends a request to create and retrieve a Modal. The request specify the <strong>token </strong>and<strong> triggerId</strong>, with the token our services validate the authenticity of the incoming request; The triggerId will be used to create a valid response to Slack API with the dialog as payload.</p><p>The whole Dialog box is nothing more than a request to Slack API with json body describing the title, fields, blocks and overall design.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a2707611e47f8b9fc167ef7175ea8cc/href">https://medium.com/media/0a2707611e47f8b9fc167ef7175ea8cc/href</a></iframe><p>The <a href="https://github.com/segpacto/weather-slack-app/tree/master/apps/weather-api"><strong>WeatherSlackApi</strong></a><strong> </strong>on the other hand will handle the Dialog’s Form submitted data, retrieve the weather forecast from the external service <strong>WeatherAPI</strong> and post it into Slack.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a8a85ef2437a8b184f3c894fc90ca39/href">https://medium.com/media/3a8a85ef2437a8b184f3c894fc90ca39/href</a></iframe><p>After deploying the AWS services, notice that our API Gateway will publish one API with two endpoints(<strong>/weather-slack-modal</strong> &amp; <strong>/weather-api</strong>). These will be the endpoints used by Slack to interact with our backend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7rqwpac5nUHKS1kITtvXvQ.png" /><figcaption>Amazon API Gateway configuration</figcaption></figure><h3>Setup of Slack App and Configuration</h3><p>Now, let’s configure Slack to connect our backend…</p><ol><li>Create on <a href="https://api.slack.com/apps">Slack</a> the Weather app.</li><li>On section <strong>Features</strong> &gt; <strong>OAuth &amp; Permissions</strong> add the scopes <strong>chat:write</strong>, <strong>chat:write.public</strong> and <strong>incoming-webhook</strong>.</li><li>On section <strong>Features</strong> &gt; <strong>OAuth &amp; Permissions</strong> create an OAuth Token on your Workspace for Bots. The Bot token will be used as credentials for all future calls to Slack API.</li><li>On section <strong>Slash Commands</strong> create a new command <strong>/weather</strong> with the Request URL pointing to the <strong>WeatherSlackModalApi </strong>endpoint (<a href="https://ai3x4olac5.execute-api.eu-central-1.amazonaws.com/prod/weather-slack-modal"><em>https://xxxxx.execute-api.eu-central-1.amazonaws.com/prod/weather-slack-modal</em></a>). By doing this Slack will call the lambda function every time the command is executed.</li><li>On section <strong>Interactivity &amp; Shortcuts </strong>set the <strong>Request URL </strong>pointing to the <strong>WeatherSlackApi</strong> endpoint (<a href="https://ai3x4olac5.execute-api.eu-central-1.amazonaws.com/prod/weather-slack-modal"><em>https://xxxxx.execute-api.eu-central-1.amazonaws.com/prod/weather-api</em></a>). These will send to our lambda function the submitted data from the modal form.</li><li>On section <strong>Incoming Webhooks </strong>add a new webhook to your workspace. With the generated URL the Bot’s process located in our backend will be able to post forecast requested in a particular channel.</li></ol><p>As shown above, Slack is not only a great communication tool for teams, also enables the integration of graphics, dialogs and more with your APIs and notify about the iterations between its users.</p><p>You can check out the <a href="https://github.com/segpacto/weather-slack-app">full code implementation</a> on <strong>Github</strong>. To get more information about the <strong>What&amp;Hows</strong> please visit the official <a href="https://api.slack.com/">Slack API documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e1af97f6036" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Documentation: the hidden treasure]]></title>
            <link>https://medium.com/@segpacto/documentation-the-hidden-treasure-8b22b3d933d7?source=rss-287306dec4cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b22b3d933d7</guid>
            <category><![CDATA[good-practices]]></category>
            <category><![CDATA[consultant]]></category>
            <category><![CDATA[techniques]]></category>
            <category><![CDATA[experience]]></category>
            <category><![CDATA[documentation]]></category>
            <dc:creator><![CDATA[Martinez Pupo Ivan]]></dc:creator>
            <pubDate>Wed, 01 Feb 2023 15:23:58 GMT</pubDate>
            <atom:updated>2023-08-07T08:09:35.644Z</atom:updated>
            <content:encoded><![CDATA[<p>Lessons learned about documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*2XVTNf3M5PbOHw_bXa9Bmg.jpeg" /></figure><p>In the fast-paced world of project development and teamwork, there’s a common issue that hinders companies and teams from reaching their full potential — documentation. Often seen as a task that can be postponed or overlooked, documentation doesn’t receive the attention and recognition it truly deserves. However, I believe that documentation is the hidden treasure that can unlock an organization’s true potential.</p><p>In this article, I’ll guide you through the importance of documentation, when it’s needed, and how to create approachable and impactful documentation.</p><blockquote>To whom this article might be of interest? This guide is for anyone aiming to create an impact on an organization by facilitating everyone’s lives beyond coding and writing features. While it is written from the perspective of a software engineer, the principles apply to various domains.</blockquote><h3>Why document things that could change tomorrow?</h3><p>In a world where being the first to market can bring success, it’s easy to neglect documentation in favor of rapid development. However, good organizations understand that investing time in properly documenting their workflows, projects, and processes is essential for long-term success. The consistency of writing documentation offers numerous benefits:</p><ul><li><strong>Promotes and encourages people to share knowledge</strong>: When knowledge is shared through documentation, the entire team benefits, and expertise becomes more accessible.</li><li><strong>Avoids pitfalls, waste of energy, and speeds up onboarding</strong>: Clear documentation helps newcomers integrate quickly and avoid repeating past mistakes.</li><li><strong>Enables transparency, common understanding and establishes guidelines</strong>: Documentation clarifies the “what/whys/hows” and aligns the team’s vision and goals.</li><li><strong>Reduces the space for assumptions</strong>: Documentation eliminates ambiguity and reduces the risk of misunderstandings.</li><li><strong>Empowers development continuity</strong>: Even as team members change, documentation remains as a reliable source of information.</li></ul><h3>When do things need documentation?</h3><p>Many times, we find ourselves struggling with the same issues repeatedly, or witnessing newcomers asking the same questions that were answered before. Here are some indicators that it’s time to prioritize documentation:</p><ul><li><strong>Several people asking the same question through multiple channels</strong>: Frequent repetition of questions indicates a need for clear documentation.</li><li><strong>Spending time figuring out something already solved</strong>: If you find yourself spending more than half a day trying to solve a problem that someone else addressed quickly, documentation is necessary.</li><li><strong>Difficulty understanding your own previous work</strong>: If you spend more than 15 minutes trying to comprehend your past work, it’s time to document your processes and decisions.</li><li><strong>Creating a product with high usage expectations</strong>: Documentation becomes crucial when the stakes are high.</li><li><strong>Keeping customer expectations aligned:</strong> Documentation helps ensure that what is delivered meets customer expectations.</li><li>Dealing with <strong>topics that invite various interpretations or extensive discussions</strong>.</li></ul><p>Remember that what seems obvious to you might not be the same for newcomers or those trying to understand your domain or system.</p><h3>How to document things?</h3><p>It is common to believe that simply providing a thorough set of instructions or configuration will do it, maybe just for the sake of “We are documenting and that is all”. Unfortunately, this is often not the case. <strong>It’s not just about documenting; it’s about doing it right</strong>. Approachable and impactful documentation requires attention to detail and consideration of the audience:</p><ul><li><strong>Use precise information and simple words</strong>: Avoid jargon and technical language when it’s not necessary.</li><li><strong>Describe the intended audience briefly</strong>: Make it clear who the documentation is for.</li><li><strong>Indicate prerequisites and related topics:</strong> Provide links or references to relevant information instead of duplicating content.</li><li><strong>Utilize helpful abbreviations and acronyms:</strong> Ensure they are explained and relevant to the topic.</li><li><strong>Choose appropriate tools, templates, language, and formats:</strong> Tailor the documentation to the current technology or problem at hand.</li><li><strong>Use visuals to explain concepts:</strong> Diagrams, models, and pictures can enhance understanding and make the documentation more engaging.</li><li><strong>Track versions:</strong> Keep track of changes to maintain an up-to-date and accurate record.</li><li><strong>Encourage contributions:</strong> Allow others to contribute to the documentation to keep it current and comprehensive.</li><li><strong>Provide contact information:</strong> Let others know how to reach you with questions or suggestions.</li></ul><p>It is essential to remember that the value of a good experience is immeasurable when it comes to documentation. Imagine if Albert Einstein hadn’t documented his findings on the laws of relativity!</p><p>Documentation is not just a chore; it is a powerful tool that empowers organizations and teams to thrive. By fostering a culture of documentation, we promote knowledge sharing, efficiency, and transparency. Embrace the hidden treasure of documentation, and watch your organization’s potential unfold like never before. Happy documenting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b22b3d933d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a GraphQL Gateway With REST APIs]]></title>
            <link>https://medium.com/better-programming/how-to-create-a-graphql-gateway-with-rest-apis-and-not-dying-in-the-intent-e4eee697c51b?source=rss-287306dec4cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4eee697c51b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Martinez Pupo Ivan]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 13:44:39 GMT</pubDate>
            <atom:updated>2022-08-08T08:55:35.554Z</atom:updated>
            <content:encoded><![CDATA[<h4>Exploring different options and challenges</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xzWiKWaCji96k29m" /><figcaption>Photo by <a href="https://unsplash.com/@ibidsy?utm_source=medium&amp;utm_medium=referral">Clayton</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>How many times when working with REST-based distributed architectures, we end up with projects having API complexity problems, because, as the project grows :</p><ul><li>more and more services directly depend on / care coupled with each other</li><li>data aggregation between the services (for e.g. frontend consumption) becomes a significant burden, slowing the project down</li><li>the number of services increases, which can be a maintainability issue if there are no communication contracts between them</li></ul><p>On the front-end, the complications roughly mirror the issues outlined above:</p><ul><li>Communicating with many different REST APIs can be cumbersome</li><li>Especially when there are data dependencies between the APIs, retrieving all of the relevant data for a single view may involve several REST API calls, making development and the application slow</li></ul><p>Many of these complexities can be simplified by using a <strong>GraphQL Gateway</strong>. It unifies and standardizes communication between REST Microservices, and brings a unique access interface with well-defined auto-generated data types, queries, and mutations to the frontend.</p><p>In short, a GraphQL Gateway creates data relations between a growing number of Entities that belong to different services without the danger of creating deep coupling or an unstoppable mesh of REST calls.</p><h3><strong>What is GraphQL?</strong></h3><blockquote>GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.</blockquote><blockquote>More on <a href="https://graphql.org/faq/">GraphQL Documentation</a>.</blockquote><p>Let&#39;s take as an example, this <a href="https://github.com/segpacto/graphql-gateway-microservices-sample">repository</a>. It contains the implementation of two microservices — <a href="https://github.com/segpacto/graphql-gateway-microservices-sample/tree/master/customer">Customer</a> and <a href="https://github.com/segpacto/graphql-gateway-microservices-sample/tree/master/invoice">Invoice</a>. Both expose a REST API documented using OpenAPI/Swagger.</p><p>Now, we would like to show on the Frontend the invoice paid amount and the customer name. How would we implement this?</p><h3><strong>Option 1</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*5pXB51K16RLfeGyXqRs5Gw.png" /></figure><p>We could move the business logic to the clients (browser, phone etc), so it creates two REST calls, one to the Customer API and another one to the Invoice API, in that case, calls continue growing along with the amount of new microservices.</p><p>In this approach, the Frontend needs to be aware of multiple APIs, which is hard to maintain when the amount of microservices is continuously increasing.</p><p>Also, when new microservices are incorporated into the architecture our Frontend needs to add new URLs, and endpoints if there are more than one and deal with the different types of HTTP requests and their configuration.</p><p>In this case, the web page is showing the relation between the Entities customer and invoice(Per customer a list of invoices).To access the same data aggregation on the phone app it needs to be implemented there again because the entities&#39; relations canʼt be reused.</p><p>In addition to the previous, controlling REST APIs response payloadʼs properties doesn’t come out of the box. Which could mean, everytime we request the customer or invoice data it comes the Entity with all the properties whether we need it or not. Which could cause performance issues due to network latencies and the transference of big data chunks over the internet.</p><h3><strong>Option 2</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*WjlyKU9TVPxRaTAsmBfDFA.png" /></figure><p>Another way is to create an <a href="https://microservices.io/patterns/data/api-composition.html">API Composer service</a>, which should expose endpoints that allow us to retrieve the entities with their aggregations by doing only one call on the Frontend. Ex one customer with all associated invoices.</p><p>The service no doubt performs better than the previous Option, since reduce the amount of calls, but relations continue to be non reusable, we could get the relationship customer and invoices from the API Composer service on a particular GET endpoint but canʼt do the same on another endpoint that uses POST and returns the same Customer Entity without manually implementing the aggregation of data, so again another solution needs to be found.</p><p>Each endpoint on the API Composer service returns a relation between entities(Ex : Customer — Invoice, Customer — Reservation, Invoice — Reservation), but as soon as new relation is needed like Customer — Invoice — Reservation the response payload becomes huge because REST calls do not exclude properties from the response without implementing it and previous relations canʼt be reused between endpoints, needs to be reimplemented turning into an unmanageable grow.</p><h3><strong>GraphQL Gateway as solution</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*1ndcu7j7ouWoBO0GB5Anyg.png" /></figure><p>By introducing the <a href="https://github.com/segpacto/graphql-gateway-microservices-sample/tree/master/graphql-gateway">GraphQL Gateway</a> service on our architecture the Frontend has a single entry point to access the data no matter how many services are in the Backend.</p><p>Data relations/aggregations can be reused by different clients(web app, phone app) because they are established between Entities. Once we declare that Customer Entity has a relation with Invoice Entity, it becomes available to all operations(Query, Mutation) that use those Entities.</p><p>GraphQL Types and resolvers for Queries and Mutations are automatically generated, which means that the service creates on its own GraphQL Types out of the OpenAPI documentation and knows where to find the data and which HTTP methods (POST, GET, etc) to use.</p><p>The Frontend requests and receives only the Entityʼs properties needed, which reduces the amount of data traveling over the internet between our Backend and Frontend. The previous advantage also contributes to getting the Customer and associated Invoices by doing only one request.</p><p>Adding to our Backend new services does not require any changes on the Frontend to access new Data Types, Queries and Mutations.</p><h3><strong>What does GraphQL Gateway actually do ?</strong></h3><p>GraphQL Gateway is using the package <a href="https://www.npmjs.com/package/gql-gateway">gql-gateway</a> internally, which is in charge of connecting to each one of the microservices, reading, interpreting, transforming automatically all the OpenApi/Swagger documents into GraphQL Types and auto-generating resolvers for all Queries and Mutations.</p><p>The service creates an <a href="https://www.apollographql.com/docs/apollo-server/">Apollo Server</a> with all its features, and takes care of validating the Input data, and resolving only those properties requested by the client.</p><p>So, when the Frontend requests the entities Customer and Invoice the service knows precisely to which service connects to retrieve the data.</p><p>The service is completely stateless which allows us to scale it according to the amount of requests and usage.</p><h3><strong>How hard would it be to implement this approach?</strong></h3><p>The creation of the <a href="https://github.com/segpacto/graphql-gateway-microservices-sample/tree/master/graphql-gateway">gateway</a> with all the auto-generated GraphQL Types, Queries and Mutations should take no more than a few lines of code.</p><p>Let&#39;s start from the beginning …</p><p>Imagine we have two microservices that are exposing the OpenApi/Swagger documentation on ports 3000 and 3001 which describe endpoints to retrieve <a href="https://github.com/segpacto/graphql-gateway-microservices-sample/blob/master/customer/swagger.json">customers</a> and <a href="https://github.com/segpacto/graphql-gateway-microservices-sample/blob/master/invoice/swagger.json">invoices</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7b80c45e23f050b7716d3c8645b786a/href">https://medium.com/media/b7b80c45e23f050b7716d3c8645b786a/href</a></iframe><p>The constant endpointsList contains a list of all the microservices OpenApi/Swagger documentation. This configuration is passed to the <a href="https://www.npmjs.com/package/gql-gateway">gql-package</a> which takes care of creating the Apollo Server which listens on port 5000.</p><p>We can access the <a href="https://www.apollographql.com/docs/apollo-server/v2/testing/graphql-playground/">apollo playground</a> by navigating to <a href="http://localhost:5000/">http://localhost:5000</a> which gives an idea of all the auto-generated Types, Queries, and Mutations available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28dYILb9msgSMT5s8FIb3w.png" /></figure><p>Now, let&#39;s create some Entity relations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/870e4887d8691a75b0e160e800701443/href">https://medium.com/media/870e4887d8691a75b0e160e800701443/href</a></iframe><p>All this might look like a complicated code but is actually the standard way of creating <a href="https://www.graphql-tools.com/docs/schema-delegation">GraphQL Schema Delegation</a>, which means that the resolution of a particular property within the Entity is going to be delegated to a specific Query or Mutation.</p><p>In this case, to indicate that the Customer is going to have a list of associated invoices we just extend the Customer Type on the localSchema constant by adding an array of the Invoice Type. Then, on the resolvers we indicate that the invoices property of the Customer is going to be resolved by delegating it to the Query getInvoicesByCustomerId that belongs to the invoiceApi.</p><blockquote>For a deeper look into the <strong>gql-package</strong> check the <a href="https://github.com/segpacto/gql-gateway"><strong>README</strong></a> or the <a href="https://github.com/segpacto/gql-gateway/blob/master/examples/advanced.js"><strong>advanced example</strong></a>.</blockquote><p>From now on, every time a Customer is included in the response of any of the GraphQL queries or mutations we also have access to the Invoices and the other way around too. <a href="https://github.com/segpacto/graphql-gateway-microservices-sample/blob/master/graphql-gateway/index.js">Delegations and Schema Stitching</a> are an elegant way to resolve and create data relations in a scalable way.</p><p>Of course, the GraphQL Gateway per se is not the solution to all problems, and this is just a simplified representation in the direction of boosting development speed.</p><p>To successfully apply solutions like the ones described above, the implementation should come accompanied by good development practices, APIs gateways as an intermediary between our services and the internet, load balancers, well-designed cache policies, and good CI/CD strategies just to mention a few. There is no silver bullet to tackle big infrastructures technical issues, but experimenting continues to be the best way to learn how to.</p><p>For a deep dive into related topics, you can take a look at:</p><ul><li><a href="https://microservices.io/patterns/data/api-composition.html">API Composition Pattern</a></li><li><a href="https://dzone.com/articles/microservices-integration-aggregators">Aggregator vs API Composition Pattern</a></li><li><a href="https://itnext.io/auto-generated-graphql-gateways-bring-your-rest-apis-together-for-great-and-for-better-9d74470820cc">GraphQL Gateway Review</a></li><li><a href="https://www.apollographql.com/docs/federation/gateway/">Apollo Gateway</a></li><li><a href="https://www.apollographql.com/docs/federation/">Apollo Federation</a></li><li><a href="https://www.apollographql.com/docs/apollo-server/v2/api/graphql-tools/#delegatetoschema">GraphQL Schema Delegation</a></li><li><a href="https://www.apollographql.com/docs/federation/migrating-from-stitching/">GraphQL Schema Stitching</a></li><li><a href="https://swagger.io/specification/">OpenAPI/Swagger</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4eee697c51b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-create-a-graphql-gateway-with-rest-apis-and-not-dying-in-the-intent-e4eee697c51b">How to Create a GraphQL Gateway With REST APIs</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>