<?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 yoonsin91 on Medium]]></title>
        <description><![CDATA[Stories by yoonsin91 on Medium]]></description>
        <link>https://medium.com/@yoonsin91?source=rss-9434289cf5b2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*i7_ibVc8Ocf6NAq9NDtWSQ.jpeg</url>
            <title>Stories by yoonsin91 on Medium</title>
            <link>https://medium.com/@yoonsin91?source=rss-9434289cf5b2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 17:12:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yoonsin91/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[Elevating Web Experience: A Refined Approach to HTTP Caching]]></title>
            <link>https://levelup.gitconnected.com/elevating-web-experience-a-refined-approach-to-http-caching-7eed0727b328?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eed0727b328</guid>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[http-cache]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Sat, 16 Sep 2023 05:44:38 GMT</pubDate>
            <atom:updated>2023-09-18T13:33:50.739Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p46-j9mmcFJmer3LF0Oebg.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>At our company, we’re always striving to deliver the best web experience to our users. Part of this mission involves optimizing our HTTP caching strategy. Recently, we discovered a common practice in our codebase — using no-cache, no-store, and private directives to ensure data accuracy at the expense of potentially slower load times. While this approach was aimed at preventing user confusion when content changes occur, we’ve decided to rethink our strategy. Today, we’re sharing our journey to find a better caching solution that provides both data freshness and optimal performance.</p><h3><strong>Reevaluating Cache Directives</strong></h3><p>The use of no-cache, no-store, and private directives can be quite effective in guaranteeing users always see the most up-to-date content. However, it often results in retrieving data from the origin server every time, which can lead to slower page load times. To address this, we’re focusing on two primary challenges:</p><h3><strong>1. Dynamic Script Content</strong></h3><p>A significant challenge arose with dynamic script content, which evolves based on user actions. To harmonize caching with these updates, we’re shifting our approach. Instead of entirely bypassing caching, we’re now appending a timestamp as a query parameter to the script’s URL. Here’s the transformation:</p><p><strong>Before:</strong> `example.com/scripts.js` (fetching the latest content)</p><p><strong>After:</strong> `example.com/scripts.js?t=1232345` (ensuring fresh content after every update)</p><p>By introducing this timestamp parameter, we’ve ensured that whenever a user modifies their settings, the script URL changes, prompting the browser to fetch the most recent version. This way, we maintain data accuracy without compromising on performance.</p><h3><strong>Cache Control for Dynamic Script Content</strong></h3><p>After implementing the timestamp parameter solution for dynamic script content, we set the cache control to `public, max-age=3600`. This allows the browser to cache the script content for up to an hour, providing a balance between data freshness and optimal performance.</p><h4>Result:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mlBaC8z-KSmnL96IsaOJBw.png" /></figure><h3><strong>Leveraging ETag and Must-Revalidate Strategy</strong></h3><p>In cases where script content is updated by us, rather than by the user, we sought a solution to prompt the browser to fetch the latest content without entirely bypassing caching. We’ve decided to implement an ETag and must-revalidate strategy. While this approach still involves a call to the origin server, it significantly reduces data transfer, optimizing both performance and data accuracy.</p><h3><strong>The Process in Action</strong></h3><p>To clarify the process:</p><p>1. When a request is sent to the server without an If-None-Match request header, the server responds with a 200 HTTP code and includes an ETag in the response header.</p><p>2. The browser caches the script content and retains the ETag value.</p><p>3. In subsequent requests, the browser appends the If-None-Match request header with the ETag value from the previous response.</p><p>4. The server validates the If-None-Match header. If the content is unchanged, it returns a 304 HTTP code with an empty body. The browser serves the content from its cache. Otherwise, it reverts to step 1.</p><h4>Result:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cI5l3XKEC2vRPfNjzfC28g.png" /></figure><h3><strong>Conclusion</strong></h3><p>Our journey to enhance HTTP caching reflects our commitment to providing the best possible web experience. By reevaluating and fine-tuning our approach, we’re confident that we can deliver faster load times and reduced server load without sacrificing data freshness.</p><p>With these improvements, we’re poised to elevate the user experience to new heights. We look forward to seeing the positive impact this will have on our website’s performance and our users’ satisfaction. Stay tuned for more updates on our ongoing efforts to enhance HTTP caching!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eed0727b328" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/elevating-web-experience-a-refined-approach-to-http-caching-7eed0727b328">Elevating Web Experience: A Refined Approach to HTTP Caching</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Balancing Bug Fixes and Features in Software Development]]></title>
            <link>https://levelup.gitconnected.com/balancing-bug-fixes-and-features-in-software-development-27fdb369195a?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/27fdb369195a</guid>
            <category><![CDATA[systems-thinking]]></category>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[feature-development]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 15:56:23 GMT</pubDate>
            <atom:updated>2023-09-08T15:23:15.582Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LVmW32X5uNMlEBp56kb0SQ.png" /></figure><p>Can a software ever be completely free of bugs? To some, the answer might seem straightforward: “Yes, if there’s no one using the software or if it consists of just a few lines of code.” However, the reality of the tech world is far more complex. As software grows in complexity, the challenges it poses, including bugs, become increasingly intricate.</p><p>In the world of software engineering, the perennial dilemma often faced by developers is whether to prioritize bug fixes or continue with feature development.</p><h3>Embracing Whole System Thinking</h3><h4>Beyond Feature-Centric Development</h4><p>One of the challenges often faced by software engineers is the tendency to become entrenched in the specific feature or component they are working on. While this focus is essential for detailed and thorough development, it can sometimes lead to a myopic view. Engineers may inadvertently overlook the broader implications of their work within the entire system.</p><h4>The Power of Whole System Thinking</h4><p>Whole system thinking is a mindset that encourages engineers to step back and view the software as a cohesive entity rather than a collection of isolated features. When engineers adopt this perspective, they begin to see the interconnectedness of various components and how changes in one area can ripple through the entire system.</p><h4>Whole System Thinking in the Restaurant Business</h4><h4>Beyond Individual Dishes</h4><p>Imagine you’re the owner of a restaurant, and you’re planning to introduce a new menu item — a delectable pasta dish. Your head chef, skilled in pasta preparation, starts working on perfecting the recipe. It’s tempting to focus solely on the details of this dish — the type of pasta, the sauce, and the garnishes.</p><h4>The Whole Dining Experience</h4><p>However, whole system thinking urges you to step back and consider the broader context. In a restaurant, the dining experience is not just about individual dishes; it’s about the entire journey from the moment a customer enters to the moment they leave.</p><h4>Identifying Interconnections</h4><p>By adopting this perspective, you may realize that the new pasta dish, while delicious on its own, might not align with the overall theme or cuisine of your restaurant. Or, you may recognize that the timing of dish preparation needs to sync with appetizers and other courses to ensure a smooth dining flow.</p><h4>A Software Development Parallel</h4><p>In the same way, software engineers can sometimes become fixated on specific features or components, potentially losing sight of how these elements fit into the larger system. Just as a restaurant owner considers the entire dining experience, software developers need to think about the overall user experience, system performance, and how changes in one part of the codebase can impact other areas.</p><h3>Prioritizing Bug Fixes: Industry-Specific Considerations</h3><h4>Embracing Realism</h4><p>Admitting that achieving a completely bug-free software is a formidable challenge is the first step toward effective bug management. In the world of complex software, perfection is often elusive, and it’s essential to acknowledge this reality.</p><h4>Industry-Specific Critical Areas</h4><p>In various industries and software domains, the definition of critical issues that demand immediate attention can differ significantly. Let’s explore a few examples:</p><p><strong>1. Healthcare Software</strong>: In healthcare software applications, the utmost priority may be patient safety and data integrity. Any bug or vulnerability that compromises patient records or clinical processes must be treated as critical. Ensuring compliance with healthcare regulations and standards is also paramount.</p><p><strong>2. Financial Software</strong>: For financial software, accuracy in financial calculations and transaction processing is crucial. Any bug that affects the integrity of financial data or compliance with financial regulations must be addressed urgently. Security vulnerabilities that could lead to financial fraud or data breaches are high-priority concerns.</p><p><strong>3. Aerospace and Aviation Software</strong>: In the aerospace and aviation industry, software bugs can have life-or-death consequences. Issues related to flight control systems, navigation, or communication can be catastrophic if not addressed immediately. Rigorous testing and validation are essential in these contexts.</p><p><strong>4. E-commerce Platforms</strong>: Returning to our previous example, in e-commerce platforms, critical issues might revolve around payment processing, order fulfillment, and data security. Any bug that disrupts the checkout process, leading to revenue loss or customer dissatisfaction, is a top priority.</p><h4>Tailoring Prioritization for Your Context</h4><p>Tech teams should adapt their prioritization strategies to the specific industry and software they are working on. Identifying and closely monitoring these industry-specific critical areas ensures that software remains reliable, secure, and aligned with industry standards and user expectations.</p><h3>Conclusion</h3><p>In the world of software development, where time and resources are often constrained, making the right choices regarding bug fixes and feature development is paramount. We’ve seen that achieving a completely bug-free software can be an elusive goal, especially in complex systems.</p><p>Recognizing this reality and embracing a holistic view of the software, one that considers the entire ecosystem, is a crucial first step. Just as importantly, acknowledging the unique demands of your industry or software domain can guide your prioritization efforts effectively.</p><p>In an environment with limitations, whether it’s a tight project deadline or a constrained budget, the ability to identify the right pieces of the puzzle and allocate effort where it matters most becomes a strategic advantage. It’s about focusing on the critical areas that align with your goals, meet industry standards, and ultimately deliver the most significant value to users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27fdb369195a" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/balancing-bug-fixes-and-features-in-software-development-27fdb369195a">Balancing Bug Fixes and Features in Software Development</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Data Visualization: How Aggregation Can Improve Performance]]></title>
            <link>https://levelup.gitconnected.com/optimizing-data-visualization-how-aggregation-can-improve-performance-6cbf6fd9277e?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cbf6fd9277e</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[reporting]]></category>
            <category><![CDATA[code-performance]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Sat, 02 Sep 2023 15:34:04 GMT</pubDate>
            <atom:updated>2023-09-03T15:29:32.276Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JqvD_lKDQBDfh_hMIdB9gg.png" /></figure><p>In today’s data-driven world, whether you’re an experienced e-commerce entrepreneur or anyone else, harnessing the power of data is paramount. We rely on data to inform our decisions, track progress, and uncover hidden insights. One common task, often underestimated in complexity, is visualizing data over extended periods. In this article, we’ll explore the challenges of visualizing extensive time-series data and share strategies to optimize performance. We’ll focus on how data aggregation can drastically reduce the dataset’s size while maintaining its representational value.</p><h3>The Challenge: Visualizing Time-Intensive Data</h3><p>Imagine you’re a data-driven e-commerce entrepreneur, running a successful online store. To refine your business strategy and make informed decisions, you decide to visualize your store’s total sales data over an extended period. It seems straightforward — a mere graphical representation of data, right? However, as you delve deeper into this task, you soon encounter a formidable challenge: performance issues that threaten to slow down your analytical processes.</p><h3>Understanding the Performance Bottlenecks</h3><ol><li>Data Volume Overload: The primary hurdle you face is the sheer volume of data. Accumulating a substantial amount of time-series data, be it for one year, seven years, or any extended duration, results in a massive dataset with potentially millions of data points. Attempting to load and process this extensive dataset in real-time becomes akin to trying to sip from a firehose. Your computing resources may struggle to cope, leading to slow response times and potential system crashes.</li><li>User Experience: If you intend to present these graphs in a user-facing application or dashboard, slow loading times can frustrate users, undermining their engagement with your analytics. This, in turn, can have tangible consequences for your e-commerce business.</li></ol><h3>Optimization Strategy: Data Aggregation for Efficiency</h3><p>Now that we’ve unraveled the challenges, let’s explore the power of data aggregation as one of the solution to optimize the performance of visualizing extensive time-series data:</p><p>Data Aggregation: Instead of plotting the raw daily data, consider aggregating the data into more manageable intervals, such as weekly or monthly summaries. This strategy drastically reduces the number of data points while preserving the essential trends and patterns. In essence, you’re looking at the forest instead of each individual tree.</p><ul><li>Example: Let’s say you have two years of daily sales data for your online store. This amounts to over 700 data points. By aggregating this data into monthly summaries, you reduce the dataset to just 24 data points — one for each month. The resulting graph is much easier to visualize, loads faster, and still conveys the overall sales trend. This transformation simplifies complex data into a clearer, more manageable format.</li></ul><p>Visual Comparison: To illustrate the impact of data aggregation, consider these two scenarios:</p><ol><li>Daily Data (700 data points): Visualizing your sales data on a daily basis results in a cluttered graph with numerous data points. While it captures fine-grained fluctuations, it can be overwhelming, especially when attempting to identify long-term trends.</li><li>Monthly Aggregated Data (24 data points): Aggregating your data into monthly summaries produces a cleaner, more concise graph. It retains the crucial insights about sales trends while eliminating the noise of daily fluctuations, offering a broader view of your business’s performance.</li></ol><h3>Conclusion: Efficiency Through Data Aggregation</h3><p>Visualizing extensive time-series data no longer needs to be a daunting task. By strategically implementing data aggregation, you can conquer the challenges, ensure smooth performance, and extract valuable insights to drive your decisions forward.</p><p>From a business perspective, it’s important to recognize that not all data requires the same level of granularity. While daily or even hourly data may be crucial for specific scenarios, such as monitoring real-time trends or responding to immediate changes, monthly data often suffices for broader insights and strategic decision-making. Striking the right balance between granularity and performance can result in a more efficient use of computational resources, ultimately enhancing your ability to extract actionable insights from your data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cbf6fd9277e" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/optimizing-data-visualization-how-aggregation-can-improve-performance-6cbf6fd9277e">Optimizing Data Visualization: How Aggregation Can Improve Performance</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Preventing Data Inconsistencies in MySQL: Strategies for Avoiding Lost Updates]]></title>
            <link>https://levelup.gitconnected.com/preventing-data-inconsistencies-in-mysql-strategies-for-avoiding-lost-updates-cfdb04107f7c?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfdb04107f7c</guid>
            <category><![CDATA[query-optimization]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[data-consistency]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Wed, 29 Mar 2023 18:09:40 GMT</pubDate>
            <atom:updated>2023-04-06T02:14:08.464Z</atom:updated>
            <content:encoded><![CDATA[<p>A few weeks ago, I encountered a situation where our inventory tracking system reported inconsistencies. After researching the issue, I discovered that concurrency problems in our MySQL database may have been the root cause. Further investigation revealed a “lost update” concurrency issue. To prevent similar issues from arising in the future, I have been exploring various strategies for optimizing our database. Before finding a solution, it is necessary to understand what concurrency is and why transaction isolation is important.</p><h4>Concurrency Issues in MySQL</h4><p>Concurrency situations in MySQL can occur when multiple transactions attempt to access or modify the same data simultaneously, which can potentially result in data inconsistencies or errors. These situations include lost updates, dirty reads, and phantom reads.</p><ul><li>A lost update occurs when two transactions attempt to update the same data, but only one of them is successful, causing the changes made by the other transaction to be lost. To prevent lost updates, a transaction isolation level of at least REPEATABLE READ is required, which uses shared locks to prevent other transactions from modifying the data.</li><li>Dirty reads occur when a transaction reads uncommitted changes made by another transaction, which may later be rolled back. A transaction isolation level of READ COMMITTED or higher can prevent dirty reads.</li><li>Phantom reads occur when a transaction sees a set of rows that satisfies a certain condition, but another transaction inserts or deletes rows that also satisfy the same condition, causing the first transaction to see a different set of rows. To prevent phantom reads, a transaction isolation level of at least REPEATABLE READ is required, which uses gap locks to prevent other transactions from inserting or deleting rows that would affect the first transaction’s results.</li></ul><h4>Transaction Isolation Levels in MySQL</h4><p>Isolation is critical in databases as it ensures transactional consistency and prevents data corruption or inconsistencies caused by concurrent updates. It enables transactions to occur in isolation, allowing them to commit or roll back independently of other transactions, ensuring that the data remains consistent and accurate.</p><p>MySQL provides four transaction isolation levels that determine how transactions interact with one another and how changes are visible to other transactions.</p><ol><li>READ UNCOMMITTED: Allows dirty reads, meaning a transaction can read uncommitted changes made by another transaction.</li><li>READ COMMITTED: Prevents dirty reads by only allowing a transaction to read changes that have been committed by other transactions.</li><li>REPEATABLE READ: Ensures that a transaction can read the same set of rows consistently, even if other transactions are updating the same data simultaneously. This is achieved by placing shared locks on all the rows accessed by the transaction.</li><li>SERIALIZABLE: Provides the highest level of isolation by ensuring that transactions are executed in a serialized manner, preventing any concurrent modifications to the data. This is achieved by placing range locks on all the rows that the transaction accesses.</li></ol><h4>How do lost updates happen?</h4><p>In my case, my database is using repeatable read isolation. Here is a situation where a lost update can occur:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7OvERn578IouQ_Zy33KVqQ.png" /><figcaption>Credit to: <a href="https://medium.com/@chester.yw.chu/%E5%B0%8D%E6%96%BC-mysql-repeatable-read-isolation-%E5%B8%B8%E8%A6%8B%E7%9A%84%E4%B8%89%E5%80%8B%E8%AA%A4%E8%A7%A3-7a9afbac65af">https://medium.com/@chester.yw.chu/對於-mysql-repeatable-read-isolation-常見的三個誤解-7a9afbac65af</a></figcaption></figure><p>A lost update in inventory occurs when two transactions try to update the same item simultaneously, but only one succeeds, causing the other transaction’s changes to be lost, leading to inventory inconsistencies.</p><h4>How to avoid lost update?</h4><ul><li>Use Atomic operations</li></ul><pre>UPDATE inventory SET quantity = quantity - 4 WHERE item = A;</pre><ul><li>use lock</li></ul><pre>SELECT * FROM inventory FOR UPDATE; <br>UPDATE inventory SET quantity = 6 WHERE item = A; COMMIT;</pre><h3>Summary</h3><p>Ensuring transactional consistency is crucial for preventing data corruption or inconsistencies caused by concurrent updates. Concurrency issues in MySQL can occur when multiple transactions access or modify the same data simultaneously. To prevent lost updates, dirty reads, and phantom reads, MySQL provides several transaction isolation levels. In cases where lost updates may occur, atomic operations or locks can be used to prevent inventory inconsistencies. By understanding these concepts and implementing appropriate strategies, databases can be optimized to prevent concurrency issues and ensure transactional consistency.</p><h4>Credit:</h4><ul><li><a href="https://medium.com/@chester.yw.chu/%E5%B0%8D%E6%96%BC-mysql-repeatable-read-isolation-%E5%B8%B8%E8%A6%8B%E7%9A%84%E4%B8%89%E5%80%8B%E8%AA%A4%E8%A7%A3-7a9afbac65af">對於 MySQL Repeatable Read Isolation 常見的三個誤解</a></li><li><a href="https://medium.com/@chester.yw.chu/%E8%A4%87%E7%BF%92%E8%B3%87%E6%96%99%E5%BA%AB%E7%9A%84-isolation-level-%E8%88%87%E5%B8%B8%E8%A6%8B%E7%9A%84%E4%BA%94%E5%80%8B-race-conditions-%E5%9C%96%E8%A7%A3-16e8d472a25c">複習資料庫的 Isolation Level 與常見的五個 Race Conditions 圖解</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfdb04107f7c" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/preventing-data-inconsistencies-in-mysql-strategies-for-avoiding-lost-updates-cfdb04107f7c">Preventing Data Inconsistencies in MySQL: Strategies for Avoiding Lost Updates</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cleaning Up Your Rails Application: How to Identify and Categorize Unused Controller Methods]]></title>
            <link>https://levelup.gitconnected.com/cleaning-up-your-rails-application-how-to-identify-and-categorize-unused-controller-methods-7288ee88b5c5?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7288ee88b5c5</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Tue, 21 Mar 2023 19:21:07 GMT</pubDate>
            <atom:updated>2023-04-06T02:13:58.267Z</atom:updated>
            <content:encoded><![CDATA[<p>To begin, let’s discuss the importance of identifying unused controller methods in a Rails application. As the codebase grows, there may be some controller methods that are no longer being used. These methods could have been created for a specific use case that is no longer relevant, or maybe they were created as part of the initial implementation but were never used. Unused controller methods can clutter the codebase, making it difficult to understand the code and even slowing down the application’s performance.</p><h3>Code Block Breakdown</h3><p>To identify these unused controller methods, we can use the provided code block. The code block utilizes Rails’ routing API and Ruby’s reflection capabilities to retrieve all the routes for the current Rails application and all the controller methods for each controller in the app/controllers folder, respectively.</p><h3>Retrieving Routes</h3><p>The first part of the code block retrieves all the routes for the current Rails application and extracts the controller and action for each route.</p><pre>routes = Rails.application.routes.routes.each_with_object([]) do |r, tmp_routes|<br>  tmp_routes &lt;&lt; r<br>end<br><br>routed_actions = routes.map do |r|<br>  # Extract the controller name and convert to CamelCase.<br>  controller = r.requirements[:controller].to_s<br>  controller = controller.split(&quot;/&quot;)<br>  controller = controller.map { |s| s.camelize }<br>  controller = controller.join(&quot;::&quot;)<br>  controller = &quot;#{controller}Controller&quot;<br>  &quot;#{controller}##{r.requirements[:action]}&quot;<br>end.sort</pre><h3>Retrieving Controller Methods</h3><p>The second part of the code block retrieves all the controller methods for each controller in the app/controllers folder (excluding subdirectories with ‘concerns’) and extracts the controller and method name for each.</p><pre>controllers = Dir.glob(Rails.root.join(&#39;app/controllers/**/*_controller.rb&#39;)).reject { |f| f.include?(&#39;concerns/&#39;) }.map { |f| f.sub(Rails.root.join(&#39;app/controllers/&#39;).to_s, &#39;&#39;).sub(/\\.rb$/, &#39;&#39;).camelize }<br><br>all_actions = controllers.flat_map do |controller|<br>  # Get the controller class and extract the public, protected and private instance methods.<br>  klass = &quot;#{controller}&quot;.safe_constantize<br>  if klass<br>    public_instance_methods = klass.public_instance_methods(false)<br>    protected_instance_methods = klass.protected_instance_methods(false)<br>    private_instance_methods = klass.private_instance_methods(false)<br>    # Return an array of strings in the format &quot;Controller#method&quot;.<br>    (public_instance_methods + protected_instance_methods + private_instance_methods).map { |m|<br>      &quot;#{controller.camelize}##{m}&quot;<br>    }<br>  else<br>    []<br>  end<br>end.sort</pre><h3>Subtracting Unused Methods</h3><p>The third part of the code block subtracts the routed_actions from the methods to get the unused methods.</p><pre>result = all_actions - routed_actions<br>result = result.sort</pre><p>In conclusion, identifying and categorizing unused controller methods in a Rails application is an important process to maintain a clean and efficient codebase. The provided code block offers a way to retrieve all the routes and controller methods in the application, allowing developers to easily identify unused methods. By removing these unused methods, developers can improve the readability of the codebase and potentially increase the application’s performance.</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>💰 Free coding interview course ⇒ <a href="https://skilled.dev/?utm_source=luc&amp;utm_medium=article">View Course</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7288ee88b5c5" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/cleaning-up-your-rails-application-how-to-identify-and-categorize-unused-controller-methods-7288ee88b5c5">Cleaning Up Your Rails Application: How to Identify and Categorize Unused Controller Methods</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing AWS Costs: Essential Tips for Maximizing Efficiency]]></title>
            <link>https://levelup.gitconnected.com/optimizing-aws-costs-essential-tips-for-maximizing-efficiency-f6efe255b786?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6efe255b786</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cloud-cost-optimization]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Mon, 06 Mar 2023 17:07:17 GMT</pubDate>
            <atom:updated>2023-03-06T17:07:17.082Z</atom:updated>
            <content:encoded><![CDATA[<p>As more and more organizations move their operations to the cloud, AWS has become a popular choice for managing and deploying workloads.</p><p>While AWS offers many benefits, it’s important to ensure that you’re using the platform in a cost-effective way to avoid unexpected expenses. Fortunately, there are many strategies you can use to optimize your AWS environment and reduce costs.</p><p>From choosing the right instance type and storage class to taking advantage of cost-effective network options and implementing best practices for general optimization, this summary will provide you with some essential tips for maximizing cost efficiency in AWS. By following these tips, you can ensure that you’re getting the most out of your AWS investment while keeping your costs under control.</p><h4>Compute Optimization:</h4><ul><li>Use AWS Graviton for RDS to potentially save on costs.</li><li>Observe your instances’ CPU and memory usage, such as RDS and ECS Fargate. Sometimes there is room for downsizing.</li></ul><h4>Storage Optimization:</h4><ul><li>RDS storage, especially Multi-AZ, can be expensive.</li><li>Consider using GP3 storage to isolate IOPS with storage. Unlike GP2, GP3 allows you to use a certain amount of storage to have good IOPS.</li><li>Recycle unused RDS snapshots to avoid unnecessary charges.</li><li>Utilize the S3 storage lens metric to understand your S3 usage.</li><li>Consider deleting non-current version S3 objects or putting them into a suitable storage class.</li><li>If your bucket is versioned, delete objects with delete markers.</li><li>Choose the right size of EBS to avoid over-provisioning and excess charges.</li></ul><h4>Network Optimization:</h4><ul><li>Put your instances in the correct zone to avoid cross-zone charges.</li><li>Use CloudFront to serve static content to reduce data transfer costs.</li><li>Remove unassociated Elastic IP addresses.</li></ul><h4>General Optimization:</h4><ul><li>Multi-AZ is resilient and good for production environments, but try to balance cost as much as possible.</li><li>Cross-check any unnecessary usage across multiple AWS accounts for each environment.</li><li>Choose a suitable AWS support plan to balance cost and support needs.</li></ul><p>By implementing these cost optimization measures, you can improve the efficiency and reduce costs across various areas of your AWS environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6efe255b786" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/optimizing-aws-costs-essential-tips-for-maximizing-efficiency-f6efe255b786">Optimizing AWS Costs: Essential Tips for Maximizing Efficiency</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guidelines for Migrating a Large Dataset Database from RDS to RDS with Minimal Downtime]]></title>
            <link>https://levelup.gitconnected.com/guidelines-for-migrating-a-large-dataset-database-from-rds-to-rds-with-minimal-downtime-f0a70122be43?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0a70122be43</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[database-migration]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Wed, 22 Feb 2023 15:59:23 GMT</pubDate>
            <atom:updated>2023-04-06T02:12:53.038Z</atom:updated>
            <content:encoded><![CDATA[<p>Migrating a large dataset database with minimal downtime can be a daunting task, but with careful planning and execution, it is possible to minimize downtime and ensure a smooth transition. This article will provide a step-by-step guide to migrating a large dataset database, based on the guidelines outlined in our document.</p><h3>Getting Started</h3><p>Before we dive into the steps, it is important to understand the importance of planning and executing the migration carefully. A poorly executed migration can result in data loss or extended downtime, which can have a significant impact on your business. To avoid these issues, it is essential to carefully plan the migration, test it thoroughly, and have a rollback plan in case of any issues.</p><p>The first step in migrating a large dataset database is to modify the custom DB parameter group by setting the parameter <strong>log_bin_trust_function_creators</strong> to <strong>1</strong>. This will allow the database to trust stored functions and procedures, which is necessary for replication.</p><p>The next step is to prepare an EC2 machine with sufficient storage. This machine will be used to back up data from the source slave database. It is essential to ensure that the backup machine has enough storage capacity to hold the database backup.</p><p>Once the backup machine is ready, the binlog retention period for the source master database should be set to a sufficiently long duration. This can be done by connecting to the source master using MySQL Workbench and executing the following command:</p><pre>CALL mysql.rds_set_configuration(&quot;binlog retention hours&quot;, 24);</pre><p>It is important to note that this command sets the binlog retention period in hours. You should set it to a value greater than the expected duration of the migration to ensure that you have enough time to complete the migration.</p><p>The source slave database should also be readied at this point. This involves ensuring that the database is up to date and that there are no issues that could cause the migration to fail.</p><p>Before proceeding further, it is important to verify that the retention settings on both the master and slave databases are identical. The retention period should be set to the same value on both databases. This can be checked by connecting to both the source master and slave with MySQL Workbench and executing the command:</p><pre>CALL mysql.rds_show_configuration;</pre><p>This command will show the current configuration of the database, including the binlog retention period. Ensure that the retention period is set to the same value on both databases.</p><p>At this point, replication of data from the source master database to the source slave database should be stopped. This can be done by connecting to the source slave with MySQL Workbench and executing the command:</p><pre>CALL mysql.rds_stop_replication;</pre><p>Stopping replication ensures that there are no changes to the database during the migration process.</p><p>The mysql client should then be installed into the backup machine, and data should be backed up from the source slave database to the backup machine using the following command:</p><pre>mysqldump -h source-database-rep.abc.ap-southeast-1.rds.amazonaws.com -u root -pPASSWORD --single-transaction --all-databases --triggers --routines --events &gt; your-backup.sql</pre><p>This command will create a backup of the entire database and store it in the file <strong>your-backup.sql</strong>. It is important to ensure that the backup file is stored in a secure location and that it is not accessible to unauthorized users.</p><p>The target master database can now be prepared, and the backup can be restored into the target master database. It is recommended to execute this using Unix screen to ensure that the process is not interrupted.</p><p>Once the backup has been restored, the name and position of the last bin log file from the source slave database should be copied. This can be done by connecting to the source slave database with MySQL Workbench and executing the command:</p><pre>show slave status;</pre><p>This command will show the replication status of the database, including the name and position of the last bin log file. These values should be copied and used to configure the target master database to replicate data from the source master database.</p><p>The target master database can now be set to replicate data from the source master database by connecting to the target master with MySQL Workbench and executing the following command:</p><pre>CALL mysql.rds_set_external_master (<br>  source-database-rep.abc.ap-southeast-1.rds.amazonaws.com,<br>	3306,<br>  source-database-root,<br>  source-database-password,<br>  Relay_Master_Log_File value,<br>  Exec_Master_Log_Pos value,<br>  0<br>);<br>CALL mysql.rds_start_replication;</pre><p>This command will configure the target master database to replicate data from the source master database. It is important to wait until the target master database catches up with the source master database before proceeding. This can be checked by connecting to the target master with MySQL Workbench and executing the command:</p><pre>show slave status;</pre><p>This command will show the replication status of the target master database. Wait until the replication status shows that the target master database has caught up with the source master database.</p><p>Once the target master database is caught up with the source master database, several tables should be compared between the source and target master databases to ensure that the data has been migrated correctly. It is important to verify that the data has been migrated correctly before proceeding.</p><p>At this point, your services should be paused, and the instances in the source cluster should be stopped. The replication connection between the target master database and the source master database should then be cut off by connecting to the target master with MySQL Workbench and executing the command:</p><pre>CALL mysql.rds_stop_replication;<br>CALL mysql.rds_reset_external_master;</pre><p>This command will stop the replication connection and reset the external master configuration. The target slave database should now be prepared if necessary, and the target cluster can be promoted as the new primary. The source cluster can then be deleted.</p><p>Finally, the custom DB parameter group should be modified by setting the <strong>log_bin_trust_function_creators</strong> parameter to default.</p><p>By following these steps, it is possible to migrate a large dataset database with minimal downtime and ensure a smooth transition. It is important to plan the migration carefully, test it thoroughly, and have a rollback plan in case of any issues.</p><p>References:</p><p><a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Exporting.NonRDSRepl.html">https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Exporting.NonRDSRepl.html</a></p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>💰 Free coding interview course ⇒ <a href="https://skilled.dev/?utm_source=luc&amp;utm_medium=article">View Course</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0a70122be43" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/guidelines-for-migrating-a-large-dataset-database-from-rds-to-rds-with-minimal-downtime-f0a70122be43">Guidelines for Migrating a Large Dataset Database from RDS to RDS with Minimal Downtime</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How do I setup my co-found website with just $5]]></title>
            <link>https://medium.com/@yoonsin91/how-do-i-setup-my-co-found-website-with-just-5-be1dcb3092bb?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/be1dcb3092bb</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[digitalocean]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[cloudflare]]></category>
            <category><![CDATA[website-development]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Sun, 16 Sep 2018 07:58:16 GMT</pubDate>
            <atom:updated>2018-09-16T07:58:16.181Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z4pIWStAawzZV9Tc4heK_g.png" /><figcaption>https://www.flashub.co</figcaption></figure><p>I recently getting started on my part-time entrepreneurship. After weeks of discussion with my founding team, we ended up to start up a company focusing on social proof marketing. We believe we could help e-commerce businesses to gain more sales and leads using social proof marketing. So we started our first move, building our official website. So we need few things in order to host our website, which is virtual server, DNS management, SSL.</p><h3><strong>Selecting the right cloud solution for your current phase</strong></h3><p>We had experiences with Amazon Web Services(AWS) for couple years, we ended up choosing <a href="https://m.do.co/c/8744cd78bfcd">DigitalOcean</a> as our cloud service provider.</p><p>The reason behind choosing <a href="https://m.do.co/c/8744cd78bfcd">DigitalOcean</a> is cost optimization. DigitalOcean’s pricing is the most affordable among all cloud service providers. Pricing start at $0.007/hr or $5/mo and they provide an easy transition between the hourly and monthly tariffs. On AWS. t3.small instance which goes for $0.0264/hr. The plus point is that <a href="https://m.do.co/c/8744cd78bfcd">DigitalOcean</a> does not have any extra charges for fixed IP, bandwidth and etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*ZZRToWStQ_LS38viy84_lg.png" /></figure><h3>Cloudflare, the Best DNS for Everyone</h3><p><a href="https://www.cloudflare.com/">Cloudflare</a> is a U.S. company that provides DNS services, a Content Delivery Network (CDN), DDoS protection, and other Internet security services.</p><p>Cloudflare DNS is one of best DNS providers in the world. It offers free accounts so everyone can not only manage their domain names, but also benefit from the additional security and performance enabled by their integrated features.</p><p>Cloudflare Basic account is $0/month(FREE). Which included DNS management, global CDN, unmetered mitigation of DDoS, shared SSL certificates, and etc in Basic account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*JBg9qqkAthaaOX2BWKpF3A.png" /></figure><p>We migrated our domain DNS to Cloudflare DNS. The best part of Cloudflare DNS migration is that Cloudflare able to detect all your DNS records. So you can migrate easily with one click without key in one more time for all your DNS records.</p><p>Cloudflare is offering free wildcard SSL certificates for all the domain that hosted on Cloudflare. This helping us to reduce our cost to getting a paid SSL certificate.</p><h3>A well manage startup budget is key to success</h3><p>Having a well manage startup budget could help us to create more valuable business. Flashub founding team believe that, we should optimize our infrastructure costing. So we could put our budget towards to marketing ads, hiring more peoples to bring values to the market.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be1dcb3092bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The secret of selling more online using simple product recommendation]]></title>
            <link>https://medium.com/@yoonsin91/the-secret-of-selling-more-online-using-simple-product-recommendation-6f958ef836fb?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f958ef836fb</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Sun, 17 Dec 2017 10:14:20 GMT</pubDate>
            <atom:updated>2017-12-17T10:14:20.195Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*jECj_4eOd3XcPKD9ziKcDg.png" /></figure><p>In this article, I will explain how to build a simple product recommendation using an online store’s order data.</p><p>I will start with a definition. A recommendation system is a technology that is deployed in the environment where <strong><em>items </em></strong><em>(products, movies, events, articles)</em><strong><em> </em></strong>are to be recommended to <strong><em>users </em></strong><em>(customers, visitors, app users, readers) </em>or the opposite. Typically, there are <em>many </em>items and <em>many </em>users present in the environment making the problem hard and expensive to solve. Imagine a store selling fruits online, having a lot orders from past few months or years. They would like to increase their profits and customer satisfactions by quality recommendations.</p><p>First of all, we need the store’s order items dataset in order to design the algorithm. The more you know about your users and items, the better results can be expected. Below, I prepare a simple example of dataset:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EGaTI6xGtmCW6steDzskwA.png" /><figcaption>A set of order items bought by every buyers</figcaption></figure><p>The second step will prepare a table to with all your products. A graph or a table is for us to plot data and visualize with our result to allow us more understand what the data mean to us. Below, I prepare a simple example of dataset table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*PAtECYWmY6ldddscn0tnsQ.png" /></figure><p>We got our dataset and table, so we gonna step into the fun part. Prepare algorithm to find the relationship between all the order item. So the first thing to do is, select the first item in every orders as primary item. Example as below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0dIaeHwZ0C1PvA8Y9-3Xg.png" /></figure><p>The formula I designed for determine the relationship between items and the primary item is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/62/1*xl4FlovbAnsEPjyny3JzQA.png" /><figcaption><strong><em>X is the range between item and primary item</em></strong></figcaption></figure><p>Example as below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e57IMvJiHuLJZFJMRbgVvg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wcXYYAp1w6syKx24VZL3wg.jpeg" /></figure><p>The X with a circle which means there is no relationship between them. For example, apple and orange relationship had counted. So the second relationship between apple and orange is not necessary to be included.</p><p>At last, we should sum up all the result together and plot into the table we setup earlier. The final result will be similar like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*nYaZNY9n6KuUSEm-by09ig.png" /></figure><p>Based on the result, we should know what items to recommend for our users when they start adding their first product into cart. I hope this article will help you start with a simple way to create your own product recommendation system.</p><p>Again, you can expect better performance of recommender system, when the feedback is rich.</p><p>Last but not least, please leave your comment to help me to become more knowledgeable person. Thanks everyone!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f958ef836fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Repositories Pattern in Lumen]]></title>
            <link>https://medium.com/@yoonsin91/the-repositories-pattern-in-lumen-75cf08145d96?source=rss-9434289cf5b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/75cf08145d96</guid>
            <category><![CDATA[lumen]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[yoonsin91]]></dc:creator>
            <pubDate>Sun, 29 Oct 2017 07:45:05 GMT</pubDate>
            <atom:updated>2017-10-29T07:45:05.524Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*fGIunnfcTkvrBUhOWERDUg.png" /></figure><p><strong>What is repositories pattern?</strong></p><p>“Repository commonly refers to a storage location, often for safety or preservation.” — Wikipedia</p><p>This is how Wikipedia described about repository. What I think of repository is some sort of collections. It’s contain of entities and data sources. You can filtered and return what entities back based on the needs of your application.</p><p><strong>What can repositories pattern help?</strong></p><p>The repositories pattern is widely used pattern whose main point is that the application does not have to know data is implemented. This makes it easier to switch to another data source or implement structural changes to the existing data source.</p><p><strong>So how repositories work?</strong></p><p>The repositories pattern introduced repository interface, which define how application communicate with entities. Each repository has its own class which implements the repository interface. The controller class will just call method that defined in interface and will not know how and where the data from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xrqi9vAS__B9Ot1qK578Gw.jpeg" /></figure><p><strong>Implementation in Lumen</strong></p><p>Imagine you need to create a simple API endpoint for create user. So Firstly, you design a RESTful POST route and UserController.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*DIO8iEeXJ0uxzy6UjnEkGw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X5muvXZD4371CdxanfL22w.png" /></figure><p>The next thing is, create a repository interface. It can be located anywhere. but in this example, we will use the following directory structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZ6CR-SrxN0fRtJEPTILXw.png" /></figure><p>So let’s create UserRepository that is responsible for holding business rules and business logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JlhHH_lGXjHeejYI-vPVHw.png" /></figure><p>To be able to use these classes in the framework, we need to register the service provider:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Exqc_ZKNa44mwSm1emE76Q.png" /></figure><p>At this point, the repository can be injected into controller classes. An example controller would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dj0KThWO5mTAx78bi8e4EQ.png" /></figure><p><strong>Summary</strong></p><p>The separation of data access from business logic have many benefits. Some of them are:</p><ul><li>Centralization of the data access logic makes code easier to maintain</li><li>Business and data access logic can be tested separately</li><li>Reduces duplication of code</li><li>A lower chance for making programming errors</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75cf08145d96" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>