<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Azhan7</title>
    <description>The latest articles on Forem by Azhan7 (@azhan7).</description>
    <link>https://forem.com/azhan7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1025513%2Ff76eb219-95d5-4030-b8f7-23b8ce2eab83.jpeg</url>
      <title>Forem: Azhan7</title>
      <link>https://forem.com/azhan7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/azhan7"/>
    <language>en</language>
    <item>
      <title>Why you should (not) use GraphQL ?</title>
      <dc:creator>Azhan7</dc:creator>
      <pubDate>Sun, 19 Feb 2023 19:25:03 +0000</pubDate>
      <link>https://forem.com/azhan7/why-you-should-not-use-graphql--4m3g</link>
      <guid>https://forem.com/azhan7/why-you-should-not-use-graphql--4m3g</guid>
      <description>&lt;p&gt;Recently, I read about the GraphQL which is a query language for APIs. I thought to give a try and share the experience with you.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is GraphQL?
&lt;/h2&gt;

&lt;p&gt;As described earlier, GraphQL is a query language for APIs. Basically, it gives clients the power to ask for exactly what they want.&lt;/p&gt;

&lt;p&gt;To understand it further, consider that your backend APIs are consumed by two front-end interfaces: web and mobile. And for some reason, both interfaces require separate fields. Without GraphQL, either you need to implement two types of APIs, one for your web client and one for your mobile client, or you need to send the exact same data to both of your clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problems with sending excess data
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Slower API performance&lt;/li&gt;
&lt;li&gt;Increased network bandwidth&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To solve this problem, GraphQL comes into play. It lets your client ask for what he/she wants and filters the results automatically depending on the client's needs. How do we use GraphQL?&lt;/p&gt;

&lt;p&gt;To use GraphQL, we need to define the graphQL schema. The schema consists of types that define the fields inside it, as described in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnuiyogj1vubzl86wa9a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnuiyogj1vubzl86wa9a.png" alt=" " width="800" height="688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The ! at the end of the ID present in book type makes it a non-nullable type. The Query depicts the methods that endpoints can use.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft1brox97zcxuzoeqfvq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft1brox97zcxuzoeqfvq1.png" alt=" " width="800" height="884"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how I have used the allBooks and getBook methods defined in the Query type of the GraphQL schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing via Postman:
&lt;/h2&gt;

&lt;p&gt;Now, let's see how we can test the newly implemented GraphQL API. Look at the below-mentioned image. I requested three fields: title, description, and author. And the API has given me the exact same response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwzkwmaiq7i8rwbnle9zt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwzkwmaiq7i8rwbnle9zt.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let's ask for some different parameters. And GraphQL has given the exact same response which we have asked for.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhyadez1fze35fyw9tzn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhyadez1fze35fyw9tzn.png" alt=" " width="800" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Problems of using GraphQL?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It is hard to cache the response. Although it is possible to cache the response, it becomes difficult as clients are free to ask for whatever field(s) they want.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generally, when we use REST APIs, we find out if everything runs smoothly through the status code, but this is not the case with GraphQL. If you get an error in GraphQL, you need to parse the body.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpscovdz31p0v868x4nw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpscovdz31p0v868x4nw9.png" alt=" " width="800" height="746"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  When you should use GraphQL ?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It is advisable to use GraphQL if you have a complex API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you have multiple interfaces, using GraphQL can be a good idea.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you're worried about bandwidth, GraphQL might be a good option.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you are getting data from multiple sources. For example, if you are making a dashboard and want to receive data from multiple services, such as a logging service, an analytics service, and a monitoring service, It is a good idea to use GraphQL so that the client can specify exactly what it wants.&lt;/p&gt;

