<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Samvita Karkal on Medium]]></title>
        <description><![CDATA[Stories by Samvita Karkal on Medium]]></description>
        <link>https://medium.com/@samvitaskarkal?source=rss-f5c865fa1aef------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*V21HpwYlauvojzD68jmkhQ.jpeg</url>
            <title>Stories by Samvita Karkal on Medium</title>
            <link>https://medium.com/@samvitaskarkal?source=rss-f5c865fa1aef------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 14:58:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samvitaskarkal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Guide To Optimize Your APIs Part 2: Memory Efficiency]]></title>
            <link>https://blog.nonstopio.com/guide-to-optimize-your-apis-part-2-memory-efficiency-8aaa7e4f6235?source=rss-f5c865fa1aef------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aaa7e4f6235</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[memory-improvement]]></category>
            <category><![CDATA[memory-management]]></category>
            <dc:creator><![CDATA[Samvita Karkal]]></dc:creator>
            <pubDate>Thu, 06 Feb 2025 05:55:05 GMT</pubDate>
            <atom:updated>2025-02-06T05:55:05.202Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5qVBEf94FUEQt6Ehq5H2g.png" /><figcaption>How to optimize memory usage of your APIs</figcaption></figure><p>In the <a href="https://blog.nonstopio.com/guide-to-optimize-your-apis-part-1-performance-efficiency-2cace1d7e5ff">first part of this series</a>, we explored various strategies to enhance <strong>API performance</strong> by reducing response times and optimizing queries. Now, let’s dive into another crucial aspect of API optimization — <strong>memory efficiency</strong>.</p><p>Have you ever encountered a situation where your API runs smoothly in <strong>development</strong> but crashes in <strong>production</strong> due to high memory usage? Or maybe your server constantly runs at <strong>95–99% memory utilization</strong>, causing slow responses or unexpected failures? If so, it’s time to dive into <strong>memory optimization</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gCY7bemf--rSMVgH-_9Jjg.png" /><figcaption>Overly used memory, overheated and ready to explode</figcaption></figure><p>Performance optimization in API development involves improving the efficiency, speed, and scalability of an API to handle requests more effectively. The goal is to minimize response times, reduce resource consumption, and ensure that the API can handle a high volume of requests without degrading performance.</p><h3>HOW TO OPTIMIZE PERFORMANCE OF YOUR API?</h3><p>Let’s say you have an API that takes a lot of time to load. To optimize this API, you can consider the following approaches:</p><h4>1. Query Optimization:</h4><p>👉 <strong>Indexing:</strong> Ensure you have optimally indexed database columns used in your query (particularly the foreign keys and most accessed attributes).<br> 👉 <strong>Query Optimization:</strong> Use <em>EXPLAIN</em> to analyze the query and identify any inefficiencies. Try to make queries as simple as possible.<br> 👉 <strong>Pagination:</strong> Implement pagination for large data sets.<br> 👉 <strong>Caching:</strong> Cache the results of the query most fetched.</p><h4>2. Asynchronous Processing:</h4><p>👉 <strong>Background Jobs:</strong> Offload fetching expensive operations to a background job, allowing the API to respond immediately and send the results to the client once ready using Polling/Callbacks mechanisms.</p><h4>3. API Response Optimization:</h4><p>👉 <strong>Selective Data Loading:</strong> Only return the data that is necessary for the client. Avoid fetching and returning large amounts of unnecessary data.<br> 👉<strong>JSON Serialization:</strong> Use efficient JSON serialization techniques with optimized templates to serialize the data quickly (eg: Jbuilder)<br> 👉 <strong>Eager Loading:</strong> Use `<em>eager_load</em>` or `<em>includes</em>` to preload associated data to avoid the N+1 query problem (in ruby).</p><h4>4. Parallelization:</h4><p>👉 <strong>Multithreading/Multiprocessing:</strong> If possible, process certain operations in parallel using threads or processes to reduce the overall time.<br> 👉 <strong>Concurrent Requests:</strong> If the data is coming from multiple sources, consider making concurrent API calls to gather the data simultaneously.</p><h4>5. Rate Limiting and Throttling:</h4><p>👉 <strong>Rate Limiting:</strong> Implement rate limiting to prevent abuse and excessive load on the API. This helps maintain consistent performance during high-traffic periods.<br> 👉 <strong>Throttling:</strong> Throttle requests from individual users or clients to prevent them from overloading the API.</p><h4>6. Load Balancing:</h4><p>Distribute the API requests across multiple servers using a load balancer. This helps manage traffic more effectively and prevents any single server from becoming a bottleneck.</p><h4>Conclusion:</h4><p>By combining these approaches, you can significantly reduce the load time of the API and provide a more responsive experience to the users.</p><p>Also, there are multiple tools available online that can help you analyze your API performance and help you with optimization. Some of these tools are:<br>1. <a href="https://www.datadoghq.com/dg/apm/application-observability/?utm_source=google&amp;utm_medium=paid-search&amp;utm_campaign=dg-apm-apac-india&amp;utm_keyword=application%20performance%20optimization&amp;utm_matchtype=p&amp;igaag=153090778752&amp;igaat=&amp;igacm=20461585326&amp;igacr=670220208924&amp;igakw=application%20performance%20optimization&amp;igamt=p&amp;igant=g&amp;utm_campaignid=20461585326&amp;utm_adgroupid=153090778752&amp;gad_source=1&amp;gclid=CjwKCAiAnKi8BhB0EiwA58DA4SwYpVhhpNrbNtFNFIWCq9kYt_L3di_V91IqflMYYCp3MTjxVw-2gBoCa_oQAvD_BwE">DataDog</a><br>2. <a href="https://newrelic.com/lp/developersignup-wglp?utm_medium=cpc&amp;utm_source=google&amp;utm_campaign=EVER-GREEN_BRAND_SEARCH_BRAND_APAC_INDIA_EN&amp;utm_network=g&amp;utm_keyword=new%20relic&amp;utm_device=c&amp;_bt=665522260713&amp;_bm=e&amp;_bn=g&amp;cq_cmp=11600474383&amp;cq_con=112697457323&amp;cq_plac=&amp;l5_source=googleads&amp;l5_cid=11600474383&amp;l5_adid=665522260713&amp;mkt_network=g&amp;adgroup=new_relic&amp;gad_source=1&amp;gclid=CjwKCAiAnKi8BhB0EiwA58DA4SrAUAf-qzFulL5dxRIoR-QGIR0RDhLd2b1znfinQxh8aIcPXHb6LBoCGJ0QAvD_BwE">NewRelic</a><br>3. <a href="https://www.dynatrace.com/">Dynatrace</a></p><p>For further optimization techniques, stay tuned!</p><h3>You can follow me on:</h3><ul><li><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/samvita-karkal-354628168/">https://www.linkedin.com/in/samvita-karkal-354628168/</a></li><li><strong>X / Twitter</strong>: <a href="https://x.com/karkalsamvita">https://x.com/karkalsamvita</a></li><li><strong>Peerlist: </strong><a href="https://peerlist.io/samvitak">https://peerlist.io/samvitak</a></li></ul><blockquote>Here to make the community stronger by sharing our knowledge. Follow <a href="https://medium.com/@samvitaskarkal">me</a> and <a href="https://medium.com/nonstopio">my team</a> to stay updated on the latest and greatest in the web &amp; mobile tech world.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aaa7e4f6235" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/guide-to-optimize-your-apis-part-2-memory-efficiency-8aaa7e4f6235">Guide To Optimize Your APIs Part 2: Memory Efficiency</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guide To Optimize Your APIs Part 1: Performance Efficiency]]></title>
            <link>https://blog.nonstopio.com/guide-to-optimize-your-apis-part-1-performance-efficiency-2cace1d7e5ff?source=rss-f5c865fa1aef------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cace1d7e5ff</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Samvita Karkal]]></dc:creator>
            <pubDate>Tue, 21 Jan 2025 06:54:52 GMT</pubDate>
            <atom:updated>2025-01-22T06:50:54.505Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*et9UE4IAMWJLIkm2K7NhGQ.png" /><figcaption>How to make your apps performace efficient</figcaption></figure><p>Are you a backend engineer looking forward to take the next step in your career? Do you want your work to show more efficiency and impact than it does now?</p><p>To function as a mid/senior developer, you <strong>NEED</strong> to start thinking of how you can optimize your APIs for better performance. For this we need to understand the different considerations needed to be made to optimize APIs and how can they be implemented in our solutions.</p><p>API optimization can be broken down into several categories, each targeting different aspects of performance, scalability, and memory efficiency. These are as follows:</p><ol><li><strong>Performance Optimization</strong><br><strong>Goal:</strong> Reduce latency and improve response times.</li><li><strong>Memory Optimization<br>Goal:</strong> Reduce memory leaks and ensure efficient memory usage.</li><li><strong>Database Optimization<br>Goal:</strong> Speed up data access and reduce DB overhead.</li><li><strong>Network Optimization</strong><br><strong>Goal:</strong> Reduce network latency and improve data transfer efficiency.</li><li><strong>Rate Limiting and Security<br>Goal:</strong> Protect APIs from abuse while maintaining performance.</li><li><strong>Scalability Optimization<br>Goal:</strong> Ensure the API can handle increasing traffic and load.</li><li><strong>Code and Logic Optimization<br>Goal:</strong> Make API code more efficient and performant.</li><li><strong>Response Time Optimization<br>Goal:</strong> Reduce response delays and ensure fast returns.</li></ol><p>In this part, let’s focus on <strong>Performance Optimization,</strong> understanding <strong>what it is, why is it needed</strong> and <strong>how can it be implemented in your application</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AgMkFr7WF9vbSqVnN_IiXA.png" /><figcaption>Approach taken by smart developers who want to progress in their careers</figcaption></figure><h3>WHAT IS PERFORMANCE OPTIMIZATION?</h3><p>Performance optimization in API development involves improving the efficiency, speed, and scalability of an API to handle requests more effectively. The goal is to minimize response times, reduce resource consumption, and ensure that the API can handle a high volume of requests without degrading performance.</p><h3>HOW TO OPTIMIZE PERFORMANCE OF YOUR API?</h3><p>Let’s say you have an API that takes a lot of time to load. To optimize this API, you can consider the following approaches:</p><h4><strong>1. Query Optimization:</strong></h4><p>👉 <strong>Indexing:</strong> Ensure you have optimally indexed database columns used in your query (particularly the foreign keys and most accessed attributes).<br> 👉 <strong>Query Optimization:</strong> Use <em>EXPLAIN</em> to analyze the query and identify any inefficiencies. Try to make queries as simple as possible.<br> 👉 <strong>Pagination:</strong> Implement pagination for large data sets.<br> 👉 <strong>Caching:</strong> Cache the results of the query most fetched.</p><h4><strong>2. Asynchronous Processing:</strong></h4><p>👉 <strong>Background Jobs:</strong> Offload fetching expensive operations to a background job, allowing the API to respond immediately and send the results to the client once ready using Polling/Callbacks mechanisms.</p><h4><strong>3. API Response Optimization:</strong></h4><p>👉 <strong>Selective Data Loading:</strong> Only return the data that is necessary for the client. Avoid fetching and returning large amounts of unnecessary data.<br> 👉<strong>JSON Serialization:</strong> Use efficient JSON serialization techniques with optimized templates to serialize the data quickly (eg: Jbuilder)<br> 👉 <strong>Eager Loading:</strong> Use `<em>eager_load</em>` or `<em>includes</em>` to preload associated data to avoid the N+1 query problem (in ruby).</p><h4><strong>4. Parallelization:</strong></h4><p>👉 <strong>Multithreading/Multiprocessing:</strong> If possible, process certain operations in parallel using threads or processes to reduce the overall time.<br> 👉 <strong>Concurrent Requests:</strong> If the data is coming from multiple sources, consider making concurrent API calls to gather the data simultaneously.</p><h4><strong>5. Rate Limiting and Throttling:</strong></h4><p>👉 <strong>Rate Limiting:</strong> Implement rate limiting to prevent abuse and excessive load on the API. This helps maintain consistent performance during high-traffic periods.<br> 👉 <strong>Throttling:</strong> Throttle requests from individual users or clients to prevent them from overloading the API.</p><h4><strong>6. Load Balancing:</strong></h4><p>Distribute the API requests across multiple servers using a load balancer. This helps manage traffic more effectively and prevents any single server from becoming a bottleneck.</p><h4>Conclusion:</h4><p>By combining these approaches, you can significantly reduce the load time of the API and provide a more responsive experience to the users.</p><p>Also, there are multiple tools available online that can help you analyze your API performance and help you with optimization. Some of these tools are:<br>1. <a href="https://www.datadoghq.com/dg/apm/application-observability/?utm_source=google&amp;utm_medium=paid-search&amp;utm_campaign=dg-apm-apac-india&amp;utm_keyword=application%20performance%20optimization&amp;utm_matchtype=p&amp;igaag=153090778752&amp;igaat=&amp;igacm=20461585326&amp;igacr=670220208924&amp;igakw=application%20performance%20optimization&amp;igamt=p&amp;igant=g&amp;utm_campaignid=20461585326&amp;utm_adgroupid=153090778752&amp;gad_source=1&amp;gclid=CjwKCAiAnKi8BhB0EiwA58DA4SwYpVhhpNrbNtFNFIWCq9kYt_L3di_V91IqflMYYCp3MTjxVw-2gBoCa_oQAvD_BwE">DataDog</a><br>2. <a href="https://newrelic.com/lp/developersignup-wglp?utm_medium=cpc&amp;utm_source=google&amp;utm_campaign=EVER-GREEN_BRAND_SEARCH_BRAND_APAC_INDIA_EN&amp;utm_network=g&amp;utm_keyword=new%20relic&amp;utm_device=c&amp;_bt=665522260713&amp;_bm=e&amp;_bn=g&amp;cq_cmp=11600474383&amp;cq_con=112697457323&amp;cq_plac=&amp;l5_source=googleads&amp;l5_cid=11600474383&amp;l5_adid=665522260713&amp;mkt_network=g&amp;adgroup=new_relic&amp;gad_source=1&amp;gclid=CjwKCAiAnKi8BhB0EiwA58DA4SrAUAf-qzFulL5dxRIoR-QGIR0RDhLd2b1znfinQxh8aIcPXHb6LBoCGJ0QAvD_BwE">NewRelic</a><br>3. <a href="https://www.dynatrace.com/">Dynatrace</a></p><p>For further optimization techniques, stay tuned!</p><h3>You can follow me on:</h3><ul><li><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/samvita-karkal-354628168/">https://www.linkedin.com/in/samvita-karkal-354628168/</a></li><li><strong>X / Twitter</strong>: <a href="https://x.com/karkalsamvita">https://x.com/karkalsamvita</a></li><li><strong>Peerlist: </strong><a href="https://peerlist.io/samvitak">https://peerlist.io/samvitak</a></li></ul><blockquote>Here to make the community stronger by sharing our knowledge. Follow <a href="https://medium.com/@samvitaskarkal">me</a> and <a href="https://medium.com/nonstopio">my team</a> to stay updated on the latest and greatest in the web &amp; mobile tech world.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cace1d7e5ff" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/guide-to-optimize-your-apis-part-1-performance-efficiency-2cace1d7e5ff">Guide To Optimize Your APIs Part 1: Performance Efficiency</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails Through the Years: Key Changes from Version 1 to 8]]></title>
            <link>https://blog.nonstopio.com/rails-through-the-years-key-changes-from-version-1-to-8-123996b583f7?source=rss-f5c865fa1aef------2</link>
            <guid isPermaLink="false">https://medium.com/p/123996b583f7</guid>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[web-apps]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Samvita Karkal]]></dc:creator>
            <pubDate>Thu, 02 Jan 2025 04:46:54 GMT</pubDate>
            <atom:updated>2025-01-02T04:46:54.263Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8IonEem5qw47D_8MlQFFeA.png" /><figcaption>Rails Through the Years: Key Changes from Version 1 to 8</figcaption></figure><p>Ruby on Rails has been a cornerstone in web development since its inception, empowering developers to build scalable and maintainable web applications. As Rails evolved, each version introduced features, performance improvements, and enhanced security. Due to its open-source nature, developers continuously tackled existing issues and added improvements, keeping the framework aligned with emerging trends. So, let’s read along to uncover the journey of Rails as a framework from inception to latest advances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pWU1avosew-Fmypi" /><figcaption>Change, the only constant in technology</figcaption></figure><h3>The Birth of Rails (2004): Why Rails Was Created</h3><p>In the early 2000s, building web applications was often tedious and required repetitive code for handling database interactions and application logic. <strong>David Heinemeier Hansson (DHH)</strong>, while developing Basecamp, recognized the need for a framework that emphasized <strong>convention over configuration</strong> and <strong>developer happiness</strong>.</p><ul><li><strong>Core Philosophy of Rails:</strong></li></ul><blockquote><strong>DRY (Don’t Repeat Yourself):</strong> Reduce code duplication by abstracting repetitive patterns.</blockquote><blockquote><strong>Convention over Configuration:</strong> Provide sensible defaults to minimize configuration overhead.</blockquote><blockquote><strong>Full-stack Framework:</strong> Offer tools for the entire development process, from database migrations to front-end asset management.</blockquote><p>Rails was born to streamline web development by reducing boilerplate code and offering a structured yet flexible framework.</p><h3>Rails 1 (2005): The Beginning of Simplicity</h3><p><em>Rails 1 introduced the world to a fresh and revolutionary way of building web applications, focusing on developer productivity and ease of use.</em></p><ul><li><strong>Key Changes:</strong></li></ul><blockquote><strong>1. ActiveRecord:</strong> Provided an ORM for managing database records.<br><strong>2. Scaffolding:</strong> Automatically generated models, views, and controllers, accelerating prototyping.<br><strong>3. Migrations:</strong> Simplified database schema changes, reducing manual SQL writing.<br><strong>4. Helper Methods:</strong> Encouraged code separation for cleaner views and better maintainability.<br><strong>5. Integrated Testing:</strong> Testing became an essential part of Rails, streamlining the TDD process.</blockquote><p>Rails 1 was a good start. In 2006, it won the <strong>“Programming Language of the Year” award from Tiobe </strong>but then the dev team started facing some issues such as:<br>1. limited scalability for larger applications.<br>2. lack of RESTful routing led to disorganized controllers.<br>3. Security vulnerabilities such as mass assignment risks were prevalent.</p><p>This lead to the next version of Rails, Rails 2.</p><h3>Rails 2 (2007): Strengthening the Foundation</h3><p><em>Rails 2 solidified the framework by enhancing scalability, introducing RESTful design, and improving security.</em></p><ul><li><strong>Key Changes:</strong></li></ul><blockquote><strong>1. RESTful Routing:</strong> Simplified and standardized how applications handled URLs and controllers.<br><strong>2. Resource Generators:</strong> Enhanced scaffolding to align with RESTful architecture.<br><strong>3. HTTP Caching:</strong> Improved performance by adding built-in HTTP caching mechanisms.<br><strong>4.</strong> <strong>Security Enhancements:</strong> CSRF protection was introduced to prevent cross-site request forgery attacks.<br><strong>5. Gems and Plugins:</strong> Simplified the addition of third-party libraries and plugins.</blockquote><ul><li><strong>Notable Methods/Features:</strong></li></ul><blockquote>named_scope =&gt; for chaining query methods.</blockquote><blockquote>before_filter =&gt; (later before_action) for DRY controller actions.</blockquote><blockquote>respond_to =&gt; for handling multiple response formats (HTML, JSON, XML).</blockquote><p>The popularity of Rails has now started rising. Major web applications like <strong>Twitter, Hulu, </strong>and<strong> Shopify</strong> started using it as their <strong>base framework</strong>.</p><p>On 23 December 2008, <a href="https://en.wikipedia.org/wiki/Merb">Merb</a>, another web application framework, was launched which was very similar to Rails and caused a lot of clashes in their respective communities. This is when the Rails team worked with Merb and Merb was merged into Rails. Yet, the system had its own flaws. The plugins and gems lacked standardization, performance bottlenecks in complex queries were becoming a pain, and manual handling of state and complex model logic was becoming problematic.</p><h3>Rails 3 (2010): Consolidation and Modularization</h3><p><em>Rails 3 marked a pivotal moment in Rails’ history by unifying fragmented components into a cohesive framework. This version laid the foundation for modern Rails, streamlining development and improving performance.</em></p><ul><li><strong>Key Changes:</strong></li></ul><blockquote><strong>1. Merging of Rails Components:</strong> Unified Rails components (ActionPack, ActiveModel, etc.) into a single cohesive framework to reduce fragmentation and improve maintainability.<br><strong>2. ActiveRelation:</strong> Introduced to enhance ActiveRecord queries through method chaining, improving readability and performance.<br><strong>3. Validations Refactor:</strong> Extracted and modularized ActiveModel validations, allowing reuse outside of ActiveRecord for greater flexibility.<br><strong>4. Routing Enhancements:</strong> Simplified route definitions with a new DSL, addressing the need for more readable and organized routing.<br><strong>5. XSS Protection by Default:</strong> Strengthened security by default to combat rising cross-site scripting vulnerabilities.</blockquote><ul><li><strong>Notable Methods/Features:</strong></li></ul><blockquote>where method for ActiveRecord to simplify complex queries.</blockquote><blockquote>respond_to improved to handle multiple response formats elegantly.</blockquote><blockquote>Asset pipeline (added in 3.1) to standardize JavaScript, CSS, and image management, addressing scalability concerns for front-end assets.</blockquote><p>Now, these changes caused their own set of issues. The asset pipeline added complexity in development workflows. Performance issues started occurring in large-scale deployments and background job handling was limited.</p><h3>Rails 4 (2013): Performance and Convention Improvements</h3><p><em>Building on the solid foundation of Rails 3, Rails 4 refined performance, improved security, and introduced conventions that made applications more robust.</em></p><ul><li><strong>Key Changes:</strong></li></ul><blockquote><strong>1. Strong Parameters:</strong> Added to prevent mass assignment vulnerabilities, following increased security concerns around parameter tampering.<br><strong>2.</strong> <strong>Turbolinks:</strong> Boosted performance by loading partial HTML rather than full page reloads, addressing slow navigation.<br><strong>3. Background Jobs:</strong> ActiveJob introduced as an abstraction layer, allowing standardized background processing across different job backends.<br><strong>4. ActionMailer Enhancements:</strong> Simplified email templates and enabled inline previews to improve developer productivity.<br><strong>5. Concerns:</strong> Encouraged separation of shared logic into concerns, addressing code organization and reducing model bloat.</blockquote><ul><li><strong>Notable Methods/Features:</strong></li></ul><blockquote>belongs_to associations became required by default to prevent data integrity issues.</blockquote><blockquote>enum for ActiveRecord to manage state with integer mappings, reflecting the need for simpler state management.</blockquote><blockquote>has_secure_password incorporated directly into ActiveModel to simplify authentication workflows.</blockquote><p>In this version, <strong>turbolinks</strong> introduced inconsistencies with complex JavaScript applications, asset pipeline performance slowed with as the apps grew in size and <strong>Redis</strong> dependency for background jobs increased infrastructure complexity. This called for the next version of Rails, Rails 5.</p><h3>Rails 5 (2016): API Mode and Real-Time Features</h3><p><em>Rails 5 embraced the growing demand for APIs and real-time features, setting the stage for more interactive and scalable applications.</em></p><ul><li><strong>Key Changes:</strong></li></ul><blockquote><strong>1. API Mode:</strong> rails new app --api introduced lightweight, API-only Rails applications, driven by the surge in mobile and single-page apps.<br><strong>2. ActionCable:</strong> Integrated WebSocket support to enable real-time features, responding to increased demand for live data and chat functionality.<br><strong>3. ActiveRecord Attributes API:</strong> Enabled customization of attribute behavior and types, enhancing ActiveRecord’s flexibility.<br><strong>4. Turbolinks 5:</strong> Extended support to native mobile apps, reducing load times and improving mobile development.<br><strong>5. Controller Renaming:</strong> Split ApplicationController into APIController and BaseController to streamline API development.</blockquote><ul><li><strong>Notable Methods/Features:</strong></li></ul><blockquote>Enhanced after_commit and after_rollback hooks for more precise control over database transactions.</blockquote><blockquote>rails db:setup simplified initial database setup with schema and seed data in one command.</blockquote><p>While Rails 5 introduced API mode, many applications still faced <strong>challenges</strong> in <strong>separating monolithic</strong> structures, leading to performance issues in larger apps. Although ActionCable was introduced, real-time WebSockets introduced <strong>scalability and deployment complexities</strong> and a <strong>lack of a unified way to manage background job</strong> <strong>queues</strong> led to inconsistencies and dependencies on multiple gems. This was when Rails 6 was introduced.</p><h3>Rails 6 (2019): Productivity and Scalability</h3><p><em>Rails 6 focused on improving developer productivity and scaling, ensuring Rails apps could handle modern demands.</em></p><ul><li><strong>Key Changes:</strong></li></ul><blockquote><strong>1. ActionText:</strong> Introduced for rich text content, addressing the need for integrated, user-friendly text editing.<br><strong>2. Multiple Databases:</strong> Native support for multiple databases emerged as applications required horizontal scaling.<br><strong>3. Parallel Testing:</strong> Reduced test suite runtimes by running tests in parallel, reflecting the need for faster development cycles.<br><strong>4. Webpacker by Default:</strong> Shifted JavaScript management to Webpack to align with modern front-end tooling.<br><strong>5. ActionMailbox:</strong> Allowed incoming emails to be processed directly in Rails models, simplifying email workflows.</blockquote><ul><li><strong>Notable Methods/Features:</strong></li></ul><blockquote>has_rich_text method streamlined rich text management.</blockquote><blockquote>rails db:system:change enabled seamless database engine switching.</blockquote><blockquote>Improved performance for has_many :through associations.</blockquote><p>In Rails 6, Sprockets became increasingly slow for large applications, causing performance bottlenecks. <strong>Webpacker</strong> improved asset management, but <strong>configuring it was complex</strong> and prone to errors. Upgrading to the versions above became a hassle because of webpack issues. While multi-database support was introduced, caching and performance tuning still required significant <strong>manual intervention</strong>.</p><h3>Rails 7 (2021): Full-stack Development and Simplicity</h3><p><em>Rails 7 simplified full-stack development by minimizing JavaScript dependencies and promoting a more Rails-centric approach.</em></p><p><strong>Key Changes:</strong></p><blockquote><strong>1. Import Maps:</strong> Eliminated the need for Node.js or Webpack for JavaScript, simplifying front-end asset management.</blockquote><blockquote><strong>2. Hotwire Integration:</strong> Brought Turbo and Stimulus to the forefront, promoting minimal JavaScript for faster front-end interactions.</blockquote><blockquote><strong>3. Async Queries:</strong> Enabled asynchronous ActiveRecord queries to handle long-running database operations.</blockquote><blockquote><strong>4. Zeitwerk by Default:</strong> Enhanced autoloading, addressing performance bottlenecks during app boot.</blockquote><blockquote><strong>5. Security Updates:</strong> Strengthened CSRF protections to mitigate increasing attack vectors.</blockquote><ul><li><strong>Notable Methods/Features:</strong></li></ul><blockquote>config.load_defaults 7.0 streamlined upgrading to newer defaults.</blockquote><blockquote>rails new app --css=tailwind simplified Tailwind CSS integration.</blockquote><blockquote>Inline encryption added for sensitive ActiveRecord attributes.</blockquote><p>Until now, background job processing heavily relied on Redis, increasing infrastructure costs and complexity and no built-in authentication led to reliance on Devise or custom implementations, adding to project overhead.</p><h3>Rails 8 (2024): Efficiency, Simplicity, and New Deployment Tools</h3><p><em>Rails 8 introduces a range of features that prioritize deployment efficiency, leaner configurations, and seamless authentication.</em></p><ul><li><strong>Key Changes:</strong></li></ul><blockquote><strong>1. Effortless Deployments:</strong> Integration with Kamal 2 and Thruster streamlines deployment workflows.<br><strong>2. Solid Queue for Background Jobs:</strong> Replaces Redis, allowing Active Job to process background tasks without relying on external systems.<br><strong>3. Propshaft Asset Pipeline:</strong> A leaner alternative to Sprockets, simplifying asset management.<br><strong>4. Built-in Authentication:</strong> Out-of-the-box authentication, reducing reliance on external gems like Devise.<br><strong>5. Script Folder and Generator:</strong> A new script directory for organizing custom scripts and a streamlined generator for creating boilerplate code faster.</blockquote><ul><li><strong>Notable Methods/Features:</strong></li></ul><blockquote>authenticate method directly in controllers for session handling.<br>deploy command for seamless deployments.<br>propshaft.append_path for asset management customization.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OHVsMxEL7-fK9FZ6YK2Oww.jpeg" /><figcaption>Man awaiting to unlock the mystic realm of AI powered Rails</figcaption></figure><h3>Conclusion</h3><p>Rails has grown from a simple web framework to a powerful, scalable solution for modern web applications. Each version reflects the evolving needs of developers and the tech landscape. Whether you’re maintaining a legacy Rails 3 app or starting fresh with Rails 7, understanding the journey helps you build better, faster, and more secure applications. Also, the future of Rails points toward <strong>AI-driven development</strong> and cutting-edge technology like <strong>WebAssembly</strong>, continuing to innovate and <strong>simplify workflows</strong>. So, stay tuned to the latest updates.</p><p>For references, visit <a href="https://en.wikipedia.org/wiki/Ruby_on_Rails#:~:text=Ruby%20on%20Rails%20evolves%20radically,in%20favour%20of%20new%20techniques">wikipedia</a>, <a href="https://guides.rubyonrails.org/">rails-guides</a>, <a href="https://github.com/rails/rails">rails</a>.</p><h3>You can follow me on:</h3><ul><li><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/samvita-karkal-354628168/">https://www.linkedin.com/in/samvita-karkal-354628168/</a></li><li><strong>X / Twitter</strong>: <a href="https://x.com/karkalsamvita">https://x.com/karkalsamvita</a></li><li><strong>Peerlist: </strong><a href="https://peerlist.io/samvitak">https://peerlist.io/samvitak</a></li></ul><blockquote>Here to make the community stronger by sharing our knowledge. Follow <a href="https://medium.com/@samvitaskarkal">me</a> and <a href="https://medium.com/nonstopio">my team</a> to stay updated on the latest and greatest in the web &amp; mobile tech world.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=123996b583f7" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/rails-through-the-years-key-changes-from-version-1-to-8-123996b583f7">Rails Through the Years: Key Changes from Version 1 to 8</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails State Management: Enum Vs AASM Explained (with React references)]]></title>
            <link>https://blog.nonstopio.com/rails-state-management-enum-vs-aasm-explained-with-react-references-bc9267e6a73c?source=rss-f5c865fa1aef------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc9267e6a73c</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[state-machine]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Samvita Karkal]]></dc:creator>
            <pubDate>Mon, 30 Dec 2024 08:29:12 GMT</pubDate>
            <atom:updated>2024-12-31T13:19:57.528Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*arYHA-Pzf73CXdq3G9m7NQ.png" /><figcaption>Fig 1. Rails State Management: Enum Vs AASM Explained (with React references)</figcaption></figure><p>When building complex web applications, managing the state of different objects is crucial to ensuring smooth workflows and predictable behavior. If you come from a React background, you’re likely familiar with tools like Redux or useContext for handling global state. In Rails, state management can feel different, but the core principles remain the same with AASM gem or Rails Enum. How are these similar to state management in React? Let’s dive in to learn more. (<strong>bonus points in comments section</strong>)</p><h3>What are States and Why Does State Management Matter?</h3><p>In web apps, state represents the current status or condition of a system, object, or component. State management refers to the mechanisms used to handle and transition between these states. Effective state management ensures:</p><ul><li><strong>Consistency: </strong>Keeps data accurate across components.</li><li><strong>Better User Experience: </strong>Provides real-time feedback and predictable UI behavior.</li><li><strong>Data Handling: </strong>Tracks data changes and prevents inconsistencies.</li><li><strong>Complex Task Management: </strong>Enables structured workflows.</li><li><strong>Scaling Up: </strong>Simplifies the process of scaling apps.</li><li><strong>Improved Debugging: </strong>Makes it easier to track and reproduce bugs.</li></ul><p>Good state management keeps everything running smoothly and helps apps perform well as they grow or handle more complex tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wL10kxGHnBB-FiJM6Kz2Zg.jpeg" /><figcaption>Fig 2. Image portraying different complicated states in a mechanical bird</figcaption></figure><h3>How Rails Manages State: Enum vs AASM</h3><p>Similar to managing component state in React, Rails allows developers to manage the state of ActiveRecord models. Two popular techniques are:</p><ol><li><strong>Rails Enum</strong> — Simple state management, like useState or useContext. A simple way to map symbolic states to integers.</li><li><strong>AASM Gem</strong> — Advanced state machines, comparable to Redux for structured workflows. A more sophisticated approach for defining state machines with transitions and callbacks.</li></ol><p>Let’s break down each method and how they compare to <strong>Redux </strong>and<strong> useContext/useState.</strong></p><h4>1. Rails Enum: Simple State Management</h4><p><strong>Rails Enum</strong> is the ActiveRecord equivalent of basic state management, similar to React’s useContext or useState hooks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PQ-PBpuA-L1tm2HLN5-puQ.png" /><figcaption>Fig 3. Sample modal with Rails Enum used to manage status of orders</figcaption></figure><p><strong>How Enum Works:<br></strong>Rails Enum maps symbolic values to a single integer column in a database table. Using integer columns in table, it allows you to work with meaningful symbols in your application code. These symbols can be called directly on objects to transition the state (as shown in Fig. 3). <br>An example of adding status enum to a table using a migration:</p><pre>class CreateOrders &lt; ActiveRecord::Migration[7.1]<br>  def up<br>    create_table :orders do |t|<br>     t.string :customer_email<br>     t.integer :status, default: 0, null: false<br>     t.timestamps<br>    end<br>  end<br>end</pre><p><strong>React Analogy:</strong> enum is like useState for managing local component state or useContext for sharing simple global state.</p><h4>2. AASM Gem: Advanced State Management</h4><p><strong>AASM</strong> stands for <strong>Acts As State Machine</strong>. It uses the concept of finite state machines to bring structure to states, allowing you to define states, transitions, and callbacks directly within your model. It’s ideal for managing workflows with multiple stages, akin to <strong>Redux</strong> managing complex global state.</p><figure><img alt="Fig 4. Sample modal of how AASM can be integrated into your application" src="https://cdn-images-1.medium.com/max/852/1*8EA7CPjP-jKX9_c-1yAlUw.png" /><figcaption>Fig 4. Sample modal of how AASM can be integrated into your application</figcaption></figure><p><strong>How AASM Works:<br>AASM</strong> tracks state using a column in the database but provides more granular control by generating helper methods and allowing callbacks or guards during transitions. This creates a <strong>structured workflow</strong> that models complex state machines in Rails applications. Integration in modal is as demonstrated in <strong>Fig. 4</strong>.</p><p>After setting up the model, for each event defined in your state machine, AASM automatically generates different types of <strong>helper methods </strong>which are as follows:</p><p><strong>a. Transition Check Methods:<br></strong>These are automatically generated methods to verify if a transition is possible.</p><blockquote><strong>i. may_&lt;event&gt;?</strong>: Checks if the event can be triggered from current state. <br><strong>Eg:</strong> may_complete? checks if the complete event can be triggered.</blockquote><blockquote><strong>ii. &lt;event&gt;!</strong>: Triggers the state transition.<br><strong>Eg: </strong>complete! triggers the complete event, changing the state from shipped to completed.</blockquote><blockquote><strong>iii. &lt;event&gt;</strong>: Attempts to trigger the event but returns false instead of raising an exception if the transition is not allowed.<br><strong>Eg: </strong>complete would attempt the transition and return false if it’s not possible.</blockquote><p><strong>b. State Query Methods:<br></strong>These methods help check or return the current state of an object.</p><blockquote><strong>i. &lt;state&gt;?</strong>: Checks if the current state matches the specified state.<br><strong>Eg: </strong>order.pending? returns true if the order is in the pending state.</blockquote><blockquote><strong>ii. current_state</strong>: Returns the current state of the object.<br><strong>Eg: </strong>order.current_state returns the current state of the order.</blockquote><p><strong>c. Transition Methods:<br></strong>Force transitions to specific states, bypassing event validation.</p><blockquote><strong>i. &lt;state&gt;!</strong>: Forcibly transitions the object to the specified state without running any event callbacks or guards.<br><strong>Eg: </strong>order.pending! sets the order state to pending directly.</blockquote><p><strong>d. Callback Methods:<br></strong>AASM allows you to define callbacks that run at various points during state transitions</p><blockquote><strong>i. before_&lt;event&gt;</strong>: Runs before the specified event is triggered (can be used for running validations).<br><strong>Eg:</strong> before_complete :prepare_order runs the prepare_order method before transitioning to completed.</blockquote><blockquote><strong>ii. after_&lt;event&gt;</strong>: Runs after the specified event is triggered.<br><strong>Eg:</strong> after_complete :notify_user runs the notify_user method after transitioning to completed.</blockquote><blockquote><strong>iii. before_enter_&lt;state&gt;</strong>: Runs before entering the specified state (runs before the state is entered, but after the transition has been validated and is about to complete).<br><strong>Eg:</strong> before_enter_shipped :check_inventory runs the check_inventory method before entering the shipped state.</blockquote><blockquote><strong>iv. after_enter_&lt;state&gt;</strong>: Runs after entering the specified state.<br><strong>Eg:</strong> after_enter_shipped :send_confirmation runs the send_shipping_confirmation method after entering the shipped state.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FU8siIU9rM1fFA2IFzKeXA.jpeg" /><figcaption>Fig 5. Image portraying different states in a mechanical bird working together to make it functional</figcaption></figure><p><strong>React Analogy:</strong> AASM is like Redux – designed for complex state logic, strict transitions, and event-driven workflows.</p><h3>Which One Should You Use?</h3><p>Both Enum and AASM can be really powerful when used in the appropriate context. You can decide which one is appropriate for your use case like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o13bf0PKcfuK8pO1z2v7eA.png" /><figcaption>Fig. 6. Comparison of Rails Enum vs AASM and when each has to be used</figcaption></figure><p>By understanding these tools, Rails developers can manage state as effectively as frontend frameworks, ensuring scalable and maintainable applications. To know more in detail, you can refer <a href="https://api.rubyonrails.org/v5.1/classes/ActiveRecord/Enum.html">ActiveRecords::Enum</a>, <a href="https://github.com/aasm/aasm">AASM</a>, <a href="https://redux.js.org/">Redux</a> and <a href="https://react.dev/reference/react/useContext">useContext</a>.</p><h3>You can follow me on:</h3><ul><li><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/samvita-karkal-354628168/">https://www.linkedin.com/in/samvita-karkal-354628168/</a></li><li><strong>X / Twitter</strong>: <a href="https://x.com/karkalsamvita">https://x.com/karkalsamvita</a></li><li><strong>Peerlist: </strong><a href="https://peerlist.io/samvitak">https://peerlist.io/samvitak</a></li></ul><blockquote>Here to make the community stronger by sharing our knowledge. Follow <a href="https://medium.com/@samvitaskarkal">me</a> and <a href="https://medium.com/nonstopio">my team</a> to stay updated on the latest and greatest in the web &amp; mobile tech world.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc9267e6a73c" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/rails-state-management-enum-vs-aasm-explained-with-react-references-bc9267e6a73c">Rails State Management: Enum Vs AASM Explained (with React references)</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Guide to Web Application Security: Types of Attacks, Prevention Techniques, and Best…]]></title>
            <link>https://blog.nonstopio.com/the-ultimate-guide-to-web-application-security-types-of-attacks-prevention-techniques-and-best-a871ea5f0d9b?source=rss-f5c865fa1aef------2</link>
            <guid isPermaLink="false">https://medium.com/p/a871ea5f0d9b</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[website-security]]></category>
            <category><![CDATA[prevention]]></category>
            <dc:creator><![CDATA[Samvita Karkal]]></dc:creator>
            <pubDate>Fri, 27 Dec 2024 13:52:26 GMT</pubDate>
            <atom:updated>2024-12-30T14:16:39.620Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Ultimate Guide to Web Application Security: Types of Attacks, Prevention Techniques, and Best Practices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQyWyb5rCP1n8giBaqnTjw.png" /><figcaption>The Ultimate Guide to Web Application Security</figcaption></figure><p>In today’s digital world, everything from your finances to your medical history is online. Large servers hold this data and it is easily accessible to anyone with ill intentions to exploit it unless you have secured it well.</p><p>So as a software engineer, how can you ensure the website you are working on will not be the culprit of losing such critical data? Curious? Keep reading on..</p><p>To properly safeguard data linked to our web applications, we need to first understand what the 8 different types of web attacks are and different ways we can adopt to protect our apps from them, starting from:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dwZ3B1DJiiCAghR7CIEGbA.png" /><figcaption>Different types of Web Security Attacks possible on your Website</figcaption></figure><h3>1. Input Validation and Injection Attacks</h3><p>These attacks exploit how a web application handles untrusted input, aiming to manipulate queries or execute malicious commands. It has 3 sub-types:<br> <strong>a. SQL Injection Attack<br> b. Command Injection Attack<br> c. No-SQL Injection Attack</strong></p><p><strong>a. SQL Injection Attack: </strong>Occurs when an attacker manipulates an application’s SQL query to execute unintended commands. Say, in</p><pre>SELECT * FROM users WHERE email = &#39;email-input&#39; AND password = &#39;pass-input&#39;;</pre><p>the user puts email-input = <strong><em>‘ OR ‘1’=’1</em></strong> then, the result returns all values as the <em>where </em>condition will always return <em>true.</em></p><p><strong><em>PREVENTION: </em></strong>Use parameterized queries, avoid string interpolation in SQL, validate and sanitize inputs.</p><p><strong>b. Command Injection Attack: </strong>Allows an attacker to execute arbitrary system commands on the server. Like:</p><pre>system(&quot;ping #{params[:host]}&quot;)</pre><p>if the user puts params[:host] = <strong><em>“127.0.0.1; rm -rf /”</em></strong> then, it could delete all server files<em>.</em></p><p><strong><em>PREVENTION: </em></strong>Avoid using system commands with untrusted input, use libraries like Open3 that separate input from commands.</p><p><strong>c. NoSQL Injection Attack: </strong>Targets NoSQL databases (e.g., MongoDB) by injecting malicious queries. Attacker can use the following command to bypass authentication.</p><pre>User.where({&quot;$where&quot; =&gt; &quot;this.name == &#39;admin&#39; || true&quot;})</pre><p><strong><em>PREVENTION: </em></strong>Use ORMs like ‘Mongoid’ for parameterized queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*uDEau1aEweM-YLt8mmXwGg.jpeg" /><figcaption>Authentication and Authorization attacks prevention for your system</figcaption></figure><h3>2. Authentication and Authorization Attacks</h3><p>These attacks target the mechanisms that verify and authorize users. It has 3 sub-types:<br> <strong>a. Brute Force Attacks<br> b. Session Hijacking<br> c. Privilege Escalation</strong></p><p><strong>a. Brute Force Attacks: </strong>Attacker attempts to guess passwords using repeated attempts. For example, attacker tries all combinations of password for an existing user in your application.</p><p><strong><em>PREVENTION: </em></strong><em>r</em>ate-limit login attempts using rack-attack, lock accounts after several failed attempts, use CAPTCHA for repeated failures.</p><p><strong>b. Session Hijacking: </strong>Attackers steal session tokens (via XSS or sniffing) to impersonate users. Say a genuine user has signed into your app and the attacker steals the session token from headers to get direct access into the application using the genuine user’s account.</p><p><strong><em>PREVENTION: </em></strong>Use HTTPS and secure HttpOnly cookies, regenerate session IDs after login, invalidate sessions on logout or password change.</p><p><strong>c. Privilege Escalation: </strong>Attackers gain access to higher privilege levels, often by manipulating roles. Say, the ‘Admin Dashboard’ to your application is supposed to be only visible to admins but an attacker with a compromised normal user’s access tries to call an admin only API and gets the data.</p><p><strong><em>PREVENTION: </em></strong>Enforce role-based access control (e.g., Pundit, CanCanCan), Validate user permissions at the controller and model level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CC_cahGDrbTCoS3fLmi1JQ.png" /><figcaption>Cross Site Scripting attacks and their prevention</figcaption></figure><h3>3. Cross-Site Attacks</h3><p>These attacks involve manipulating or exploiting web requests and responses. It has 2 sub-types:<br> <strong>a. Cross-Site Scripting (XSS)<br> b. Cross-Site Request Forgery (CSRF)</strong></p><p><strong>a. Cross-Site Scripting (XSS): </strong>XSS occurs when an attacker injects malicious scripts into web pages that are viewed by other users. These scripts run in the context of the victim’s browser and can steal cookies or other sensitive information, or even perform actions on behalf of the victim.</p><p><strong>Subcategories:<br>=&gt; Stored XSS:</strong> Malicious script stored in a database and displayed later.<br>=&gt; <strong>Reflected XSS:</strong> Malicious script embedded in a URL and executed immediately.<br>=&gt; <strong>DOM-based XSS:</strong> Script injected into client-side JavaScript.</p><p><strong><em>PREVENTION: </em></strong>Escape and sanitize inputs with sanitize or escape, avoid raw in views, implement a Content Security Policy (CSP).</p><p><strong>b. Cross-Site Request Forgery (CSRF): </strong>CSRF tricks a logged-in user into performing an unintended action on a trusted site. The attacker leverages the user’s authenticated session to execute unwanted actions like changing account settings or transferring funds.</p><p><strong><em>PREVENTION: </em></strong>Enable CSRF protection with protect_from_forgery, use csrf_meta_tags to include the CSRF token in the page&#39;s &lt;head&gt;, validate the Origin header in API requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*T5gPPiIUz4kDoiU5TubS4w.jpeg" /><figcaption>Data Exposure and Object Access Attacks</figcaption></figure><h3>4. Data Exposure and Object Access Attacks</h3><p>These attacks exploit access control and sensitive data handling. It has 3 sub-types:<br> <strong>a. Insecure Direct Object References (IDOR)<br> b. Mass Assignment Vulnerabilities<br> c. Data Exposure</strong></p><p><strong>a. Insecure Direct Object References (IDOR): </strong>Attackers manipulate object references (e.g., IDs) to access unauthorized data. A URL like /users/1234 may allow changing the ID to /users/1235 to access another user’s data.</p><p><strong><em>PREVENTION: </em></strong>Validate object ownership usingcurrent_user.id == User.find(params[:id]).id, use non-predictable identifiers (e.g., UUIDs).</p><p><strong>b. Mass Assignment Vulnerabilities: </strong>Attackers exploit bulk updates to modify sensitive attributes. Say, attacker updates the role of a pre-existing compromised user ot admin while updating some other user detail.</p><p><strong><em>PREVENTION: </em></strong>Use strong parameters like params.require(:user).permit(:name, :email), use attr_protectedfor versions below Rails 3.2.</p><p><strong>c. Data Exposure: </strong>Sensitive data, such as passwords or API keys, is leaked.</p><p><strong><em>PREVENTION: </em></strong>Encrypt sensitive data with Rails’ encryption APIs and Mask sensitive data in logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wn2PpOJrTJJrfYQTy7Q8TA.jpeg" /><figcaption>Distributed Denial of Service (DDoS) Attacks and prevention</figcaption></figure><h3>5. Distributed Denial of Service (DDoS) Attacks</h3><p>These attacks aim to disrupt service availability using various techniques. It has 2 sub-types:<br> <strong>a. HTTP Flooding<br> b. Resource Exhaustion</strong></p><p><strong>a. HTTP Flooding: </strong>Attackers overload servers with a high volume of requests. Do you recall the time when the BookMyShow site went down as soon as the booking went live for the ColdPlay concert? Yes.. an attack similar to that.</p><p><strong><em>PREVENTION: </em></strong>Use rate-limiting middleware like rack-attack, cache responses using Rails caching mechanisms.</p><p><strong>b. Resource Exhaustion: </strong>Attackers deplete server resources by exploiting high-cost operations. A very recent example of this is the <strong>CVE-2022–20426</strong> vulnerability in the Android Operating System. Discovered in 2022, this vulnerability would crash the android phone when a user would select a phone account as it would create multiple copies and deplete the memory of the device.</p><p><strong><em>PREVENTION: </em></strong>Limit file upload sizes using config.active_storage, validate inputs to avoid excessive resource usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v500C6YkLqAEYiAoBHqsyg.jpeg" /><figcaption>File Upload and Deserialization Attacks</figcaption></figure><h3>6. File Upload and Deserialization Attacks</h3><p>Web applications often handle user-generated content, such as file uploads, or deserialize data for performance and flexibility. However, these processes can introduce significant security vulnerabilities if not handled properly. To understand this better, let’s understand it’s 2 sub-types:<br> <strong>a. Malicious File Uploads<br> b. Insecure Deserialization</strong></p><p><strong>a. Malicious File Uploads: </strong>Attacker uploads files containing malicious scripts or malware to corrupt the system. Let’s say a file was uploaded into the system that contained a malware which would damage the entire system.</p><p><strong><em>PREVENTION: </em></strong>Validate file types and sizes using gems like carrierwave or shrine, store uploaded files in a safe location, not the root directory.</p><p><strong>b. Insecure Deserialization: </strong>In this type of attack, unsafe deserialization is exploited to execute malicious payloads. In 2017, a critical vulnerability in Apache Struts 2, a popular open-source web application framework, allowed attackers to perform remote code execution by exploiting insecure deserialization. This vulnerability was notably responsible for the massive <strong>Equifax data breach</strong>, which exposed the personal information of <strong>147 million people</strong>.</p><p><strong><em>PREVENTION: </em></strong>Avoid deserializing untrusted input and Use JSON or YAML parsers that do not evaluate code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94NnIQCx7du69_LeYblYPA.jpeg" /><figcaption>Missed Configuration and Security Misconfigurations being misused</figcaption></figure><h3>7. Configuration and Security Misconfigurations</h3><p>As the name suggests, these attacks happen when some configuration is missing or some mis-configuration occurs in the application. <br><strong>For example:</strong><br><strong>a. </strong>Lack of headers like X-Content-Type-Options and CSP allows attacks like XSS.<br>b. Sensitive debugging details (e.g., stack traces) are left in console exposing these details to users.</p><p><strong><em>PREVENTION: </em></strong>Disable detailed error messages in production using config.consider_all_requests_local = false, Use custom error pages for production.</p><h3>8. Business Logic Attacks</h3><p>Here, the attacker Exploits weaknesses or edge cases that were not handled properly in application logic. <br><strong>For example:</strong> A discount coupon can be reused indefinitely due to missing validations.</p><p><strong><em>PREVENTION: </em></strong>Test edge cases in business logic and validate workflows and enforce state transitions in models.</p><h3>General Best Practices:</h3><ul><li><strong>Update Rails and Dependencies Regularly:</strong> Stay protected against known vulnerabilities.</li><li><strong>Perform Security Audits:</strong> Use tools like Brakeman for static analysis.</li><li><strong>Use security gems: </strong>Use gems like rack-attack, rack-cors, secure-headers and brakeman to secure your apps.</li><li><strong>Educate Your Team:</strong> Awareness of common vulnerabilities ensures better prevention.</li></ul><blockquote>To read more about application security, refer <a href="https://guides.rubyonrails.org/security.html">rails-guides</a>, <a href="https://github.com/rack/rack-attack">rack-attack</a>, <a href="https://github.com/cyu/rack-cors">rack-cors</a>, <a href="https://github.com/github/secure_headers">secure-headers</a> and <a href="https://github.com/presidentbeef/brakeman">brakeman</a> for information specific to rails and <a href="https://www.invicti.com/learn/cross-site-scripting-xss/">XSS</a> for cross-site scripting attacks.</blockquote><h3>Summary:</h3><p>Staying up-to-date and checking your applications for different security threats is very important. We never know how the slightest negligence can rob away years of work and cause legal implications. Hence, <br><strong>Stay aware, stay vigilant!</strong></p><h3>You can follow me on:</h3><ul><li><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/samvita-karkal-354628168/">https://www.linkedin.com/in/samvita-karkal-354628168/</a></li><li><strong>X / Twitter</strong>: <a href="https://x.com/karkalsamvita">https://x.com/karkalsamvita</a></li><li><strong>Peerlist: </strong><a href="https://peerlist.io/samvitak">https://peerlist.io/samvitak</a></li></ul><blockquote>Here to make the community stronger by sharing our knowledge. Follow <a href="https://medium.com/@samvitaskarkal">me</a> and <a href="https://medium.com/nonstopio">my team</a> to stay updated on the latest and greatest in the web &amp; mobile tech world.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a871ea5f0d9b" width="1" height="1" alt=""><hr><p><a href="https://blog.nonstopio.com/the-ultimate-guide-to-web-application-security-types-of-attacks-prevention-techniques-and-best-a871ea5f0d9b">The Ultimate Guide to Web Application Security: Types of Attacks, Prevention Techniques, and Best…</a> was originally published in <a href="https://blog.nonstopio.com/">nonstopio</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NPM or YARN? Best package management tool for your Javascript projects.]]></title>
            <link>https://medium.com/@samvitaskarkal/npm-or-yarn-best-package-management-tool-for-your-next-javascript-project-4c37e0b09e4c?source=rss-f5c865fa1aef------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c37e0b09e4c</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[smart-package-locker]]></category>
            <category><![CDATA[yarn-package-manager]]></category>
            <category><![CDATA[npm-package]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Samvita Karkal]]></dc:creator>
            <pubDate>Fri, 03 Mar 2023 11:28:43 GMT</pubDate>
            <atom:updated>2024-12-23T18:57:39.955Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZYArRaVq0i773vGh" /><figcaption>Package management tool confusion</figcaption></figure><p>Have you ever come across this error before?</p><pre>❗ Fix the upstream dependency conflict, or retry <br>npm ERR! this command with - force, or - legacy-peer-deps <br>npm ERR! to accept an incorrect (and potentially broken) dependency resolution.</pre><p>Or have you ever worked on multiple projects where some use npm and others use yarn as their <strong>package manager</strong>? Using npm and yarn together in the same project is not advisable as both create their own package-lock files (<strong><em>package-lock</em></strong> and <strong><em>yarn-lock file</em></strong> respectively) which causes <strong>resolution inconsistencies</strong> due to <strong>unsynchronised log files</strong> (The above error).</p><p>Yet, remembering which package manager to use while installing your packages and doing other package management activities is quite annoying for sure! <strong>What do we do to prevent this?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NJ3fp0ld56Me7et-" /><figcaption>Photo by <a href="https://unsplash.com/ja/@towfiqu999999?utm_source=medium&amp;utm_medium=referral">Towfiqu barbhuiya</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Using <strong>NI package manager</strong> helps resolve these woes! It’s a simple tool to use and yet is super effective!</p><p><a href="https://github.com/antfu/ni">GitHub - antfu/ni: 💡 Use the right package manager</a></p><ol><li>To <strong>globally install</strong> ni in your system, <strong>run</strong> npm i -g @antfu/ni in your terminal.</li><li>Now run ni in your <strong>project terminal</strong> and <strong>Voila!</strong> all your packages are installed <strong>without any inconsistency issues</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-FqpodKeJexGjrQz" /><figcaption>Photo by <a href="https://unsplash.com/de/@ambreenhasan?utm_source=medium&amp;utm_medium=referral">Ambreen Hasan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Using <strong>ni</strong> to do other package management activities is also as easy as eating a piece of cake!</p><p>Want to install a specific package?</p><blockquote>run ni package-name in your project terminal.</blockquote><p>Have a dev dependancy?</p><blockquote>run ni react-router-dom -D.</blockquote><p>Want to run a script?</p><blockquote>run nr script-name.</blockquote><p>want to start you react app,</p><blockquote>run nr start.</blockquote><p><strong>Pretty convenient right?</strong> Give it a try and let me know if you find it useful :D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q1xloBD0w3VThoik" /><figcaption>Photo by <a href="https://unsplash.com/@bendavisual?utm_source=medium&amp;utm_medium=referral">Benjamin Davies</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c37e0b09e4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Sidekiq with Rails to download CSV files in the background]]></title>
            <link>https://medium.com/@samvitaskarkal/using-sidekiq-with-rails-to-download-csv-files-in-the-background-a6ad375a55d5?source=rss-f5c865fa1aef------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6ad375a55d5</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[background-jobs]]></category>
            <category><![CDATA[sidekiq]]></category>
            <category><![CDATA[csv-file]]></category>
            <dc:creator><![CDATA[Samvita Karkal]]></dc:creator>
            <pubDate>Sun, 08 Aug 2021 17:47:24 GMT</pubDate>
            <atom:updated>2024-12-30T14:01:29.368Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VEO2UTBKKW86ip6XnQPN5g.jpeg" /></figure><p>Many-a-times, we come across processes that do not need user intervention, yet take up a lot of server time. This time could have been used, otherwise, to do multiple other tasks. Let’s take the example of downloading a large file as a csv. In such a case, when the data to be processed gets large enough, it’s always a good idea to run this process in the background and let the user continue using the application to do other tasks. Processes can be run in the background as background jobs.</p><p>Background jobs are <strong>jobs</strong> <strong>that can be run asynchronously in the background</strong> without any user intervention. Rails has <a href="https://guides.rubyonrails.org/active_job_basics.html">Active Job</a> that can be used to process background jobs and make them run on a variety of background adapters such as <a href="https://sidekiq.org/">Sidekiq</a> or <a href="https://github.com/resque/resque">Resque</a>. To explain the process better, let’s take the <strong>example of a Bookstore</strong> and use Sidekiq as the background adapter.</p><h3>Installing Sidekiq in Ubuntu 20.04</h3><p>To use Sidekiq in Ubuntu, we will need to <a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-20-04">install redis</a> as a prerequisite. Redis is used by Sidekiq as an in-memory data structure store.</p><p>After installing redis, We can go ahead and install Sidekiq. To do so, first open the Gemfile, add <strong>gem “sidekiq” </strong>and run <strong>bundle install</strong> in the terminal.</p><pre>gem “sidekiq”</pre><pre>bundle install</pre><p>Now, open <strong>config/application.rb </strong>and inside class Application, enter the lines as shown:</p><pre>class Application &lt; Rails::Application<br>…<br>  config.active_job.queue_adapter = :sidekiq<br>…<br>end</pre><p>Now, to get started with sidekiq, simply run</p><pre>bundle exec sidekiq</pre><p>You must be able to see some output on the terminal along with the sidekiq logo towards the end, to indicate a running sidekiq server.</p><h3>Writing the background jobs</h3><p>Installing Sidekiq in your project automatically creates <strong>app/jobs</strong> folder. All the background jobs concerning to this particular project reside in this folder. Moving back to our example, let’s say, we want to download details of all the books available in the bookshop.</p><p>Let’s create a job <strong>file_downloader_job.rb</strong>. This job will prepare the csv file with id, name and price of each book as the columns of the csv. Enter the following code in it:</p><pre>class FileDownloaderJob &lt; ApplicationJob<br>  queue_as :default</pre><pre>  def perform(all)<br>    attributes = %w{book_id book_name price}<br>    CSV.generate(headers: true) do |csv|<br>      csv &lt;&lt; attributes<br>      all.each do |book|<br>        csv &lt;&lt; book.attributes.values_at(*attributes)<br>      end<br>    end<br>  end<br>end</pre><p>Now, let’s call this job in the <strong>book.rb</strong> model. Here, you can generalize this process by writing the .to_csv function in application_record.rb model and writing variable attributes in the filedownloader job.</p><pre>class Book &lt; ActiveRecord::Base<br>  self.abstract_class = true</pre><pre>  def self.to_csv<br>    FileDownloaderJob.new.perform(all)<br>  end<br>end</pre><p>This job is called in the to_csv function to keep the controller clean. Now, write the following code in<strong> books_controller.rb</strong>.</p><pre>class BooksController &lt; ApplicationController<br>def index <br>  books = Book.all </pre><pre>respond_to do |format| <br>    format.html {render status: :ok, json: books.organize()}<br>    format.csv { send_data books.to_csv.perform_async(*args), <br>      filename: “books-#{Date.today}.csv” } <br>  end <br>end</pre><p>And done! Your csv file that shows the contents of the <strong>Books</strong> table starts download in the background as soon as the index action of the books controller is called with .csv extension.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6ad375a55d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>