<?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>DEV Community: Decentro</title>
    <description>The latest articles on DEV Community by Decentro (@decentrotech).</description>
    <link>https://dev.to/decentrotech</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%2F663565%2F2f6faef5-d848-4431-8f46-19a07230354f.png</url>
      <title>DEV Community: Decentro</title>
      <link>https://dev.to/decentrotech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/decentrotech"/>
    <language>en</language>
    <item>
      <title>Minimize Downtimes in Financial Services with RDS Blue Green Deployment</title>
      <dc:creator>Decentro</dc:creator>
      <pubDate>Tue, 27 Jun 2023 03:10:57 +0000</pubDate>
      <link>https://dev.to/decentrotech/minimize-downtimes-in-financial-services-with-rds-blue-green-deployment-1j8e</link>
      <guid>https://dev.to/decentrotech/minimize-downtimes-in-financial-services-with-rds-blue-green-deployment-1j8e</guid>
      <description>&lt;p&gt;It was just another deployment cycle.&lt;/p&gt;

&lt;p&gt;A housekeeping exercise. &lt;/p&gt;

&lt;p&gt;A planned two-hour maintenance window turned into a six-hour nightmare as the update script took more time than expected. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k6290dHn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jwu2wviaz40qwvd54g6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6290dHn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jwu2wviaz40qwvd54g6.gif" alt="Image description" width="320" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unfavorable? Yes.&lt;/p&gt;

&lt;p&gt;Unacceptable? Not as much. &lt;/p&gt;

&lt;p&gt;If you’ve spent a decent amount of time in software development, chances are you have encountered similar downtimes at least once in your career. As much as it’s a nightmare for the entire engineering team, its impact on the business is also pretty significant.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EDFMKUy4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nodptvtaah56k38pprf5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EDFMKUy4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nodptvtaah56k38pprf5.png" alt="Image description" width="800" height="283"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To put things into perspective, according to &lt;a href="https://itic-corp.com/forty-percent-of-enterprises-say-hourly-downtime-costs-top-1million/?ref=geektime.com"&gt;Information Technology Intelligence Consulting (ITIC)&lt;/a&gt;, &lt;strong&gt;40% of enterprises said a single hour of downtime could cost between $1 million and over $5 million&lt;/strong&gt; – exclusive of any legal fees, fines, or penalties. In a Gartner survey, &lt;strong&gt;98% of companies stated the cost of IT downtime ranged from $100,000 to $540,000 per hour.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now imagine the same in the context of working in the Fintech domain.&lt;/p&gt;

&lt;p&gt;No enterprise has ever wanted downtime of their services, especially in the financial services industry. When your business use case relies on trust and funds, downtime’s impact snowballs into skewed customer experience, loss of trust, and brand value in the market.&lt;/p&gt;

&lt;p&gt;So what is the way around it? &lt;/p&gt;

&lt;p&gt;Downtime happens. It’s critical to acknowledge and accept. But there are steps companies can take to reduce and mitigate the risk. They can build resilient infrastructure and implement disaster recovery and redundancy across their infrastructure.&lt;/p&gt;

&lt;p&gt;In the case of Decentro, it was a simple yet effective RDS Blue/Green Deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is RDS Blue/Green Deployment&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Downtime can be a significant headache if you’re running a production database. Not only does it disrupt business operations, but it can also result in lost revenue, frustrated customers, and a tarnished reputation. Many organizations are turning to RDS Blue/Green deployments to minimize the impact of downtime. And so have we. &lt;/p&gt;

&lt;p&gt;The general idea is that when you have an RDS instance, the tool will take the production DB environment (known as “Blue”) and create a read-replica (clone) of it in a new staging environment (also known as “Green”). &lt;/p&gt;

&lt;p&gt;This clone is kept in sync with production by replicating all data updates. You can change the staging environment, like upgrading server types or applying security patches. When satisfied with the changes, you can switch the servers over in minutes, with minimal downtime and complete confidence that no data will be lost.&lt;/p&gt;

&lt;p&gt;As it’s a managed service by AWS, you essentially are delegating the internal housekeeping to the AWS team, taking a significant load off your shoulders.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qSvViLUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2epdsrcpohw335z8p98.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qSvViLUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2epdsrcpohw335z8p98.png" alt="Image description" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So if we had to make a checklist of its benefits, we would have&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Managed service:&lt;/strong&gt; You don’t have to worry about maintenance, which eventually saves you time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Minimized downtime:&lt;/strong&gt; By having two separate environments, you can switch between them as needed, minimizing the rest that your customers experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Ease of deployment:&lt;/strong&gt; With RDS Blue/Green deployments, you can deploy changes to the green environment and test them thoroughly before making them live. This helps to ensure that your changes are working as expected and reduces the risk of downtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Reduction of risk:&lt;/strong&gt; With RDS Blue/Green deployments, a fully functional production environment is always available. If anything goes wrong during the deployment, you can switch back to the blue background, ensuring your customers are not impacted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Increased confidence:&lt;/strong&gt; By testing changes in a separate environment before making them live, you can improve your faith in the changes and reduce the risk of bugs or other issues cropping up in production.&lt;/p&gt;

&lt;p&gt;Now that we have sold its benefits to you allow us to walk you through its seamless set-up! &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Setting up RDS Blue-Green Deployment&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We will use the AWS console to set up RDS Blue-Green Deployment.&lt;/p&gt;