&lt;p&gt;I've also attached the github repository link incase you want to explore in depth.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Azhan7" rel="noopener noreferrer"&gt;
        Azhan7
      &lt;/a&gt; / &lt;a href="https://github.com/Azhan7/Exploring-GraphQL" rel="noopener noreferrer"&gt;
        Exploring-GraphQL
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/50276587/219134268-65390ab9-c53b-43ed-a656-29a3b6b021c3.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F50276587%2F219134268-65390ab9-c53b-43ed-a656-29a3b6b021c3.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Project Idea&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;Recently, during my reading sessions, I've came across GraphQL. I found the idea exciting and wanted to give it a try by implementing a basic project using GraphQL.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;What is GraphQL&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;GraphQL is a query language for APIs. Basically, it gives clients the power to ask exactly what they want. To understand it further, consider your backend APIs are consumed by two front-end interfaces, be it Desktop and Mobile. And for some reason, both interfaces require separate fields. Without GraphQL, either you need to implement two types of APIs, one for your Desktop client and one for your Mobile Client, or you need to send the exact same data which you are sending to Desktop to your Mobile interface as well. But the problem is you are sending quite many fields to your mobile which is not being used by your mobile. To solve this issue GraphQL comes…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Azhan7/Exploring-GraphQL" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Why Microservices are more complex than you think ?</title>
      <dc:creator>Azhan7</dc:creator>
      <pubDate>Sun, 12 Feb 2023 21:57:19 +0000</pubDate>
      <link>https://forem.com/azhan7/why-microservices-are-more-complex-than-you-think--59i7</link>
      <guid>https://forem.com/azhan7/why-microservices-are-more-complex-than-you-think--59i7</guid>
      <description>&lt;p&gt;Microservices are a distributed system architecture, and they have lots of problems associated with them. Nowadays, more and more companies claim they are using microservices, whereas the reality is quite different from what they claim.&lt;/p&gt;

&lt;p&gt;The defining characteristics of microservices are&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;They are small.&lt;/li&gt;
&lt;li&gt;Focused on One Task&lt;/li&gt;
&lt;li&gt;Aligned with a bound context&lt;/li&gt;
&lt;li&gt;Autonomous&lt;/li&gt;
&lt;li&gt;Independently deployable&lt;/li&gt;
&lt;li&gt;Losely coupled&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  They are small.
&lt;/h2&gt;

&lt;p&gt;Early pioneers of microservices used to respond to the question by saying that &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An ideal microservice fits inside James Lewis' head.&lt;br&gt;
James Lewis was the one who popularised the idea of microservices. The rationale behind that was to compartmentalise a problem.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  How to measure if the given microservice is actually micro
&lt;/h3&gt;

&lt;p&gt;If you can recode the microservice in a week or two, I think you are on the right path. That's one of the ways to measure if you are on the right scale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Focused on One Task
&lt;/h2&gt;

&lt;p&gt;To segregate a monolithic architecture, we must first determine which sub-problems our microservices should be divided into.Each microservice aims to achieve one task when viewed from the outside.&lt;/p&gt;

&lt;h2&gt;
  
  
  Aligned with a bounded context
&lt;/h2&gt;

&lt;p&gt;This idea comes from the book &lt;strong&gt;Domain-Driven Design&lt;/strong&gt;, written by &lt;strong&gt;Eric Evans&lt;/strong&gt;. As per Eric, "bounded context" can be defined as &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A defined part of software where particular terms, definitions, and rules apply in a consistent way.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This means that if we fail to segregate our services well, breaking our application into microservices could actually backfire as it will make services tightly coupled.&lt;/p&gt;

&lt;h2&gt;
  
  
  Autonomy
&lt;/h2&gt;

&lt;p&gt;The team handling each microservice should be autonomous in changing the implementation. The true value of microservices is that the autonomy and lack of coordination they provide enable organisations to scale quickly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deployable on its own
&lt;/h2&gt;

&lt;p&gt;Since microservices give the team options to deploy without being constrained by other teams, it makes their progress more significant.&lt;/p&gt;

&lt;p&gt;Now the problem arises: if you always test your service with others before release, it is not independently deployable.&lt;/p&gt;

&lt;p&gt;The real value that microservices bring to the table is that they can be built, tested, and deployed independently.&lt;/p&gt;

&lt;p&gt;So, in short, one can say, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Microservices are an organization's decoupling strategy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Losely Coupled
&lt;/h2&gt;

&lt;p&gt;The interface to a microservice is a public API. Therefore, it should be changed with great care. If you keep changing the API too often, this defeats the whole purpose of the microservices architecture. Also, when consuming an API, use the minimum data that you can to reduce coupling.&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
