<?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 Tanish Sharma on Medium]]></title>
        <description><![CDATA[Stories by Tanish Sharma on Medium]]></description>
        <link>https://medium.com/@tanish2001sharma?source=rss-aec55723385b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dUVdGbVs6abYaDWJsXa5jw.jpeg</url>
            <title>Stories by Tanish Sharma on Medium</title>
            <link>https://medium.com/@tanish2001sharma?source=rss-aec55723385b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 17:25:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tanish2001sharma/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[Decoupled Web & Worker Modules to Scale Like a Pro]]></title>
            <link>https://medium.com/@tanish2001sharma/decoupled-web-worker-modules-to-scale-like-a-pro-6b134c117662?source=rss-aec55723385b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b134c117662</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Tanish Sharma]]></dc:creator>
            <pubDate>Sun, 20 Jul 2025 14:01:54 GMT</pubDate>
            <atom:updated>2025-07-20T14:01:54.198Z</atom:updated>
            <content:encoded><![CDATA[<p>When things get bulky in a codebase, you know it’s time to hit the brakes and refactor. That’s exactly what happened to me recently. Our application had grown pretty decently, and while it was holding up, the structure wasn’t doing it any favours. So, I decided to clean things up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MB2gW4pkPy_r4-utwQrowA.jpeg" /></figure><h3><strong>What Was Bugging Me?</strong></h3><p>Initially, the worker logic was sitting cozily inside the web module — yep, all REST APIs and background processing tangled together. It worked… until it didn’t. Asynchronous tasks like Kafka consumers, scheduled jobs, and heavy background processing started to clutter the web module.</p><p>So I thought —</p><blockquote>“Yo, this needs to breathe.”</blockquote><h3><strong>Objective</strong></h3><p>Split it up! The idea was simple:</p><ul><li>The <strong>web module</strong> would only handle REST calls and deal with client interactions.</li><li>The <strong>worker module</strong> would do all the async heavy lifting — Kafka consumers, cron jobs, delay queues — you name it.</li></ul><p>Result? Better modularity, clearer separation of concerns, and smoother deployment.</p><h3>The Changes I Made</h3><p>Here’s a quick breakdown of how I pulled it off:</p><h4>Introduced a main class in the worker module</h4><p>Sounds basic, but this was the foundation. The worker needed to run on its own, independently of the web module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VahwVaJ8Julr6F2gn1ekDg.png" /></figure><p><strong>Removed the web-to-worker dependency</strong></p><p>The worker used to be a sub-module of the web app. Not anymore. I removed the ucm-worker dependency from the web module&#39;s pom.xml. Now they’re peers, not siblings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0sxxJV0m9M1qIIxL__m0Q.png" /></figure><p><strong>Introduce <em>Spring Boot Maven Plugin</em></strong><em> </em>in ucm-worker’s pom.xml</p><p>This allowed me to run the worker module as a standalone Spring Boot app. Now both web and worker can be independently started and managed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uIrJg3zlhRXjzqrDuACTrA.png" /></figure><p><strong>Introduced profiles &amp; Consul</strong></p><p>I added support for different environments like dev, prod, prod-dr, and local. Used Consul for external configuration management. Now each profile can pull its own config via bootstrap.yml—flexibility FTW.</p><p>Yes, it did require syncing with the config repo, but once done, it was totally worth it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*rdRMuEM8JtG3MPet49S_Bw.png" /></figure><p><strong>Added environment-specific </strong><strong>log4j2.xml</strong></p><p>Because logs matter. Especially when you’re debugging that one elusive Kafka issue at 2 AM 😅</p><h4>Running Separately Like Champs</h4><p>Both modules now run on different ports. Just fire them up and watch them fly. The web handles incoming traffic, while the worker crunches away in the background.</p><h3>Why It Matters</h3><p>This little move made my life (and my CI/CD pipeline) <em>so</em> much easier:</p><ul><li>✅ Independent deployments</li><li>✅ Less cluttered codebases</li><li>✅ Easier testing</li><li>✅ Scalable architecture</li></ul><p>And more importantly — it made our system future-proof for any crazier workloads that come our way.</p><h3>Final Thoughts</h3><p>Sometimes, the smartest move is to break things apart — intentionally. This refactor helped me draw clear boundaries, move fast, and scale without crying over deployment issues. If you’re still bundling all your logic into one big app, maybe it’s time you showed your architecture some love too?</p><p>Let me know if you’ve done something similar — or if you’re stuck somewhere. Always up for a nerdy chat. 😄</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b134c117662" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Designed a Real-Time Notification System from Scratch]]></title>
            <link>https://medium.com/@tanish2001sharma/how-i-designed-a-real-time-notification-system-from-scratch-e458b068b33e?source=rss-aec55723385b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e458b068b33e</guid>
            <category><![CDATA[asynchronous-programming]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[notifications]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Tanish Sharma]]></dc:creator>
            <pubDate>Sun, 20 Jul 2025 12:36:36 GMT</pubDate>
            <atom:updated>2025-07-20T12:36:36.857Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>In today’s digital ecosystem, timely and reliable communication with users is critical. Whether it’s sending an OTP, promotional push, or alert email — a well-architected <strong>notification system</strong> plays a central role in any modern application.</p><p>This article presents the <strong>High-Level Design (HLD)</strong> of a <strong>real-time, scalable notification system</strong> that supports:</p><ul><li>Multiple notification types: <strong>Email, SMS, Push</strong></li><li><strong>Scheduled</strong> and <strong>instant</strong> notifications</li><li><strong>Bulk campaign uploads</strong></li><li><strong>Priority-based</strong> processing and delivery</li></ul><p>The architecture is designed to be <strong>fault-tolerant</strong>, <strong>asynchronous</strong>, and <strong>horizontally scalable</strong>, leveraging components like <strong>Kafka</strong>, <strong>Delay Queues</strong>, and <strong>modular adapters</strong>. This post follows a structured HLD format — including domain understanding, component boundaries, data flow, scaling decisions, and failure handling — making it useful for system design interviews or real-world implementation planning.</p><h3>1. Domain-Derived Design</h3><h3>1.1 Event Storming</h3><p>We started with identifying the key events that need to trigger notifications:</p><ul><li><strong>User Registration Completed</strong> → Send welcome Email/SMS</li><li><strong>Payment Successful</strong> → Send confirmation Email/SMS</li><li><strong>OTP Verification</strong> → Send OTP via SMS</li><li><strong>Bulk Campaign Notification</strong> → Trigger batch notification job</li></ul><h3>1.2 Discuss Missed Events</h3><ul><li>Failure events like <strong>DeliveryFailed</strong>, <strong>RetryExhausted</strong>, and <strong>UserUnreachable</strong> were added for tracking failure metrics and fallback notifications.</li><li>Added <strong>BulkCampaignCreated</strong> and <strong>CampaignExecutionStarted</strong> to support scheduled/bulk use cases.</li></ul><h3>1.3 Context Bounding</h3><p><strong>Notification Context</strong>:</p><ul><li>NotificationType (EMAIL, PUSH, SMS)</li><li>Metadata (recipient, content, template params)</li><li>Status (TRIGGERED, SENT, FAILED)</li><li>TriggerType (INSTANT, SCHEDULED, BULK)</li></ul><p><strong>System Context</strong>:</p><ul><li>Notification Service</li><li>Channel Adapters: EmailService, PushService, OtpService</li><li>API Gateway → Web/Client → Notification API → Kafka → Worker → Adapter</li></ul><h3>2. Requirements</h3><h3>2.1 Functional Requirements</h3><ul><li>Support for EMAIL, PUSH, and SMS notifications</li><li>Trigger notifications synchronously or asynchronously</li><li>Support bulk campaign notifications</li><li>Prioritize high-value notifications</li><li>Store notification history and status</li></ul><h3>2.2 Non-Functional Requirements</h3><ul><li>High throughput and low latency</li><li>Horizontal scalability</li><li>Failure handling with retries and dead-lettering</li><li>Resilience to third-party service failures</li><li>Observability (logs, metrics, traces)</li></ul><h3>3. APIs</h3><ul><li>POST /notification/send</li><li>Body: { type, recipient, metadata, triggerType }</li><li>Triggers a single notification</li><li>POST /notification/bulk</li><li>Body: { campaignId, type, recipients[], metadata }</li><li>Accepts bulk upload for campaign notifications</li><li>GET /notification/status/{notificationId}</li><li>Fetch status of a specific notification</li></ul><h4>1. POST /notification/send</h4><ul><li>Client sends request with notification details.</li><li>NotificationService checks if similar notification is recently sent (via cache).</li><li>Persist notification with TRIGGERED status.</li><li>Push message to Kafka (topic: notification-high or notification-low based on priority).</li><li>Return HTTP 202 Accepted with notificationId.</li></ul><h4>2. POST /notification/bulk</h4><ul><li>Client submits bulk list.</li><li>Split into batches (size = 500, configurable).</li><li>For each batch:</li><li>Persist with TRIGGERED.</li><li>Publish each to Kafka (batched).</li><li>Return campaignId and job ID.</li></ul><h4>3. GET /notification/status/{notificationId}</h4><ul><li>First check Redis cache for recent status.</li><li>If cache miss, query MongoDB.</li><li>Return notification status.</li></ul><h3>4. Data Flow</h3><ol><li><strong>Client</strong> sends request to API Gateway</li><li>Gateway routes to Notification API</li><li>API decides notification type, stores TRIGGERED status in DB</li><li>Publishes message to Kafka (single or multi-topic based on priority)</li><li><strong>Worker</strong> consumes messages → routes to respective <strong>Adapter</strong></li><li>Adapter triggers notification (Email/SMS/Push)</li><li>Updates final status (SUCCESS/FAILED) in DB</li><li>Updates Redis cache with final result (TTL = 10 minutes)</li></ol><h3>5. Scaling &amp; Trade-offs</h3><h3>Strategy 1: Single Kafka Topic + Priority Blocking Queue</h3><ul><li>All messages go to a single topic</li><li>Worker consumes and places them in a PriorityBlockingQueue</li><li>Messages are prioritized in-memory based on metadata</li></ul><p>Pros:</p><ul><li>Simpler Kafka infra</li><li>Consumer can batch messages</li></ul><p>Cons:</p><ul><li>Memory-bound (risk of OOM in extreme bulk)</li><li>Slight delay in pulling high-priority items</li></ul><h3>Strategy 2: Multiple Topics for Priority Levels</h3><ul><li>notification-high, notification-medium, notification-low</li><li>Workers consume from all, with scheduling priority given to higher topics</li></ul><p>Pros:</p><ul><li>Strong separation of concerns</li><li>Independent scaling of high-priority traffic</li></ul><p>Cons:</p><ul><li>Kafka topic explosion</li><li>Coordination overhead</li></ul><h3>Bulk Campaign Support</h3><ul><li>POST /notification/bulk uploads campaign</li><li>Internally chunks requests and publishes batched messages</li><li>Batching is used at consumer to process in parallel</li></ul><h3>6. Component Failure Control</h3><ul><li><strong>Retries</strong> with exponential backoff (3 attempts default)</li><li><strong>Dead-letter queue</strong> for messages exceeding retries</li><li><strong>Circuit Breakers</strong> for adapter failures (third-party APIs)</li><li><strong>Idempotency</strong> using notificationId</li><li><strong>Fallbacks</strong>: If PUSH fails, try SMS</li></ul><h3>7. Data Store</h3><ul><li>MongoDB (schema-less)</li><li>Suits dynamic metadata for templates</li><li>Low latency writes, horizontal scalability</li></ul><h3>Considerations:</h3><ul><li>Indexed fields: notificationId, type, status, createdAt</li><li>TTL indexes for cleaning old data</li><li>Redis cache for status fetch and duplicate suppression (short TTL)</li></ul><h3>8. DB Schema and Entities</h3><p><strong>NotificationEntity</strong> <strong>{</strong><br> notificationId: UUID,<br> recipient: String,<br> type: “EMAIL” | “PUSH” | “SMS”,<br> metadata: Map&lt;String, String&gt;,<br> triggerType: “INSTANT” | “SCHEDULED” | “BULK”,<br> status: “TRIGGERED” | “SENT” | “FAILED”,<br> createdAt: Timestamp,<br> updatedAt: Timestamp,<br> priority: HIGH | MEDIUM | LOW,<br> campaignId?: String<br><strong>}</strong></p><h3>9. Module Architecture</h3><ul><li><strong>Web Layer</strong>: Sync controller</li><li><strong>Worker Layer</strong>: Async Kafka consumers</li><li><strong>Adapter Layer</strong>: Email, Push, SMS clients (resilient wrappers)</li><li><strong>Common Layer</strong>: DTOs, enums, utils, mappers</li></ul><h3>10. Sequence Diagrams</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-nTyQM9RTLUy7r9ahDCxZw.png" /></figure><h3><strong>Conclusion</strong></h3><p>Designing a robust, real-time <strong>notification system</strong> goes beyond just sending messages. It requires careful consideration of scalability, failure recovery, prioritization, and delivery guarantees. In this HLD, we explored how to handle multiple notification channels (Email, SMS, Push), support both instant and scheduled notifications, process bulk campaigns, and incorporate priority-based queuing — all while keeping the architecture modular and extensible.</p><p>By decoupling core components through Kafka, introducing a delay queue for scheduled messages, and using an adapter layer for external integrations, this system is equipped to handle high throughput and future scaling needs.</p><p>Whether you’re preparing for a <strong>system design interview</strong> or building a real-world notification platform, this blueprint can act as a solid foundation to build upon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e458b068b33e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Developer’s Guide to Automating App Version Logging in Java Applications]]></title>
            <link>https://medium.com/@tanish2001sharma/a-developers-guide-to-automating-app-version-logging-in-java-applications-74d30e3bfc3e?source=rss-aec55723385b------2</link>
            <guid isPermaLink="false">https://medium.com/p/74d30e3bfc3e</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[analytics-engineering]]></category>
            <category><![CDATA[spring-boot-3]]></category>
            <category><![CDATA[app-version]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Tanish Sharma]]></dc:creator>
            <pubDate>Wed, 04 Dec 2024 19:33:08 GMT</pubDate>
            <atom:updated>2024-12-04T19:33:08.980Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>A Developer’s Guide to Automating App Version Logging in Java Applications</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uXoI2TGluup-oBvo" /><figcaption>Photo by <a href="https://unsplash.com/@ngeshlew?utm_source=medium&amp;utm_medium=referral">Lewis Kang&#39;ethe Ngugi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>The goal is to incorporate the application version into the logs, ensuring that versioning information is dynamically tied to the application’s build lifecycle. The <strong>version-manager</strong> is a JAR-based deployable dependency designed to generate and manage the application version. This version is updated automatically during the application&#39;s build process, allowing for precise version tracking in application logs.</p><p>The process of updating the application version is fully automated, ensuring seamless integration and eliminating the need for manual intervention during each build cycle.</p><p><strong><em>Code Level overview of version-manager :</em></strong></p><blockquote><strong>GitHub link</strong> : <a href="https://github.com/Tanishsharma23/version-manager">https://github.com/Tanishsharma23/version-manager</a></blockquote><p>The version-manager module provides functionality to manage and log application version information dynamically. Key components include:</p><ol><li><strong>Interceptor (</strong><strong>MdcInterceptor)</strong>:<br>Adds the application&#39;s build timestamp to the MDC (Mapped Diagnostic Context) for inclusion in logs. It ensures the timestamp is dynamically tied to the request lifecycle.</li><li><strong>Version Service (</strong><strong>AppVersionService)</strong>:<br>Retrieves the build timestamp and version information from the JAR&#39;s MANIFEST.MF file. This service acts as the central provider for version data.</li><li><strong>Configuration (</strong><strong>VersionProperties)</strong>:<br>Manages configurable properties like keys used in MDC for version information, making the module extensible and customisable.</li><li><strong>Web Configuration (</strong><strong>WebConfig)</strong>:<br>Registers the MdcInterceptor into the application&#39;s request lifecycle. Using Spring&#39;s WebMvcConfigurer, the interceptor is added to the InterceptorRegistry, ensuring it processes every incoming HTTP request to append build version metadata.</li><li><strong>Integration with Build Process</strong>:<br>Automatically generates and embeds the Build-timestamp and other version metadata into the MANIFEST.MF file during the Maven build process, ensuring accurate version tracking.</li><li><strong>Logging Support</strong>:<br>Enables logs to include application version details via Log4j2 integration, improving traceability and debugging capabilities.</li></ol><p>This module is lightweight, deployable as a dependency, and ensures fully automated app version management with seamless integration into the application’s lifecycle.</p><h3>Integration with Client</h3><ul><li><strong>Add Manifest Dependency</strong>:<br>Include the version-manager dependency in the client&#39;s pom.xml. This ensures that the module is packaged with the application and its features are available during runtime.</li></ul><pre>&lt;dependency&gt;<br>          &lt;groupId&gt;org.fs.version.manager&lt;/groupId&gt;<br>          &lt;artifactId&gt;fs-version-manager&lt;/artifactId&gt;<br>          &lt;version&gt;1.0&lt;/version&gt;<br>      &lt;/dependency&gt;  </pre><ul><li><strong>Build Before Deployment</strong>:<br>Ensure the client application is built before deployment so that the fs-version-manager can generate and embed the required metadata (e.g., Build-timestamp) into the MANIFEST.MF file. In our case, this was implemented in the ucm-web module.</li><li><strong>Add Build Timestamp Plugin</strong>:<br>Add the Maven plugin to calculate the build timestamp during the build process. This ensures the Build-timestamp value is dynamically generated and added to the MANIFEST.MF file. Example configuration:</li></ul><pre>&lt;plugin&gt;<br>    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;<br>    &lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;<br>    &lt;version&gt;1.12&lt;/version&gt;<br>    &lt;executions&gt;<br>        &lt;execution&gt;<br>            &lt;id&gt;generate-timestamp&lt;/id&gt;<br>            &lt;phase&gt;initialize&lt;/phase&gt;<br>            &lt;goals&gt;<br>                &lt;goal&gt;timestamp-property&lt;/goal&gt;<br>            &lt;/goals&gt;<br>            &lt;configuration&gt;<br>                &lt;name&gt;timestamp&lt;/name&gt;<br>                &lt;pattern&gt;yyyy-MM-dd-HH-mm-ss&lt;/pattern&gt;<br>                &lt;timeZone&gt;Asia/Kolkata&lt;/timeZone&gt;<br>            &lt;/configuration&gt;<br>        &lt;/execution&gt;<br>    &lt;/executions&gt;<br>&lt;/plugin&gt;</pre><ul><li><strong>Insert Timestamp into </strong><strong>MANIFEST.MF</strong>:<br>Add the Maven plugin to insert the calculated timestamp into the MANIFEST.MF file during the build process. In our case, the key name used is Build-timestamp.</li></ul><pre>&lt;plugin&gt;<br>    &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;<br>    &lt;version&gt;3.2.2&lt;/version&gt;<br>    &lt;configuration&gt;<br>        &lt;archive&gt;<br>            &lt;manifestEntries&gt;<br>                &lt;Build-timestamp&gt;${timestamp}&lt;/Build-timestamp&gt;<br>            &lt;/manifestEntries&gt;<br>        &lt;/archive&gt;<br>    &lt;/configuration&gt;<br>&lt;/plugin&gt;</pre><ul><li><strong>Update </strong><strong>log4j.xml File</strong>:<br>Modify the log4j.xml configuration to include the Build-timestamp value in the logging pattern for the specific profile you&#39;re using to start the client service.</li></ul><pre>&lt;Configuration status=&quot;WARN&quot;&gt;<br>    &lt;Properties&gt;<br> <br>        &lt;Property name=&quot;buildTimestamp&quot;&gt;${sys:build.timestamp}&lt;/Property&gt;<br>    &lt;/Properties&gt;<br>    &lt;Appenders&gt;<br>        &lt;Console name=&quot;Console&quot; target=&quot;SYSTEM_OUT&quot;&gt;<br>         &lt;!-- Fetching Build-timestamp from system properties --&gt;<br>                    pattern=&quot;[%d{dd-MM-yyyy HH:mm:ss.SSS}] [%-5p] [%t] [an=${spring.application.name}] [%logger{}] [ traceId=%X{traceId} spanId=%X{spanId} appVersion=%X{Build-timestamp}] - %msg%n&quot;/&gt;<br> <br>        &lt;/Console&gt;<br>    &lt;/Appenders&gt;<br>    &lt;Loggers&gt;<br>        &lt;Root level=&quot;info&quot;&gt;<br>            &lt;AppenderRef ref=&quot;Console&quot; /&gt;<br>        &lt;/Root&gt;<br>    &lt;/Loggers&gt;<br>&lt;/Configuration&gt;</pre><h3>Configuring version-manager in Client</h3><p>version-manager contains three configurable keys that need to be set in the client&#39;s configuration files. These keys help define important aspects of how the version manager interacts with the client application. Here&#39;s a breakdown of the three keys:</p><blockquote><strong>version.manager.client.target.dir</strong></blockquote><ul><li><strong>Purpose</strong>: This key defines the target directory where the .jar file (including the MANIFEST.MF file) is located. The client must provide this path so that fs-version-manager can access the JAR file and extract version information such as Build-timestamp.</li></ul><p><strong>Example Configuration</strong>:<br>In the client’s application.properties or application.yml:</p><pre>version.manager.client.target.dir=/path/to/your/artefact/target/</pre><blockquote><strong>version.manager.client.user.dir</strong></blockquote><ul><li><strong>Purpose</strong>: This key defines the user’s system directory (user.dir), typically where the application runs from. This helps the version manager in accessing and referencing relative paths, logging, or configuration files within the client&#39;s system.</li><li><strong>Example Configuration</strong>:</li></ul><pre>version.manager.client.user.dir=user.dir</pre><blockquote><strong>version.manager.client.build.timestamp.key</strong></blockquote><ul><li><strong>Purpose</strong>: This key corresponds to the name of the property that holds the dynamic build timestamp, which is set during the build process (as described in earlier steps with the Maven plugin). It will be used to fetch the Build-timestamp from the MANIFEST.MF file and dynamically inject it into the application&#39;s logging or version tracking.</li><li><strong>Example Configuration</strong>:</li></ul><pre>version.manager.client.build.timestamp.key=Build-timestamp</pre><h3>Providing Values for All Three Keys in the Client</h3><p><strong>Add Configuration to </strong><strong>application.properties or </strong><strong>application.yml</strong>: The following properties should be added to the client application’s application.properties or application.yml to provide values for the configurable keys in fs-version-manager:</p><pre>version.manager.client.target.dir=/path/to/your/artefact/target/<br>version.manager.client.user.dir=${user.home}<br>version.manager.client.build.timestamp.key=Build-timestamp</pre><ul><li><strong>target.dir</strong>: Set the path to the directory where the .jar file is located (including MANIFEST.MF).</li><li><strong>user.dir</strong>: Use ${user.home} to get the user&#39;s home directory, or specify a different directory if needed.</li><li><strong>build.timestamp.key</strong>: This corresponds to the key used to retrieve the Build-timestamp from the MANIFEST.MF file.</li></ul><h3><strong>Sample logs :</strong></h3><pre>[05-12-2024 00:59:31.245] [INFO ] [smapleThread] [an=client-service] [com.client.service.service.impl.ClientServiceImpl] [ traceId=98765432823f7ae3921 spanId=ea234fd136c37 appVersion=2024-12-03-13-16-52]-Sample - </pre><h3>Future Scope: Expanding Application Logs with version-manager</h3><p>While version-manager currently helps in injecting the <strong>app version</strong> (via Build-timestamp) into the application logs, there is significant potential to extend its capabilities in the future. Here&#39;s how we can build upon the existing functionality to enrich application logs with more valuable fields:</p><h4>1. Adding More Metadata in Logs</h4><p>In addition to the <strong>Build-timestamp</strong>, other key details from the application’s versioning and configuration can be injected into the logs for better traceability and management:</p><ul><li><strong>Application Version</strong>: Extract the complete application version (Implementation-Version) and include it in the logs.</li><li><strong>Build SCM Information</strong>: Include the source control management (SCM) revision or URL (e.g., Implementation-SCM-Revision, Implementation-SCM-Url) for tracking which exact code revision was deployed.</li><li><strong>Build Date</strong>: Inject the actual build date (i.e., the timestamp of the build) to track when the application was built.</li><li><strong>Environment Information</strong>: Include environment-specific details such as the environment type (production, staging, etc.), region, or other configuration details.</li><li><strong>Commit ID/Branch Name</strong>: Include the commit ID or Git branch name to easily correlate the logs with the exact state of the repository at the time of deployment.</li></ul><h4>2. Automating Metadata Updates</h4><p>Enhance automation of versioning:</p><ul><li><strong>Dynamic Metadata Extraction</strong>: Extend the fs-version-manager to extract and automatically inject dynamic metadata from other files or tools (like Git or Maven).</li><li><strong>Version and Build Metadata Updates</strong>: Automate updates of these fields every time a new build is created, ensuring that the application logs always contain up-to-date information.</li></ul><h4>3. Custom Metadata Fields</h4><p>Allow clients to define custom metadata fields that can be injected into logs:</p><ul><li><strong>Custom Build Parameters</strong>: Extend the configuration in version-manager to allow users to define additional fields they want to capture in the logs.</li><li><strong>Client-Specific Information</strong>: Enable the injection of client-specific fields (such as service ID, region, or environment variables) directly into the logs.</li></ul><h4>4. Centralised Logging and Traceability</h4><p>Incorporating more fields into logs will improve the ability to trace issues across different services:</p><ul><li><strong>Distributed Tracing Support</strong>: Add support for capturing and correlating distributed tracing details (e.g., Trace ID, Span ID, service name) in the logs, improving observability in microservices architectures.</li><li><strong>Log Aggregation</strong>: Support log aggregation tools (e.g., ELK Stack, Splunk, etc.) to facilitate the extraction, search, and analysis of logs with all the enriched metadata.</li></ul><h4>5. Security and Compliance</h4><p>Ensure that logs are comprehensive and secure:</p><ul><li><strong>Sensitive Data Protection</strong>: When adding metadata, ensure that no sensitive data (like passwords, tokens, etc.) is accidentally included in logs.</li><li><strong>Compliance Monitoring</strong>: Provide features to ensure that the logging system complies with regulatory requirements, such as GDPR or HIPAA, by controlling what metadata is included in logs.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74d30e3bfc3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement Kafka Producer with Spring -AOP]]></title>
            <link>https://medium.com/@tanish2001sharma/implement-kafka-producer-with-spring-aop-4fd1a01bfd82?source=rss-aec55723385b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fd1a01bfd82</guid>
            <dc:creator><![CDATA[Tanish Sharma]]></dc:creator>
            <pubDate>Thu, 04 Jan 2024 18:16:01 GMT</pubDate>
            <atom:updated>2024-01-04T18:16:01.042Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>This document provides a step-by-step guide for implementing Spring AOP (Aspect-Oriented Programming) in a Spring Boot application for a Kafka producer. AOP allows you to modularize cross-cutting concerns, such as logging, monitoring, or security, in a clean and efficient manner.</p><p>We will be implementing Kafka producer with customise annotation.</p><h3>Prerequisites</h3><ul><li>Spring Boot project with Kafka dependencies</li><li>Basic understanding of Spring Boot and Kafka concepts</li></ul><h3>Steps for Implementation</h3><h3>1. Add Dependencies</h3><p>Ensure that your Spring Boot project includes the necessary dependencies for Kafka and Spring AOP.</p><pre>&lt;!-- Kafka Dependencies --&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;org.springframework.kafka&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-kafka&lt;/artifactId&gt;<br>&lt;/dependency&gt;<br> <br>&lt;!-- Spring AOP Dependency --&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-boot-starter-aop&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><h3>2. Create Kafka Producer</h3><p>Implement a Kafka producer class that sends messages to a Kafka topic. This class will be the target for our AOP aspect.</p><p><strong>Sample code -:</strong></p><figure><img alt="Sample kafka producer" src="https://cdn-images-1.medium.com/max/1024/1*ZD1gWxs-ofpPMftQRrHBPQ.png" /></figure><h3>3. Create customised annotation</h3><pre><strong>@Target<br></strong>The @Target annotation in Java is a meta-annotation used to specify the types of elements to which a custom annotation can be applied. In other words, it defines the valid locations (or targets) where an annotation can be used within a Java program.<br> <br>The @Target annotation takes a single parameter of type ElementType or an array of ElementType. The ElementType enum includes the following constants:<br> <br>CONSTRUCTOR: Annotations can be applied to constructors.<br>FIELD: Annotations can be applied to fields (instance variables).<br>LOCAL_VARIABLE: Annotations can be applied to local variables.<br>METHOD: Annotations can be applied to methods.<br>PACKAGE: Annotations can be applied to packages.<br>PARAMETER: Annotations can be applied to method parameters.<br>TYPE: Annotations can be applied to classes, interfaces, and enums.</pre><pre><strong>@Retention<br></strong><br>The @Retention annotation in Java is a meta-annotation used to specify how long an annotation should be retained. It determines the visibility and availability of the annotation, particularly whether the annotation information should be accessible at runtime through reflection.<br> <br>The @Retention annotation takes a single parameter of type RetentionPolicy, which is an enum with the following constants:<br> <br>SOURCE: Annotations are only retained in the source code and are discarded during compilation. They are not available at runtime. This is typically used for annotations that affect the compilation process.<br> <br>CLASS: Annotations are retained in the bytecode during compilation but are not accessible at runtime. This is the default retention policy if no @Retention annotation is present.<br> <br>RUNTIME: Annotations are retained in the compiled bytecode and are available for inspection at runtime through reflection. This retention policy is used when annotations need to be processed at runtime, such as during reflection-based frameworks or custom runtime logic.</pre><p>Here is an example of making customised annotation (<strong>@UcmKafkaProduce</strong>) to produce events from UCM service via Kafka producer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PBTgXgx2N77ufcnrN2RaDw.png" /><figcaption>Sample of making custom annotation</figcaption></figure><h3>4. Applying customised annotation</h3><p>Now use <strong>@UcmKafkaProduce </strong>at method level. We are using <strong>@UcmKafkaProduce</strong> on addNodeInUcm()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uM8eUoIS37Ktel4bRhjHqQ.png" /><figcaption>Sample of using @CustomAnnotation at method level</figcaption></figure><h3>5. Create Utility class for AOP</h3><p>We need to create a utility class in an Aspect-Oriented Programming (AOP) setup using Spring and AspectJ. :</p><pre><strong>About CommanPointCutConfig class<br></strong><br>The CommanPointCutConfig class is a utility class in an Aspect-Oriented Programming (AOP) setup using Spring and AspectJ. This class is responsible for defining a reusable pointcut expression using the @Pointcut annotation. The purpose of this class is to centralise the definition of a pointcut that captures methods annotated with a specific annotation (@UcmKafkaProduce in our case).</pre><pre><strong>About Pointcut Expression<br></strong><br>The <strong>@Pointcut</strong> annotation is used to define a named pointcut.<br>@annotation is an AspectJ pointcut designator that selects join points where the executing method is annotated with a specific annotation.<br>com.airtel.fs.ucm.service.services.annotations.UcmKafkaProduce is the fully qualified name of the @UcmKafkaProduce annotation.<br> <br><strong>Purpose</strong> :<br>This pointcut expression is designed to capture methods annotated with @UcmKafkaProduce. It is commonly used in Aspect-Oriented Programming (AOP) to specify where an advice (interceptor) should be applied within the codebase.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IS4UG5ONbOZQ65Y35lftgg.png" /><figcaption>Sample code for using @pointcut as best practice for spring-aop</figcaption></figure><h3>6. Create Aspect class</h3><pre><strong>About UcmKafkaProduceAspect class<br></strong><br>UcmKafkaProduceAspect class is an Aspect class in a Spring Boot application that uses Spring AOP and AspectJ. This class defines an aspect named UcmKafkaProduceAspect that intercepts methods annotated with @UcmKafkaProduce and performs some logic after the method execution.</pre><pre><strong>About @After annotation<br></strong><br>The @After annotation in AspectJ and Spring AOP is used to define an advice, which is a block of code that runs after the execution of a matched method. Specifically, the @After advice is executed after the target method completes its execution, regardless of whether it threw an exception or not.<br> <br><strong>Usage</strong>:<br> <br><strong>@After</strong> is placed on a method within an aspect class to indicate that the contained code should be executed after the matched method is completed.<br> <br><strong>Parameters:</strong><br> <br>pointcutExpression: Specifies the pointcut expression that defines when the advice should be applied.<br>joinPoint: An optional parameter of type JoinPoint that allows access to information about the intercepted method, such as method arguments, signature, etc. This parameter is optional and may be omitted if not needed.<br> <br><strong>Execution Timing:</strong><br> <br>The advice annotated with @After is executed after the target method has completed its execution, including any return statements or exceptions thrown during the method&#39;s execution.<br> <br><strong>Use Cases:</strong><br> <br><strong>@After</strong> is often used for tasks that should be performed after the main logic of a method, such as cleanup, logging, or additional processing.<br>It is particularly useful when you want to perform certain actions irrespective of whether the target method threw an exception.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HEsiRJaqM7dOdgobkbQlXg.png" /><figcaption>deserialising via jointpoint and producing event to kafka</figcaption></figure><p>This is designed to handle Kafka message publication logic after methods annotated with @UcmKafkaProduce are executed. We have made sure that the pointcut expression and the logic inside the advice method align with our application&#39;s requirements. Also, that the CommanPointCutConfig class is correctly defining the point cut for methods annotated with @UcmKafkaProduce.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fd1a01bfd82" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>