<?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[Roadzen Engineering &amp; Data Science - Medium]]></title>
        <description><![CDATA[We are building a tech infra that powers the global insurance economy. - Medium]]></description>
        <link>https://medium.com/roadzen-engineering-and-data-science?source=rss----54389bbe7585---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Roadzen Engineering &amp;amp; Data Science - Medium</title>
            <link>https://medium.com/roadzen-engineering-and-data-science?source=rss----54389bbe7585---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:46:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/roadzen-engineering-and-data-science" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Build Dynamic forms (with dynamic Validations) from JSON using React/Redux-Form/MUI — 1]]></title>
            <link>https://medium.com/roadzen-engineering-and-data-science/build-dynamic-forms-with-dynamic-validations-from-json-using-react-redux-form-mui-1-a7d79a3f9581?source=rss----54389bbe7585---4</link>
            <guid isPermaLink="false">https://medium.com/p/a7d79a3f9581</guid>
            <category><![CDATA[redux-form]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Saksham Jain]]></dc:creator>
            <pubDate>Tue, 06 Apr 2021 07:19:45 GMT</pubDate>
            <atom:updated>2021-04-07T07:00:58.222Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build Dynamic forms (with dynamic Validations) from JSON using React/Redux-Form/MUI —Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TSFX38RPDszpHXF4.jpeg" /><figcaption>Source: <a href="https://miro.medium.com/max/3840/1*ivjksIhvAs7TUXbQCxAU0A.jpeg">https://miro.medium.com/max/3840/1*ivjksIhvAs7TUXbQCxAU0A.jpeg</a></figcaption></figure><h3><strong>Foreword</strong></h3><p>Forms are essential interaction elements on your website. Building simple forms with validations is easy, but do real-world problems need simple forms? Will a single hard-coded form, work for multiple scenarios with their custom validations and custom rules?</p><p>Multiple forms with rules and validations were out of the question as it would need a lot of maintenance and does not sound like an engineer’s solution. After researching for almost a year, all the solutions seemed like walking in the same forest and getting lost sooner or later.</p><p>I am finally glad to share a successful outcome. Let me demonstrate how to implement clean, scalable, maintainable, dynamic forms creation with dynamic validations.</p><h3>The Problem Statement</h3><p>The problem statement was wide, as I tried to cover almost every aspect of the challenge that was put forward. My vision was to keep the solution flexible and make a developer’s life easier.</p><p><strong>Multiple Forms</strong></p><p>The first challenge was — there would be multiple forms that would have the same UI, but different fields. For example, one form will take details of the user, another form will take details of his vehicle.</p><p><strong>Conditional Rendering</strong></p><p>Based on the value of a field, the visibility of another field changes. For example, for verification of a user, if the user picks ‘Phone’ then show the field asking the phone number, else if the user picks ‘Email’ then show the field asking his email id.</p><p><strong>Dynamic Validations</strong></p><p>In the above Conditional Rendering section, you might feel the need of dynamic validation. This was the next challenge on the plate, the field asking phone number will have different validation from the field asking email. Similarly, some fields are ‘required’ while some are optional.</p><p><strong>Type of Form Fields</strong></p><p>There can be different types of fields, such as Radio Group, Autocomplete, Text Field, Google Places search (Yes! Google Places search field with API call) and the list goes on…</p><p>Faced with all these challenges, one always remembers the golden rule: developers are lazy and so am I. So, the solution had to be easy to use, and maintain.</p><h3>The Solution</h3><p>I have not mentioned JSON till now, but JSON is the backbone of the solution. Let’s jump into it, but before that, there are a few pre-requisites.</p><p><strong>Pre-requisites</strong></p><ul><li>Intermediate knowledge of React</li><li>How Redux-Forms work and the power it holds</li><li>Material UI (Not necessary, but it will make life easier)</li></ul><p><strong>The JSON</strong></p><p>This is the core, and it’s hot. Below is the sample JSON.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b20a539825f6ff69820ee311106ee6c/href">https://medium.com/media/1b20a539825f6ff69820ee311106ee6c/href</a></iframe><p>The above JSON consists of sections in a form, with fields in each section.<br>Every field contains —</p><ul><li><strong>inputName</strong>: (required) Label for the field</li><li><strong>inputKey</strong>: (required) Unique key for the field (value of the field will be stored against this key)</li><li><strong>inputType</strong>: (required) Type of the field, whether a text field, autocomplete, checkboxGroup, radioGroup, etc.</li><li><strong>required</strong>: (required) Whether the field is required or optional.</li><li><strong>options</strong>: (optional) It defines the possible options for radioGroup, checkboxGroup.</li><li><strong>parent</strong>: (required) This one is the most important part. It controls the conditional rendering of the form, this makes the form dynamic. Parent denotes when the field/section should be visible.</li><li><strong>inputRegex</strong>: (required) It does dynamic validation of the form. For every field, the value of the field is checked against this regex, if this matches, only then can the form be submitted.</li><li><strong>errorPrompt</strong>: (required) Error to be shown if the value of the field does not match the inputRegex.</li><li><strong>API</strong>: (optional) In case of fields like autocomplete, Google Places search, the API will denote the path of the API to hit when the user updates the value of the field.</li></ul><p><strong>The Dynamic Rendering</strong></p><p>Below is the code for dynamically rendering the JSON discussed above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c078c02f3bbb347b26f264634e586df/href">https://medium.com/media/9c078c02f3bbb347b26f264634e586df/href</a></iframe><p>In the above code, fields and sections are rendered conditionally based on the value of parent from the JSON. If the value of the field is the desired value, only then the field/section is rendered.</p><p>Based on the value of inputType in the JSON, fetchFormField is the function which decides which field is to be rendered. This is how fetchFormField looks like.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c35cdbefc75405cad2971df371f18da/href">https://medium.com/media/9c35cdbefc75405cad2971df371f18da/href</a></iframe><p>fetchFormField is a simple switch case that returns the Redux-Form’s field for a specific value of inputType</p><p>This is how all of the above engineering looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b9UegBUiexBlIrdy.gif" /><figcaption>Conditional Rendering of Form Fields</figcaption></figure><h3><strong>Conclusion</strong></h3><p>Problem statements like dynamic forms are quite common and unavoidable. I tried to cover the conditional rendering part of the problem statement. First, we created a JSON, then used Redux-Form to display and manage the state of the form. In the next part, I will be covering dynamic validation and submission of the form using Redux-Form.<br>Until then, <strong>adiós</strong>, <strong>amigos!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7d79a3f9581" width="1" height="1" alt=""><hr><p><a href="https://medium.com/roadzen-engineering-and-data-science/build-dynamic-forms-with-dynamic-validations-from-json-using-react-redux-form-mui-1-a7d79a3f9581">Build Dynamic forms (with dynamic Validations) from JSON using React/Redux-Form/MUI — 1</a> was originally published in <a href="https://medium.com/roadzen-engineering-and-data-science">Roadzen Engineering &amp; Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate PDF from HTML webpage]]></title>
            <link>https://medium.com/roadzen-engineering-and-data-science/generate-pdf-from-html-webpage-c7f2fd8f4f51?source=rss----54389bbe7585---4</link>
            <guid isPermaLink="false">https://medium.com/p/c7f2fd8f4f51</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[pdf]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[pdf-converter]]></category>
            <dc:creator><![CDATA[Mayank Mishra]]></dc:creator>
            <pubDate>Thu, 11 Mar 2021 16:39:32 GMT</pubDate>
            <atom:updated>2021-03-11T16:41:00.969Z</atom:updated>
            <content:encoded><![CDATA[<h3>Generate Dynamic and Rich PDFs from HTML Templates</h3><h4>Using chrome cluster and puppeteer, rich PDFs can be generated from an HTML webpage along with dynamic rendering with CSS and JS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FmnuWFrZ_DLynGKdG1JJ5A.jpeg" /><figcaption>Pic Courtesy: <a href="https://www.freepik.com/vectors/website">Website vector created by stories</a></figcaption></figure><p>Almost every developer comes across PDF generation in their development timespan, and it is one of the most hectic tasks as existing tools for generating PDFs are not straightforward and don’t provide much flexibility in terms of rich PDFs.</p><p>We needed a solution that would generate PDF reports that consist of tables, images, colors, markings, etc. So we decided to use <a href="https://pdfkit.org/">PDFKit</a>.</p><p>With PDFKit, one major challenge was to develop templates quickly and PDFKit’s canvas-like API was an issue. It needed to point to the exact coordinates of the text/image/shape which was problematic for a developer.</p><p>The closest solution to developing templates was to develop a webpage and then convert it into PDF. We found out that chrome provides API to generate PDFs, which was a perfect fit for us.</p><h3>How we did it?</h3><p>We already had a headless chrome cluster for running integration test cases. So, we used that and connected it with a NodeJS library named <a href="https://github.com/puppeteer/puppeteer">puppeteer</a> that provides API to control chrome.</p><p>Puppeteer provided APIs to stream the HTML webpage from the backend to the chrome cluster and pass back the generated PDF to the backend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LIcrhkv0u9Ko4pmLOby9uw.png" /></figure><p>Now the next task was to create dynamic templates that would support CSS styling support. To do that, we used <a href="https://pugjs.org/api/getting-started.html">pug</a> one of the fastest and most robust templating engines available in NodeJS, which also provides compiled CSS support like Sass / Less / Stylus. That was the safest bet.</p><h3>How you can do it</h3><p>We have open-sourced the library that is being used to convert the templates into PDF connecting to a chrome cluster or running a local chrome. The library is available at the NPM registry. To install, use:</p><pre>npm install --save @roadzen/rusty-mould</pre><p><a href="https://www.npmjs.com/package/@roadzen/rusty-mould">@roadzen/rusty-mould</a></p><h4>Setup the Library</h4><p>To start, you need to initialize the library to connect to the chrome cluster or start a local chrome. This creates a chrome instance and loads all the templates you have created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df28310f600a9a146bde1308266e2638/href">https://medium.com/media/df28310f600a9a146bde1308266e2638/href</a></iframe><h4>Templating</h4><p>Templates should be present in templates/ the folder on your root directory. To change the directory of templates, change the options.</p><p>A complex template directory looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wb8NBrKbCvqA1XQXYzBG-A.png" /><figcaption>Multiple templates stored in templates directory like MIS, via, dashboard.</figcaption></figure><p>So you have one major index file named template.pug which has the HTML and you can use other files as fragments to segregate the code.</p><p>A complex template.pug looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba8f131ca8e647441b430fa785951433/href">https://medium.com/media/ba8f131ca8e647441b430fa785951433/href</a></iframe><p>To populate dynamic data, you can use variables in templates. For example, if company_report_details is an object having address phone and email properties, you can create a template like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d20bb3710038b120e93bf286ee48f1b/href">https://medium.com/media/2d20bb3710038b120e93bf286ee48f1b/href</a></iframe><p>You can also add images to the templates by putting images in the same folder.</p><p><em>Only SVG images are supported as of now.</em></p><h4>Using the templates with dynamic data</h4><p>Once the rusty mould instance is created, you can call the generate PDF function with variables. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05b77e9cf85aca59b70d592bf03685b7/href">https://medium.com/media/05b77e9cf85aca59b70d592bf03685b7/href</a></iframe><p>You can request rendered HTML, PDF, or JPEG of the webpage as per your requirements.</p><p>You can pass the following options,</p><ol><li>ignorePDF — this will not render the PDF, which saves the rendering time.</li><li>generateJPG — if you want to generate an image instead of a PDF, use this.</li><li>jpgQuality — sets the JPG quality to adjust the size of the generated image.</li><li>chrome — these are options directly passed to the puppeteer instance. If want to connect to the chrome cluster, use these options.</li></ol><h4><strong>Conclusion</strong></h4><p>We hope we were able to help you out of the pain of generating PDFs. Using the above library we can generate better quality PDFs with reduced size.</p><p>We have added some logic in some templates which were image heavy to resize on the fly so that the images printed on the PDFs are small. This results in reducing pdf size ~60%, but that’s a story for another time!</p><p>If you are using the above library and find some issues or would like to contribute to it, reach out by commenting below. Suggestions are welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7f2fd8f4f51" width="1" height="1" alt=""><hr><p><a href="https://medium.com/roadzen-engineering-and-data-science/generate-pdf-from-html-webpage-c7f2fd8f4f51">Generate PDF from HTML webpage</a> was originally published in <a href="https://medium.com/roadzen-engineering-and-data-science">Roadzen Engineering &amp; Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upgrading your Mongo Cluster: Step by Step Tutorial]]></title>
            <link>https://medium.com/roadzen-engineering-and-data-science/upgrading-your-mongo-cluster-step-by-step-tutorial-3829ac57cb35?source=rss----54389bbe7585---4</link>
            <guid isPermaLink="false">https://medium.com/p/3829ac57cb35</guid>
            <category><![CDATA[database-administration]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[mongo]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Mayank Mishra]]></dc:creator>
            <pubDate>Fri, 19 Feb 2021 06:34:47 GMT</pubDate>
            <atom:updated>2021-02-19T06:37:35.585Z</atom:updated>
            <content:encoded><![CDATA[<h3>Upgrading your Mongo Cluster: Step by Step Tutorial (15 Steps)</h3><h4>No Worries! Easy upgrading the production cluster with zero downtime.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsyM9COYU7WemlKvqV2GrQ.jpeg" /><figcaption>Source: <a href="https://www.freepik.com/fullvector">https://www.freepik.com/fullvector</a></figcaption></figure><ol><li>ssh in your mongo machines.</li><li>Login using admin credentials on mongo</li><li>On primary instance, run</li></ol><pre>mongo:PRIMARY&gt; rs.config()</pre><p>4. Remove the node which is secondary.</p><pre>mongo:PRIMARY&gt; rs.remove(&quot;&lt;secondary-node:port&gt;&quot;)</pre><p>5. Check logs on the secondary node</p><pre>ubuntu@mongo~#: tail -f /var/log/mongo/mongod.log</pre><p>6. When the replication stops on the secondary node, check the status on both nodes.</p><pre>mongo:PRIMARY&gt; rs.status() mongo:SECONDARY&gt; rs.status()</pre><p>7. Stop the mongo service on the secondary node. ( run any of the below commands which work)</p><pre>sudo systemctl mongod stop<br>sudo service mongo stop</pre><p>8. Upgrade the mongo instance on the secondary node. Find the upgrading steps on the internet.</p><p>a. Change the apt-repo and run the apt-get upgrade if you are using ubuntu.</p><pre>apt-get upgrade -y</pre><p>9. Start the mongo service</p><pre>sudo systemctl mongod start<br>sudo service mongo start</pre><p>10. Add the node again back to the replica set on the primary server.</p><pre>mongo:PRIMARY&gt; rs.add(&#39;&lt;secondary-ip:port&gt;&#39;)</pre><p>11. check for the status on both nodes if it is in sync or not</p><pre>mongo:PRIMARY&gt; rs.status() mongo:SECONDARY&gt; rs.status()</pre><p>if not in sync check for configurations in the secondary node in /etc/mongo.conf or check the daemon logs for more clarification in /var/log/mongo/mongod.log</p><p>12. Wait for the two instances to sync.</p><p>13. Change the priority of the second instance to make it primary, run the following commands on the primary.</p><pre>mongo:PRIMARY&gt; cfg = rs.config()<br>mongo:PRIMARY&gt; cfg.members[0].priority = 0.5; <br>mongo:PRIMARY&gt; cfg.members[1].priority = 0.5;<br>mongo:PRIMARY&gt; cfg.members[2].priority = 1;<br>mongo:PRIMARY&gt; rs.reconfig(cfg)</pre><p>13. Step down the primary instance to secondary.</p><pre>mongo: PRIMARY&gt; rs.stepDown()</pre><p>14. Check if the secondary instance is primary,</p><pre>mongo:SECONDARY&gt; rs.status()</pre><p>15. When the primary and secondary are switched, follow the same steps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3829ac57cb35" width="1" height="1" alt=""><hr><p><a href="https://medium.com/roadzen-engineering-and-data-science/upgrading-your-mongo-cluster-step-by-step-tutorial-3829ac57cb35">Upgrading your Mongo Cluster: Step by Step Tutorial</a> was originally published in <a href="https://medium.com/roadzen-engineering-and-data-science">Roadzen Engineering &amp; Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>