<?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[GoComet - Medium]]></title>
        <description><![CDATA[GoComet’s easy-to-use, intuitive multi-modal logistics platform deploys the power of data science and advanced machine learning intelligence to enable double-digit cost savings for your company. - Medium]]></description>
        <link>https://medium.com/gocomet?source=rss----68e263d32af2---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>GoComet - Medium</title>
            <link>https://medium.com/gocomet?source=rss----68e263d32af2---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 21:17:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/gocomet" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Blocking Code Blues: Frontend Server’s Worst Nightmare]]></title>
            <link>https://medium.com/gocomet/blocking-code-blues-frontend-servers-worst-nightmare-a72bec89081a?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/a72bec89081a</guid>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[postmortem-report]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[rca]]></category>
            <dc:creator><![CDATA[Chetas Sharma]]></dc:creator>
            <pubDate>Wed, 26 Jun 2024 12:21:59 GMT</pubDate>
            <atom:updated>2024-06-26T12:21:59.849Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Picture this</strong>: It’s a sunny afternoon, and your website is buzzing with activity. Users are happily clicking away, eagerly awaiting the lightning-fast responses they’ve come to expect. But suddenly, on some pages, API requests time out, and even temporary downtime for a few minutes is experienced with 503 error and your once-happy users are left staring. What’s going on? Welcome to the world of synchronous code — a seemingly harmless addition that turned into a front-end server’s worst nightmare.</p><p>We’ll dive deep into how a few lines of blocking code can choke the front-end server. Buckle up, as we navigate through the synchronous execution and uncover the path to a more resilient, responsive frontend.</p><p>So, here’s the scoop: A while back, we rolled out this slick new feature letting users rate vendors on our platform. Sounds simple enough, right? Well, we needed an API to fetch the top-performing vendors for a client company. In an ideal world, we’d whip up a single API on the backend to get the <br>whole enchilada in one go. But guess what? The backend query seemed heavy, and we were racing against the clock.</p><p>So, in our desperation, we rigged up an API on our Next.js server. This API made a bunch of network calls to a few backend APIs, mashed up all those responses, and spit out the final list of top-notch vendors. It was kind of a makeshift, but it worked… until it didn’t.</p><p>Little did we know, our makeshift solution was a ticking time bomb, ready to wreak havoc as soon as the user traffic spiked. And boy, did it spike! The server got choked, and our users were left high and dry. Lesson learned: shortcuts and quick fixes can come back to bite you hard.</p><h3>Fun Time</h3><p>But before we dive into the nitty-gritty code, let’s tackle a burning question. We all love sprinkling <strong>async/await </strong>in our JavaScript, but does it block the <strong>main thread of execution</strong>?</p><p>By “main thread,” we’re talking about the <strong>event loop</strong>. (If you’re scratching your head wondering what the heck the event loop is, do check out this <a href="https://www.youtube.com/watch?v=8aGhZQkoFbQ&amp;ab_channel=JSConf">talk</a> — it’s a game-changer.)</p><p>Now, let’s have some fun and see if we can figure out the output of this code snippet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*s7YNa2uMdKVIw1EH5mNdaA.png" /></figure><p>The output will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*4wd-zJwGOFPCvlJ66rjOPA.png" /></figure><p>You might notice that the statement <strong>“Task ends” prints first,</strong> even though we used await in the fn method.</p><h3>So what’s the deal?</h3><p>The reason is that <strong>async/await</strong> doesn’t block the main thread (the event loop). It pauses the execution within the async function (in this case, fn) until the next promise is resolved. So, the code for <em>msg2</em> will only run after the promise for <em>msg1</em> is resolved, and so on. These steps are picked up again from the <strong>callback queue</strong> and moved into the <strong>call stack </strong>later, following the usual event loop mechanics.</p><p>In JavaScript, code execution is non-blocking, and asynchronous operations are handled by the event loop. <br>The event loop continuously checks if any tasks need to be processed on the task queue.</p><p>When an async operation is initiated just like the fn method, it’s handed off to a system outside of the JavaScript runtime (like the web browser or Node.js APIs), which processes it in the background. Once that operation is complete, a callback for that operation is queued on the task queue, allowing the rest of the code outside fn to continue running in the call stack. That’s why the <strong>control isn’t blocked, and “Task ends” gets printed first</strong>.</p><p>In a nutshell, <strong>async/await makes our async code look synchronous, but under the hood, it’s all about keeping the event loop-free and clear</strong>. Neat, huh?</p><h3>What happened in our case?</h3><p>Now let’s examine what the culprit code looked like that went live</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*NtckN9xyOy-278kny6y0pQ.png" /></figure><p>Now here the API handler method is also <strong>async </strong>and inside for…of loop <strong>await</strong> is being used for <strong><em>FetchDetails</em></strong> and <strong><em>CheckIfAlreadyRated</em></strong>, both these methods make network requests to the backend server.<br>When using await inside a <em>for…of</em> loop, each iteration of the loop will wait for the asynchronous operation to complete before moving on to the next iteration. This can have a significant impact on performance, particularly when dealing with API calls or database queries.</p><h3>Here’s why this happens:</h3><p>Now, when you use await, you’re telling JavaScript to “pause” the execution of the enclosing async functions and wait for the Promise to resolve before continuing. But this “pause” doesn’t block the entire thread; it only pauses the current async function. While the function is waiting for the Promise to resolve, other tasks on the event loop can still be executed.</p><p>However, inside a for…of loop, the use of await means that these pauses happen back-to-back. Each loop iteration must finish its asynchronous work before the next iteration starts. As such, none of these operations overlap in time, and they don’t take advantage of possible concurrency. The event loop waits for the promise from one loop iteration to settle before proceeding to the next iteration. This serial processing is often not desirable when the order of completion of the tasks does not matter.</p><p>This will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*te0qAS-UmT06G-IfoGtjIQ.png" /></figure><h3>Now why is this a problem?</h3><p>In a single user’s session, if the <strong><em>FetchDetails</em></strong> operation takes a long time to complete, this approach can lead to inefficient processing. This is because one slow API call will hold up the processing of subsequent vendors. If there are many such calls to make, they are all delayed by waiting for each one to finish before starting the next, hence slowing down the user experience and timeouts.</p><p>And this is exactly what happened in our case. In fact, in our case, we had <strong>two</strong> API calls in a single iteration of the loop one for <strong><em>FetchDetails</em></strong> and one for <strong><em>CheckIfAlreadyRated</em></strong>, Although we were normalizing the top vendors list and were setting an upper bound to limit the size to 15 vendors maximum, still maximum of <strong>thirty</strong> <strong>network requests </strong>could have been made in <strong>a single API call to the next js server.</strong></p><p>These thirty network requests were getting resolved synchronously due to the blocking nature of the code that was implemented.</p><h3>How this can be solved?</h3><p>To improve efficiency and allow concurrent operations, instead of using await inside a loop initiate all asynchronous operations at once and then use Promise.all() to wait for them all to complete. With Promise.all(), the event loop can manage multiple ongoing operations simultaneously, effectively utilizing parallelism.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*KPKobXob9HmB9yz5RUHThA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a72bec89081a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/blocking-code-blues-frontend-servers-worst-nightmare-a72bec89081a">Blocking Code Blues: Frontend Server’s Worst Nightmare</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Little Dark Age]]></title>
            <link>https://medium.com/gocomet/little-dark-age-5d6ec993c897?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/5d6ec993c897</guid>
            <category><![CDATA[postmortem]]></category>
            <category><![CDATA[sidekiq]]></category>
            <category><![CDATA[bug-fixes]]></category>
            <category><![CDATA[rca]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Harshit Srivastava]]></dc:creator>
            <pubDate>Wed, 26 Jun 2024 11:48:41 GMT</pubDate>
            <atom:updated>2024-06-26T11:48:41.728Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Here is a tale of how we faced unknown errors on our platform because of the ambiguous working of Delayed Extensions in Sidekiq. Let’s see how we debugged and resolved the issue.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/0*FqbUteWd-bTy-Qxj" /><figcaption>We built a fort to conquer our scalability issues, but a bug got in through the nick in our armor. Do not worry though, because ladies and gentlemen we got him.</figcaption></figure><h3>Prologue</h3><p><em>Not so long ago, we took on a quest to improve our platform’s performance to provide a better experience to our customers. And so began the journey to handle our CPU and Memory spike issues.</em></p><p>Note: I am using Sidekiq 6.4 in my application.</p><p>Let’s take a moment to review the problem at hand, consider a Sidekiq job that you have in your application, as demonstrated in the following snippet:</p><pre>class Job<br>  include Sidekiq::Worker<br>  def perform(file, email)<br>    request_time = Time.zone.now<br>    rows = file.read<br>    rows.each do |row|<br>      errors = validate(row)<br>      return if errors.present<br>      Model.create!(row, request_time)<br>    end<br>    SuccessNotification.delay(queue: critical).send_update_to_users(request_time, email)<br>  end<br>end<br><br>class SuccessNotification<br>  def self.send_update_to_users(request_time, email)<br>    data = Model.where(&quot;created_at between ? and ?&quot;, request_time, request_time)<br>    return if data.blank?<br>    send_email(email, data)<br>  end<br>end</pre><p>The above job is fairly simple, it takes a file, validates all rows, creates records based on rows, and sends a notification against all the rows simultaneously.</p><p>The problem with this is, that when the count of rows goes north of 10_000 to 15_000, we have noticed a sudden bloat in memory/CPU Spike.</p><p>We replaced the single job processing all records with a simpler <a href="https://github.com/sidekiq/sidekiq/wiki/Batches#complex-workflows">workflow</a> using Sidekiq::Batch.</p><p>The modified job looked something like this:</p><pre>class Job<br>  include Sidekiq::Worker<br><br>  def perform(file, email)<br>    request_time = Time.zone.now<br>    rows = file.read<br>    batch = Sidekiq::Batch.new<br>    batch.on(:success, &quot;Job#send_notifications&quot;, request_time, email)<br>    batch.jobs do<br>      rows.each_slice(50).each do |row_chunk|<br>        Job.delay(queue: default).create_data(row_chunk)<br>      end<br>    end<br>    SuccessNotification.delay(queue: critical).send_update_to_users(request_time, email)<br>  end<br><br>  class &lt;&lt; self<br>    def create_data(rows)<br>      rows.each do |row|<br>        errors = validate(row)<br>        return if errors.present<br>        Model.create!(row, request_time)<br>      end<br>    end<br><br>    def send_notifications(request_time, email)<br>      SuccessNotification.send_update_to_users(request_time, email)<br>    end<br>  end<br>end<br><br>class SuccessNotification<br>  def self.send_update_to_users(request_time, email)<br>    data =  Model.where(&quot;request_time = ?&quot;, request_time)<br>    return if data.blank?<br>    send_email(email, data)<br>  end<br>end</pre><p>Now, the only thing you need to know is that earlier, we were processing all rows and then triggering a notification job, but after performance issues, we moved to a more optimized workflow that creates a batch of multiple jobs processing rows concurrently; joining individual jobs at the end with a callback to send email notifications.</p><h3>The onset of darkness for users</h3><p>Everything was working great, users were uploading Excel sheets with lots of rows, yet we did not see any CPU/ Memory alerts. However, something was wrong. You know how they say,</p><p>“<em>A single crack in the wall can topple an entire fortress.”</em></p><p>We suddenly started noticing a sudden drop in notifications. The file and rows were processed properly on our application, however, the users were in complete darkness (lack of visibility) because they weren’t receiving any notifications for the rows being processed.</p><h3>Hunting Down the Agent of Darkness</h3><p><em>Do not worry my friends for the Bounty Hunter of Bugs came to our relief and he shall crush the living soul out of those pesky little creatures.</em></p><p><strong>Why were notifications not being sent?</strong></p><p>As you can observe, the parameters given to the SuccessNotification job contains a Time object, used to query the database to get records created so that we could send emails accordingly. However, the query did not return any objects despite them being present in DB, hence no emails were sent.</p><p>We have a “request_time” attribute for all records, irrespective of when they were created. Request Time refers to the “start of the process.”</p><p><strong>Why was the query returning no records?</strong></p><p>Upon carefully observing the logs of these jobs, the bounty hunter figured it out, the request_time being passed had changed, not completely, the date was correct but it had lost the aura of Data Type and Precision unlike previously.</p><p>Argument Before Refactoring:</p><pre>&quot;---\n- !ruby/class &#39;SuccessNotification&#39;\n- :send_update_to_users\n- - !ruby/object:ActiveSupport::TimeWithZone\n    utc: 2024-03-15 06:53:13.831263941 Z\n    zone: !ruby/object:ActiveSupport::TimeZone\n      name: Asia/Kolkata\n    time: 2024-06-21 12:23:13.831263941 Z\n  - abc@example.com\n&quot;</pre><p>Argument After Refactoring:</p><pre>&quot;---\n- !ruby/class &#39;SuccessNotification&#39;\n- :send_update_to_users\n- - 2024-06-21 11:55:18 +0530\n  - abc@example.com\n&quot;</pre><p><strong>Why was the time object modified to a String?</strong></p><p><em>As it turns out our greatest ally: Sidekiq Pro has a difference of working in DelayedClass and Sidekiq::Batch Callback.</em></p><p>Now since, this was a notification job, in the previous implementation when there was a single job processing all the rows, in the end, we would schedule the SuccessNotification Job. With the newer implementation, the logic was relocated to “OnSuccess” callback.</p><p><em>Sidekiq always stores arguments as strings and parses them at the time of execution as is evident from the above argument logs.</em></p><blockquote>While <strong>delaying</strong> a Job sidekiq stringifies arguments using YAML.dump and while parsing it uses YAML.load.</blockquote><blockquote>However, in case of Callback and all other workers, it has used Sidekiq.dump_json and Sidekiq.load_json</blockquote><blockquote>Due to this change in working the Precision was lost and the TimeWithZone object was now simply a String.</blockquote><p>Sidekiq Working:</p><p><strong>TimeWithZone preserved in DelayedClass:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNXqbUYLGhZ7hGiWvRsTpQ.png" /></figure><p><strong>TimeWithZone to String in Callback:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Vq3EWKkz9oqfvGJqc0Zgw.png" /></figure><p><strong>Delayed Class:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7tq0x5LxBXE49jv_owNX9w.png" /></figure><p><strong>Batch Callbacks:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Ln-wTk8zYAIy8k_BGnk3A.png" /></figure><h3>Darkness was short-lived, for the Hunter now had his Prey!</h3><p>Now, we can’t change the working of Sidekiq. However, we realized that our existing query was using weird logic.</p><p>Our Previous query was as such:</p><p>Model.where(&quot;request_time = ?&quot;, request_time)</p><p>For Context:</p><p>Users receive notifications instantaneously as in a Single Upload Cycle, which would be the same for all requests, so request_time = &lt;some time&gt; gave us the results.</p><p>But we realized that in a Single upload cycle, we can also have the same request_id which would be the same for all the rows. So to fix our issue we modified the job as such:</p><pre>class Job<br>  include Sidekiq::Worker<br>  <br>  def perform(file, email)<br>    request_time = Time.zone.now<br>    request_id = SecureRandom.hex # Added a request id<br>    rows = file.read<br>    batch = Sidekiq::Batch.new<br>    batch.on(:success, &quot;Job#send_notifications&quot;, request_id, email)<br>    batch.jobs do<br>     ...<br>    end<br>    SuccessNotification.delay(queue: critical).send_update_to_users(request_id, email)<br>  end<br>  <br>  class &lt;&lt; self<br>    ...<br>    <br>    def send_notifications(request_id, email)<br>      SuccessNotification.send_update_to_users(request_id, email)<br>    end<br>  end<br>end<br><br>class SuccessNotification<br>  def self.send_update_to_users(request_id, email)<br>    data = Model.where(request_id: request_id) # Modified Query<br>    return if data.blank?<br>    send_email(email, data)<br>  end<br>end</pre><p>Since we eliminated the use of a Time object, our query will now give us the desired records, hence successfully sending notifications to users as well.</p><h3>Epilogue: It’s Not Over Yet!</h3><p>Although the issue is fixed because we simply removed the need to use a Time object, we still do not know WHY. Sidekiq has two different mechanisms for parsing arguments. So I raised a discussion on Sidekiq’s Forum to get the answer.</p><p><em>The creator should answer our dilemmas…</em></p><p><a href="https://github.com/sidekiq/sidekiq/discussions/6340">https://github.com/sidekiq/sidekiq/discussions/6340</a></p><blockquote><em>From this discussion and Sidekiq’s wiki, we realised that sidekiq never intended to use YAML. As in the beginning we saw that we are using sidekiq version 6 which still gives support for DelayedExtensions, however, Sidekiq discontinued it because of multiple reasons, one of which was and I quote:</em></blockquote><blockquote>“they use YAML to serialize arguments so the job payload can become very large easily if passing complex Ruby objects.”</blockquote><p>Reference Wiki: <a href="https://github.com/sidekiq/sidekiq/wiki/Delayed-extensions">Delayed extensions</a></p><h3>References:</h3><ol><li><a href="https://github.com/sidekiq/sidekiq/wiki/Delayed-extensions">Delayed extensions</a></li><li><a href="https://github.com/sidekiq/sidekiq/wiki/Batches">Batches</a></li><li>Use of YAML in Delayed Extensions: <a href="https://github.com/sidekiq/sidekiq/blob/6-x/lib/sidekiq/extensions/action_mailer.rb">https://github.com/sidekiq/sidekiq/blob/6-x/lib/sidekiq/extensions/action_mailer.rb</a></li><li>Workflows: <a href="https://github.com/sidekiq/sidekiq/wiki/Batches#complex-workflows">https://github.com/sidekiq/sidekiq/wiki/Batches#complex-workflows</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d6ec993c897" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/little-dark-age-5d6ec993c897">Little Dark Age</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimising memory consumption on a rails monolith]]></title>
            <link>https://medium.com/gocomet/optimising-memory-consumption-on-a-rails-monolith-810e78b022ce?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/810e78b022ce</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[memory-improvement]]></category>
            <dc:creator><![CDATA[Abunachar Yeahhia]]></dc:creator>
            <pubDate>Mon, 10 Jun 2024 07:02:57 GMT</pubDate>
            <atom:updated>2024-06-10T07:02:57.876Z</atom:updated>
            <content:encoded><![CDATA[<p>Around last December, our application servers were using ~70 GB of memory to serve requests at peak hours. As part of platform team, I started investigating ways to bring down our memory usage and discovered <a href="https://jemalloc.net/">jemalloc</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*gnEdseOOnyul4PBX.png" /><figcaption>memory bloat on our application server</figcaption></figure><p>In this article, I’ll be sharing the root cause for our memory bloat and how jemalloc affected the overall memory utilisation.</p><h3>Memory Allocators</h3><p>Memory allocation in Ruby involves three layers, ordered from high to low level:</p><ol><li>The Ruby interpreter manages Ruby objects.</li><li>The operating system’s memory allocator library.</li><li>The kernel.</li></ol><h3>Ruby interpreter</h3><p>On the Ruby side, Ruby organises objects in memory areas called <em>Ruby heap pages</em>. Such a Ruby heap page is split into equal-sized slots, where one object occupies one slot. Whether it’s a string, hash table, array, class, or whatever, it occupies one slot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*WoSy-1zy8E0xkRR9.png" /></figure><h3>Operation System’s Memory Allocator</h3><p>The operating system’s memory allocator is a library that is part of <em>glibc</em> (the C runtime). It has a simple API:</p><ul><li>Memory is allocated by calling malloc(size). You pass it the number of bytes you want to allocate, and it returns either the address of the allocation or an error.</li><li>Allocated memory is freed by calling free(address).</li></ul><h3>Kernel</h3><p>The kernel can only allocate memory in units of 4 KB. One such 4 KB unit is called a <em>page</em>. Not to be confused with Ruby heap pages, which again have nothing to do with this.</p><p>The reason for this is complicated, but suffice to say that all modern kernels have this property.</p><p>Allocating memory via the kernel also has a significant performance impact, so memory allocators try to minimize the number of kernel calls.</p><h3>Memory issue due to Memory fragmentation</h3><h3>What is memory fragmentation?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*CbQkb-RjSirowGiv.png" /><figcaption>memory fragmentation</figcaption></figure><p>Imagine the heap as your Lego box. It&#39;s where Ruby objects are allocated and stored.</p><ul><li>Over time, your app creates and destroys objects, leaving behind “holes” in the heap like missing Lego pieces.</li><li>These holes are small, scattered chunks of memory that can’t be used for larger objects.</li><li>When your app needs a big block of memory (e.g., to load a large image), it has to scan through the fragmented heap, potentially taking longer and even failing if no suitable chunk is found.</li></ul><h3>Mitigating Memory fragmentation</h3><p><strong>Reducing Avenues<br></strong>The major cause of fragmentation appears to be the large number of glibc memory arenas in heavily multi-threaded programs. “Heavily multi-threaded” — sound familiar? That’s Sidekiq. That reduces the “heavily multi-threaded” trigger and leads to less bloat.</p><p><strong>Change memory allocator<br></strong>Change the default memory allocator from glibc to a different one ( like Jemalloc)</p><h3>Jemalloc vs glibc</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*0EvlE8lXo88nhYz3.png" /></figure><h3>Jemalloc in action</h3><p>The results were very impressive. In fact, the outcome was much better than we expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*0tEDMuSgcXBpq9cv.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*hZxqKutf94egXbL0.png" /></figure><p>As seen, we were able to bring our peak memory consumption to ~20 GB.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=810e78b022ce" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/optimising-memory-consumption-on-a-rails-monolith-810e78b022ce">Optimising memory consumption on a rails monolith</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What if-else]]></title>
            <link>https://medium.com/gocomet/what-if-else-40bf0be57c56?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/40bf0be57c56</guid>
            <category><![CDATA[developer-productivity]]></category>
            <category><![CDATA[object-oriented-program]]></category>
            <category><![CDATA[clean-code-principle]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[object-oriented-concepts]]></category>
            <dc:creator><![CDATA[Prashant Sajwan]]></dc:creator>
            <pubDate>Tue, 21 May 2024 07:50:48 GMT</pubDate>
            <atom:updated>2024-05-21T07:50:48.297Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you seen a code having too many <strong>if-else</strong> blocks?<br>so many that you wish that you would not have to update anything there ever…<br>so many that the file is 700+ lines and difficult to navigate<br>so many that checking which cases are missed in the <strong>test-case</strong> file takes 15–30 minutes of your time<br>so many that it has bugs and too many hot-fixes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*RX5H28t4qK1ER_1t.png" /></figure><p>A year ago…</p><p>we were facing this problem which you might have seen or will see in the future hopefully…</p><p>how does this code look to you?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*etiX7HYF77O2dbvZ.png" /></figure><h3>How difficult will it be if I have to update the PAWN logic???</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*czMkms_gO2xjowKz.png" /></figure><h3>Let’s try rewriting the code</h3><p>Let’s rewrite this using <a href="https://www.jamesmichaelhickey.com/domain-driven-design-aggregates/">aggregates</a></p><blockquote><strong><em>Aggregates are like Bubbles</em></strong>.</blockquote><blockquote>Imagine your software project was not one massive code-base — but a collection of small bubbles. Each bubble can be worked on independently. That means, you only need to think about what’s in the bubble at any given moment — not the entire system all at once.</blockquote><blockquote>Aggregates are the same. They are bubbles. Just on a smaller scale.</blockquote><h3>Base class Piece defining common structure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CE_srCSJI2LYZGp0.png" /></figure><p>Pawn class defining responsibilities</p><h3>Pawn class defining responsibilities</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rXrLXAspTkY9AwAT.png" /></figure><h3>Rook class defining responsibilities</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*88z2D9dMOSpl5_2A.png" /></figure><p>Let’s compare the final changes</p><h3>Let’s compare the final changes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r3f2TyDw9d9eDbDD.png" /></figure><h3>Let’s review the problem and the fix</h3><p><strong>So what were the problems in the initial code?</strong></p><ul><li>voids the <strong>golden rule</strong> of One class One responsibility</li><li>too many <strong>if-else</strong> conditions, increases complexity, <br>bad Developer Experience</li><li>highly coupled code</li><li>difficult to write unit-test cases</li><li>large file size</li><li>difficult to create mind-map and navigate through the flow</li></ul><p><strong>How does aggregation solve this?</strong></p><ul><li><strong>One class One Responsibility:</strong> each class is isolated.</li><li>removes <strong>if-else</strong> by moving code to separate classes.</li><li>easy to <strong>read/update</strong></li><li>easy to navigate as responsibilities are divided into respective files, creating <strong>clear visibility</strong></li></ul><h3>How we solved our problem</h3><ul><li>A class responsible for giving a response to a request, here the response is <strong>Freight Cost</strong> for a <strong>Lane</strong></li><li>It also has to check which type of plan the current user has, <strong>Free/Trial/Paid</strong></li><li>All this happening in a single <strong>File</strong></li></ul><p>Previously it looked something like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W0V85CWEqMzFHqhL.png" /></figure><p>After separating <strong>Free</strong>, <strong>Trial,</strong> and <strong>Paid</strong> logic into separate classes-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n8DeQEHm0ZYsV8vD.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2C2xd3LGOjWQoOKp.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40bf0be57c56" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/what-if-else-40bf0be57c56">What if-else</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux Upgrade Guide: Boosting Code Maintainability and Re-usability]]></title>
            <link>https://medium.com/gocomet/redux-upgrade-guide-boosting-code-maintainability-and-re-usability-20030f29ed18?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/20030f29ed18</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[upgrade]]></category>
            <dc:creator><![CDATA[Dakshesh Panchal]]></dc:creator>
            <pubDate>Thu, 21 Sep 2023 07:55:09 GMT</pubDate>
            <atom:updated>2023-09-21T07:55:08.945Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will discuss the reasons behind upgrading Redux and how it can improve the maintainability and re-usability of our code. While connect() and mapStateToProps have served us well, newer alternatives and recommended patterns have emerged, providing better solutions for accessing Redux state. We will explore the issues faced with connect(), version upgrades, the benefits of using hooks, and our planned three-phase upgrade approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c-ZLZd9wCluFwX9Ftkj5qg.png" /></figure><p><strong>The Issues with </strong><strong>connect()</strong><br>a. <strong>Boilerplate Code</strong>: The connect() API often adds excessive boilerplate code to components, making the code base harder to read and maintain. This can hinder productivity and increase the chances of introducing bugs. We now have better alternatives that reduce boilerplate and enhance code clarity.<br><em>Example: Consider a simple functional component that needs to access the Redux state using </em><em>connect():</em></p><pre>const MyComponent = ({ someProp }) =&gt; {<br> // …<br>};<br>export default connect(mapStateToProps)(MyComponent);</pre><p><em>The above code can be simplified and made more readable using newer alternatives.</em></p><p>b. <strong>Prop Drilling</strong>: The connect() approach tends to encourage prop drilling, particularly when writing mapStateToProps in nested child components. This can lead to code duplication and make the codebase harder to manage. We need a more efficient way to access Redux state across components.<br><em>Example: Imagine a scenario where multiple nested functional components require access to the Redux state using </em><em>connect():</em></p><pre>const ChildComponent = ({ someProp }) =&gt; {<br>  // ...<br>};<br>const ParentComponent = ({ someProp }) =&gt; {<br>  // ...<br>  return &lt;ChildComponent someProp={someProp} /&gt;;<br>};<br>const GrandParentComponent = ({ someProp }) =&gt; {<br>  // ...<br>  return &lt;ParentComponent someProp={someProp} /&gt;;<br>};<br>export default connect(mapStateToProps)(GrandParentComponent);</pre><p><em>In this case, prop drilling becomes cumbersome and leads to code duplication. There are better alternatives available to simplify this process.</em></p><p>c.<strong> Global Search Pollution</strong>: When performing a global search for Redux actions, we often encounter unnecessary noise due to prop drilling and prop-types having the same names. This noise can make it challenging to locate where an action is actually being used. We require a cleaner and more organised approach to searching for actions.<br><em>Example: During a global search for a specific Redux action, the results might be cluttered with unnecessary references to prop drilling and prop-types, making it difficult to find the actual usage of the action.</em></p><p><strong>Version Upgrades</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*9RwjpccACqlgbwgkCieWmg.jpeg" /></figure><p>To address the aforementioned issues, we are planning the following version upgrades:</p><ul><li>redux: 4.0.1 → 4.2.1</li><li>react-redux: 8.x</li><li>redux-thunk: 2.3.0 → 2.4.0</li></ul><p>These version upgrades do not introduce any breaking changes, ensuring a smooth transition and compatibility with our existing code base. The upgrade will provide us with the latest bug fixes, performance improvements, and new features.</p><p><strong>Benefits of Using Hooks</strong><br>One key benefit of upgrading Redux is the ability to leverage hooks, which allow us to create custom hooks for abstracting and reusing stateful logic. For instance, if we need to access the state.operationsModule.clientSideEditor in multiple components, we can create a custom hook that exposes only the required state, eliminating the need to write selectors in every component. This enhances code modularity, reduces duplication, and improves overall code maintainability.<br><em>Example: Instead of using </em><em>connect() and </em><em>mapStateToProps in each component, we can create a custom hook to access the required state:</em></p><pre>const useClientSideEditorState = () =&gt; {<br>  const clientSideEditor = useSelector(state =&gt; state.operationsModule.clientSideEditor);<br>  return clientSideEditor;<br>};<br>const MyComponent = () =&gt; {<br>  const clientSideEditor = useClientSideEditorState();<br>  // Use clientSideEditor state...<br>  return (<br>    // JSX for MyComponent<br>  );<br>};<br>export default MyComponent;</pre><p><em>This approach abstracts the state access and promotes code re-usability.</em></p><p><strong>Planned Three-Phase Upgrade Approach</strong></p><p>We have meticulously planned the upgrade process to ensure a smooth transition and to take advantage of additional Redux ecosystem tools:</p><p>a. <strong>Phase 1</strong>: Upgrading Redux — We will first upgrade Redux to the latest version, addressing the issues faced with connect() and improving overall code quality.</p><p>b. <strong>Phase 2</strong>: Migrating to Redux Toolkit — Once Redux is upgraded, we will migrate to Redux Toolkit, a powerful official package that simplifies common Redux use cases, reduces boilerplate, and provides better development experiences.</p><p><em>Example: Redux Toolkit simplifies Redux code by providing utilities like </em><em>createSlice and </em><em>createAsyncThunk.</em></p><p>c. <strong>Phase 3</strong>: Adding RTK Query for Cached Response — In the final phase, we will incorporate RTK Query, another Redux Toolkit package, to efficiently handle cached responses and further optimize our application.</p><p><em>Example: RTK Query provides a declarative and efficient way to fetch and cache data in Redux applications.</em></p><p>Upgrading Redux offers significant benefits, including improved code maintainability and reusability. By moving away from connect() and adopting newer patterns and tools, we can reduce boilerplate, eliminate prop drilling, and achieve cleaner code organization. The planned three-phase upgrade approach ensures a smooth transition and allows us to take full advantage of the latest Redux ecosystem tools. With these enhancements, we can create more robust and scalable applications.</p><p>Feel free to provide any additional input or suggestions for the upgrade process in the comments. Let’s improve our codebase together!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20030f29ed18" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/redux-upgrade-guide-boosting-code-maintainability-and-re-usability-20030f29ed18">Redux Upgrade Guide: Boosting Code Maintainability and Re-usability</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streamlining Frontend Code Quality: A Deep Dive into Eslint and Prettier Integration at GoComet]]></title>
            <link>https://medium.com/gocomet/streamlining-frontend-code-quality-a-deep-dive-into-eslint-and-prettier-integration-at-gocomet-ce7074e511b9?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/ce7074e511b9</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[linting]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ashirbad behera]]></dc:creator>
            <pubDate>Thu, 24 Aug 2023 10:47:24 GMT</pubDate>
            <atom:updated>2023-08-24T10:47:24.465Z</atom:updated>
            <content:encoded><![CDATA[<p>Implementing a solid centralized linting system can enhance the efficiency of developers and avoid typical syntax issues and general javascript, react pitfalls during the development process. Therefore, it is essential to have a well-tailored linting system that aligns with our requirements.</p><h3>Problems we are facing</h3><ul><li>Like every other typical production codebase, we are already using a preconfigured ESLint setup bundled with Next.js. While ESLint primarily serves as a linter, it also includes certain code formatting rules. However, these formatting rules can occasionally clash with the rules set by Prettier, leading to inconsistencies in our code.</li><li>The problem with using ESLlint and Prettier together is we need to sync both of these tools’ configs to avoid code formatting conflicts, which is challenging because They are both opinionated tools having different code formatting style guides.</li><li>Another problem was not having a pre-commit hook in place which detects ESLint issues and prompts the developer to fix it in place before committing.</li></ul><p>In this article, I have described how we fixed the above-mentioned problems and improved the overall developer experience.</p><h3>What we use</h3><p>Our Client-side application is developed using Next.js, which provides an excellent default configuration for linting. However, there is always room for improvement, and we leverage industry-standard tools such as ESLint and Prettier to ensure code quality.</p><p>For linting and code formatting, we use the Airbnb style guide as the base configuration for JavaScript. Additionally, we use <a href="https://github.com/prettier/eslint-plugin-prettier">eslint-plugin-prettier</a> to integrate Prettier into our linting process. This plugin allows Prettier to be run as an ESLlint rule, which detects and reports any code formatting issues as individual ESLint issues</p><figure><img alt="VSCode reporting prettier issues as ESLint rules" src="https://cdn-images-1.medium.com/max/1024/0*en9NejNCnuwuyhDm" /><figcaption>Prettier issues are reported as ESLint rules</figcaption></figure><h3>Why we use Prettier as an ESLint Rule</h3><p>Previously, we were able to use ESLint and Prettier as separate tools, but there are advantages to having them work together. Specifically, Prettier’s code formatting issues are identified directly within the editor, allowing developers to address them on the spot. Additionally, since Prettier has been integrated into our Linting process, we no longer need to manage these two tools separately.</p><p>But, one caveat is that ESLlint also has some code formatting rules such as enforcing indentation and semi-colons. Since we are integrating Prettier as an ESLint rule, there might be some conflicting rules which is problematic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/0*matEsYLNXp2fIihY" /></figure><p>Prettier is a more comprehensive and dependable code formatter as compared to ESLint. As a result, we prefer to have Prettier handle all code formatting concerns, while ESLint focuses solely on handling syntactical linting issues and best practices where the tool is actually good.</p><p>After installing the eslint-plugin-prettier plugin we want all the ESLint code formatting rules to be turned off, otherwise, there may be conflicts with Prettier. To accomplish this, we used the eslint-config-prettier configuration from <a href="https://github.com/prettier/eslint-config-prettier,">https://github.com/prettier/eslint-config-prettier,</a> which essentially disables all of ESLint’s code formatting rules, allowing Prettier to function smoothly.</p><h3>Configuring VSCode according to this setup</h3><p>As almost all of our frontend developers use VSCode as their primary code editor, it’s crucial that our existing linting setup is seamlessly integrated with it.</p><p>To accomplish this, we require the ESLint extension for VSCode so that linting errors appear directly within the editor. However, we also want to ensure that all auto-fixable issues are handled by the editor itself. To achieve this, we’ve added the following settings to our VSCode settings.json file:</p><pre>&quot;editor.codeActionsOnSave&quot;: [<br>  &quot;source.fixAll.eslint&quot;<br>],</pre><p>By doing so, we’re able to automatically fix all auto-fixable issues, including those related to Prettier. As a result, we no longer need to have the format-on-save settings enabled, as this is now unnecessary.</p><h3>Further improving our setup with pre-commit hooks</h3><p>Currently, we are at a phase where we cannot afford to unintentionally push any linting errors. To avoid such a scenario, we have introduced a pre-commit hook that assesses our code for any linting errors and notifies us about them. This approach guarantees that no flawed code is pushed to the repository.</p><p>However, running ESLint on our entire codebase is time-consuming and needless. Instead, we prefer to only lint files that have undergone changes. Therefore, we leverage the benefits of lint-staged, which enables us to execute our pre-commit hook solely on the staged files. Consequently, the linting process becomes much quicker.</p><pre>&quot;lint-staged&quot;: {<br>  &quot;*.{js,jsx,ts,tsx,css}&quot;: [<br>    &quot;prettier - write&quot;,<br>    &quot;eslint - ext .js,.ts,.jsx,.tsx&quot;<br>  ]<br>},</pre><h3>Wrapping up</h3><p>Investing time in Improving our linting and code formatting setup has made our development experience better and more streamlined. Our setup is opinionated and reflects our preferences and what works well for us, although one might not want to use prettier as an ESLint rule. It ultimately depends on how you want to use your tools. The beauty lies in the customization options available — you can adapt these tools to align with your specific requirements. Looking ahead, we’ll continue exploring emerging tools and plugins within the frontend linting ecosystem to reinforce and fortify our existing setup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce7074e511b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/streamlining-frontend-code-quality-a-deep-dive-into-eslint-and-prettier-integration-at-gocomet-ce7074e511b9">Streamlining Frontend Code Quality: A Deep Dive into Eslint and Prettier Integration at GoComet</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we removed NextJS Custom Server and migrated it to NextJS Middleware]]></title>
            <link>https://medium.com/gocomet/why-nextjs-custom-server-is-not-necessary-now-and-you-should-use-middleware-instead-2a071ab1abec?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/2a071ab1abec</guid>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[sentry]]></category>
            <category><![CDATA[nextjscustomservers]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[bundler]]></category>
            <dc:creator><![CDATA[Atul Jain]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 16:07:20 GMT</pubDate>
            <atom:updated>2023-06-08T14:20:26.589Z</atom:updated>
            <content:encoded><![CDATA[<h3>How we removed NextJS Custom Server and migrated it to NextJS Middleware?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9Ci0zghPTczHaV-DDKpfA.png" /></figure><p>With Next.js custom servers we encountered various challenges that impacted our development workflow and application performance. One common issue was the lack of access to source maps, making it difficult to effectively debug and troubleshoot client-side errors. This hindered the efficiency of the development process and extended the time required to identify and fix issues. Additionally, these custom servers often resulted in larger build sizes, leading to increased bandwidth consumption and slower loading times for the application. Furthermore, with the advancements in Next.js and the adoption of middleware, we can now have the opportunity to overcome these challenges and unlock a range of benefits. By leveraging middleware in Next.js, we can enhance performance, achieve faster and smaller builds, and seamlessly integrate hidden source maps on platforms like Sentry, enabling efficient debugging and a streamlined development experience.</p><h3>Why did we implement a Custom server earlier?</h3><p>By default, Next.js comes with a built-in server that handles rendering pages and serving static assets. However, In previous versions of Next.js one was not able to do rewrites, redirects, and dynamic routing effectively, or sometimes you might just need more flexibility or control over how the server works.</p><p>That’s where a custom server comes in, Next.js allows you to override the default behavior of the built-in server and define your own routes and logic.</p><p>For example, in old Next.js versions, you may want to</p><ol><li>Implement dynamic routing</li><li>And add middleware to modify requests or responses.</li></ol><p>With a custom server, you can do all of these things and more.</p><blockquote>Dynamic routing in next was introduced in Next 9. Refer to the <a href="https://nextjs.org/blog/next-9#dynamic-route-segments">link here</a></blockquote><h3><strong>Benefits of Removing the Custom Server in Next.js</strong></h3><p>Although the custom server in Next.js provides flexibility and control, there are significant advantages to removing it. Here’s why:</p><ol><li><strong>Incompatibility with Sentry’s Source Map Uploads:</strong> One of the main reasons for removing the custom server is its lack of compatibility with Sentry’s source map uploads. This limitation hinders effective debugging and troubleshooting of client-side errors, making it challenging to identify and resolve issues efficiently.</li><li><strong>Lack of Key Performance Optimisations:</strong> The custom server lacks important performance optimizations, such as serverless functions and Automatic Static Optimization.</li><li><strong>Middleware for Custom Headers and Authentication:</strong> Removing the custom server does not mean sacrificing the ability to use custom headers for specific URLs or relying on in-house-made authentication and authorization mechanisms that rely on the request and response objects passed from Express to Next.js. Instead, you can achieve these functionalities by utilizing middleware. Middleware allows you to modify requests and responses, enabling you to customize headers and implement authentication and authorization seamlessly.</li></ol><p>By considering the removal of the custom server in favor of Next.js’s default server and utilizing middleware, you can overcome the challenges posed by incompatibility, optimize your application’s performance, and maintain the desired level of customization.</p><h3>Understanding Middleware in Next.js</h3><p>In Next.js, middleware acts as an interceptor that can execute a process before a request is fully completed. This middleware intercepts incoming requests, providing the ability to modify the request header or response, rewrite content, redirect, or even directly respond. It allows for customizing and manipulating the request-handling process, enabling developers to tailor the behavior and responses based on specific needs or conditions.</p><p>In addition, an important aspect of middleware in Next.js is that it runs before cached content. This means that it can be used to personalize static files and pages by intercepting requests before they are served from the cache. By utilizing middleware in this manner, developers can dynamically modify or personalize the content of static files and pages, ensuring that each request is processed with the most up-to-date and customized information, even if caching is involved. This allows for a more dynamic and personalized user experience in Next.js applications.</p><blockquote>Next Middleware was stable from Next version 12.2 and we are currently using Next 12.3.</blockquote><blockquote>Features like modifying request headers, response headers, and sending responses are available from Next.js version 13.0</blockquote><h3><strong>But what’s the catch? What are the Limitations of Middleware?</strong></h3><p>Can’t pass data directly (or programmatically) to pages</p><ul><li>Middleware functions run on the server before a page is rendered, and they can modify the request or response objects, but they do not have the ability to add or change the props of the component that will render the page (_app. jsx or the component directly) the reason behind this being middleware doesn’t work is that middleware doesn’t use Node.js APIs directly.</li><li>We need authenticated user data for 3rd party javascript libraries we use in <strong><em>_document.jsx</em></strong>.</li><li>Overall, while it is not possible to pass data directly from middleware to pages in Next.js, there are several workarounds that can be used to achieve the desired functionality.</li><li>Like using <strong><em>getInitialProps, serverRuntimeConfig, or publicRuntimeConfig</em> </strong>options in your<strong> next.config.js. </strong>Store data in redux from the server response and then access that from pages</li></ul><h4>When should you use next.config.js instead of middleware?</h4><p>Any static headers, redirects, or rewrites should be done in next.config.js. Meanwhile, if you need to do custom headers, redirects, or rewrites dynamically then middleware should be used.</p><p><strong><em>For example -</em></strong><br>In the below code, headers will always be passed for the route <em>/some-public-route</em></p><p><strong>//next-config.js</strong></p><pre>import getConfig from &#39;./config&#39;<br>const config = getConfig();<br>module.exports = {<br>  headers() {<br>  return [<br>   {<br>    source: &#39;/some-public-route&#39;,<br>    headers: [<br>     {<br>      key: &#39;X-Frame-Options&#39;,<br>      value: &#39;DENY&#39;,<br>     },<br>    ],<br>   },<br>  ];<br> },<br> ...config<br>}</pre><p>But if you need to determine whether to <a href="https://nextjs.org/docs/advanced-features/middleware#setting-headers">set headers dynamically</a> or not, the code below will come into play</p><p><strong>//middleware.js</strong></p><pre>import { NextResponse } from &#39;next/server&#39;<br><br>export function middleware(request) {<br> let response = NextResponse.next()<br> if (request.geo.country == &#39;ANY_COUNTRY&#39;) {<br>   // Clone the request headers and set a new header `i18n-language`<br>   const requestHeaders = new Headers(request.headers)<br>   requestHeaders.set(&#39;i18n-language&#39;, &#39;LANGUAGE_OF_ANY_COUNTRY&#39;)<br>   response = NextResponse.next({<br>     request: {<br>       headers: requestHeaders,<br>     },<br>   })<br>   response.headers.set(&#39;i18n-language&#39;, &#39;LANGUAGE_OF_ANY_COUNTRY&#39;)<br> }<br> return response<br>}</pre><h3>Let’s see how to port the custom server to middleware:</h3><h4>Custom server overview</h4><p>Firstly, we’ll need to go through any dependencies used with our ExpressJs custom server. For us, these dependencies were <a href="https://www.npmjs.com/package/compression">compression</a> and <a href="https://www.npmjs.com/package/cookie-parser">cookie-parser</a>, both of which are already in Next.js now. These might be different for you.</p><p>Now let’s proceed with checking the current custom server file and identify changes we need to port. Below is an example of a custom server file, yours might be different:</p><p><strong>// server/index.js</strong></p><pre>const server = require(&#39;express&#39;)();<br>const compression = require(&#39;compression&#39;);<br>const cookieParser = require(&#39;cookie-parser&#39;);<br>const { PUBLIC_PATHS } = require(&#39;./config/public_paths&#39;);<br>const { app, handle } = require(&#39;./app&#39;);<br>const routes = require(&#39;./routes&#39;);<br>const checkAuthAndRender = require(&#39;./config/checkAuthAndRender&#39;);<br><br>app.prepare()<br> .then(() =&gt; {<br>  const PORT = process.env.PORT || 3000;<br>  server.use(compression());<br>  server.use(cookieParser());<br>  server.use(&#39;/&#39;, routes);<br>  server.get(&#39;*&#39;, (req, res, next) =&gt; {<br>           const isPublicPath = PUBLIC_PATHS.map(path =&gt; req.url.includes(path)).includes(true);<br>   if (isPublicPath) {<br>    handle(req, res);<br>   } else {<br>    checkLoginAndHandle(req, res, app);<br>   }<br>  });<br>  server.listen(PORT, err =&gt; {<br>   if (err) throw err;<br>   console.log(`&gt; Ready on http://localhost:${PORT}`);<br>  });<br> })<br> .catch(ex =&gt; {<br>  console.error(ex.stack);<br>  process.exit(1);<br> });</pre><p><strong>Next</strong>, it is essential to consider any custom <a href="https://expressjs.com/en/guide/using-middleware.html">Express middlewares</a> or <a href="https://expressjs.com/en/guide/routing.html">Routers</a> that you may need to migrate. In our case, we had a custom authentication middleware specifically designed for private routes. These custom middlewares play a crucial role in handling authentication and authorization logic, ensuring that only authenticated users can access certain routes or resources.</p><p>The auth middleware is used to:</p><ul><li>Parse and set subdomains in headers.</li><li>Call an HTTPS API to authenticate and verify the auth token of a logged-in user.</li><li>Redirect users to a specific URL based on their preferences or conditions.</li></ul><p>It is important to evaluate and port these custom middlewares to Next.js, allowing for a seamless transition while preserving the functionality and security of private routes.</p><p><strong>// server/config/checkAuthAndRender.js</strong></p><pre>import url from &#39;url&#39;;<br>import axios from &#39;axios&#39;;<br>import { SCHEMA_NAME } from &#39;./schema&#39;;<br><br>export default (req, res, next) =&gt; {<br>  let renderUrl = req.url;<br>  const domains = req.subdomains;<br>  const loginUrl = &#39;https://example.com/login&#39;;<br>  const hostUrl = &#39;https://example.com&#39;;<br><br>  axios<br>    .get(`${loginUrl}/api/v1/current`, {<br>      headers: {<br>        Accept: &#39;application/json&#39;,<br>        &#39;Content-Type&#39;: &#39;application/json&#39;,<br>        Authorization: req.cookies[&#39;sess&#39;],<br>        Schema: domains[0],<br>      },<br>    })<br>    .then(response =&gt; {<br>      if (response.status === 200) {<br>        const data = (response.data || {}).user || {};<br>        const { id = &#39;&#39;, name = &#39;&#39;, email = &#39;&#39; } = data;<br>        const query = {<br>          ...queryParams,<br>          ...req.query,<br>          user_id: id,<br>          user_name: name,<br>          user_email: email,<br>        };<br>        app.render(req, res, renderUrl, query);<br>      } else {<br>        const query = { ...req.query };<br>        res.redirect(url.format({ pathname: &#39;/login&#39;, query }));<br>      }<br>    })<br>    .catch(e =&gt; {<br>      if (e.response &amp;&amp; [400, 401].includes(e.response.status)) {<br>        const query = { ...req.query };<br>        let redirectUrl = `${req.protocol}://${req.hostname}${req.path}`;<br>        query.rd = redirectUrl;<br>        const newLoginUrl = url.format({ pathname: `${hostUrl}/login`, query: req.query });<br>        res.redirect(newLoginUrl);<br>      } else {<br>        res.redirect(url.format({ pathname: &#39;/_error&#39;, query: { error_id: 1001 } }));<br>      }<br>    });<br>};</pre><p>Now to port the above custom server, we will create a middleware file</p><h4>Middleware File [/middleware.js]</h4><pre>import { NextResponse } from &quot;next/server&quot;;<br>import {<br>  entriesToObject,<br>  generateUrlWithQuery,<br>  getQueryFromSearchParams,<br>} from &quot;util/middleware&quot;;<br><br>export async function middleware(request) {<br>  const requestedUrlObject = new URL(request.url);<br>  const renderURL = request.url;<br>  const requestQuery = getQueryFromSearchParams(<br>    requestedUrlObject.searchParams<br>  );<br>  const headers = entriesToObject(request.headers);<br>  const domains = headers.host.split(&quot;.&quot;);<br>  const loginUrl = &quot;https://example.com/login&quot;;<br>  const hostUrl = &quot;https://example.com&quot;;<br><br>  try {<br>    const response = await fetch(`${loginUrl}/api/v1/current`, {<br>      headers: {<br>        Accept: &quot;application/json&quot;,<br>        &quot;Content-Type&quot;: &quot;application/json&quot;,<br>        Authorization: request.cookies.get(&quot;sess&quot;),<br>        Schema: domains[0],<br>      },<br>    });<br><br>    if (response.status === 200) {<br>      const responseData = await response.json();<br>      const data = responseData.user || {};<br>      const { id = &quot;&quot;, name = &quot;&quot;, email = &quot;&quot; } = data;<br>      const query = {<br>        ...requestQuery,<br>        user_id: id,<br>        user_name: name,<br>        user_email: email,<br>      };<br>      return NextResponse.rewrite(<br>        generateUrlWithQuery(renderURL, hostUrl, query)<br>      );<br>    }<br><br>    return NextResponse.redirect(<br>      generateUrlWithQuery(&quot;/login&quot;, hostUrl, requestQuery)<br>    );<br>  } catch (e) {<br>    if (<br>      e.response &amp;&amp;<br>      (e.response.status === 401 || e.response.status === 400)<br>    ) {<br>      const { protocol, pathname, hostname } = requestedUrlObject;<br>      let redirectUrl = `${protocol}//${hostname}${pathname}`;<br><br>      if (process.env.SYSTEM_ENV === &quot;development&quot;) {<br>        redirectUrl = `${protocol}//${hostname}:${process.env.PORT}${pathname}`;<br>      }<br><br>      query.rd = redirectUrl;<br><br>      return NextResponse.redirect(<br>        generateUrlWithQuery(&quot;/login&quot;, hostUrl, requestQuery)<br>      );<br>    }<br><br>    return NextResponse.redirect(<br>      generateUrlWithQuery(&quot;/_error&quot;, hostUrl, { id: 1001 })<br>    );<br>  }<br>}<br><br>export const config = {<br>  matcher: [<br>    /*<br>     * Negative regex checking for public routes<br>     */<br>    &quot;/((?!login|signup|error|ping|favicon.ico).*)&quot;,<br>  ],<br>};</pre><p>Also, you may want to include utils that were provided by Express. We had some methods which were defined additionally in the same <strong>middleware.js</strong> file. You can also move them to <strong>utils/middleware.js</strong></p><p><strong>// middleware</strong></p><pre>const entriesToObject = (entriesObject) =&gt; {<br>  const accEntries = {};<br>  const entries = entriesObject.entries() || {};<br>  for (const [key, value] of entries) {<br>    accEntries[key] = value;<br>  }<br>  return accEntries;<br>};<br><br>const generateUrlWithQuery = (pathname, url, query = {}) =&gt; {<br>  const urlObj = new URL(pathname, url);<br>  Object.entries(query).forEach(([key, value]) =&gt; urlObj.searchParams.set(key, value));<br>  return urlObj;<br>};<br><br>const getQueryFromSearchParams = (searchParams) =&gt; entriesToObject(searchParams);</pre><blockquote>These functions perform various operations such as converting entries to an object, generating a URL with query parameters, and getting the query from search parameters.</blockquote><h3>What did we achieve?</h3><p>While there are numerous points and benefits that can be highlighted, here are some key advantages we have achieved:</p><ul><li>Better performance</li><li>Faster and smaller builds</li><li>Working Hidden Source Maps on Sentry</li></ul><p>These benefits highlight the advantages of using middleware in Next.js, including improved performance, faster build times, and enhanced debugging capabilities. By leveraging these features, you can optimize your application’s server-side processing, reduce build sizes, and streamline error handling, resulting in an overall more efficient and robust application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a071ab1abec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/why-nextjs-custom-server-is-not-necessary-now-and-you-should-use-middleware-instead-2a071ab1abec">How we removed NextJS Custom Server and migrated it to NextJS Middleware</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we upgraded our frontend architecture for performance]]></title>
            <link>https://medium.com/gocomet/how-we-upgraded-our-frontend-architecture-for-performance-5ac9e0edab98?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/5ac9e0edab98</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[seo]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Navneet Kumar]]></dc:creator>
            <pubDate>Thu, 09 Mar 2023 10:27:35 GMT</pubDate>
            <atom:updated>2023-03-09T10:27:35.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zYvw7VS94qEfJVkt" /><figcaption>Photo by <a href="https://unsplash.com/@olloweb?utm_source=medium&amp;utm_medium=referral">Agence Olloweb</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>As a company that values user experience, we realized that our website’s performance needed improvement. While our website is not an application, it is essential in growing our brand awareness. To ensure that users could quickly find us through search engine optimization (SEO), we needed to maintain fast loading speeds and rich web vitals. In this blog post, we’ll share how we upgraded our frontend architecture to boost our website’s performance.</p><h4>What is our website repo?</h4><p>Apart from our products’ frontend repo, we have a repo for a <a href="https://www.gocomet.com/">pure public website</a>. It displays information <a href="https://www.gocomet.com/about-us">about GoComet</a>, <a href="https://www.gocomet.com/freight-management-software">products</a>, <a href="https://www.gocomet.com/careers">careers</a>, <a href="https://www.gocomet.com/contact-us">contact</a>, etc. It doesn’t have any pages that would require authentication. All pages inside are public, and the contents are the same for all users.</p><h3>Why did we need to improve performance?</h3><p>At GoComet, we focus a lot on SEO to enable users to find us easily. SEO always asks for performance to rank. So, we must maintain a decent loading speed and rich web vitals.</p><p>Our website’s loading speed used to be slow. We use <a href="https://nextjs.org/">NextJS</a> for our frontend because NextJS pages hydrate on the server and serve the generated HTML to the browser (<a href="https://medium.com/gocomet/this-is-how-gocomet-is-building-its-frontend-tech-e73cbb420887">See more about our frontend tech stack</a>). This is very friendly for SEO (as compared to pure React which compiles on the browser).</p><p>But it had a huge problem that we were using <a href="https://nextjs.org/docs/api-reference/data-fetching/get-initial-props">getInitialProps</a> in our pages. This function performs some tasks after receiving the request and then populates the page accordingly. Typically, it’s used for asynchronous operations like data fetching. However, in our case, it was being used for trivial purposes like getting the layout.</p><p>Here’s an example of how we were using getInitialProps to assign page layouts. We then get this value in _app.jsx and render the layout accordingly.</p><figure><img alt="getInitialProps function writter for assigning layout" src="https://cdn-images-1.medium.com/max/483/1*7DOeSayCxT8QwhakpsMWjg.png" /><figcaption>example of a getInitialProps used for getting layout</figcaption></figure><p>However, remember that this method has a significant drawback — it enables server-side rendering while disabling static page generation. When a user requests a page, it is generated on the server and sent to the client. This process makes the pages load significantly slower and also strains the server’s CPU.</p><p>This was our web vitals score then:</p><figure><img alt="Web vitals performance showing overall score 64" src="https://cdn-images-1.medium.com/max/1024/1*MgiIIoihpKFe52C919c82g.jpeg" /><figcaption>Before Upgrade (Web vitals score by pagespeed.web.dev)</figcaption></figure><h3>What we did to improve it?</h3><p>Well, the getInitialProps is not the only problem. We discovered that the outdated version of NextJS we were using had limited features, which was one of several issues we faced.</p><p>We decided to fix these all at once and make the website super smooth.</p><p>We did the following things to improve our frontend architecture significantly:-</p><h4>1. Upgraded NextJS</h4><p>Our NextJS version was 8 at that time and the current version was 12. In an ideal scenario, people want to avoid jumping 2 or 3 major framework versions in one upgrade. Upgrading to the next major version and then upgrading one by one is often the safe option.</p><p>Despite that, we decided to jump directly four versions up! It was challenging nonetheless, but our team made a significant effort, and we spent some time fixing the compatibility issues. We also upgraded node.js <strong>from v8 to v14</strong> with it. At last, we were ready. Before diving into the approach to it, we had to address a few more things</p><h4>2. Upgraded all libraries to compatible versions with Next 12</h4><p>We upgraded every single library we use to the latest versions along with NextJS.</p><p><strong>Here’s the approach we took to do it:</strong></p><p>We first created a whole new app using yarn create next-app &lt;repo_name&gt;, this creates a new NextJS application (obviously with the current version).</p><p>Then we added all the packages back, including dev dependencies, using yarn add &lt;package_name&gt; without mentioning the version, so all the packages are installed with the latest LTS versions.</p><p>Then we moved our files and folders to this new app. We configured the app to match the latest version (as per the next.js doc). We had a significant SWC incompatibility issue, so <em>we had to disable that feature from next.config.js</em>. Fixed all the further problems and made it work.</p><blockquote>Only one package was not upgraded, next-redux-wrapper, because it had very major change.</blockquote><h4>3. Removed getInitialProps</h4><p>Finally, it’s time to remove getInitialProps.</p><p>We made some architectural changes and used other approaches to perform the tasks that we were previously doing in the getInitialProps. We removed the use of getInitialProps wherever possible. However, we couldn’t remove it in a few places due to specific use cases.</p><p>We even removed getInitialProps from the _app.jsx file, which is an entry point for all pages, as it was causing <strong>Automatic-Static-Generation to be disabled for all the pages</strong>. Although this was a difficult task because we were performing critical operations in getInitialProps in _app.jsx, we eventually succeeded.</p><p>And now, it&#39;s time to build the pages as static.</p><p>Nope! It didn’t happen….. But why?</p><figure><img alt="Warning showing “You have opted-out of Automatic Static Optimization due to `getInitialProps` in pages/_app”" src="https://cdn-images-1.medium.com/max/1024/1*UpqwFmTu3ScvFnhpdt2fmw.png" /><figcaption>Warning on build</figcaption></figure><p>The message still persists on build: You are opting out Automatic-Static-Generation because you used getInitialProps in your _app.jsx.</p><p>We were confused because we had removed it from this file.</p><p>But then, we realized that we were using a Higher-Order-Component (HOC) before exporting the App function in _app.jsx.</p><figure><img alt="export default withRedux(initStore)(App)" src="https://cdn-images-1.medium.com/max/492/1*XQg1qoIpX22a7FYvcerHcQ.png" /><figcaption>On the bottom on _app.jsx</figcaption></figure><p>This HOC comes from next-redux-wrapper, a package we use to compile redux on the server side. The only package that we didn’t upgrade. It turned out that this package was using getInitialProps internally.</p><p>In summary, even though we made significant changes to our code, including upgrading NextJS, modifying the architecture, and removing getInitialProps from everywhere, we could still not build the pages as static until we upgraded the <strong>next-redux-wrapper</strong> package that was using getInitialProps in the _app.jsx file.</p><h4>4. Removed next-redux-wrapper</h4><p>This library is used in our other frontend repos also, but here we realized that we don’t actually need the lib in this repo. Because there was nothing in the redux store to compile on the server. There are no authenticated pages so we don’t need any data on the server side. We decided to call all the APIs on the client side.</p><p>So, we removed next-redux-wrapper, and set up redux on the client level.</p><blockquote>In the current version, next-redux-wrapper does’t use getInitialProps</blockquote><p>Now, again, it&#39;s time to build and see our static pages.</p><figure><img alt="terminal message showing “Done in 39 seconds” without any warning" src="https://cdn-images-1.medium.com/max/820/1*CPDNC7NlQgjDM8t_LIfkfg.png" /><figcaption>last message on build</figcaption></figure><p>It happened! All the pages were populated and saved as HTML on build time, and now on hitting the URL, the static page comes to the browser which is super fast.</p><h4>5. Managed environment variables at build time</h4><p>Our challenges didn’t end here. When we had server-side-rendering, then we get all the environment variables from the server (host) i.e. GCP. However, we now generate pages at build time only, which occurs on Docker using Jenkins. We don’t have access to any environment variables during the build process.</p><p>Adding all the variables on build time is impossible, so we added some variables during the build time and created additional variables using those available variables through specific methods (most of our variables are API base URLs that depend on the subdomain).</p><p>Example:</p><pre>/*<br> * we added the subdomain in the Jenkins environment<br> * and now we are using that to create other variables<br> * that we were taking from .env<br>*/<br>const LIBRARY_API_ROOT_URL = `https://library.${subdomain}.gocomet.com/api/v1`;</pre><h3>Result</h3><p>It was time, the moment we had all been waiting for, which was to hit production, and when we did, our team rejoiced to see no reported errors from the QA teams or the clients.</p><p>In addition to that, our pages got faster than ever. Static files are cached easily, so after some hits, it got quicker.</p><p>We were happy to see our SEO performance spike and our page ranking rise to the top.</p><figure><img alt="Web vitals performance showing overall score 83" src="https://cdn-images-1.medium.com/max/1024/1*G1M3qxVIzJBOzBnpYw9kBQ.jpeg" /><figcaption>After Upgrade (Web vitals score by pagespeed.web.dev)</figcaption></figure><figure><img alt="SEO insight of our website showing 4x improvement after upgrade" src="https://cdn-images-1.medium.com/max/923/1*-qXTZJUbobFEnyfvsKqp_g.jpeg" /><figcaption>Improvement in SEO due to upgrade</figcaption></figure><p>Our server’s CPU load also got very lower because now pages are not compiling on the server on every hit.</p><p>You can experience the loading speed by going to these pages:<br>1. <a href="https://www.gocomet.com/">GoComet Homepage</a><br>2. <a href="https://www.gocomet.com/container-tracking-software">GoTrack product page</a><br>3. <a href="https://www.gocomet.com/freight-quotation-management-software">GoProcure product page</a></p><p>Thanks for reading this blog, please let us know your views in the comments, we’d love to hear from you.</p><h3>Join Our Team 💫</h3><p>If you wish to join our super cool and growing team. Reach out to us via our <a href="https://www.gocomet.com/careers"><em>career page</em></a> or via <a href="https://www.linkedin.com/company/go-comet/"><em>LinkedIn</em></a>.<br>We are always looking for great folks to build and grow with us :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ac9e0edab98" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/how-we-upgraded-our-frontend-architecture-for-performance-5ac9e0edab98">How we upgraded our frontend architecture for performance</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[This is how Gocomet is building its Frontend Tech]]></title>
            <link>https://medium.com/gocomet/this-is-how-gocomet-is-building-its-frontend-tech-e73cbb420887?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/e73cbb420887</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[stack]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Ruchi Sharma]]></dc:creator>
            <pubDate>Wed, 18 Jan 2023 06:51:27 GMT</pubDate>
            <atom:updated>2023-01-18T08:27:13.627Z</atom:updated>
            <content:encoded><![CDATA[<p><em>“Your website is the center of your digital eco-system, like a brick and mortar location, the experience matters once a customer enters, just as much as the perception they have of you before they walk through the door.”<br>― Leland Dieno</em></p><p>The front end of any application is the only playground for customers to interact. Thus, giving a smooth experience to its customers is a demanding real-time challenge for a company, especially for a product-based company like Gocomet, where you are tech-heavy and product-led sales are your aim.</p><p>In this blog, you will find what our engineers are working on to deliver a consistent quality product to our clients, and what technical skills you would need in case you want to join us ;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*IY08HqiemlFZVanfa5xYNw.png" /><figcaption>Frontend</figcaption></figure><p>Being a product company is always full of technical challenges and innovation which is the most fun and exciting work. You solve real-time problems for customers who have a history of doing business for millions or billions of dollars only through meetings, calls, and emails. The customers get excited to see how technology is solving the bottlenecks of their business which sometimes they even didn’t know existed.</p><p>That’s the challenge we at Gocomet are solving. The complex international logistics industry works 24x7 across the world and handles cargo worth trillions of dollars. We started back in 2016 intending to build a one-stop solution for all international logistics issues. Glad to tell you, we have big happy clients like SunPharma, Polymers International, Glenmark, Tafe, HUL, etc.</p><p>Choosing a front-end tech stack to deliver value to such enterprises needs thorough planning and research. Through this blog, we would like to show the thought process behind the setup that we currently have at Gocomet.</p><h4><strong>Frontend Tech Architecture</strong></h4><blockquote><em>It is said, “Only through meticulous planning and revisiting the challenges, can you finally achieve success.”</em></blockquote><p>We have had a similar journey, where we built products and solved problems in the logistics industry.</p><p>Our engineering stack started with a monolithic architecture, and we are currently building a micro frontend architecture with four independent services running.</p><p>Below is an illustration explaining it.</p><figure><img alt="Micro frontend architecture at Gocomet" src="https://cdn-images-1.medium.com/max/1024/1*oJPhZldc-x49vbSdQN5J5w.png" /><figcaption>Micro-frontend architecture</figcaption></figure><p>The above diagram is the high-level architecture of our frontend system, which is split into four independent apps working loosely together. Each of them is maintained and deployed independently and serves an individual purpose.</p><p><strong>Core Product App: </strong>It handles our core enterprise clients, large MNCs dealing with international logistics, and has access to our main products.</p><p>Each of the products has its tough journey from core features to an advanced products as it has iterated with continuous feedback from multiple clients over a long period of time.</p><p>This app requires both maintenance and evolution with our client&#39;s requirements; maintaining quality with new changes is the main goal here.</p><p><strong>Experimental or Growth App: </strong>It is the app where we continuously experiment with new ideas and products. These MVPs are then tested in the market.</p><p>As International logistics is highly manual with heavy dependency on excel and email, technology adaptation here is low. We are leading the changes in this space. For that, we develop new product ideas to test our hypothesis every now and then, which could solve the problem.</p><p><strong>Common Services App: </strong>It handles the shared services and components divided among other apps. It is a single place of frequently used modules, built with the aim to ensure a similar experience across all apps, and reduce redundancy, faster changes, and code robustness.</p><p><strong>Website: </strong>It is our main website app. Whether you are an enterprise or a general customer, you can check out a trial of our products on it. Don’t forget to drop us feedback :) <br>Link — <a href="https://www.gocomet.com/">https://www.gocomet.com/</a></p><h4><strong>Frontend Tech Stack</strong></h4><p>A tech stack comes with many technical layers, each of which has its own pros and cons and entirely depends on one’s choice of what suits their requirement best at a particular time.</p><p>The following illustration offers a simple perspective into building a simple yet scalable frontend architecture around our chosen core technologies.</p><figure><img alt="tech stack at Gocomet" src="https://cdn-images-1.medium.com/max/1024/1*si8tn_Biq_7a5A5IJk33hg.png" /><figcaption>Tech stack at Gocomet</figcaption></figure><p><strong>Environment<br></strong>To develop a server-rendered application for better SEO and fast loading, we have built our front-end applications on a node environment independent of the backend.</p><p><strong>node<em> </em></strong>and <strong>npm<em> </em></strong>— package environment, for server-side development of web apps in javascript.</p><p><strong>Core libraries <br></strong>While choosing core libraries, we looked for frameworks with easier development along with strong community support, that also meets our requirements of building enterprise-specific UI components, and would make code structure more robust.</p><p><strong>react</strong> — Core Js library<br><strong>js/typescript</strong> — Core language<em><br></em><strong>antd — </strong>UI Library for enterprises. It gives many features for data-heavy components like tables, cards, filters, etc., which is what we need. <br><strong> styled-component — </strong>CSS-in-JS styling framework, allows you to write actual CSS to style React components.</p><p><strong>Linters and formatter<br></strong>For all kinds of pattern issues in javascript and consistent code styles throughout the whole codebase. We prefer -</p><p><strong>eslint</strong><em> </em>— linter for our ECMAScript.<br><strong>prettier</strong>— formatter that works with eslint plugins.</p><p><strong>Routing, bundler, transpiler, PWA<br></strong>We use the simple page-based routing framework which supports server rendering, fast development, and SEO.</p><p><strong>nextjs</strong> — from server rendering to default webpack bundler to routing to hot reloading, it handles many core features. It’s a highly recommended lib for building service-side apps. <br><strong>babel</strong> — helps us <em>transpile</em> our JS compatible with old browsers and new browsers with its support libraries.<br><strong>next-pwa</strong> — ‘nextjs progressive web app’ lib for mobile device features on the website, without requiring the end user to visit an app store, along with fast reloading, offline access, and push notifications.</p><p><strong>State Management<br></strong>To build a global data state for client details that can be shared among products and can be managed at a single point.</p><p><strong>redux</strong> — js library for managing and centralizing application state</p><p><strong>Testing<br></strong>To examine functionality in our applications during the development phase, we needed frameworks with strong support and a wide range of test assertions to test all possible unit features in our code base. We find the perfect fit that matches our requirements. Here is,</p><p><strong>jest</strong> — test environment to build and run our unit and snapshot tests.<br><strong>MSWjs</strong> — mocks the APIs to test network requests. <br>We find this lib has solved our issue for backend API testing with easy configuration and accessibility.<br><strong>testing-library/react</strong> — complete React DOM testing utilities and framework.</p><p><strong>Design Framework<br></strong>To avoid redundancy and build documentation for the component. We prefer -</p><p><strong>storybook </strong>— tool to build UI components which isolated from the business logic and context of the app</p><p><strong>Blogs and SEO<br>wordPress</strong> — publicly hosted third-party blog application.<br><strong>Lighthouse, Site Speed, google analytics — </strong>tools to manage SEO. (We have our journey with SEO scores from 20 to 100, which we will share in coming blogs.</p><p>These are the core libs and tools which we are using for our multiple applications according to our requirements; definitely, there are other supporting libs and dev dependencies that need to be mentioned here.</p><p><strong>Vision</strong><br>Our frontend team has scaled from 5 to 15 in the last 1 year, which brings us the responsibility of maintaining the code health and trying out new tech things in the market to give a better user experience to our clients.</p><p>Here are our aspirations about the same.</p><p>&gt; Work on the scalability of our code base with increased features.<br>&gt; Maintaining code health with robust architecture and guidelines.<br>&gt; Sharing and skilling up tech skills to be the best front-end team.<br>&gt; Building an automated process for developers’ growth.</p><h4><strong>Conclusion</strong></h4><p>As a Sass, we are continuously working on adapting to the challenges of international logistics.</p><p>Continuously scaling to build faster MVP for new products, maintaining the standard of the products, and meeting existing customer expectations is not an easy job, and that’s why we all love to work through it and skill up to our best level to aspire the best user experience for our client.</p><p>Let us know your views and opinions on our tech stack in the comments. We’d love to hear from you !!</p><h4>Join Our Team 💫</h4><p>If you wish to join our super cool and growing team, reach out to our <a href="https://www.gocomet.com/careers"><em>career page</em></a> or on <a href="https://www.linkedin.com/company/go-comet/"><em>LinkedIn</em></a>. <br>We are always looking for great folks to build and grow with us :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e73cbb420887" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/this-is-how-gocomet-is-building-its-frontend-tech-e73cbb420887">This is how Gocomet is building its Frontend Tech</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your EXIM stand out from the crowd by propelling your customer service journey]]></title>
            <link>https://medium.com/gocomet/make-your-exim-stand-out-from-the-crowd-by-propelling-your-customer-service-journey-cb7def0d0464?source=rss----68e263d32af2---4</link>
            <guid isPermaLink="false">https://medium.com/p/cb7def0d0464</guid>
            <category><![CDATA[freight-management-system]]></category>
            <category><![CDATA[customer-experience]]></category>
            <category><![CDATA[crm]]></category>
            <category><![CDATA[customer-service]]></category>
            <dc:creator><![CDATA[Apoorv Gokhale]]></dc:creator>
            <pubDate>Fri, 05 Jul 2019 18:02:50 GMT</pubDate>
            <atom:updated>2019-07-05T18:02:49.981Z</atom:updated>
            <content:encoded><![CDATA[<p>Historically, the term <em>logistics</em> has been associated merely with the transportation of goods from points A to B. In the last couple of decades, however, its scope has broadened to include complementary services such as packaging, storage, cargo handling, etc. As a result, customers are now also looking for these services from their suppliers.</p><p>As technology has evolved, the expectations of customers have in turn risen even more. Traditionally at most export/import (EXIM) businesses, the logistics process would include people from operations, the factory team, and an external logistics service provider, whilst the marketing, business development, and finance teams would be involved in the documentation or other formalities.</p><p>A relatively new addition to the logistics process is the customer service team. Initially thought of as an offshoot of marketing, the importance of the customer service department has grown exponentially.</p><p>With growing competition, many businesses are realising the importance of customer satisfaction and how this is intrinsically linked to customer retention. A strong bond with your customer lays the groundwork for long-standing business ties. Although it is the marketing team that lays the foundation, it is your customer service team that builds strong, long-lasting relations on top through consistent client engagement.</p><p>Here too, technology is poised to play a big part and this is evident from the adoption of various customer relationship management (CRM) tools already available on the market. The industry for CRM software is now valued over $40 billion and is poised to touch $80 billion by 2025 (IBM, Superoffice). As a result, many companies are now looking at other innovative avenues to add value to their CRM efforts and make them stand out from the crowd.</p><p>Within logistics, one of the major opportunities to enhance the customer experience is to facilitate customer visibility over their cargo status. This method has already been vindicated by the majority of major e-commerce players as they jostle to gain prominence in that crowded market. Similarly, within the EXIM industry, cargo status updates form a major part of their CRM efforts. Despite this, however, the current process is often prone to errors and missed updates due to excessive dependency on manual inputs.</p><p>GoComet offers you the solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*uKSdz9snq6sblS-uOEwIkA.png" /></figure><p>For any EXIM business, the easiest way to eliminate these errors and automate real-time cargo status updates is by using GoComet’s proprietary container tracking solution. Our unique ‘single source of truth’ platform allows you to constantly monitor your good’s shipment movements from a unified, consolidated screen — whomever the freight forwarder or shipping line — and in addition provides you with proactive updates throughout its journey. What’s more, you can also enable your customers to access and enjoy this service to track their shipments and receive customised notifications directly to their email inbox.</p><p>Mirroring the impact of CRM software, GoComet’s container tracking solution is propelling the customer service of our clients to the next level. With year-on-year client adoption growth of 300%, GoComet’s container tracking changing the landscape of international logistics customer service.</p><p>GoProfits. GoDigital. GoComet.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb7def0d0464" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gocomet/make-your-exim-stand-out-from-the-crowd-by-propelling-your-customer-service-journey-cb7def0d0464">Make your EXIM stand out from the crowd by propelling your customer service journey</a> was originally published in <a href="https://medium.com/gocomet">GoComet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>