&lt;p&gt;Step 1: Log in to the AWS console, go to the RDS section, and click on the database for which you want to configure RDS Blue Green.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hPyK5Y7k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0tcsfqdq5eypc1ckmdtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hPyK5Y7k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0tcsfqdq5eypc1ckmdtg.png" alt="Image description" width="800" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 2: You will see &lt;strong&gt;Create Blue/Green Deployment under Actions.&lt;/strong&gt; Let’s open that.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nVKMXNOl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjz3povn698wfc8uzbc8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nVKMXNOl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjz3povn698wfc8uzbc8.png" alt="Image description" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 3: A form opens, and we must fill in a few basic details about our RDS Blue green setup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BXAL_zpC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7r4gy88s8brnhkhijzbq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BXAL_zpC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7r4gy88s8brnhkhijzbq.png" alt="Image description" width="800" height="721"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blue/Green Deployment identifier&lt;/strong&gt; – Identifier for our setup. Let’s put “blue-green-setup.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Engine version for your Green database&lt;/strong&gt; – We can upgrade the engine version. Major upgrades can introduce changes that are not compatible with existing applications. A minor upgrade includes only changes that are backward compatible with existing applications. To reduce complexity, select the same version in our central RDS instance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameter Group&lt;/strong&gt; – A parameter group is a collection of engine configuration values you set for your RDS database instance. We will be using the same parameter group of our central RDS instance.&lt;/p&gt;

&lt;p&gt;Step 4: It will take some time to provision the Green setup for our database. We have our blue-green setup ready. AWS will configure that replica of the db setup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sv8RyPsr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qad2ok40j26h9lrlj4q7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sv8RyPsr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qad2ok40j26h9lrlj4q7.png" alt="Image description" width="800" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PKAfRYxi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/giqejy6faf71ga1atr2i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PKAfRYxi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/giqejy6faf71ga1atr2i.png" alt="Image description" width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pg8rEDsM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f8z4znyemp3898uchbsi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pg8rEDsM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f8z4znyemp3898uchbsi.png" alt="Image description" width="800" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applying changes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As our blue-green setup is ready, we can connect to our green database and apply the necessary changes. The URL for the green database can be found in the RDS console. The username and password will remain the same as the blue (current database).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Switchover&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A switchover refers to redirecting the traffic from the blue environment (current production environment) to the green environment (updated environment) once the green environment is thoroughly tested and validated. The switchover is pivotal when the green environment becomes the new live production environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mdrxkxor--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwum2lbueor85j29lxpf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mdrxkxor--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwum2lbueor85j29lxpf.png" alt="Image description" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you are ready for the switchover, start your downtime, as the database won’t be available during the switchover.&lt;/p&gt;

&lt;p&gt;RDS gives you the option to configure the timeout for your switchover. The timeout setting in switchover refers to the duration for switching traffic from the blue to the green environment. It defines the maximum time the deployment process can take before timing out. If the switchover doesn’t complete within the configured time, the process will be aborted, and the original RDS instance will continue to serve traffic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X9Aq6rpT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhhjru8sa2m8lg95huw0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X9Aq6rpT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhhjru8sa2m8lg95huw0.png" alt="Image description" width="800" height="501"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NIed3EXw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d4wmex9b0cdxpopnjw3s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NIed3EXw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d4wmex9b0cdxpopnjw3s.png" alt="Image description" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GmzP-RlV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmf86mq1ubjfxpfsuthl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GmzP-RlV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmf86mq1ubjfxpfsuthl.png" alt="Image description" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now for the things that need a little more attention,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K6060p77--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfgyjybgggsioikfjy47.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K6060p77--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfgyjybgggsioikfjy47.png" alt="Image description" width="800" height="262"&gt;&lt;/a&gt;&lt;br&gt;
Things that should be kept in mind while performing the switchover.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Replication lag:&lt;/strong&gt; Make sure there is no replication lag when switching over. This will increase the chances of the switchover not timing out.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Validation:&lt;/strong&gt; Once the traffic is redirected, monitoring the green environment is crucial to ensure it functions correctly and handles the incoming traffic as expected. This validation phase helps confirm that the deployment was successful and that the green environment operates as intended.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Rollback option:&lt;/strong&gt; It’s essential to have a rollback option available during the switchover procesIfase any unexpected issues arise with the green environment, you can quickly revert the traffic to the blue environment to minimize the impact on users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Post-switchover activities:&lt;/strong&gt; After the switchover, it’s essential to conduct post-deployment activities, such as monitoring the system’s performance, analyzing logs, and performing any necessary cleanup tasks.&lt;/p&gt;

&lt;p&gt;The following salient features also help you navigate the switchover seamlessly. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RDS Blue/Green deployment does not mean Zero downtime deployment. As mentioned earlier, during the switchover, the database connection in your application will fail.&lt;/li&gt;
&lt;li&gt;Thoroughly test the DB instances in the green environment before switching over.&lt;/li&gt;
&lt;li&gt;When using a blue/green deployment to implement schema changes, make only replication-compatible changes.&lt;/li&gt;
&lt;li&gt;For example, you can add new columns at the end of a table, create indexes, or drop indexes without disrupting replication from the blue deployment to the green deployment. However, schema changes, such as renaming columns or re-naming tables, break binary log replication to the green deployment. &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/replication-features-differing-tables.html"&gt;Click here for more details.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Please ensure your setup supports RDS Blue/Green deployment. In our setup, we were using RDS proxy, and RDS Blue/Green doesn’t support it, so we have to remove the RDS proxy from our setup to use this feature. You can find detailed limitations &lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-overview.html#blue-green-deployments-limitations"&gt;here&lt;/a&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To conclude, RDS Blue/Green Deployment is a powerful strategy for reducing database downtime during updates. Organizations can minimize the customer impact and ensure uninterrupted service by maintaining two identical environments and carefully testing changes in the green environment before switching traffic. &lt;/p&gt;

&lt;p&gt;With its minimal downtime approach, easy rollback capability, and simplified deployment process, RDS Blue/Green Deployment offers a reliable and efficient solution for managing database updates in production environments.&lt;/p&gt;

&lt;p&gt;With that, we have come to the end of another immersive experience of the production world. &lt;/p&gt;

&lt;p&gt;If you wish to read more such &lt;a href="https://decentro.tech/blog/engineering-and-apis/"&gt;blogs&lt;/a&gt;, please check our website’s [Blogs] section. We have previously covered topics like &lt;a href="https://decentro.tech/blog/jspdf/"&gt;JsPDF&lt;/a&gt;, &lt;a href="https://decentro.tech/blog/locust-load-testing/"&gt;Locust&lt;/a&gt;, and much more.&lt;/p&gt;

