<?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 Manika Tyagi on Medium]]></title>
        <description><![CDATA[Stories by Manika Tyagi on Medium]]></description>
        <link>https://medium.com/@manika.tyagi09?source=rss-893f9856f405------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qQlVaveHE_xfrCuQGwcWBw.png</url>
            <title>Stories by Manika Tyagi on Medium</title>
            <link>https://medium.com/@manika.tyagi09?source=rss-893f9856f405------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 08:43:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manika.tyagi09/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[Debugging: Your Logs Cheat Sheet]]></title>
            <link>https://medium.com/@manika.tyagi09/debugging-your-logs-cheat-sheet-169d1c7aba1f?source=rss-893f9856f405------2</link>
            <guid isPermaLink="false">https://medium.com/p/169d1c7aba1f</guid>
            <category><![CDATA[stern]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[logs]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[kubectl]]></category>
            <dc:creator><![CDATA[Manika Tyagi]]></dc:creator>
            <pubDate>Mon, 22 Sep 2025 11:50:02 GMT</pubDate>
            <atom:updated>2025-09-22T11:50:02.286Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*It38T_TaTwKqPJcj.png" /></figure><p>As an SDE, fetching logs is essential for:</p><ul><li><strong>Debugging:</strong> Quickly finding the root cause of production errors and application crashes.</li><li><strong>Monitoring:</strong> Gaining real-time visibility into an application’s health and performance.</li><li><strong>Understanding Behavior:</strong> Analyzing how your application works in a live environment to inform future development.</li><li><strong>Security &amp; Compliance:</strong> Creating an audit trail for security investigations and regulatory requirements.</li></ul><h3>kubectl logs</h3><p>kubectl krew install tail</p><ul><li>kubectl logs is the built-in Kubernetes tool for viewing logs. It&#39;s available on any system with kubectl installed, and it works directly with the Kubernetes API.</li><li>It’s best for fetching a one-time snapshot of logs or for following a single pod’s log stream in real-time (-f flag).</li><li>While it can aggregate logs from multiple pods via a label selector, the output can be hard to read as it doesn’t color-code or easily distinguish logs from different pods.</li></ul><h3>stern</h3><p>Installation: <a href="https://github.com/stern/stern">https://github.com/stern/stern</a></p><p>brew install stern</p><ul><li>Stern is a third-party, specialized tool designed specifically for tailing logs from multiple pods and containers. You must install it separately.</li><li>Stern’s main advantage is its use of color-coding to differentiate log lines from various pods and containers, making it much easier to follow logs from a complex application.</li><li>It offers robust filtering capabilities, allowing you to use regular expressions to target specific pod names, container names, or even specific log content.</li></ul><h3>FETCHING LOGS FROM COMMAND</h3><h4>1) lists all pods in the namespace</h4><p>kubectl get pods -n &lt;namespace-name&gt; — context &lt;context-name&gt;</p><h4>2) lists all pods in the namespace within the cluster context and displays their labels</h4><p>kubectl get pods -n &lt;namespace-name&gt; — context &lt;context-name&gt; — show-labels</p><h4>3) Fetch live logs from all pods</h4><ul><li>Kubectl command:</li></ul><p>kubectl logs — selector=app=&lt;app-name&gt; — context &lt;context&gt; — all-containers — max-log-requests=1000 -f -n &lt;namespace&gt;</p><ul><li>Stern Command:</li></ul><p>stern — context ph2 -n &lt;namespace&gt; &lt;app-name&gt; — since=1s — max-log-requests 1000</p><h4>4) Fetch old logs from all pods</h4><ul><li>Kubectl command:</li></ul><p>kubectl tail -n &lt;namespace&gt; -l app=&lt;app-name&gt; — since=&lt;time&gt; — context &lt;context&gt;</p><ul><li>Stern Command:</li></ul><p>stern — context ph2 -n &lt;namespace&gt; &lt;app-name&gt; — since=&lt;time&gt; — max-log-requests 1000</p><h4>5) Fetch single pod live logs</h4><ul><li>Kubectl commond:</li></ul><p>kubectl tail -n &lt;namespace&gt; -l app=&lt;deployment-name&gt; -p &lt;pod-name&gt; — since=1s — context ph2</p><ul><li>Stern Command:</li></ul><p>stern — context ph2 &lt;pod-name&gt; -n &lt;namespace&gt; &lt;pod-name&gt; — since=1s</p><h4>6) Fetch single pod old logs</h4><ul><li>Kubectl commond:</li></ul><p>kubectl tail -n &lt;namespace&gt; -l app=&lt;deployment-name&gt; -p &lt;pod-name&gt; — since=30 — context ph2</p><ul><li>Stern Command:</li></ul><p>stern — context ph2 &lt;pod-name&gt; -n &lt;namespace&gt; &lt;pod-name&gt; — since=30m</p><h4>7) Grep Command</h4><p>We can combine the above commands with grep statements to get the desired output.</p><p>example:</p><p>stern — context ph2 &lt;pod-name&gt; -n &lt;namespace&gt; &lt;pod-name&gt; — since=1s | grep “ERROR”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=169d1c7aba1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering SOLID Principles: Writing Better Object-Oriented Code]]></title>
            <link>https://medium.com/@manika.tyagi09/mastering-solid-principles-writing-better-object-oriented-code-3fd71d60ef95?source=rss-893f9856f405------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fd71d60ef95</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[object-oriented-concepts]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[solid-principles-in-java]]></category>
            <dc:creator><![CDATA[Manika Tyagi]]></dc:creator>
            <pubDate>Tue, 20 May 2025 11:36:40 GMT</pubDate>
            <atom:updated>2025-05-20T11:36:40.586Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/0*PgonEmvBP-QkCeIa.png" /></figure><blockquote>In the ever-evolving world of software development, writing clean, maintainable, and scalable code is more critical than ever. As applications grow in complexity, developers often face challenges related to code readability, reusability, and flexibility. This is where the <strong>SOLID principles</strong> come into play. Coined by Robert C. Martin (Uncle Bob), SOLID is an acronym representing five core design principles that guide developers in crafting better object-oriented software. Whether you’re a seasoned engineer or just starting out, understanding and applying these principles can dramatically improve the structure and longevity of your codebase.</blockquote><p><strong>SOLID</strong> stands for:</p><p>S — Single Responsibility Principle (SRP)</p><p>O — Open/Closed Principle (OCP)</p><p>L — Liskov Substitution Principle (LSP)</p><p>I — Interface Segregation Principle (ISP)</p><p>D — Dependency Inversion Principle (DIP)</p><h4><strong>The Single Responsibility Principle</strong></h4><p>The Single Responsibility Principle emphasizes that a class should have only one reason to change — meaning it should handle a single responsibility or function. If a class has more than one reason to change, it has more than one responsibility. Instead, we should break it into smaller classes, where each class handles just one task. This makes the code easier to understand, test, and update.</p><p>SRP Example — Violating SRP</p><pre>public class Report {<br> public String generateReport() {<br> // Logic to generate report<br> return “Report Content”;<br> }<br>public void saveToFile(String content) {<br> // Logic to save report to a file<br> System.out.println(&quot;Saving to file: &quot; + content);<br> }<br>}</pre><p><strong>Issue</strong>: This class is doing <strong>two responsibilities</strong>: Generating the report , Saving it to a file. It <strong>violates SRP</strong> because changes in saving logic or generation logic could force changes in the same class.</p><p>Refactored Version — Follows SRP</p><pre>public class Report {<br>    public String generateReport() {<br>        return &quot;Report Content&quot;;<br>    }<br>}<br><br>public class ReportSaver {<br>    public void saveToFile(String content) {<br>        System.out.println(&quot;Saving to file: &quot; + content);<br>    }<br>}</pre><p>Now each class has one responsibility, report is only responsible for generating data. ReportSaver is only responsible for saving.</p><h4><strong>The open close principle</strong></h4><p><em>software should be open for extension but closed for modification.</em></p><p>The Open/Closed Principle says that code should be open for adding new features but closed for making changes to existing code. This means when requirements change or new features are needed, developers should be able to extend the current functionality without changing the original code. Instead of editing old code, we should add new code in a way that works with what’s already there. This helps keep existing code stable and reduces the risk of breaking something that already works.</p><p>OCP Example — Violating OCP</p><p>Suppose you want to add more ways to save the report (e.g., to a file, database, or cloud). Here’s a design that violates OCP:</p><pre>public class ReportSaver {<br>    public void save(String content, String type) {<br>        if (type.equals(&quot;file&quot;)) {<br>            System.out.println(&quot;Saving to file: &quot; + content);<br>        } else if (type.equals(&quot;db&quot;)) {<br>            System.out.println(&quot;Saving to database: &quot; + content);<br>        }<br>        // Adding more types will require modifying this class again<br>    }<br>}</pre><p>Refactored Version — Follows OCP using Abstraction</p><pre>public interface ReportSaver {<br>    void save(String content);<br>}<br><br>public class FileReportSaver implements ReportSaver {<br>    public void save(String content) {<br>        System.out.println(&quot;Saving to file: &quot; + content);<br>    }<br>}<br><br>public class DatabaseReportSaver implements ReportSaver {<br>    public void save(String content) {<br>        System.out.println(&quot;Saving to database: &quot; + content);<br>    }<br>}</pre><p>Open for extension — just create a new class like CloudReportSaver. Closed for modification — existing logic doesn’t need to change.</p><h4><strong>The Liskov substitution principle</strong></h4><p>The Liskov Substitution Principle states that objects of a subclass should be able to replace objects of the superclass without changing how the program works. In simple terms, if class B is a subclass of class A, then you should be able to use B anywhere A is expected — without causing errors or unexpected behavior. This principle supports the idea of reliable inheritance.</p><p>Violating LSP Example</p><p>Let’s say we introduce a ReadOnlyReportSaver subclass that does not allow saving at all:</p><pre>public class ReadOnlyReportSaver implements ReportSaver {<br>    public void save(String content) {<br>        throw new UnsupportedOperationException(&quot;Saving not allowed.&quot;);<br>    }<br>}<br><br>ReportSaver saver = new ReadOnlyReportSaver();<br>saver.save(&quot;Report Content&quot;);  // This will crash</pre><p>This class inherits the interface, but violates the contract by not behaving like other ReportSaver types. It breaks LSP because substituting ReadOnlyReportSaver causes unexpected failure.</p><p>Refactored Version — Follows LSP</p><pre>// Only real savers implement this<br>public interface ReportSaver {<br>    void save(String content);<br>}<br><br>public class FileReportSaver implements ReportSaver {<br>    public void save(String content) {<br>        System.out.println(&quot;Saving to file: &quot; + content);<br>    }<br>}<br><br>// Read-only report should not implement ReportSaver<br>public class ReadOnlyReport {<br>    public String getContent() {<br>        return &quot;Read-only content&quot;;<br>    }<br>}<br><br>ReportSaver saver = new FileReportSaver();   <br>saver.save(&quot;Report Content&quot;);<br><br>ReadOnlyReport readOnly = new ReadOnlyReport(); </pre><p>Now all subclasses of ReportSaver are substitutable without breaking the code — upholding LSP.</p><h4><strong>The Interface Segregation Principle</strong></h4><p>The Interface Segregation Principle states that no client should be forced to depend on methods it does not use. In other words, interfaces should be small and specific to the needs of the implementing classes, rather than large and general-purpose. When an interface contains too many unrelated methods, it becomes difficult to implement and maintain. By splitting large interfaces into smaller, role-specific ones, we ensure that each class only depends on what it actually needs, making the design cleaner, more flexible, and easier to manage.</p><p>Violating ISP</p><pre>public interface ReportActions {<br> void generate();<br> void save();<br> void print();<br>}</pre><p>Now suppose a CloudReport only supports generating and saving, but not printing</p><pre>public class CloudReport implements ReportActions {<br>    public void generate() {<br>        System.out.println(&quot;Generating cloud report&quot;);<br>    }<br><br>    public void save() {<br>        System.out.println(&quot;Saving to cloud&quot;);<br>    }<br><br>    public void print() {<br>        throw new UnsupportedOperationException(&quot;Printing not supported.&quot;);<br>    }<br>}</pre><p>Problem: CloudReport is forced to implement print() even though it doesn’t support it. This violates ISP.</p><p>Refactored Version — Follows ISP</p><p>Break the interface into <strong>smaller, specific interfaces</strong>:</p><pre>public interface ReportGenerator {<br>    void generate();<br>}<br><br>public interface ReportSaver {<br>    void save();<br>}<br><br>public interface ReportPrinter {<br>    void print();<br>}<br><br>public class CloudReport implements ReportGenerator, ReportSaver {<br>    public void generate() {<br>        System.out.println(&quot;Generating cloud report&quot;);<br>    }<br><br>    public void save() {<br>        System.out.println(&quot;Saving to cloud&quot;);<br>    }<br>}</pre><p>Now classes only implement what they actually use — following ISP.</p><h4><strong>The Dependency Inversion Principle</strong></h4><p>The Dependency Inversion Principle encourages a design where high-level modules (which contain business logic) do not depend on low-level modules (which handle specific tasks like database access or file operations). Instead, both should depend on abstractions, such as interfaces. This helps reduce tight coupling between components, making the system easier to maintain and extend. Additionally, abstractions should not rely on concrete implementations — rather, the details should be built around the abstractions. By inverting the traditional dependency direction, we achieve a more flexible and testable architecture, where components can be easily swapped or modified without affecting the core logic.</p><p>Violating DIP</p><pre>public class Report {<br>    private FileReportSaver fileSaver = new FileReportSaver();<br><br>    public void save(String content) {<br>        fileSaver.save(content);<br>    }<br>}<br><br>public class FileReportSaver {<br>    public void save(String content) {<br>        System.out.println(&quot;Saving to file: &quot; + content);<br>    }<br>}</pre><p>The Report class (high-level module) is tightly coupled to FileReportSaver (low-level module). If we want to change the saving logic (e.g., to database), we must modify Report.</p><p>Refactored Version — Follows DIP</p><pre>public interface ReportSaver {<br>    void save(String content);<br>}<br><br>public class FileReportSaver implements ReportSaver {<br>    public void save(String content) {<br>        System.out.println(&quot;Saving to file: &quot; + content);<br>    }<br>}<br><br>public class DatabaseReportSaver implements ReportSaver {<br>    public void save(String content) {<br>        System.out.println(&quot;Saving to database: &quot; + content);<br>    }<br>}</pre><p>Now the Report depends on the interface, not the implementation</p><pre>public class Report {<br>    private ReportSaver saver;<br><br>    public Report(ReportSaver saver) {<br>        this.saver = saver;<br>    }<br><br>    public void save(String content) {<br>        saver.save(content);<br>    }<br>}<br><br>ReportSaver saver = new FileReportSaver();<br>Report report = new Report(saver);<br>report.save(&quot;Report Content&quot;);</pre><p>Report is decoupled from specific implementations. Easy to extend and test (e.g., use mocks or different savers). Follows Dependency Inversion Principle.</p><p><em>The SOLID principles serve as a strong foundation for writing clean, maintainable, and scalable object-oriented code. By applying these principles — Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion — you can design software that is easier to understand, extend, and test. While they may seem theoretical at first, their real value becomes clear as your codebase grows in complexity.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fd71d60ef95" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>