<?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 Harshavardhan Katkam on Medium]]></title>
        <description><![CDATA[Stories by Harshavardhan Katkam on Medium]]></description>
        <link>https://medium.com/@harshavardhan.katkam?source=rss-8d80de42dd88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*cdiZE0Xd_Lxde_oX</url>
            <title>Stories by Harshavardhan Katkam on Medium</title>
            <link>https://medium.com/@harshavardhan.katkam?source=rss-8d80de42dd88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:13:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harshavardhan.katkam/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[Favor Composition over Inheritance]]></title>
            <link>https://medium.com/@harshavardhan.katkam/favor-composition-over-inheritance-9f51a4e71a21?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f51a4e71a21</guid>
            <category><![CDATA[composition]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[inheritance]]></category>
            <category><![CDATA[java-best-practices]]></category>
            <category><![CDATA[aggregation]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Tue, 14 Oct 2025 08:37:48 GMT</pubDate>
            <atom:updated>2025-10-14T08:37:48.803Z</atom:updated>
            <content:encoded><![CDATA[<p>Because elegant design isn’t about extending classes — it’s about composing ideas</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*9BaGvIKWf7X1iTKwC8RC2w.jpeg" /><figcaption>Car Designs</figcaption></figure><h4>The Story….</h4><p>Imagine you’re designing a Car class.</p><p>Your first instinct ?</p><blockquote>A Car is a Vehicle. Let’s extend Vehicle !!</blockquote><p>Simple. Elegant. Until… You need a <strong>FlyingCar, </strong>or a <strong>BootCar</strong>, or — god forbid — a <strong>TransformerCar.</strong></p><p>Suddenly, inheritance looks like a Christmas Tree — overloaded, fragile, and one change away from chaos.</p><p>That’s when the experienced developer in you whispered:</p><blockquote>Maybe inheritance isn’t the answer. Maybe composition is.</blockquote><h4>Inheritance — The Comfortable Trap</h4><p>Inheritance gives you an easy head start:</p><pre>class Vehicle {<br>    void start() {<br>        System.out.println(&quot;Vehicle starting...&quot;);<br>    }<br>}<br><br>class Car extends Vehicle {<br>    void drive() {<br>        System.out.println(&quot;Car driving...&quot;);<br>    }<br>}</pre><p>Nice and clean.<br>But now imagine:<br>- You add Truck, Bike, ElectricCar, BoatCar..<br>- Each needs a different way to start().<br>- You override. You tweak. You break something in the base class<br>You have built a <strong>rigid hierarchy — </strong>and every child now inherits your headaches !!!<br>Inheritance is like an arranged marriage between classes — tightly coupled, lifelong, and hard to change once committed.</p><h4>Composition — The Smart Builder’s Choice</h4><p>Instead of saying “Car is a Vehicle”, say “Car <strong>has an</strong> Engine”</p><pre>class Engine {<br>    void start() {<br>        System.out.println(&quot;Engine starting...&quot;);<br>    }<br>}<br><br>class Car {<br>    private final Engine engine;<br><br>    Car(Engine engine) {<br>        this.engine = engine;<br>    }<br><br>    void drive() {<br>        engine.start();<br>        System.out.println(&quot;Car driving...&quot;);<br>    }<br>}</pre><p>Now, you can plug in any engine you like:</p><pre>class ElectricEngine extends Engine {<br>    void start() {<br>        System.out.println(&quot;Electric engine humming...&quot;);<br>    }<br>}</pre><p>Boom — your Car evolves without touching existing code.<br>Composition gives you <strong>flexibility</strong>, <strong>testability</strong>, and <strong>freedom</strong> — everything inheritance quietly takes away.</p><h4>Why Composition Wins (Every Time)</h4><p><strong>Loose Coupling:</strong> Classes depend on what others <em>do</em>, not <em>who</em> they are.<br> <strong>Reusability:</strong> A component like Engine can be reused in Boat, Drone, or even LawnMower.<br> <strong>Testability:</strong> Swap real dependencies for mocks — no refactor nightmares.<br> <strong>Flexibility:</strong> Behaviors are pluggable. Want to switch PetrolEngine to ElectricEngine at runtime? Easy.</p><h4>Composition vs Aggregation — The Subtle Difference</h4><p><strong>Composition</strong> has Strong “has-a” relationship and Child <strong>cannot</strong> exist without parent Car → Engine <br><strong>Aggregation</strong> has Week “has-a” relationship and Child <strong>can</strong> exist independently Team → Player</p><h4>Composition Example:</h4><pre>class Engine {}<br>class Car {<br>    private final Engine engine = new Engine(); // owned by Car<br>}<br><br>// If Car dies, Engine dies.</pre><h4>Aggregation Example:</h4><pre>class Player {}<br>class Team {<br>    private List&lt;Player&gt; players; // Team uses but doesn’t own<br>}<br><br>// If Team is disbanded, players still exist.</pre><h4>Real-World Analogy</h4><p>Inheritance is like buying a prebuilt house — beautiful but hard to modify.<br> Composition is like using LEGO bricks — you can rebuild, extend, and evolve infinitely.<br>Modern systems — from Spring Boot to microservices — thrive on <strong>composition</strong> because it’s <strong>modular</strong> and <strong>adaptable</strong>.</p><h4>Best Practices</h4><ol><li>Use <strong>inheritance</strong> only for clear “is-a” relationships.</li><li>Use <strong>composition</strong> for shared or replaceable behavior.</li><li>Design around <strong>interfaces</strong>, not implementations.</li><li>Don’t subclass for code reuse — delegate instead.</li></ol><h4><strong>Conclusion</strong></h4><p>Inheritance gives convenience; composition gives <strong>control</strong>. The more your system grows, the more composition will save you from brittle hierarchies and endless refactors.</p><p>So next time your fingers type extends, pause and ask:</p><blockquote><em>“Can I compose this instead?”</em></blockquote><p>Your future self — and your code reviewers — will thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f51a4e71a21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From God Classes to Graceful Design — Our Journey Applying “Tell, Don’t Ask” in the Wild]]></title>
            <link>https://medium.com/@harshavardhan.katkam/from-god-classes-to-graceful-design-our-journey-applying-tell-dont-ask-in-the-wild-e7e8e9365c6c?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7e8e9365c6c</guid>
            <category><![CDATA[utilities]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[tell-dont-ask]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Tue, 14 Oct 2025 05:10:29 GMT</pubDate>
            <atom:updated>2025-10-14T05:10:29.744Z</atom:updated>
            <content:encoded><![CDATA[<h3>From God Classes to Graceful Design — Our Journey Applying “Tell, Don’t Ask” in the Wild</h3><p><em>By </em><a href="https://medium.com/u/1128620caadb"><em>Sravani isha</em></a><em> &amp; </em><a href="https://medium.com/u/8d80de42dd88"><em>Harshavardhan Katkam</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uwkCIbiFRtsrhHp8NVy8nw.png" /><figcaption>Refactoring</figcaption></figure><h4>TL;DR</h4><p>We refactored a bloated domain class that did <em>everything</em> into a clean design guided by <strong>Tell, Don’t Ask</strong> and <strong>Domain-Driven Design (DDD)</strong>.<br> The outcome: fewer dependencies, expressive code, and a model that actually “tells its story.”</p><blockquote>“This class does everything… and nothing well.”</blockquote><h4>That’s how this story started….</h4><p>That was the note I (Harsha) left in a PR review one Friday evening.<br> The code? A domain model that had turned into a mini universe — fetching data, validating, calculating, and even logging errors.</p><p>Sravani replied with the perfect one-liner:</p><blockquote><em>“It’s like a Swiss Army knife with a toaster attached.”</em></blockquote><p>We knew it was time for a cleanup.<br> And that’s how we stumbled into the practical side of <strong>Tell, Don’t Ask</strong> — and came out with a design that felt more like poetry than plumbing.</p><h4>The Problem: When Your Entity Thinks It’s the CEO</h4><p>Imagine a simple online learning platform.</p><p>We have a Course entity.<br> At first, it just stored basic info. But as features grew, so did its <em>ego</em>.</p><p>Soon it looked like this:</p><pre>@Entity<br>public class Course {    <br>@OneToMany(mappedBy = &quot;course&quot;)<br>    private List&lt;Enrollment&gt; enrollments;<br><br>    public List&lt;Enrollment&gt; getTopPerformers() {<br>            return enrollments.stream()<br>                    .filter(e -&gt; e.getGrade() &gt;= 90)<br>                    .sorted(Comparator.comparing(Enrollment::getGrade).reversed())<br>                    .toList();<br>        }<br><br>    public Enrollment getPreviousEnrollment(Student student) {<br>        List&lt;Enrollment&gt; list = repository.findByCourseAndStudentOrderByDateDesc(this, student);<br>        return list.size() &gt;= 2 ? list.get(1) : null;<br>    }<br><br>    public boolean hasActiveStudents() {<br>        return enrollments.stream().anyMatch(Enrollment::isActive);<br>    }<br>    }</pre><p>Not bad… until you realize:</p><ul><li>It’s <strong>talking to the repository directly</strong>.</li><li>It’s <strong>doing business logic</strong> and <strong>query orchestration</strong>.</li><li>It’s not a model anymore — it’s a <em>manager of everything</em>.</li></ul><p>This violated a principle that’s both simple and profound:</p><blockquote><em>“Objects should tell, not ask.”</em></blockquote><h4>The Spark: Tell, Don’t Ask</h4><p>“Tell, Don’t Ask” sounds philosophical — but it’s deeply practical.</p><p>It means:</p><blockquote><em>Instead of asking an object for its data and deciding externally,<br> </em><strong><em>tell the object what you want it to do</em></strong><em>, and let it decide internally.</em></blockquote><p>For example — this is “asking”:</p><pre>if (course.getEnrollments().stream().anyMatch(Enrollment::isActive)) {<br>    course.setStatus(CourseStatus.RUNNING);<br>}</pre><p>And this is “telling”:</p><pre>course.startIfHasActiveStudents();</pre><p>That one line changes the <em>entire</em> mindset.<br> The logic is now where it belongs — inside the domain, not scattered outside it.</p><h4>The Refactor: Dividing the Responsibilities</h4><p>We decided to split our bloated model into three focused parts:</p><p>Responsibility Belongs To Domain behavior (state, rules) Course entity Business logic needing repositories EnrollmentService Data access EnrollmentRepository</p><p>Simple boundaries, massive impact.</p><h4>New Design</h4><h4>Domain Entity — Course</h4><pre>@Entity<br>public class Course {<br><br>    @OneToMany(mappedBy = &quot;course&quot;)<br>    private List&lt;Enrollment&gt; enrollments;<br><br>    private CourseStatus status;<br><br>    public void startIfHasActiveStudents() {<br>        boolean hasActive = enrollments.stream().anyMatch(Enrollment::isActive);<br>        if (hasActive) {<br>            this.status = CourseStatus.RUNNING;<br>        }<br>    }<br><br>    public boolean isOngoing() {<br>        return this.status == CourseStatus.RUNNING;<br>    }<br>}</pre><h4>Domain Service — EnrollmentService</h4><pre>@Service<br>public class EnrollmentService {<br><br>    private final EnrollmentRepository repository;<br>    public EnrollmentService(EnrollmentRepository repository) {<br>        this.repository = repository;<br>    }<br>    public List&lt;Enrollment&gt; getTopPerformers(Course course) {<br>        return repository.findTopPerformersByCourse(course.getId());<br>    }<br>    public Enrollment getPreviousEnrollment(Course course, Student student) {<br>        List&lt;Enrollment&gt; list = repository.findByCourseAndStudentOrderByDateDesc(course, student);<br>        return list.size() &gt;= 2 ? list.get(1) : null;<br>    }<br>    public boolean isEligible(Student student) {<br>        return student.getStatus() == StudentStatus.ACTIVE;<br>    }<br>}</pre><h4>What Changed — and Why It Feels Better</h4><p>Before After Entities queried repositories Entities just manage state Circular dependencies everywhere Clean directional flow Utils doing business logic Domain services instead Hard to test Every layer mockable and isolated Database leaks in domain Domain code is pure and expressive</p><p>The result?<br> Our code started <em>reading like English</em>.</p><p>Instead of:</p><pre>if (course.getEnrollments().stream().anyMatch(...)) { ... }</pre><p>We had:</p><pre>course.startIfHasActiveStudents();</pre><p>That’s <strong>domain language</strong>. That’s DDD magic.</p><h4>Lessons We Learned</h4><ol><li><strong>Boundaries &gt; Convenience</strong><br> When logic lives “where it’s easy,” it always comes back to bite you.</li><li><strong>Good domain design feels boring</strong> — and that’s a compliment.<br> Predictable, clear, and easy to reason about.</li><li><strong>“Tell, Don’t Ask” is empathy for your code.</strong><br> You’re letting each class live its best life, with clarity and purpose.</li><li><strong>Collaboration matters.</strong><br> This refactor wasn’t a solo mission — it was <em>pair-refactoring</em> between two curious engineers learning together.</li></ol><h4>The Aftertaste</h4><p>When we finally merged the refactored code, the diff was smaller than expected — <br> but the <em>impact</em> was huge.<br> No circular references. No hidden DB calls. No utility monsters.</p><p>Just clean, meaningful code that mirrors the real world.</p><blockquote><em>“Tell, Don’t Ask” isn’t just a design principle — <br> it’s how you make your code sound like a conversation, not a command.</em></blockquote><p>#CleanCode #DomainDrivenDesign #Refactoring #TellDontAsk #SoftwareEngineering #Java</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7e8e9365c6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prefer Interfaces Over Abstract Classes]]></title>
            <link>https://medium.com/@harshavardhan.katkam/prefer-interfaces-over-abstract-classes-0a4ce534f0d1?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/0a4ce534f0d1</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[interfaces]]></category>
            <category><![CDATA[abstract-class]]></category>
            <category><![CDATA[java8]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Fri, 26 Sep 2025 07:04:18 GMT</pubDate>
            <atom:updated>2025-09-26T07:04:18.268Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Practical tips and proven habits for professional Java development</em></p><h4>Introduction:</h4><p>Whenever we are designing reusable and extensible systems in Java, one of common question arises:<br><strong>Should I use an Abstract class or an Interface ?</strong></p><p>Both are tools for abstraction, but they serve different purposes. Choosing between them is not just a syntax decision — it impacts <strong>flexibility, maintainability, and testability</strong> of your code.</p><p>In most cases, the best practice is to <strong>prefer interfaces</strong> over abstract classes. Let’s see why.</p><h4>Abstract Classes:</h4><p>An <strong>abstract class</strong>:</p><ul><li>Can have both <strong>abstract methods</strong> (unimplemented) and <strong>concrete methods</strong> (implemented).</li><li>Can define and maintain <strong>state</strong> via instance variables.</li><li>Cannot be instantiated directly.</li><li>Supports <strong>single inheritance only</strong> — a class can extend <em>only one</em> abstract class.</li></ul><pre><br>*/  EXAMPLE  */<br><br>abstract class Printer {<br>    protected String format;<br><br>    public Printer(String format) {<br>        this.format = format;<br>    }<br><br>    abstract void print(String message);<br><br>    public String getFormat() {<br>        return format;<br>    }<br>}</pre><p>This works well when you need shared fields or behavior.</p><p><strong>The drawback</strong>:</p><ul><li>A class can <strong>extend only one abstract class</strong> in Java.</li><li>Once you commit to an abstract class, you <strong>can’t extend another</strong>.</li><li>This leads to <strong>rigid hierarchies</strong> and reduced flexibility.</li></ul><pre>abstract class Printer { abstract void print(String message); }<br>abstract class Logger { abstract void log(String info); }<br><br>// Not allowed: Multiple inheritance of classes<br>class ConsolePrinter extends Printer, Logger {}</pre><h4>Interfaces: The Flexible Choice</h4><p>Interfaces are designed for <strong>contracts</strong>: they say <em>what</em> should be done, not <em>how</em>.</p><p>Key points:</p><ul><li>A class can implement <strong>multiple interfaces</strong> → more flexibility.</li><li>From Java 8+, interfaces can contain: <strong>Default methods</strong> (with implementations), <strong>Static methods &amp; Private methods</strong> (Java 9+).</li></ul><pre>interface Printer {<br>    void print(String message);<br><br>    default void preview(String message) {<br>        System.out.println(&quot;Preview: &quot; + message);<br>    }<br>}<br><br>interface Logger {<br>    void log(String info);<br>}<br><br>class ConsolePrinter implements Printer, Logger {<br>    public void print(String message) {<br>        System.out.println(message);<br>    }<br><br>    public void log(String info) {<br>        System.out.println(&quot;LOG: &quot; + info);<br>    }<br>}</pre><p>ConsolePrinter now acts as both a Printer and a Logger without rigid inheritance.</p><h4>Don’t: Overuse Abstract Classes</h4><pre>// Overkill for simple contracts<br>abstract class SimplePrinter {<br>    abstract void print(String message);<br>}</pre><p>This blocks flexibility and prevents multiple inheritance of behavior.</p><h4><strong>Do: Use Interfaces for Contracts</strong></h4><pre>// Cleaner, more flexible<br><br>interface Printer {<br>    void print(String message);<br>}<br><br>class ConsolePrinter implements Printer {<br>    public void print(String message) {<br>        System.out.println(message);<br>    }<br>}<br><br>class FilePrinter implements Printer {<br>    public void print(String message) {<br>        // write to file<br>    }<br>}</pre><p>Multiple implementations can exist without hierarchy constraints: ConsolePrinter, FilePrinter, NetworkPrinter, etc.</p><h4>When Abstract Classes Still Make Sense ?</h4><p>Abstract classes are useful when you need:</p><ul><li>Shared <strong>state</strong> across subclasses.</li><li><strong>Partial implementations</strong> (template methods).</li><li>Controlled construction logic.</li></ul><pre>abstract class AbstractPrinter {<br>    protected String format;<br><br>    public AbstractPrinter(String format) {<br>        this.format = format;<br>    }<br><br>    public void showFormat() {<br>        System.out.println(&quot;Format: &quot; + format);<br>    }<br><br>    abstract void print(String message);<br>}</pre><p>Good use case: common fields and base behavior (format, showFormat()) with extensible parts (print()).</p><h4>The Hybrid Approach: Interface + Abstract Class</h4><ul><li>Define the <strong>contract</strong> in an interface.</li><li>Provide <strong>shared behavior</strong> in an abstract class.</li></ul><pre>interface Printer {<br>    void print(String message);<br>}<br><br>abstract class AbstractPrinter implements Printer {<br>    protected String format;<br><br>    public AbstractPrinter(String format) {<br>        this.format = format;<br>    }<br><br>    public void showFormat() {<br>        System.out.println(&quot;Format: &quot; + format);<br>    }<br>}<br><br>class ConsolePrinter extends AbstractPrinter {<br>    public ConsolePrinter(String format) {<br>        super(format);<br>    }<br><br>    @Override<br>    public void print(String message) {<br>        System.out.println(message);<br>    }<br>}</pre><p>Flexible and reusable: ConsolePrinter implements the contract and reuses common behavior.</p><h4>Best Practices Recap</h4><ol><li><strong>Default to interfaces</strong>: lightweight, flexible, and test-friendly.</li><li><strong>Use abstract classes sparingly</strong>: only when shared state or partial implementation is required.</li><li><strong>Leverage Java 8+ features</strong>: default methods reduce the need for abstract classes.</li><li><strong>Combine both</strong> when necessary: interface for contract, abstract class for shared logic.</li></ol><h4>Conclusion:</h4><p>Choosing between interfaces and abstract classes is a key design decision in Java that affects flexibility, maintainability, and scalability. By preferring interfaces for defining contracts, you enable multiple implementations and avoid rigid inheritance hierarchies, while using abstract classes sparingly for shared state or partial implementations. Strategically combining both allows you to write clean, extensible, and future-proof code that adapts easily to evolving requirements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0a4ce534f0d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why DevOps Matters for Developers: Build It, Run It, Own It]]></title>
            <link>https://medium.com/@harshavardhan.katkam/why-devops-matters-for-developers-build-it-run-it-own-it-60b035011b09?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/60b035011b09</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[engineering-culture]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Sat, 05 Jul 2025 07:37:03 GMT</pubDate>
            <atom:updated>2025-07-05T07:37:03.407Z</atom:updated>
            <content:encoded><![CDATA[<p>In modern engineering teams, DevOps isn’t just a role — it’s part of every developer’s toolkit. Here’s why awareness matters and how it improves code, teams, and systems.</p><blockquote>“Code doesn’t live in isolation — it lives in environments, pipelines, and production systems.”</blockquote><p>In many engineering teams today, there’s an unspoken divide: developers focus on building features, while DevOps or platform engineers handle infrastructure, deployments, and monitoring. While this split may exist in org structures, it doesn’t reflect how modern systems work.</p><p>The reality is: DevOps knowledge isn’t just useful for developers — it’s essential. Whether working on microservices, monoliths, or mobile backends, understanding how code flows from laptop to production helps developers write better software and collaborate more effectively.</p><p>This post explores why DevOps awareness matters for developers, based on common patterns and learnings seen across projects and teams.</p><h4>1. DevOps Awareness Bridges Gaps Between Teams</h4><p>In fast-moving projects, developers often work in functional teams (sometimes called pods or streams), but share common pipelines and environments. Without DevOps context, even small changes can unintentionally disrupt other teams.</p><p><strong>Example Scenario: </strong>A minor config change in one team’s service accidentally caused failures in another team’s deployment. It turned out to be a shared pipeline step that behaved differently based on a flag. If teams had visibility into pipeline logic and ownership boundaries, this could have been avoided.</p><p><strong>Takeaway</strong>: When developers understand CI/CD pipelines and shared infrastructure, they can prevent breakages and reduce cross-team dependencies.</p><h4>2. Debugging is Faster When You Know the Tools</h4><p>Logs, metrics, dashboards, and tracing tools aren’t just for SREs. Developers who know how to interpret them can identify and fix issues faster — especially in distributed systems.</p><p><strong>Common Learning: </strong>Structured logging and trace IDs can help track a single request across multiple services. Developers who regularly use observability tools are often the first to flag and fix production bugs — even before formal alerts go out.</p><p><strong>Takeaway</strong>: Observability is part of development. Knowing your monitoring tools makes you more effective in diagnosing real-world problems.</p><h4>3. CI/CD Is Part of Code Quality</h4><p>Many bugs or delays in release cycles come from pipeline misconfigurations or surprises in non-prod environments. Contributing to pipeline improvements is as important as writing testable code.</p><p><strong>Common Pattern: </strong>In some setups, new services or modules are added frequently. Teams that treat pipelines as code — versioning them, reviewing changes, and automating validations — tend to have fewer release issues and faster feedback loops.</p><p><strong>Takeaway</strong>: A developer who understands CI/CD can ensure their code reaches production reliably — not just locally.</p><h4>4. Infrastructure as Code Is Still Code</h4><p>Tools like Terraform, Pulumi, and Helm allow infrastructure to be versioned, tested, and reviewed — just like application code. Developers who get comfortable with these tools can contribute more confidently to cloud automation and environment setup.</p><p><strong>Observation: </strong>When developers pair with infra specialists or take time to read and update infrastructure modules, teams often see better rollout strategies, safer changes, and smoother environment provisioning.</p><p><strong>Takeaway</strong>: Understanding infra code allows developers to take part in shaping runtime behavior, not just business logic.</p><h4>5. DevOps Builds Empathy Across Roles</h4><p>When developers understand the challenges of scaling, deployment safety, or incident response, they build empathy for platform, QA, and operations teammates.</p><p><strong>Team Benefit: </strong>Onboarding becomes smoother, team boundaries become clearer, and communication improves. Everyone speaks a more common technical language.</p><p><strong>Takeaway</strong>: DevOps context strengthens cross-functional collaboration and reduces handoff friction.</p><h4>Getting Started as a DevOps-Aware Developer:</h4><p>You don’t need to become a DevOps engineer. But here are a few practical steps developers can take to build awareness:</p><p><strong>Explore your CI/CD pipeline</strong> — Understand what happens after you push code.<br> <strong>Check logs and dashboards</strong> — Get familiar with how your services behave in production.<br><strong>Read infrastructure files</strong> — See how environments and services are defined.<br><strong>Learn cloud basics</strong> — Knowing how storage, compute, and identity work goes a long way.<br> <strong>Contribute small improvements</strong> — Even a doc update or a flag change builds confidence.</p><h4>Final Thoughts:</h4><blockquote>“It’s not just about writing code anymore. It’s about owning what we build.”</blockquote><p>As software systems grow more complex, the boundaries between development and operations are naturally blending. DevOps isn’t about replacing roles — it’s about shared ownership and better systems thinking.</p><p>When developers understand how their code runs in the real world, they don’t just write features — they deliver reliable experiences.</p><p>And in today’s fast-moving teams, that mindset makes a huge difference.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60b035011b09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Java Is NOT Call by Reference ?]]></title>
            <link>https://medium.com/@harshavardhan.katkam/why-java-is-not-call-by-reference-133174c5e72e?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/133174c5e72e</guid>
            <category><![CDATA[call-by-reference]]></category>
            <category><![CDATA[pass-by-value]]></category>
            <category><![CDATA[java-tips]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-best-practices]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Wed, 11 Jun 2025 02:37:43 GMT</pubDate>
            <atom:updated>2025-06-11T02:37:43.402Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why Java Is NOT Call by Reference ?</h3><p>One of the most persistent myths among Java developers is the confusion over how Java passes arguments to methods:</p><blockquote><em>“Is Java pass by value or call by reference?”</em></blockquote><p>Let’s break down what really happens under the hood, bust the myths, and see practical code that proves why <strong>Java is NOT call by reference</strong></p><h4>The Basics: Pass by Value vs Call by Reference</h4><p>Before we dive into Java’s specifics, let’s quickly clarify the two concepts:</p><p><strong>Pass by Value:</strong><br> The method receives a copy of the argument. Any changes made inside the method do NOT affect the original variable.</p><p><strong>Call by Reference:</strong><br> The method receives a direct reference (the <em>actual variable</em>). Changes made inside the method (including reassignments) DO affect the original variable outside the method.</p><p><strong><em>Java’s Approach: Always Pass by Value<br></em></strong>Yes, you read that right:</p><blockquote>Java is always pass by value.</blockquote><p>But… here’s the twist:<br>For <strong>primitives</strong> (like int, char, etc.), the value is the actual data.<br>For <strong>objects</strong>, the value is the <em>reference</em> (the address) to the object, but <em>that reference itself</em> is passed by value (copied).</p><p><strong>Let’s Prove It with Code<br>1. Primitives</strong></p><pre>void updateValue(int x) {<br>    x = 10;<br>}<br>int a = 5;<br>updateValue(a);<br>System.out.println(a); // Output: 5</pre><p>The value of a does NOT change, because the method only got a <em>copy</em>.</p><p><strong>2. Objects (Reference Variables)</strong></p><pre>class Student {<br>    String name;<br>}<br>void updateName(Student s) {<br>    s.name = &quot;Alice&quot;;<br>}<br>Student student = new Student();<br>student.name = &quot;Bob&quot;;<br>updateName(student);<br>System.out.println(student.name); // Output: Alice</pre><p>The field name changes! Why? Because both student and s refer to the <em>same</em> object.</p><p>But, crucially: <strong>the reference was passed by value</strong>.</p><h4>Why Java is NOT Call by Reference ?</h4><p>Let’s examine what would happen if Java was truly “call by reference”.</p><p><strong>The Key Test: Can You Change the Reference Itself?</strong></p><p>Try this:</p><pre>void reassign(Student s) {<br>    s = new Student(); // reassign to a new object<br>    s.name = &quot;Charlie&quot;;<br>}<br>Student student = new Student();<br>student.name = &quot;Bob&quot;;<br>reassign(student);<br>System.out.println(student.name); // Output: Bob</pre><p><strong>Result:</strong> The original student variable still points to &quot;Bob&quot; (not changed).</p><p>The reassignment only affected the <em>local copy</em> (s), not the original reference.</p><h4>If Java Was Call by Reference, Here’s What Would Happen:</h4><ul><li>The method would receive the <em>actual variable</em> (student), not just a copy of the reference.</li><li>When you write s = new Student(); inside the method, the <strong>original variable</strong> (student) outside the method would also point to this new object.</li><li>So, after the method call, student.name would be &quot;Charlie&quot;!</li></ul><p>In Java? This never happens.</p><h4>Do’s and Don’ts</h4><p><strong>Do’s</strong></p><ul><li><strong>Do</strong> modify object fields inside methods if you want the changes to be visible outside.</li><li><strong>Do</strong> use defensive copies if you want to avoid unexpected external modifications to your objects.</li></ul><p><strong>Don</strong>’ts</p><ul><li><strong>Don’t</strong> expect reassigning an object parameter inside a method to update the original variable.</li><li><strong>Don’t</strong> assume Java behaves like languages with true call by reference (like C++ with pointers or C#’s ref keyword).</li></ul><p><strong>Practical Tip: Want to Change the Reference? Return It!<br></strong>If you <em>need</em> a method to update the object reference outside, you must return the new object:</p><pre>Student changeReference(Student s) {<br>    s = new Student();<br>    s.name = &quot;Charlie&quot;;<br>    return s;<br>}<br>student = changeReference(student);</pre><h4>Summary</h4><ul><li>Java always passes by value.</li><li>For primitives: passes the actual value.</li><li>For objects: passes a copy of the reference.</li><li>Modifying the <em>object’s fields</em> inside a method affects the original object.</li><li>Reassigning the parameter inside the method does NOT affect the original reference outside the method.</li><li>If Java were call by reference, you could change what the caller’s variable points to from inside the method — but you can’t.</li></ul><p><strong>Found this helpful? Follow me for more practical Java insights, and drop your questions or confusions in the comments!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=133174c5e72e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Immutable Objects in Java: When and How to Design Them]]></title>
            <link>https://medium.com/@harshavardhan.katkam/immutable-objects-in-java-when-and-how-to-design-them-0f7209610e83?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f7209610e83</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[immutable-objects]]></category>
            <category><![CDATA[javaimmutable]]></category>
            <category><![CDATA[javadesign]]></category>
            <category><![CDATA[immutability]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Tue, 10 Jun 2025 02:36:48 GMT</pubDate>
            <atom:updated>2025-06-10T02:36:48.340Z</atom:updated>
            <content:encoded><![CDATA[<p>In modern Java development, <strong>immutability</strong> is one of those magic words — often heard, less often truly understood or consistently applied. Yet, embracing immutable objects is a proven way to write cleaner, safer, and more maintainable code, especially as your codebase and team grow.</p><p>In this post, I’ll break down:</p><ul><li>What makes an object <em>immutable</em></li><li>Why and when to design your classes as immutable</li><li>The <em>right</em> way to do it in Java, with real code</li><li>Practical do’s and don’ts</li><li>Real-world examples</li></ul><h4>What is an Immutable Object?</h4><p>An immutable object’s state cannot be changed after it’s created. Every “modification” returns a new object. This is the opposite of a mutable object, where fields can be changed after construction.</p><p>Classic Example: Java’s String</p><pre>String a = &quot;hello&quot;;<br>String b = a.replace(&quot;h&quot;, &quot;j&quot;); // a is still &quot;hello&quot;, b is &quot;jello&quot;</pre><p>Strings are immutable. Any method that seems to change its contents actually returns a <em>new</em> String.</p><h4>Why and When Should You Design Immutable Objects?</h4><p><strong>When to Prefer Immutability:<br></strong>Value Objects:<br> Like Money, Color, DateRange, etc.—objects that just represent a value.<br>Thread Safety:<br> Immutables are <em>inherently thread-safe</em> — no locking or synchronization needed.<br>Functional Programming:<br> Methods without side effects make code easier to reason about and test.<br>Cache Keys/Map Keys:<br> If used as keys in HashMap or in sets, mutability can break contracts.</p><p><strong>When Not to Use Immutability</strong>:<br>When object construction is <em>very expensive</em> and frequent copying would hurt performance.<br>For entities with identity and lifecycle that change over time (e.g., database records).</p><h4><strong>How to Design an Immutable Class (The Right Way)</strong></h4><p>Let’s build a classic example: a Person value object.</p><pre>public final class Person {<br>    private final String name;<br>    private final int age;<br>    private final List&lt;String&gt; favoriteBooks;<br><br>    public Person(String name, int age, List&lt;String&gt; favoriteBooks) {<br>        this.name = name;<br>        this.age = age;<br>        // Defensive copy!<br>        this.favoriteBooks = List.copyOf(favoriteBooks);<br>    }<br><br>    public String getName() { return name; }<br>    public int getAge() { return age; }<br>    public List&lt;String&gt; getFavoriteBooks() { <br>        // Defensive copy (Java 10+), or Collections.unmodifiableList(favoriteBooks)<br>        return List.copyOf(favoriteBooks); <br>    }<br>}</pre><p>Key Points:</p><ul><li>final class: Can’t be subclassed.</li><li>final fields: Must be set once in constructor.</li><li>No setters!</li><li>Defensive copy: Copy any mutable input (like lists, arrays) to prevent outside changes.</li><li><strong>Defensive copy:</strong> Copy any mutable input (like lists, arrays) to prevent outside changes.</li></ul><h4>Real-World Example: Immutable Money Value Object</h4><pre>public final class Money {<br>    private final int amount;<br>    private final String currency;<br><br>    public Money(int amount, String currency) {<br>        this.amount = amount;<br>        this.currency = currency;<br>    }<br><br>    public int getAmount() { return amount; }<br>    public String getCurrency() { return currency; }<br><br>    public Money add(Money other) {<br>        if (!currency.equals(other.currency)) throw new IllegalArgumentException(&quot;Different currency&quot;);<br>        return new Money(this.amount + other.amount, currency);<br>    }<br>}</pre><p>Usage:</p><pre>Money salary = new Money(50000, &quot;INR&quot;);<br>Money bonus = new Money(10000, &quot;INR&quot;);<br><br>Money total = salary.add(bonus); // New Money object; salary and bonus are unchanged!</pre><h4>Do’s and Don’ts</h4><p><strong>Do’s</strong></p><ul><li>Make the class final</li><li>Mark all fields as private final</li><li>Initialize fields via constructor only</li><li>Always return copies of mutable objects in getters</li><li>Prefer immutability for simple value-like classes</li></ul><p><strong>Don’ts</strong></p><ul><li>Don’t provide setters or any methods that modify fields</li><li>Don’t return references to mutable internal objects directly</li><li>Don’t make mutable fields (List, arrays) directly accessible</li><li>Don’t ignore thread safety for shared objects — immutability helps!</li></ul><h4>Takeaways:</h4><p>Immutability brings safety, simplicity, and thread-safety by default.</p><p>Always use immutable objects for <em>values</em> and <em>shared data</em>.</p><p>Defensive copying and final are your best friends.</p><p>Use mutability sparingly, only when needed for performance or real-world identity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f7209610e83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Copy Constructors in Java: Deep vs Shallow Copy]]></title>
            <link>https://medium.com/@harshavardhan.katkam/copy-constructors-in-java-deep-vs-shallow-copy-89aa0bd3a77d?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/89aa0bd3a77d</guid>
            <category><![CDATA[copy-constructor]]></category>
            <category><![CDATA[shallow-vs-deep-copy]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-best-practices]]></category>
            <category><![CDATA[copy-object]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Mon, 09 Jun 2025 04:11:40 GMT</pubDate>
            <atom:updated>2025-06-09T04:12:35.481Z</atom:updated>
            <content:encoded><![CDATA[<p>Targeted audience: Early-career Java Developers, Self-taught developers and Developers switching to Java.</p><p><strong>Introduction:<br></strong>Copying objects in Java is deceptively complex topic. Many developers fallen into subtle bugs by misunderstanding shallow and deep copy. In this post, we will unravel:</p><ul><li>What are copy constructors are,</li><li>The difference between Deep and shallow copies,</li><li>How to implement them correctly,</li><li>Real — World pitfalls,</li><li>Do’s and Don’ts for robust Java Code</li></ul><p><strong>What is a Copy Constructor ?</strong><br>A copy constructor is a special constructor used to create a new object as a copy of the existing object. <br><strong>Syntax example:</strong></p><pre>public class Employee {<br>    String name;<br>    int age;<br>  <br>    // Copy constructor<br>    public Employee(Employee other) {<br>        this.name = other.name;<br>        this.age = other.age; <br>    }<br>}</pre><p><strong>Why use it ?</strong></p><ul><li>Cloning objects safely.</li><li>Preventing accidental side effects.</li><li>Customizing the copy behavior ( shallow / deep).</li></ul><h3>Shallow vs. Deep Copy</h3><p><strong>Shallow Copy ?<br></strong>A shallow copy duplicates as little as possible. For objects references, it copies the references — not the objects they point to. <br><strong>For Example:</strong></p><pre>class Address {<br>  String city;<br>  public Address(String city) {<br>      this.city = city;<br>    }<br>}<br><br>class Employee {<br>  String name;<br>  Address address;<br><br>  // Copy constructor<br>  public Employee(Employee other) {<br>      this.name = other.name;<br>      this.address = other.address; // Shallow Copy !<br>    }<br>}</pre><p>Pitfall: Changing the address in one Employee affects the other!</p><pre>Employee e1 = new Employee(&quot;John&quot;, new Address(&quot;Delhi&quot;));<br>Employee e2 = new Employee(e1);<br><br>e2.address.city = &quot;Mumbai&quot;;<br>System.out.println(e1.address.city); // Outputs &quot;Mumbai&quot;</pre><p><strong>Deep Copy: <br></strong>A deep copy duplicates everything. New objects are created for all referenced fields.</p><pre>public class Employee {<br>    String name;<br>    Address address;<br><br>    public Employee(Employee other) {<br>        this.name = other.name;<br>        // Deep copy for address<br>        this.address = new Address(other.address.city);<br>    }<br>}</pre><p>Now, modifying e2.address does not affect e1.address.</p><p><strong>Real-World Example: Why Deep Copy Matters ?<br></strong>Imagine you’re building an Order Management System. Each Order has a Customer. If you use shallow copy for orders, two orders may end up referring to the same customer object. Updates in one place might accidentally affect another order—this could be a disaster in production!</p><p><strong>Do’s</strong></p><ul><li>Use deep copy for mutable objects or collections (e.g., lists, custom objects).</li><li>Implement copy constructors for every class with complex/mutable fields.</li><li>Document your copy behavior in Javadoc.</li><li>Test your copy constructors — especially in multi-level/nested objects.</li></ul><p><strong>Don’ts</strong></p><ul><li>Don’t use shallow copy for mutable fields (e.g., arrays, lists, custom objects).</li><li>Don’t assume Object.clone() does a deep copy—it’s shallow by default.</li><li>Don’t expose internal mutable objects directly — use <a href="https://medium.com/@harshavardhan.katkam/java-defensive-copying-how-to-truly-protect-your-class-1355b0fac11b">defensive copying</a>.</li></ul><p><strong>Conclusion:<br></strong>Copy constructors are a powerful tool in Java, but only when used with a clear understanding of shallow vs. deep copying. Always think about whether your fields are mutable, and default to deep copy for safety.<br> Robust copy logic makes your code safer, more modular, and easier to maintain!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89aa0bd3a77d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Java] Defensive Copying — How to Truly protect your class]]></title>
            <link>https://medium.com/@harshavardhan.katkam/java-defensive-copying-how-to-truly-protect-your-class-1355b0fac11b?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/1355b0fac11b</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-best-practices]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[encapsulation]]></category>
            <category><![CDATA[java-tips]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Sun, 08 Jun 2025 08:57:25 GMT</pubDate>
            <atom:updated>2025-06-08T12:20:27.323Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Java] Defensive Copying — How to Truly protect your class ?</h3><p>Targeted audience: Early-career Java Developers, Self-taught developers and Developers switching to Java.</p><p><strong>What is Defensive Copying ?<br></strong>Defensive copying is a core Java practice for Encapsulation. It is a technique in Java ( and other OOP languages) to protect the internal state of an object from begin modified by external code. It means never exposing your class’s internal, mutable state ( like arrays, lists, maps or custom objects) directly to the outside world — neither in your constructors, setters, nor getters. Instead, always work with copies.</p><p><strong>Why do we need Defensive Copying ?</strong><br>If you return a reference to a mutable object field via a getter, outside code can change it and break your object invariants.</p><p><strong>Don’t Do This:</strong></p><pre>public class Student {<br><br>private List&lt;String&gt; subjects = new ArrayList&lt;&gt;();<br><br>public List&lt;String&gt; getSubjects() {<br><br>  return subjects; // BAD: returns reference<br> }<br><br>}<br><br><br>Student s = new Student();<br>List&lt;String&gt; subs = s.getSubjects();<br>subs.add(&quot;Hacking&quot;); // Also modifies s.subjects !</pre><p><strong>How to implement Defensive Copy ? <br></strong>Return a copy of an internal object, not the original reference.</p><pre>public class Student {<br><br>private List&lt;String&gt; subjects = new ArrayList&lt;&gt;();<br><br>public List&lt;String&gt; getSubjects() {<br><br>  return new ArrayList&lt;&gt;(subjects); // Good<br> }<br><br>}<br><br>Student s = new Student();<br>List&lt;String&gt; subs = s.getSubjects();<br>subs.add(&quot;Hacking&quot;); // Does not modify s.subjects !</pre><p><strong>Defensive Coping in Setters/Constructors ?<br></strong>If you store the reference directly, the original object can be changed outside the class → even after assignment.</p><pre>// Taken int array as an example<br><br>public class Student {<br>    private int[] subjects;<br><br>    // Defensive copy<br>    public Student(int[] subjects) {<br>        this.subjects = subjects.clone(); // or Arrays.copyOf(items, items.length)<br>    }<br><br>    // or setter<br>    <br>    public void setSubjects(int[] subjects) {<br>      this.subjects = subjects.clone();<br>    }<br>}<br><br>int[] subjects = {&quot;OS&quot;, &quot;COA&quot;, &quot;DSA&quot;};<br>Student stu = new Student(subjects);<br>subjects[0] = &quot;DAA&quot;; // stu.subjects[0] is STILL OS. No external modification possible!</pre><p><strong>Key Points ?</strong></p><ul><li><strong>Always</strong> make a defensive copy in setters/constructors/getters when accepting or exposing mutable objects.</li><li>This practice <strong>prevents bugs</strong> and keeps your class truly encapsulated.</li><li>You don’t need this for immutable objects like String, Integer etc.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1355b0fac11b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Event-Driven Stability: Evolving Kafka Schemas Safely with AWS Glue & Amazon MSK]]></title>
            <link>https://medium.com/@harshavardhan.katkam/event-driven-stability-evolving-kafka-schemas-safely-with-aws-glue-amazon-msk-f421c18f4f23?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/f421c18f4f23</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[avro-schema]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Wed, 14 May 2025 05:40:45 GMT</pubDate>
            <atom:updated>2025-05-16T05:31:25.985Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Targeted Audience:<br>This blog is for developers building event-driven microservices using <strong>Amazon MSK</strong>, especially those new to <strong>Avro</strong>, schema registries, or serialization strategies. If you’re maintaining Kafka producers/consumers and struggling with <strong>schema versioning</strong>, or looking to understand <strong>data contracts</strong>, <strong>compatibility </strong>— this guide is for you.</blockquote><h4>What This Blog Is About</h4><p>Building event-driven microservices using <strong>Amazon MSK (Managed Streaming for Apache Kafka)</strong> can unlock massive scalability — but evolving schemas without breaking existing consumers is tricky.<br>In this blog, you’ll learn a practical, production-ready way to:</p><ul><li>Define and manage <strong>Avro schemas</strong> for your event payloads</li><li>Use <strong>AWS Glue Schema Registry</strong> for centralized schema control</li><li>Apply safe <strong>schema evolution</strong> using <strong>backward compatibility</strong></li><li>Automate <strong>versioning</strong>, <strong>registration</strong>, and <strong>POJO generation</strong> through CI/CD</li><li>Build a <strong>reliable producer-consumer model</strong> with shared domain contracts<br>By the end, you’ll have a well-defined approach to eliminate serialization issues, maintain compatibility, and evolve your data contracts safely — without disrupting your consumers.</li></ul><h4>The Problem: Microservices + Schema Evolution</h4><p>In distributed systems, teams evolve at different speeds. That means event payloads — your Avro schemas — often change over time. But if a producer changes a schema in a way that a consumer can’t handle, it leads to:</p><ul><li>🔴 <strong>Deserialization errors</strong></li><li>🐞 <strong>Hidden data loss or corruption</strong></li><li>❌ <strong>Broken contracts between services</strong></li></ul><p>Without a clear strategy, evolving schemas can cause more harm than good</p><h4>The Solution: AWS Glue + Avro + Domain Modeling</h4><p>This approach enforces structure, improves visibility, and makes serialization more predictable. To handle this cleanly, we introduced a <strong>shared domain schema strategy</strong> powered by:</p><ul><li><strong>Avro</strong> for compact, strongly typed schema definitions</li><li><strong>AWS Glue Schema Registry</strong> for schema storage, validation, and governance</li><li><strong>Amazon MSK</strong> as our Kafka backbone</li><li>A <strong>centralized repo</strong> (schemas-repo) that generates and publishes POJO libraries</li></ul><h4>Proposed Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hqz8npBsukNLtEbUURkiZA.png" /><figcaption>Proposed architecture</figcaption></figure><p>This diagram shows how to manage event-driven microservices using <strong>Amazon MSK</strong> and <strong>AWS Glue Schema Registry</strong>. It demonstrates how schema changes are handled safely with backward compatibility, allowing producers and consumers to communicate without breaking. The architecture uses Avro for event serialization and automates schema management through CI/CD pipelines for seamless integration.</p><h4>Introducing AWS Glue Schema Registry</h4><p><a href="https://docs.aws.amazon.com/glue/latest/dg/schema-registry.html"><strong>AWS Glue Schema Registry</strong></a> provides a <strong>centralized, managed repository</strong> to store, validate, and evolve message schemas.<br>Here’s what it offers out-of-the-box:</p><ul><li>Compatibility rules: Prevents breaking schema changes</li><li>Schema version history: Track every evolution and rollback if needed</li><li>IAM-based access control: Secure access to schema definitions</li><li>Visibility: Inspect schemas and versions via AWS Console</li><li>Multi-format support: Works with Avro, Protobuf, JSON</li><li>When used with <strong>Avro</strong>, it becomes a powerful tool to <strong>safely evolve data contracts</strong>.</li></ul><h4>A Shared Domain Model Strategy</h4><p>To streamline schema evolution, we introduced a <strong>central schema library</strong> — a separate project (a JAR or package) that:</p><ul><li>Contains only .avsc files (Avro schema definitions)</li><li>Auto-generates Avro POJOs (Plain Old Java Objects)</li><li>Gets versioned, built, and published like any other internal dependency</li></ul><blockquote><em>🧠 Think of it as a “contract JAR” shared by all producer and consumer services.</em></blockquote><h4>Benefits:</h4><ul><li>No duplication of schemas across services</li><li>Changes are <strong>version-controlled</strong> and <strong>reviewed</strong></li><li>Easy to integrate in CI/CD</li><li>Developers get strongly typed models (no manual mapping)</li></ul><h4>Versioning &amp; Compatibility in CI/CD</h4><p>A strong schema strategy doesn’t just live in code — it’s enforced in CI/CD. A typical flow:</p><p><strong>Developer modifies schema</strong></p><ul><li>Adds a new optional field in .avsc</li><li>Updates the schema version (e.g., 1.0.0 → 1.1.0)</li></ul><p><strong>Pull request includes:</strong></p><ul><li>Updated Avro file(s)</li><li>Version bump</li><li>Explanation of compatibility (e.g., “added optional field — backward compatible”)</li></ul><p><strong>CI Pipeline does:</strong></p><ul><li>Linting and syntax validation</li><li>Compatibility check using AWS Glue APIs</li><li>Avro POJO generation and unit tests</li><li>Publishes new schema version to internal registry or AWS Glue</li><li>Tags the repo with the release version (e.g., v1.1.0)</li></ul><p>✅ Bonus: Version tagging helps correlate exactly which service versions use which schema.</p><h4>Why Not Use Avro Serializer Directly?</h4><p>You <em>can</em> use the Avro serializer, but you’ll lose some powerful benefits that come with AWS Glue. The <strong>Glue Schema Registry Serializer</strong> adds:</p><ul><li>✅ Automatic schema registration (no manual steps)</li><li>✅ Compatibility checks before publishing</li><li>✅ Schema version tracking</li><li>✅ IAM-secured access</li><li>✅ UI for schema management &amp; auditing via AWS Console</li></ul><p>In contrast, the plain Avro serializer offers none of these.<br> So, if you’re working in a team or scaling across environments, the Glue serializer gives you <strong>safety, consistency, and better governance</strong> out of the box.</p><h4>Conclusion</h4><p>As event-driven systems grow, so does the complexity of maintaining schema compatibility across teams and services. Without a solid contract and governance model, even small changes can ripple into production issues.</p><p>By combining <strong>Amazon MSK</strong>, <strong>AWS Glue Schema Registry</strong>, and a <strong>shared Avro-based domain schema strategy</strong>, we create a developer-friendly and scalable way to:</p><ul><li>Define and evolve schemas safely</li><li>Automate POJO generation and CI/CD integration</li><li>Prevent runtime surprises with compatibility checks</li><li>Foster collaboration between producers and consumers</li></ul><p>This approach isn’t just about serialization — it’s about building <strong>confidence, clarity, and consistency</strong> in how services communicate. Whether you’re starting out with Kafka or maturing your event architecture, adopting a schema-first mindset backed by tooling like AWS Glue can save you time, effort, and production headaches.</p><p>Start small, evolve safely, and scale with trust.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f421c18f4f23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best practices for writing Terraform code]]></title>
            <link>https://awstip.com/best-practices-for-writing-terraform-code-852aad68caa1?source=rss-8d80de42dd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/852aad68caa1</guid>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[terraform-cloud]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Harshavardhan Katkam]]></dc:creator>
            <pubDate>Thu, 06 Jul 2023 08:48:49 GMT</pubDate>
            <atom:updated>2023-07-07T13:34:07.096Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*RwiR74al0xLzz0pkbLmcGg.png" /><figcaption>Terraform log</figcaption></figure><blockquote><em>Terraform is a popular infrastructure-as-code tool used to automate the deployment and management of cloud resources. To make sure your Terraform code is maintainable and scalable, it’s important to follow some best practices. In this blog post, we’ll discuss some best practices for writing Terraform code along with code examples using AWS provider.</em></blockquote><h4>Use Git to version control your Terraform code</h4><p>First best practice for writing Terraform code is to use Git to version control your code. Version control provides a history of changes to your code and allows you to roll back changes if necessary. It’s also a great way to collaborate with your team members. In the terraform project you have created make initial commit as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ymH6ZuaGCNMzZAUbWNNz-g.png" /></figure><h4>Organize your code into modules</h4><p>One of the best practices for writing Terraform code is to organize your code into modules. Modules are reusable components that can be used across your Terraform codebase. Modules are typically used to abstract away the implementation details of a particular resource and provide a simple interface for consumers. For example, you can create a module for creating an EC2 instance, a VPC, or a load balancer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hYVEOlDbWxxfesE-Lxn04w.png" /></figure><h4>Use variables to make your code more flexible</h4><p>Variables allow you to make your Terraform code more flexible. Variables can be used to pass in configuration values to your modules and resources. This allows you to reuse your code across multiple environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tVH7Tx9kyp__hLdEQ4Kwxg.png" /></figure><h4>Use descriptive naming conventions and comments</h4><p>When writing Terraform code, it’s important to use descriptive naming conventions and comments. Descriptive naming conventions make your code more understandable and easier to read. Comments provide additional context and help other developers understand your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pK86JnaYMv3NH9YWFXYzVA.png" /></figure><h4>State Locking and Backend Configuration using DynamoDB and S3</h4><p>When working with Terraform, it’s important to manage state information. State information is used to store information about your infrastructure, such as the configuration settings for your resources and the current status of your infrastructure. Remote state is a feature in Terraform that allows you to store your state information outside of your local environment.</p><p>Using remote state can help you avoid issues such as state file conflicts and data loss. Remote state can be stored in various backends such as S3, Consul, or Azure Blob Storage.</p><p>By using remote state, you can share your infrastructure configuration with your team members, and keep a record of changes made to your infrastructure. It also enables you to collaborate with others and to maintain a consistent state across all deployments.</p><p>Here’s an example of how to use remote state with S3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u4-hmS4egTvY652lCohUXQ.png" /></figure><p>We’re also using DynamoDB for state locking by specifying the DynamoDB table name in the backend configuration.</p><p>To initialize the backend, run the following command:<br>$ terraform init</p><p>Terraform will create the S3 bucket and the DynamoDB table if they don’t exist, and configure the backend to use them for state storage and locking.</p><h4>Use conditional expressions</h4><p>Conditional expressions in Terraform can be used to control the creation of resources based on certain conditions. This can help you to manage resources more efficiently and avoid unnecessary resource creation.</p><p>Here’s an example of how to use conditional expressions in Terraform:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dUd7nd5Sxs6nPO1HfNC7-g.png" /></figure><p>In this example, the “aws_instance” resource is only created if the “create_instance” variable is set to “true”. If the variable is set to “false”, no resources will be created. This can be useful in situations where you only want to create certain resources under certain conditions, or when you want to avoid creating unnecessary resources.</p><p>You can also use conditional expressions to control the values of certain resource attributes. Here’s an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CQFCQ2PXhckXuK6uueccvg.png" /></figure><p>In this example, the “aws_security_group_rule” resource is only created if the “enable_http” variable is set to “true”. If the variable is set to “false”, the “security_group_id” attribute is set to “null”, which effectively disables the rule. This can be useful in situations where you want to enable or disable certain rules based on certain conditions.</p><p>By using conditional expressions in your Terraform code, you can make your code more flexible and efficient, and avoid unnecessary resource creation.</p><h4>Use tfsec</h4><p>Tfsec is an open-source static analysis tool for Terraform that helps you detect potential security and compliance issues in your Terraform code. It provides a set of rules that check for common security issues and compliance violations, such as using weak passwords, exposing sensitive data in configuration files, and using insecure network protocols.</p><p>Here’s an example of how to use tfsec in your Terraform project:</p><ul><li>Install tfsec using the following command:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eDZY9vkkwVmpOSiPqXJsnQ.png" /></figure><ul><li>Run tfsec against your Terraform code (In your code repo):<br>$ tfsec .</li><li>Fix any issues identified by tfsec.</li></ul><p>Tfsec will provide you with a list of issues that it has identified in your Terraform code, along with suggestions on how to fix them.</p><p>By using tfsec in your Terraform project, you can ensure that your code is free from common security issues and compliance violations, and that it adheres to best practices for secure infrastructure deployment.our code, it will suggest using a stronger password.</p><h4>Conclusion:</h4><p>In conclusion, following best practices for writing Terraform code, such as organizing code into modules, using version control, employing descriptive naming and comments, utilizing variables, and adopting advanced techniques like remote state and conditional expressions, enhances the maintainability, scalability, and security of your infrastructure. Additionally, incorporating state locking with DynamoDB and configuring S3 as the backend ensures consistency and security in multi-user environments. By adhering to these practices, you can optimize your Terraform workflows and build robust infrastructure deployments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=852aad68caa1" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/best-practices-for-writing-terraform-code-852aad68caa1">Best practices for writing Terraform code</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>