</description>
      <category>financial</category>
      <category>fintech</category>
      <category>engineer</category>
      <category>deployment</category>
    </item>
    <item>
      <title>Jest: The Fast and Effective Framework for Unit Testing</title>
      <dc:creator>Decentro</dc:creator>
      <pubDate>Mon, 23 Jan 2023 06:38:11 +0000</pubDate>
      <link>https://dev.to/decentrotech/jest-the-fast-and-effective-framework-for-unit-testing-n2p</link>
      <guid>https://dev.to/decentrotech/jest-the-fast-and-effective-framework-for-unit-testing-n2p</guid>
      <description>&lt;p&gt;Unit testing is a crucial part of the software development process. It allows developers to verify that individual code units are working as expected. &lt;/p&gt;

&lt;p&gt;This blog post will discuss how to perform unit testing in a ReactJS application using the Jest testing framework.&lt;/p&gt;

&lt;p&gt;Some critical aspects of Unit testing for ReactJS:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The chances of code failure are less. It prevents unexpected errors even at the time of production&lt;/li&gt;
&lt;li&gt;It allows developers to focus on their current task rather than worrying about the previous task.&lt;/li&gt;
&lt;li&gt;It reduces the need for manual testing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Well, now we know why we need unit testing, let’s look at what the market offers in terms of great durability, stability, and performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U3OX5EF3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlf07978p16fvnuu7lpq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U3OX5EF3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlf07978p16fvnuu7lpq.jpeg" alt="Players in the unit testing market" width="880" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enzyme:&lt;/strong&gt;&lt;br&gt;
Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components’ output.&lt;/p&gt;

&lt;p&gt;Enzyme, created by Airbnb, adds some great utility methods for rendering a component (or multiple components), finding elements, and interacting with elements.&lt;/p&gt;

&lt;p&gt;It must be installed in addition to tools already bundled with CRA.&lt;/p&gt;

&lt;p&gt;Enzyme has many more traversal and interactive methods (including first and setProps).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cypress:&lt;/strong&gt;&lt;br&gt;
Cypress is a free and open-source automation tool, MIT-licensed and written in JavaScript. As of this writing, it has over 19.3K Stars on Github and is used by organizations such as NASA and DHL. With the help of Cypress End to End test, integration and unit tests are easy to write and debug. &lt;/p&gt;

&lt;p&gt;Cypress is built and optimized as a tool for local development. Cypress also offers a visual interface to indicate what all tests and which all commands are running, passed, or failed. It allows us to test highly interactive applications and carry out different tests, such as &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Manipulating the DOM&lt;/li&gt;
&lt;li&gt;Asserting that some element is available or present on the screen, &lt;/li&gt;
&lt;li&gt;Reading or writing data into/from fields&lt;/li&gt;
&lt;li&gt;Submitting forms, and &lt;/li&gt;
&lt;li&gt;Redirection to a different page without actually making direct modifications to your code.
&lt;/li&gt;
&lt;li&gt;In fact, after using Cypress for some time, you may be tempted to do all of your development within it since it provides a platform to debug and maintain your code easily and quickly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Mocha&lt;/strong&gt;&lt;br&gt;
Mocha is a feature-rich JavaScript test framework running on node.js and the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting while mapping uncaught exceptions to the correct test cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Jest&lt;/strong&gt; &lt;br&gt;
And finally, the crowd favorite, Jest.&lt;/p&gt;

&lt;p&gt;Unit testing in ReactJS is typically done using a combination of the React Test Renderer and the Jest testing framework. The React Test Renderer library allows developers to render React components and perform assertions on their output.&lt;/p&gt;

&lt;p&gt;Now, Wait a minute, is it that Fast ?!&lt;/p&gt;

&lt;p&gt;Well yes!&lt;/p&gt;

&lt;p&gt;Like a 500-horsepower car, Jest has out-of-the-box features that can be integrated immediately. It is as simple as creating a file with the suffix “.spec.js” file.&lt;/p&gt;

&lt;p&gt;Let’s break down exactly how the Jest framework has an advantage over the other tools that we have in the market for unit testing React Js applications. Real speed is determined by Performance, Snapshot Testing, and finally, Test Isolation and sandboxing.&lt;/p&gt;

&lt;p&gt;Here is how Jest is a superior tool in the given three parameter&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance: (Engine)&lt;/strong&gt;&lt;br&gt;
Jest is made for scale to support both vast and little projects. It’ll always be fast because it runs tests in parallel. It’s simply not helpful to attend for a code base to be built before tests are often run and not scalable for more significant projects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vAQ4Wq9I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1wa14g7inm7dmbpew9l.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vAQ4Wq9I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1wa14g7inm7dmbpew9l.gif" alt="Performance Engine" width="700" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Jest can execute the tests and provide feedback on whether they passed or failed. If any tests fail, Jest will provide detailed information about the failure, including the expected and actual values, so you can troubleshoot and fix the issue.&lt;/p&gt;

&lt;p&gt;In a nut-shell unit, testing is an integral part of the software development process, and By writing and running tests using Jest, you can ensure that your ReactJS components are working as expected, helping to prevent bugs and other issues in your application&lt;/p&gt;

&lt;p&gt;Now that we know what’s under this powerful Framework jest, let’s look into how we can use it and read the user’s manual.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Snapshot Testing (Brakes)&lt;/strong&gt;&lt;br&gt;
Yep take a snap, and voila, your test cases are done. &lt;/p&gt;

&lt;p&gt;As oversimplified, the statement made above looks that is the basic idea behind it.&lt;/p&gt;

&lt;p&gt;Jest supports snapshot testing, which can be handy for preventing accidental UI regressions when doing React development. These tests record snapshots of rendered component structure and compare them to future renderings. Your test fails when they don’t match, indicating that something has changed. You can quickly tell Jest to update the snapshot if this change is expected (e.g., for a newly added feature).&lt;/p&gt;

&lt;p&gt;A similar approach can be taken when testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BEzUd8WT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/irs7y80ifn68855xmp4l.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BEzUd8WT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/irs7y80ifn68855xmp4l.jpeg" alt="Best practices to make snapshots easier" width="880" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Best practices to make snapshots easier&lt;br&gt;
Best practices to make snapshots easier&lt;br&gt;
There are a few basic practices that make creating snapshots easier&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Treat snapshots as code&lt;/li&gt;
&lt;li&gt;Tests should be deterministic&lt;/li&gt;
&lt;li&gt;Use descriptive snapshot names&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Test isolation and sandboxing: (Transmission)&lt;/strong&gt;&lt;br&gt;
No two tests will ever conflict with one another, nor will there ever be any global or module local state that’s getting to cause trouble.&lt;/p&gt;

&lt;p&gt;So let’s say we have three components in the react tree, and we are creating two to three test cases for each element that may create conflict, but in jest, as we have test isolation and also every test file is sandboxed, the execution of these test cases are uniquely handled, and the interference of two cases is not likely to happen&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to drive Jest Fast! (Users manual)&lt;/strong&gt;&lt;br&gt;
To write unit tests in Jest, you will need to have a basic understanding of the following concepts:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QBVZEAci--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vc1q25fqqsjg8u3zn6n3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QBVZEAci--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vc1q25fqqsjg8u3zn6n3.jpeg" alt="Basics of unit tests in Jest" width="880" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Test case: A test case is a single scenario you want to test. For example, you might have a test case that checks if a user can log in to your application.&lt;/li&gt;
&lt;li&gt;Test suite: A test suite is a collection of test cases grouped because they test the same functionality or feature.&lt;/li&gt;
&lt;li&gt;Assertion: An assertion is a statement that checks whether the output of a particular piece of code matches the expected result. Jest provides many built-in assertions that you can use to make assertions about the values of your code.&lt;/li&gt;
&lt;li&gt;Mocking: Mocking replaces a function or module with a fake implementation used to control the code’s behavior under test. This can be useful when testing how a code reacts to different inputs or scenarios.
To start unit testing in Jest, you first need to install the jest npm package. You can do this by running the following command:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev jest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once Jest is installed, you can create a test file for your React component by adding a .test.js file in the same directory as your component. For example, if your component is called MyComponent, you might create a test file called MyComponent.test.js.&lt;/p&gt;

&lt;p&gt;To write a test case, you will need to use the test function provided by Jest. This function takes two arguments: a string that describes the test case and a callback function that contains the code for the test case. &lt;/p&gt;

&lt;p&gt;For example, the following code shows a simple test case that checks if a user can log in to your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test('User can login', () =&amp;gt; {
  // Code for the test case goes here
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the callback function, you can use Jest’s built-in assertions to make assertions about the values of your code. For example, the following code shows how you might assert that a user’s name is displayed after they have logged in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test('User can login', () =&amp;gt; {
  // Code for logging in the user goes here

  // Assert that the user's name is displayed
  expect(user.name).toBe('Decentro');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the expected function is used to assert the value of the user.name property. The toBe function is used to check if the value of user.name is equal to the string ‘Decentro’. &lt;/p&gt;

&lt;p&gt;If the value of user.name is not equal to this string, the test case will fail. You can use Jest’s mocking capabilities to control the behavior of your code under test. For example, the following code shows how you might mock a function called login that is used for logging a user in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test('User can login', () =&amp;gt; {
  // Mock the login function
  const login = jest.fn();

  // Code for logging in the user goes here

  // Assert that the login function was called
  expect(login).toHaveBeenCalled();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are functions that allow you to test different aspects of the component, such as whether it renders correctly or whether it responds to user input as expected. For example, the following code shows how to test a simple ReactJS component that displays a message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { shallow } from 'enzyme';
import MyComponent from './MyComponent';

describe('MyComponent', () =&amp;gt; {
  it('renders the correct message', () =&amp;gt; {
    const wrapper = shallow(&amp;lt;MyComponent /&amp;gt;);
    const message = wrapper.find('.message');
    expect(message.text()).toBe('Hello, Decentro!');
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we are using Jest’s description and it functions to organize our tests. The describe function groups together related tests, while it function specifies a single test. In this case, the test checks that the component renders the correct message by using Jest expect a function to compare the actual message with the expected message.&lt;/p&gt;

&lt;p&gt;Once you have written your tests, you can run them using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm test 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This test imports the MyComponent component and renders the Shallow method from the enzyme library. The shallow method allows us to render the component without rendering any of its children. This is useful for isolating the component and ensuring that our test only covers its behavior and not the behavior of any child components.&lt;/p&gt;

&lt;p&gt;Once the component has been rendered, we can use the expected function from Jest to make assertions about its output. In this case, we are using the&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;toMatchSnapshot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;method that will take a snapshot of the component’s output and save it to a file. This snapshot can be used as a reference for future tests, allowing us to verify that the component’s output has not changed unexpectedly.&lt;/p&gt;

&lt;p&gt;To run your tests, you can use the&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;command. This will execute all of the tests in your project and report on their results. &lt;/p&gt;

&lt;p&gt;You can also use the&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--watch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;flag to automatically run your tests whenever a file in your project is changed.&lt;/p&gt;

&lt;p&gt;In addition to the shallow method, the enzyme library provides several other practical methods for rendering and testing React components. For example, the mount method will render the component and all of its children, allowing you to test the component in a more realistic environment. On the other hand, the render method will return an HTML string representation of the component, which can be helpful for testing components that generate HTML output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing a login component(Test Drive!)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After reading the user’s manual and understanding the basics let’s put this knowledge to use. &lt;/p&gt;

&lt;p&gt;The scenario? To test a login component that has two input fields and two buttons.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XAFYrewZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pscfdpgioajtypy2tt5a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XAFYrewZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pscfdpgioajtypy2tt5a.png" alt="Test Cases" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Test cases &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To check whether we have two buttons&lt;/li&gt;
&lt;li&gt;To check whether the input type of the password field is the password&lt;/li&gt;
&lt;li&gt;To check whether the email verification takes place 
Let’s get coding &lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;To check whether we have two buttons submit and reset
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {render,screen} from "@testing-library/react"
import {Login,validate} from "Login"
describe("Login component test",async()⇒{
test( 'render two buttons on the login page ',()⇒{
render(&amp;lt;Login/&amp;gt;)
const buttons = await screen.findAllByRole('button')
expect(buttons).toHaveLength(2)
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;To check whether the input type of the password field is the password
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test('password input should be of type password ',async()⇒{
render(&amp;lt;Login/&amp;gt;)
const password = screen.getByPlaceholderText("password")
expect(password).toHaveAttribute('type','password')
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;To check whether the email verification takes place
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test('email validation function to be tested ',async()⇒{
render(&amp;lt;Login/&amp;gt;)
const testmail = 'decentro.com'
expect(validate(testmail).not.toBe(true))
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s look at the code and see the results for the test cases &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZGs1eScw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xir1f8e2r4buvrozruf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZGs1eScw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xir1f8e2r4buvrozruf.png" alt="Test Cases" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above image, you can see that the test suite of testing the login component has passed and the test cases have also passed&lt;/p&gt;

&lt;p&gt;Let’s say we enter the right email address in the test email variable as &lt;a href="mailto:decentro@gmail.com"&gt;decentro@gmail.com&lt;/a&gt;. This scenario should fail the test case as we have set it not to be true.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uezD4BmX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ve7plugdts5ot3i9hadk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uezD4BmX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ve7plugdts5ot3i9hadk.png" alt="Test Cases" width="880" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There you have it! A pretty smooth test drive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Jest helped Decentro cross the finish line.&lt;/strong&gt;&lt;br&gt;
Decentro’s ethos lies in building and making use of reusable components. These components have a lot of use cases that require them to have a different set of inputs, which render the desired outputs.&lt;/p&gt;

&lt;p&gt;The best way to test them is to make use of the toMatchSnapshot method which is provided by Jest. The ability to test out the simulated outputs for the specific components for the particular use case furnishes the following advantages &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Yd7uQBl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j432z5wbqkypb1sx4b8y.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Yd7uQBl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j432z5wbqkypb1sx4b8y.jpeg" alt="Advantages of Jest for Decentro" width="880" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It gives us a good overview of the component interaction &lt;/li&gt;
&lt;li&gt;UX flows can be designed in a specific way when we know the use cases of the components &lt;/li&gt;
&lt;li&gt;Development can be accelerated and fed into the feature rollout funnel.
The ability to use cases and the components accordingly allows the Decentro team to fulfill client requirements in an accelerated yet precise timeline.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion (Finish Line!)&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;In conclusion, unit testing is an integral part of the software development process, and ReactJS and Jest provide a powerful combination of tools for performing unit tests. By using the React Test Renderer and the enzyme library, you can quickly render and test your React components and use the Jest testing framework to make assertions about their output.&lt;/p&gt;

&lt;p&gt;It is a match made in speed heaven.&lt;/p&gt;

&lt;p&gt;With that, we have reached the end of an immersive read elucidating the world of unit testing. The developers at Decentro, incessantly work on getting their subject matter expertise to you via these technical write-ups. Feel free to check out our workaround, Data Tables, and Next, and leave suggestions of what you wish to read next.&lt;/p&gt;

&lt;p&gt;In case you wish to connect with us, &lt;a href="https://decentro.tech/signup/?utm_campaign=india-jest_blog-january-2023&amp;amp;utm_medium=referral&amp;amp;utm_source=Dev.to&amp;amp;utm_term=&amp;amp;utm_content="&gt;Click Here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>python</category>
      <category>react</category>
    </item>
    <item>
      <title>The Pocket Guide To API Request Validation You Wish You Had Earlier</title>
      <dc:creator>Decentro</dc:creator>
      <pubDate>Fri, 07 Jan 2022 06:27:25 +0000</pubDate>
      <link>https://dev.to/decentrotech/the-pocket-guide-to-api-request-validation-you-wish-you-had-earlier-gmm</link>
      <guid>https://dev.to/decentrotech/the-pocket-guide-to-api-request-validation-you-wish-you-had-earlier-gmm</guid>
      <description>&lt;p&gt;Have you ever integrated with an internal/external service? Ever wondered how the service is returning different kinds of errors &amp;amp; issues so quickly? Or about the process that is happening behind the scenes to facilitate this?&lt;/p&gt;

&lt;p&gt;Yes, you are right. We are talking about the validations! &lt;/p&gt;

&lt;p&gt;Just imagine what a chaotic world it would be if there are no validations or prechecks in a service. &lt;/p&gt;

&lt;p&gt;There would be just a successful response if you are very lucky, or there would be an arbitrary error, mostly internal server error or request timeout, which leaves you with no clue of what went wrong.&lt;/p&gt;

&lt;p&gt;Thankfully someone has thought through this issue and found a way out of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is API Request Validation?
&lt;/h2&gt;

&lt;p&gt;API request validation is the process of checking the alignment of client requests with the laid-out API specifications. &lt;/p&gt;

&lt;p&gt;It’s a very crucial process in the request lifecycle. An API request needs to be validated for correctness before processing further to avoid unexpected/wrong errors and slow/invalid responses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do We Need API Request Validation?
&lt;/h2&gt;

&lt;p&gt;In the context of REST APIs, a request body is deliberately designed based on the required parameters for the processes happening behind the scenes. If there is a miss in any mandatory parameter(s), the process will fail. &lt;/p&gt;

&lt;p&gt;Now there is nothing wrong with the process failing. However, if we talk about scale, there is a cost involved both for the client and the server; just think of the cost as request latency and server resources. All that is because of a miss in the request body, which can be handled in a much better way at the beginning of the request. &lt;/p&gt;

&lt;p&gt;In the coming sections of this blog, we will be exploring different ways to handle cases like these and how we at Decentro are dealing with them, then we will have a quick implementation of the same. &lt;/p&gt;

&lt;p&gt;Our core application is on Flask; hence, the illustrations will be similar. Flask is a web framework for python. It is a small and easy to extend microframework without the native support of ORM. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--238uWZJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xvm40jw545d5vd7yhnua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--238uWZJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xvm40jw545d5vd7yhnua.png" alt="Image description" width="880" height="464"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;API INIT – Initial part of the flow, where we check the credits, headers, auth, etc.&lt;br&gt;
API Process INIT – The core flow is based on the business logic.&lt;/p&gt;
&lt;h2&gt;
  
  
  What are We Trying to Do Here?
&lt;/h2&gt;

&lt;p&gt;Consider the following request body, we will be using the same throughout the blog post.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We want to validate the request body and transform in some cases, based on whether all the required parameters are received and all the values obtained for the parameters are of acceptable types and ranges. Consider the following validation rules for this request body.&lt;/p&gt;

&lt;p&gt;name&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It should be a json object&lt;/li&gt;
&lt;li&gt;first and last are required&lt;/li&gt;
&lt;li&gt;middle is optional&lt;/li&gt;
&lt;li&gt;All nested values are string&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;date_of_birth&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should be a string, matching YYYY-MM-DD format.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;gender&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should be a string.&lt;/li&gt;
&lt;li&gt;Should match any of the following [M, F, O]&lt;/li&gt;
&lt;li&gt;Should transform the value to upper case before checking the match.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;address&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It should be a json object&lt;/li&gt;
&lt;li&gt;flat_number, locality, and pincode are required&lt;/li&gt;
&lt;li&gt;landmark is optional&lt;/li&gt;
&lt;li&gt;pincode should be of six-digit string&lt;/li&gt;
&lt;li&gt;need to extract area, city, and state from pincode and add them to this object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;social_presence&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;this is a list of object&lt;/li&gt;
&lt;li&gt;the list can be empty&lt;/li&gt;
&lt;li&gt;if an object is present then it should be mandatory to have site_name and site_url.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let’s have a look at some of the ways we can handle the verification and validation of the above request packet given the domain rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Different Ways to Implement API Request Validation
&lt;/h2&gt;

&lt;h2&gt;
  
  
  The Noob Way
&lt;/h2&gt;

&lt;p&gt;You can write a method for this API to validate the request body and raise an exception if something goes wrong. For instance,&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This type of implementation will work, but there are a few issues with it&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This will not be easy to manage and maintain, and there will be more chances of missing a parameter validation.&lt;/li&gt;
&lt;li&gt;The complexity of handling this will increase when we add more parameters to the request body, adding 2nd order nesting.&lt;/li&gt;
&lt;li&gt;Think of a scenario where we need to add/update a parameter in one of the nested blocks in further API iterations. Then?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Is there any better way to do this job?&lt;/p&gt;

&lt;p&gt;Yes, of course!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Champ Way!
&lt;/h2&gt;

&lt;p&gt;We can use serializers.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Serializers are built to convert data from one form to another; For instance, it can convert a queryset into a python dict or create a data class from a JSON object. We can leverage this functionality and add validations between the flow.&lt;br&gt;
In serializers, we define a schema with validation rules and transformation methods. Then, we need to load the data in the serializer, and if there is an issue with the data, the serializer will raise an exception or return the transformed data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can even add a pre-serialization method and post-serialization to pre-process and post-process the data, which can be executed in the respective sequence.&lt;/p&gt;

&lt;p&gt;These methods are also beneficial. Consider the case of gender parameter; it is a categorical variable and case insensitive, so we need to upper-case this before further validation check.&lt;/p&gt;

&lt;p&gt;We will be using this approach to validate the request body in this blog post. And we at Decentro are following a very similar approach to deal with validations and transformation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here Comes Marshmallow!
&lt;/h2&gt;

&lt;p&gt;Marshmallow is the object serialization library that we will be using. We will be resolving the nested blocks first.&lt;/p&gt;

&lt;p&gt;Resolving Name Block&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Resolving the Address&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Resolving the Social Presence, Each Object&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, since we have built subschemas for all the nested blocks, let’s build the schema for the parent block.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Finally, we just need to load the request data and handle the exception raised from the schema, if any, and handle it appropriately.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And, that’s all we have to do in order to validate the request body.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oq0yRefk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yddk0ilpec4d63pik22a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oq0yRefk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yddk0ilpec4d63pik22a.png" alt="Image description" width="521" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just to complete things, this is how you will be seeing the errors, if there is a miss in the request body.&lt;/p&gt;

&lt;p&gt;Just to complete things, this is how you will be seeing the errors, if there is a miss in the request body.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  What’s Next?
&lt;/h2&gt;

&lt;p&gt;This was a brief introduction to the serializer-based validation using marshmallow. There is a lot more to explore in this, many more cases to be handled, listing a few of them which are in my thoughts are following.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conditional validation in the nested fields, think of the scenario where one parameter in a block has a direct relationship with a parameter in another block or consider parent block parameter relationship with the child block parameter.&lt;/li&gt;
&lt;li&gt;Advanced pre-processing and transformation of the request body, optimizing the request body, consider it as taking a few parameters from the client and transforming them at the server end, like what we have done for the address field.&lt;/li&gt;
&lt;li&gt;Reusing existing serializers in other APIs, think of name and address as nested fields in other APIs. We can even extend this without changing the base serializer; these are classes only. So let’s suppose you want to have a salutation field in the name block in one of the APIs. You can extend the name serializer and add salutation and related validations; the rest are already there. How amazing! Right?&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We can use these API serializers to generate dynamic documentation of your API. These serializers hold everything you need for the API documentation, parameters, accepted values, accepted types, accepted ranges, error messages.&lt;br&gt;
What would you like us to take up in this series? Let us know in the comments; we’re all ears! 😇&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;So till now, I guess I was able to illustrate my point of using serializers for the request validation and how effective the whole process is in order to maintain and extend the API validations.&lt;/p&gt;

&lt;p&gt;You can find the fully functional code of the example mentioned in this blog on &lt;a href="https://github.com/decentro-in/API-Request-Validation"&gt;Decentro’s GitHub&lt;/a&gt; page.&lt;/p&gt;

&lt;p&gt;References&lt;/p&gt;

&lt;p&gt;&lt;a href="https://marshmallow.readthedocs.io/"&gt;Marshmallow&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally published at: &lt;a href="https://decentro.tech/blog/pocket-guide-to-api-request-validation/"&gt;https://decentro.tech/blog/pocket-guide-to-api-request-validation/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>We DON’T Need NGINX Anymore. Hello, KONG API Gateway!</title>
      <dc:creator>Decentro</dc:creator>
      <pubDate>Wed, 08 Dec 2021 07:29:35 +0000</pubDate>
      <link>https://dev.to/decentrotech/we-dont-need-nginx-anymore-hello-kong-api-gateway-3oli</link>
      <guid>https://dev.to/decentrotech/we-dont-need-nginx-anymore-hello-kong-api-gateway-3oli</guid>
      <description>&lt;p&gt;API development has moved from a single stack monolithic architecture to the majestic microservices architecture.&lt;/p&gt;

&lt;p&gt;This requires a gateway server that should manage redirection, proxying and security over multiple requests. This means our old faithful NGINX has become a little outdated. (Let’s not even talk about Apache HTTP Server here!)&lt;/p&gt;

&lt;p&gt;Even if you run a monolithic application, The API Gateway is still a good pick. Apart from proxying, there are many other benefits. &lt;/p&gt;

&lt;p&gt;The API Gateways should give us the developer the ability to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scale: As you grow, so should your application&lt;/li&gt;
&lt;li&gt;Provide security: Applying SSL is just scratching the surface&lt;/li&gt;
&lt;li&gt;Have a GUI: This would make life 10 times easier&lt;/li&gt;
&lt;li&gt;Be Intuitive: Should be self explanatory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;_“But what does it do?” &lt;br&gt;
_&lt;br&gt;
You may ask. Good question.&lt;/p&gt;

&lt;p&gt;Suppose we have an API stack with multiple APIs spanning over a bunch of microservices. Let’s look at the diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fw42ax0dcy9esii1f0g0u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fw42ax0dcy9esii1f0g0u.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can see the API Gateway being the lord and the savior for the application instances running behind it. It proxies the requests to the requisite application instance (as a reverse proxy). Now your endpoint can be independent of the microservice it caters to. &lt;/p&gt;

&lt;p&gt;So if you want to have multiple endpoints (e.g., /docs, /documents, /documentation) connected to the same application, you can. Just reverse proxy it, baby!&lt;/p&gt;

&lt;p&gt;Farewell, NGINX!&lt;br&gt;
Here at Decentro, we used to work with NGINX as our reverse proxy server. But we grew out of it. We had to log in to our instance to reload NGINX via CLI and had to learn to manage configurations when using NGINX. It didn’t have consumer-level handling for API management. &lt;/p&gt;

&lt;p&gt;We needed something extra. After logging our heads together for quick brainstorming and crossing the Is’ &amp;amp; Ts’ on the Pros/Cons list, we found the one!&lt;/p&gt;

&lt;p&gt;Dhumm… Dhumm… Dhumm…&lt;/p&gt;

&lt;p&gt;Did you feel it?&lt;/p&gt;

&lt;h2&gt;
  
  
  Here comes KONG!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fqxfhh9c6buh7efmswvvm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fqxfhh9c6buh7efmswvvm.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Source: Github&lt;/p&gt;

&lt;p&gt;As is evident from the image above, Kong provides a lot of features out of the box. No recompilation. No command-line configuration. No extra cost.&lt;/p&gt;

&lt;p&gt;Kong comes with its own RESTful Admin APIs. It is built on top of OpenResty (an extension of NGINX) and LuaJIT. These provide access to all kinds of configurations that can be made available. We have done another addition on top of it by adding the Konga dashboard to manage Kong via a GUI. &lt;/p&gt;

&lt;p&gt;Kong API Gateway Structure&lt;br&gt;
The API structure in Kong is pretty simple:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Services – The logical representation of your microservice or monolithic application&lt;/li&gt;
&lt;li&gt;Routes – The logical representation of endpoints that are accessible within the service.&lt;/li&gt;
&lt;li&gt;Consumers – The clients that are going to be using the services.&lt;/li&gt;
&lt;li&gt;Plugins – This is where the magic happens. Plugins can be applied to either of the above entities mentioned. 
So let’s talk about an example.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I have a microservice that takes care of sending emails. I will declare a Service with the name “emails” (Pretty innovative.. I know). This will contain the details of the application server, which it will reverse proxy for.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fviv5hqf5f63u9quf0tnj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fviv5hqf5f63u9quf0tnj.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F3ze6hb3frk1ci15cxng8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F3ze6hb3frk1ci15cxng8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s make Routes for this service. So we have two kinds of emails to be sent.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transactional – Sent by the API&lt;/li&gt;
&lt;li&gt;Marketing – Sent by the marketing department to let the clients know about the new features of our awesome product.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fjjap310kvw35msy7jfhx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fjjap310kvw35msy7jfhx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fjwkxc45h26s7zmhwknco.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fjwkxc45h26s7zmhwknco.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fw0hxat0q4t0h2tpm1pe7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fw0hxat0q4t0h2tpm1pe7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we will put an API Key authentication plugin on top of the “emails” service. This will ensure that no bad actors try to get access to our APIs.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fegoy1vno5u9mn9i77ymo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fegoy1vno5u9mn9i77ymo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fwr2n1i7liksrtfkauzzm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fwr2n1i7liksrtfkauzzm.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Faoa0d5zjfi58nq734uft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Faoa0d5zjfi58nq734uft.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Rate-limit Plugins
&lt;/h2&gt;

&lt;p&gt;We will also add a rate-limit plugin (to limit the number of API hits) on the different routes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transactional (600 per minute) – Since this API is triggered by other flows, we need a high rate limit.&lt;/li&gt;
&lt;li&gt;Marketing (1 per minute) – Since this is manually triggered, we don’t need to go beyond 1 per minute&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fs0q73qhjnggvnbgpohsx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fs0q73qhjnggvnbgpohsx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fboh7pud8y192tq70kfmo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fboh7pud8y192tq70kfmo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to further enhance our security, we will allow only certain IP addresses to be able to access our transactional email route as it will be triggered only by our internal systems, and we know the IP address range for our internal systems.&lt;/p&gt;

&lt;p&gt;We will set it open to the world (Potentially insecure) for the marketing emails as the marketing peeps should be able to access it from any cafe that they wish to work out of.&lt;/p&gt;

&lt;p&gt;Now we want only authorized consumers to access the APIs, so we will set up a consumer and add the API authentication credentials for them to use.&lt;/p&gt;

&lt;p&gt;Now our email service is ready to serve consumers. We can integrate it into our code and give it to the marketing peeps for them to use it manually.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Things Up
&lt;/h2&gt;

&lt;p&gt;As you can see, using Kong as an API Gateway is simple and takes the hassle of managing APIs. Kong provides many other features like upstreams, certificate management, request and response transformation, serverless code execution, logging, and CORS, which are very helpful when you wish to develop APIs quickly.&lt;/p&gt;

&lt;p&gt;I rest my case!&lt;/p&gt;

&lt;p&gt;NGINX and other reverse proxy servers are simply blown out of the water by the ease of configurability and sheer dexterity that KONG provides out of the box.&lt;/p&gt;

&lt;p&gt;If you have the same love as we do for Engineering, we encourage you to check out the careers page . Be a part of our passionate journey towards making stellar products!&lt;/p&gt;

&lt;p&gt;Until we see you next time with another tech story!&lt;/p&gt;

&lt;p&gt;Originally published at: &lt;a href="https://decentro.tech/blog/why-we-moved-from-nginx-to-kong-api-gateway/" rel="noopener noreferrer"&gt;https://decentro.tech/blog/why-we-moved-from-nginx-to-kong-api-gateway/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>productivity</category>
      <category>programming</category>
      <category>kong</category>
    </item>
    <item>
      <title>Fragmented Databases: Access Easily With Utility APIs</title>
      <dc:creator>Decentro</dc:creator>
      <pubDate>Thu, 08 Jul 2021 10:16:09 +0000</pubDate>
      <link>https://dev.to/decentrotech/fragmented-databases-access-easily-with-utility-apis-4pd7</link>
      <guid>https://dev.to/decentrotech/fragmented-databases-access-easily-with-utility-apis-4pd7</guid>
      <description>&lt;p&gt;Earlier this year, we'd released a set of FREE utility APIs, which help individual developers, startups, and companies alike by being a one-stop-shop to check KYC IDs’ formats and search for an IFSC!&lt;/p&gt;

&lt;p&gt;How about we dive deep and know about them?&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Utility APIs?
&lt;/h2&gt;

&lt;p&gt;For most start-ups today, a significant part of the product roadmap is driven by their collective knowledge, and the remaining learning occurs from the feedback given by early customers. However, to implement that knowledge, teams need access to information, sometimes at their fingertips, to make informed actions that impact the revenue positively.&lt;/p&gt;

&lt;p&gt;At Decentro, we realized the importance of access to information when we started and realized its importance- not just for us but for any budding fintech.&lt;/p&gt;

&lt;p&gt;Thus, we’ve taken the first step in our efforts to consolidate &amp;amp; share the knowledge that will go a long way in helping emerging fintech gather information without incurring any additional costs. We developed these no-cost utilities based on our interaction with our initial customers.&lt;/p&gt;

&lt;p&gt;From January 5th, 2021, these common utility APIs will be available for everyone to access.&lt;br&gt;
In phase 1, anyone can use these APIs to &lt;a href="https://decentro.tech/blog/what-is-kyc-why-is-it-important/"&gt;validate the format of a given ID&lt;/a&gt; (currently supported – Aadhar/PAN/GSTIN) or check the branch details for an IFSC of any bank in the country.&lt;/p&gt;

&lt;p&gt;From our experience, we understand that consumers can easily make mistakes while entering their ID numbers or, in some cases, even enter junk data. This becomes a major blocker in ID verification as valuable time &amp;amp; money is spent to perform the task again. These utilities verify whether the entered ID is authentic by checking its format as prescribed by the Government of India.&lt;/p&gt;

&lt;p&gt;In addition, IFSC search is also an important check not just from a business point of view but also from consumers’. Many a time, &lt;a href="https://decentro.tech/blog/what-no-one-will-tell-you-about-upi-payment-links-payment-gateways/"&gt;money transfer&lt;/a&gt; requests fail due to an incorrect IFSC. Having a preliminary check done for the same before initiating a money transfer eliminates any delay or loss.&lt;/p&gt;

&lt;p&gt;More features are slated to join this set pretty soon. So, keep an eye peeled for our newsletters!&lt;/p&gt;

&lt;p&gt;To know about the free utility APIs, here's the &lt;a href="https://docs.decentro.tech/"&gt;documentation&lt;/a&gt;. We hope our fellow fintech enthusiasts will find tremendous use from these. Do check them out and kindly shoot feedback &amp;amp; love in our general direction. It will help us make a better, more holistic product that you cannot stop raving about and recommending to your peers &amp;amp; colleagues.&lt;/p&gt;

&lt;p&gt;As someone rightly said, “Knowledge grows only when you share it,” we hope to keep sharing our knowledge with you and make Fintech great again!&lt;/p&gt;

&lt;p&gt;The dangers posed by the pandemic have not subsided yet. Do consider all the precautions suggested by the authorities and the medical experts to enjoy a safe onward journey to the future where these troubling times become just a passing topic of discussion.&lt;/p&gt;

&lt;p&gt;We hope you remain safe, your family in the pink of their health, and your goals for the next year, super achievable.&lt;/p&gt;

&lt;p&gt;From all of us here at Decentro. Thanks for reading!&lt;br&gt;
Cheers!&lt;/p&gt;

&lt;p&gt;Previously published on &lt;a href="https://decentro.tech/blog/utility-apis-enabling-easy-access-to-fragmented-databases/"&gt;Utility APIs: Enabling Easy Access To Fragmented Databases&lt;/a&gt;&lt;/p&gt;

</description>
      <category>api</category>
    </item>
  </channel>
</rss>
