<?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 SHARATH K on Medium]]></title>
        <description><![CDATA[Stories by SHARATH K on Medium]]></description>
        <link>https://medium.com/@sharathk4u?source=rss-4adaef7a22c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7OSsl1usFrLmWQKo.</url>
            <title>Stories by SHARATH K on Medium</title>
            <link>https://medium.com/@sharathk4u?source=rss-4adaef7a22c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:59:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sharathk4u/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[A Practical Guide for Resilient Services : Bulkheads]]></title>
            <link>https://medium.com/javarevisited/a-practical-guide-for-resilient-services-bulkheads-e02e1a54c079?source=rss-4adaef7a22c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e02e1a54c079</guid>
            <category><![CDATA[resilience]]></category>
            <category><![CDATA[bulkhead]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[SHARATH K]]></dc:creator>
            <pubDate>Mon, 09 Nov 2026 06:13:20 GMT</pubDate>
            <atom:updated>2026-11-09T06:13:20.163Z</atom:updated>
            <content:encoded><![CDATA[<h3>Overview</h3><p>We were modernising a critical payment system by replacing its legacy validation platform with a more capable strategic service. Replacing the legacy platform in one go was a little risky as the new service had not yet been proven in production. Hence we had to move the traffic from old system to new system in a phased manner. We also needed to isolate the two systems so that problems in the strategic service would not affect the legacy platform.</p><p>This is where the Bulkhead Pattern became a key design decision. I’ll describe the scenario, the options we considered, and the solution we chose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*Kx9_3Nt8UipT850eEEFXoA.png" /><figcaption>Spring Boot + Resilence4j</figcaption></figure><h3><strong>The challenge: New integration impacting existing flows</strong></h3><p>We were operating a payment system with an important component that validated each payment. This component was a separate system that had been running in production for quite some time. It was battle-tested and stable, handling millions of transactions each month. However, it had it’s own limitations because of which we had to migrate to a new system. The system was not available 24x7, had occasional downtime and had SLAs that did not meet everyone’s expectations.</p><p>The strategic service we were moving addressed many of these problems including 24x7 availability and offered new capabilities for the business. Since we were among its first consumers and it had limited production exposure, we decided to run both systems in parallel. Only a small portion of the business that is low risk used the new system while most transactions continued to use the legacy platform.</p><p>During a design review, one question revealed a serious flaw — what would happen if the new system became blocked or very slow? If it started responding slowly the application threads could become exhausted. The legacy path would then be deprived of the threads it needed to process transactions resulting in the shut down of the whole system.</p><p>This is a common problem in high-throughput systems which means shared resources create shared risk. We had two traffic paths, but they were not fully isolated. The application and its thread pool were shared, which meant that a problem in one path could affect the other.</p><h3><strong>The solution : Applying the Bulkhead Pattern</strong></h3><p>The Bulkhead Pattern is the exact resilience pattern that you need when you want to isolate shared flows.</p><p>&gt; Isolate the elements of an application into pools so that if one element fails, the others continue to function. This approach, also known as a cell-based architecture, makes an application tolerant of failure and stops a fault in one part of the system from cascading across the rest.</p><p>This could mean separating flows for different downstream or upstream dependencies, or isolating independent work in an application to minimise interference. In our case, if the new strategic service started failing we needed and isolation that would prevent that failure from taking down the legacy path.</p><h3><strong>Resilence4j to the rescue</strong></h3><p>We were already using Resilience4j, and this pattern fit naturally into our stack. Resilience4j gives you several resilience patterns out of the box such as timeouts, retry, circuit breaker etc which we were already using. It was particularly attractive because it does not require a large architectural rewrite.</p><p>The two most relevant options in Resilience4j were:</p><ul><li>SemaphoreBulkhead which uses Semaphores</li><li>FixedThreadPoolBulkhead which uses a bounded queue and a fixed thread pool.</li></ul><p><strong>Semaphore bulkhead</strong></p><p>A semaphore bulk head as your rightly guessed, use a semaphore to control the number of concurrent execution. It also runs the flow in the same application thread. If the semaphore is full, it’ll reject the extra requests that has come in. Some of the key properties that we should be defining are as follows.</p><ul><li>maxConcurrentCalls: Max amount of parallel executions allowed by the bulkhead</li><li>maxWaitDuration : Max amount of time a thread should be blocked for when attempting to enter a saturated bulkhead.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dxw3Wb_7beEUYfzdBOWL_A.png" /><figcaption>Semaphore Bulkhead</figcaption></figure><p>If we increase the maxWaitDuration, this could have an impact on the number of available application threads. If we reduce the maxDuration to zero, if our concurrency is higher than the configured number, it would be immediately rejected. So we should be careful about these numbers when configuring and should be tested properly.</p><p><strong>Fixed Thread-pool bulkhead</strong></p><p>FixedThreadPoolBulkhead does not use a semaphore to limit concurrent calls. Instead, it uses a bounded queue and a dedicated thread pool. The work runs in that pool, allowing the application thread to return after submitting the task rather than executing the downstream call itself.</p><ul><li>maxThreadPoolSize : the maximum size of the thread pool</li><li>coreThreadPoolSize : the core size of the thread pool</li><li>queueCapacity : the capacity of the queue</li></ul><p>When a request arrives, it is submitted to the queue and picked up by a thread in the pool. If all threads are busy, the request waits in the queue. When the queue is full, new requests are rejected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ajVBfr5YigXHsnUWBJBPNA.png" /><figcaption>Fixed Threadpool Bulkhead</figcaption></figure><p>For a payment platform with slower, blocking downstream calls, ThreadPoolBulkhead was the safer option for this design. It isolates the dependency call in its own thread pool, which addresses our main concern: allowing a slow call to consume the application threads needed by other work.</p><p>One of the biggest lessons from this design was that async processing was an essential requirement. If we had kept the downstream call synchronous and used the same application threads, the pattern would not have been effective. We would have received high level of failures which would have been difficult to manage from an operations perspective or we risked having a slow strategic system impact the legacy path as we still used the same application threads. Hence it was important for us to follow the asynchronous path as demonstrated below.</p><p><strong>Example implementation</strong></p><p>A typical Java implementation looks like this:</p><pre>@Bean<br>public ThreadPoolBulkheadConfig threadPoolBulkheadConfig() {<br>  return ThreadPoolBulkheadConfig.custom()<br>  .maxThreadPoolSize(20)<br>  .coreThreadPoolSize(10)<br>  .queueCapacity(50)<br>  .build();<br>}<br><br>@Bulkhead(name = &quot;paymentValidationStrategic&quot;, type = Bulkhead.Type.THREADPOOL)<br>public CompletableFuture&lt;ValidationResponse&gt; callStrategicValidation(ValidationRequest request) {<br>  return CompletableFuture.supplyAsync(() -&gt; {<br>    return strategicValidationClient.validatePayment(request);<br>  }, executorService);<br>}</pre><h3><strong>Conclusion</strong></h3><p>The important lesson from this design was that shared capacity can create cross-system failures. When two systems run in parallel, one slow dependency can affect the wider platform if it consumes the same execution resources as other work. The Bulkhead Pattern addresses this by creating independent execution compartments. In our case, Resilience4j bulkheads and asynchronous execution gave us a safety net while we migrated from a stable legacy validation platform to its strategic replacement.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e02e1a54c079" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/a-practical-guide-for-resilient-services-bulkheads-e02e1a54c079">A Practical Guide for Resilient Services : Bulkheads</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spec-Driven Development: A Practical Way to Build with More Clarity]]></title>
            <link>https://medium.com/javarevisited/spec-driven-development-a-practical-way-to-build-with-more-clarity-b53fa4ebd6d9?source=rss-4adaef7a22c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b53fa4ebd6d9</guid>
            <category><![CDATA[spec-driven-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[SHARATH K]]></dc:creator>
            <pubDate>Tue, 18 Aug 2026 22:06:42 GMT</pubDate>
            <atom:updated>2026-08-22T15:40:55.457Z</atom:updated>
            <content:encoded><![CDATA[<p>Spec-driven development has been a hot topic for some time now. This blog reflects how I use it on a day-to-day work as a senior developer. Not as a theoretical framework, but as a practical way to reduce ambiguity, align the stakeholders, and keep delivery moving without losing control of the work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*-ouM_2e3z7T_53zk9FKDVA.png" /></figure><h3>What is spec-driven development</h3><p>Spec-driven development is a way of working where you define the behaviour, constraints, and acceptance criteria of a change before you start building it. In simple terms, it is the opposite of coding first and documenting later. Following are some of the common definitions.</p><h4><strong>As per Github</strong></h4><blockquote>Spec-Driven Development (SDD) inverts this power structure. Specifications don’t serve code — code serves specifications. The Product Requirements Document (PRD) isn’t a guide for implementation; it’s the source that generates implementation. Technical plans aren’t documents that inform coding; they’re precise definitions that produce code. This isn’t an incremental improvement to how we build software. It’s a fundamental rethinking of what drives development.</blockquote><h4>As per IBM</h4><blockquote>Spec-driven development (SDD) is a software methodology in which a detailed specification of implementation details is authored and agreed upon before development begins. In other words, it serves as a single source of truth for what to build and how to build it.</blockquote><h3>Spec-driven development variations</h3><p>There are a few variations of this approach, and they sit on a spectrum.</p><h4>Spec-first development</h4><p>In spec-first development, the specification is created before any code is written. It usually takes the form of a user story with acceptance criteria or a requirements document from a Business Analyst. The goal is to create initial clarity before implementation begins.</p><p>The specification will not be maintained throughout implementation phase. But it still serves as the entry point into spec-driven work. For small or straightforward changes this is enough.</p><h4>Spec-anchored development</h4><p>In spec-anchored development, the specification imrpoves alongside the code implementation. As requirements becomes clearer and architecture is refined, the spec is updated to reflect the current state of the system.</p><p>This is especially useful for large features that involves multiple stories and the requirement continues to change as discussion with various stake holders progress. It gives the team structure without making the process too rigid. This is the version I find most practical for most engineering teams especially for the senior developers who acts as force multipliers. It stays close to the existing ways of working by approaching the solutions in an iterative manner.</p><h4>Spec-as-source development</h4><p>At the far end of the spectrum is spec-as-source development. In this model, changes in the spec automatically trigger changes in the code. No human is directly refactoring the code.</p><p>This is an idealistic AI-first version of the approach. It can be powerful, but it requires a high level of confidence in the quality and consistency of the tooling, the prompts, and the validation pipeline. Here, your role becomes that of a facilitator where you make the ecosystem ideal for the Agents to do it’s work. As a software engineer, it might be mentally difficult to transition to this appraoch by letting go of the control that you have on the SDLC process.</p><h3>My approach to Spec Driven Development</h3><p>I follow spec-anchored development because it works well for the responsibility that I have and the way I actually build software. As a tech lead, I don’t work on single stories, but on large features that span across multiple sprints. I won’t be able to start with a perfect final spec as the requirement itself will evolve over a period of time based upon the discussions with stake holders and the understanding of the system. I start with an initial spec, which evolve as I learn more.</p><p>The initial spec usually comes from a few places:</p><ul><li>My initial requirement document created by the Business Analyst</li><li>Research into the relevant part of the codebase</li><li>Conversations with stakeholders or other engineers</li><li>An initial understanding of the architecture and constraints.</li></ul><p>As I progress, I gain more clarity both on the requirements and the architecture. Some assumptions changes while some requirements become complicated. Some times edge cases results in new scenario’s. When that happens, I improve the spec along the way.</p><p>This approach gives me a balance between direction and flexibility.</p><h4>Documents</h4><p>I think this works best when the spec is not just a single document in isolation. It becomes part of a broader knowledge system.</p><h4>Project-level memory bank</h4><p>At the project level, I like to maintain a memory bank that gives context to the work. This is useful for onboarding and for keeping the team aligned over time.</p><p>A typical project-level setup includes things like:</p><ul><li>A Confluence page for the project,</li><li>Architectural documents and Architecutre Decision Records</li><li>Code analysis and architectural principles</li><li>Coding guidelines and implementation standards</li></ul><p>This helps create a shared foundation for the work.</p><h4>Feature-level spec</h4><p>For an individual feature, I prefer a lighter, more focused spec. It should capture the high-level intent without becoming too heavy.</p><p>I like to include the following as a start.</p><ul><li>requirement</li><li>plan</li><li>task breakdown</li></ul><p>I feel this is enough to make the work progress in a structured manner without making this a documentation overhead.</p><h3>How do I create this evolutionary spec</h3><p>The process usually looks like this:</p><ol><li>Start with the initial business requirement from the confluence page created by the Business Analyst.</li><li>Research the relevant code and architecture.</li><li>Write down the first version of the spec.</li><li>Use that spec to guide implementation.</li><li>As I learn more, refine the spec.</li><li>Keep updating it until it reflects the current understanding of the feature.</li></ol><p>This is important because the spec is not a frozen artifact. It keeps evolving. This approach has worked well for me, especially at the feature level. It gives me a better way to break a feature into smaller pieces. It helps me think clearly, and make sure all the decisions go through my vetting process. It also helps me stay in control of the implementation instead of following instructions blindly.I feel in control of the process.</p><p>I think there are two useful ways to apply this depending on the size and complexity of the work.</p><h4>Large features spanning multiple stories</h4><p>For larger features, I prefer a more structured flow. I use SpecKit for this kind of work because the scope is usually broader and the level of ambiguity is higher. The process becomes:</p><ul><li>requirement,</li><li>plan,</li><li>tasks,</li><li>implementation,</li><li>and then iteration through clarification as new edge cases, better ideas, or pivots come up.</li></ul><p>This works especially well when the feature spans several stories and needs coordination across different parts of the system. The spec gives me a place to capture the larger intent, while the plan and tasks help break that intent into something executable.</p><p>What I like most about this approach is that it does not freeze the work too early. As I learn more, I can revisit the spec, clarify assumptions, and adjust the plan without losing the overall direction.</p><h4>Smaller ones</h4><p>For smaller work, I use OpenSpec. The process is lighter. I move from plan to implementation more directly, and I break the work into tasks without spending too much time on ceremony.</p><p>This is often enough when the change is small and well understood. The extra structure of a big spec can become overhead rather than help.</p><h3>Conclusion</h3><p>Overall, the biggest benefit for me has been mental clarity. Instead of just following a plan without understanding it, I can review the spec, do my own research in a separate agent or context, and then provide better input. That makes me feel more in control of the work and more aware of where the decisions are being made. I feel more confident in the decisions that are made and implemenation that has been executed. In the end, for me, spec driven development help keep me alive and interested in the AI assisted software development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b53fa4ebd6d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/spec-driven-development-a-practical-way-to-build-with-more-clarity-b53fa4ebd6d9">Spec-Driven Development: A Practical Way to Build with More Clarity</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Batch in Action- Part 2 : Reliable Batch Processing in Production]]></title>
            <link>https://medium.com/@sharathk4u/spring-batch-in-action-part-2-reliable-batch-processing-in-production-64792c6493e2?source=rss-4adaef7a22c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/64792c6493e2</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring-batch]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[batch-processing]]></category>
            <dc:creator><![CDATA[SHARATH K]]></dc:creator>
            <pubDate>Sat, 18 Jul 2026 11:12:13 GMT</pubDate>
            <atom:updated>2026-07-18T11:12:13.730Z</atom:updated>
            <content:encoded><![CDATA[<p>In Part 1, we built the core comparison flow between two systems and started generating discrepancy output. Now that it has worked functionally, we wanted to check operational readiness.</p><p>Once we pushed the job to UAT and started load testing, we started seeing some problems. Some records failed due to downstream API issues. Some failed because input data was not valid. And it became clear that we need solid exception handling and auditability to make this production ready.</p><p>This part is about making the same batch flow reliable, auditable, and easier to operate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*L4UKNKmrxIDDqKGK.png" /></figure><h3>What it means to be Production ready</h3><p>A batch job that compares data across systems is not a one off script. It runs every day, with strict timelines, and we need a proper audit of everything that happened, including successfully processed records, failed records, and reasons for failure.</p><p>In our case, the following were our top 3 priorities.</p><ol><li>Retry only failures that are likely to recover like a network issue when calling a downstream API.</li><li>Avoid retrying records that have data issues.</li><li>Produce a full audit record for business and engineering teams.</li></ol><p>If these three are missing, operations become difficult and you often won’t have answers when things go wrong.</p><h4>Grouping Retryable and Non-Retryable Failures</h4><p>The first improvement was a standard one. Create two different groups of exceptions, retryable and non-retryable, based on the scenarios. Handle them differently.</p><p>Temporary failures like API timeouts, cache issues, and short-lived connectivity issues went into the retryable exception group. Data issues, validation, and business rule failures were grouped into non-retryable exceptions.</p><h4>Making the Job Fault-Tolerant</h4><p>The compare step is where most of the logic is there and high chances of issues. It reads the source record, compares state across systems, and writes outcomes to audit tables. So this is where we added fault tolerance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*5kTUKX6Foy-dwCOCNUZhGw.png" /></figure><p>A couple of notes from our implementation:</p><ul><li>retryLimit(3) was enough for most temporary failures.</li><li>skipLimit(20) gave us protection from silent data issues. If too many records started failing, we wanted to fail the job.</li><li>noRetry(...) for data issues and validation/business exceptions to prevent unnecessary reprocessing.</li></ul><h4>Validation in the Processor: Catch Problems Early</h4><p>Validation lived inside the processor, before and after comparison logic. If there were data issues in the incoming record or after we processed the records, we were able to identify the issues early on. These were thrown as exceptions, which were eventually handled by our skip listeners. A basic validation of input and output could look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*2lKAk1H_fhvl0bZpEYgVpQ.png" /></figure><p>This was important for two reasons:</p><ul><li>We failed fast on structurally bad input. And if an entire feed was wrong or had bad structure, our job also failed.</li><li>We avoided producing partially valid output and caught issues early from our side.</li></ul><h4>Auditing Every Failure</h4><p>We needed proper auditability for each and every record. We created an audit table that captured the status of each record, whether it is successful or failed, and if failed, the reason for failure along with details. This way, when needed, we could execute SQL queries to slice and dice our data. We used SkipListeners to handle this scenario. If the error happened during processing or writing, we handled that record through the skipListener, which updated the database table with the details.</p><p>Listeners gave us a clean hook for this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*ar4eoqf7zVfgLk6sQxXGMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*TstZx15UDSqPDpYt2iUBxQ.png" /></figure><p>In addition to logging, we persisted status and error reason in audit tables so each record had a clear outcome. This made business reporting much more reliable, and debugging became faster because failures were already categorized.</p><h3>Chunk Size, Memory, and Throughput Trade-Off</h3><p>We processed an average of 50k+ records on a normal day and 1M+ records on special requirements.</p><p>We chose chunk size 100 because each item had so much data transformation that involved string manipulations, encoding issue fixes, structural changes of data, etc. A bigger chunk gave slightly better throughput, but we soon saw memory spikes that made it unreliable, and going with a larger batch caused OOM exceptions and failed jobs.</p><p>The practical rule we followed was: choose chunk size based on per-item work complexity, not total record count. Observe the infra for each run and take a conscious choice. Never left these to guesswork.</p><p>Paged readers also helped us keep memory stable. We streamed records incrementally instead of pulling large sets into memory at once.</p><h4>Why Spring Batch Internal Tables Help in Real Operations</h4><p>Spring Batch metadata tables ended up being very useful beyond restart behavior. Some of the tables we referred to were: BATCH_JOB_EXECUTION and BATCH_STEP_EXECUTION.</p><p>They gave us quick visibility into:</p><ul><li>step-level read/write/skip counts,</li><li>execution status and duration,</li></ul><p>Combined with our audit tables, this gave both engineering and operations a complete picture of each run.</p><h3>What Changed After These Improvements</h3><p>After these changes, the job became far easier to trust.</p><p>Temporary failures recovered automatically. Logical data failures were captured clearly and pushed back for correction. Every record had an outcome trail. And run-level metrics were easy to verify.</p><p>These are important when so many eyes are on the job that you are running and you get requests for reports from leadership in unexpected formats. Hence, it is important to capture as much data as possible for you to handle these requests.</p><h3>What Is Next</h3><p>In the next part, we go deeper into restart strategy, partitioning, and parallel execution patterns so the same job scales with larger volumes while keeping reliability intact.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64792c6493e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Batch in Action-Part 1: Getting Started]]></title>
            <link>https://medium.com/@sharathk4u/spring-batch-in-action-part-1-getting-started-971a22244c1a?source=rss-4adaef7a22c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/971a22244c1a</guid>
            <category><![CDATA[spring-batch]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[level-up-in-tech]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[SHARATH K]]></dc:creator>
            <pubDate>Sat, 28 Jun 2025 10:39:55 GMT</pubDate>
            <atom:updated>2025-06-28T10:39:55.514Z</atom:updated>
            <content:encoded><![CDATA[<h3>Overview</h3><p>We had a legacy project in which we had two different data sources which was used by different end users. An audit revealed system glitches had caused those disparate data sources to fall out of sync. We needed an automated process to compare those sources at regular intervals and flag any discrepancies. Our goal was to identify each difference, determine its cause, and restore consistency. From the onset it was clear that Spring Batch would be an ideal solution for this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*-H5-0aGmi0XdSOE_yyGOeg.png" /></figure><h3>Spring Boot Components</h3><p>As per spring boot official documentation, sprint batch is</p><blockquote>A lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems.</blockquote><blockquote>Spring Batch provides reusable functions that are essential in processing large volumes of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and features that will enable extremely high-volume and high performance batch jobs through optimization and partitioning techniques. Simple as well as complex, high-volume batch jobs can leverage the framework in a highly scalable manner to process significant volumes of information.</blockquote><p>The overall steps for our solution were the following.</p><ul><li>Identify the set of records to be compared. For example the employees newly onboarded to the system in the last week. We had the set of records to be compared in an audit table.</li><li>Fetch the data from the two systems. Compare them and find the differences if any.</li><li>Store the details of the fields with discrepancies in an assessment table for report generation.</li></ul><h4>High Level Architecture</h4><p>At a high level Spring Batch uses three core elements:</p><ul><li><strong>Job Launcher</strong> to trigger the job and pass parameters</li><li><strong>Job </strong>to define the sequence and conditions of processing steps</li><li><strong>Step </strong>as the smallest unit of work within a job.</li></ul><p>Spring Batch internally has a job repository that keep track of the job, manage the records processed, handle failures etc. Spring boot also takes care of the transaction management.</p><p>The overall spring batch flow will look like below. We’ll go into each of the steps and understand the significance one by one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KCj92mRv7kGgWX5UXpVVKA.png" /></figure><h4>Implementing the Spring Batch Job</h4><p>As the first step, after creating the spring boot project, add the following dependencies. One for spring batch and another for running tests for spring boot as testing a batch is quite different from how you would do other applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*S4nIfvimbPVgIXPrFDhuyQ.png" /></figure><p><strong>Spring Batch Configuration</strong></p><p>Job launcher is where you will trigger the job. When triggering the job, you can pass job parameters that are needed to guide the job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*SuoI0J6z2BcrweogNNn4Rg.png" /></figure><p>We created a configuration and registered three beans:</p><ul><li><strong>JobRepository </strong>to link Spring Batch tables and track job progress</li><li><strong>PlatformTransactionManager </strong>to manage transactions</li><li><strong>Repository </strong>to keep track of the records that we wanted to process. In our case we supplied the list of employees onboarded in the last week</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*3OHEh4do4DRFKLWnTv_ALw.png" /></figure><p><strong>Job : As a Sequence of Steps</strong></p><p>job is generally composed of one or more steps that are executed sequentially — or sometimes in parallel. We created a job, using the JobBuilder which takes in a job name and the JobRepository object. We then mentioned the steps to be executed using the builder class provided. We can also have conditional execution of steps or listener attached to the job. However, in our case there was no need for the same and we created a job with two steps — loadMetadata and compareData.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*MftYIHxbc5gYUf7a-H9M-A.png" /></figure><p><strong>Steps : Tasklet and Chunk Oriented Steps</strong></p><p>Steps are the smallest working unit in a batch job. A step can either be a tasklet or a chunk oriented step. In our case, loading the metadata at the start of the job was handled by a tasklet, while processing individual records and finding the data discrepancies were done by the chunk oriented step.</p><ul><li>A <strong>tasklet </strong>runs once per job, making it ideal for startup actions. This could be scenario’s like loading metadata at the start of the job. Implement the Tasklet interface and override the execute method with your custom logic to create a tasklet as shown below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*7cQYPpux9HIr-HlcCAF3wA.png" /></figure><ul><li>A chunk oriented step on the other hand is used to process large amount of records, in a set of smaller batches called chunks. Each Step has a reader, processor and a writer as shown below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*IjYG0GfoLUzR2LTUuAX8RQ.png" /></figure><p><strong>Readers Writers and Processors</strong></p><p>I you have 1 million records to be processed and if the chunk size is 100, the batch job will take care of processing them sequentially in chunks of 100:</p><ol><li>Reader reads 100 records</li><li>Processor applies business logic to each record</li><li>Writer persists all 100 processed records.</li></ol><p>Spring Batch offers a variety of out-of-the-box readers and writers:</p><ul><li>JpaPagingItemReader/JpaItemWriter for JPA sources</li><li>JdbcPagingItemReader/JdbcBatchItemWriter for JDBC sources</li><li>FlatFileItemReader/FlatFileItemWriter or MultiResourceItemReader/MultiResourceItemWriter for flat files</li><li>KafkaItemReader/KafkaItemWriter for Kafka streams</li><li>RedisItemReader/RedisItemWriter for Redis stores</li></ul><p>Depending upon our requirement we can take the appropriate readers and writers. If none of this works, we can write your own custom reader or writer by implementing the ItemReader or ItemWriter interfaces. In our case we used JpaPagingItemReader to fetch audit records and a custom writer to update the database and invoke external APIs.</p><h3>What’s Next</h3><p>We’ve learned the basics of Spring Batch job processing. But a production‐ready job requires resilience and performance tuning. In remaining parts we will explore restart strategies, error handling, parallel processing, and batch job monitoring.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=971a22244c1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reliable Messaging: Implementation of Transactional Outbox and Kafka Connect]]></title>
            <link>https://medium.com/@sharathk4u/reliable-messaging-implementation-of-transactional-outbox-and-kafka-connect-e8f57bc2f769?source=rss-4adaef7a22c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8f57bc2f769</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[kafka-connect]]></category>
            <dc:creator><![CDATA[SHARATH K]]></dc:creator>
            <pubDate>Sun, 02 Feb 2025 19:06:12 GMT</pubDate>
            <atom:updated>2025-02-02T19:07:32.281Z</atom:updated>
            <content:encoded><![CDATA[<h3>Overview</h3><p>For the implementation of Transaction Outbox pattern with Kafka Connect, let us consider the following scenario. There is a microservice that is used for order management. Let us assume the orders are created in a Couchbase database where we have a bucket called Orders. The objective is to publish the records from the couch base database to a Kafka topic based upon an event type(Create or Update). For a conceptual overview of the implementation please read Part 1 <a href="https://medium.com/@sharathk4u/reliable-messaging-a-guide-to-transactional-outbox-and-kafka-connect-9a7cbb3271db">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*uvVRZwxfPDr82Fsxf2LnEA.png" /></figure><h3>Implementation Details</h3><p>Since we have to emit event from Database to Kafka, we’ll have to use source connector. Couchbase internally uses DCP(Distributed Change Protocol) to capture the changes in the database and publish them to a Kafka topic.</p><h4><strong>Configuration</strong></h4><p>A sample configuration for the Kafka couch base source connector looks like below. As per the configuration we are defining a couch base source connector with 2 tasks. The connector will monitor the orders bucket and will emit events to streaming-topic-create-order. In this case we defined two connectors — one for create and another for update. Based upon the configuration, for each entry in the orders couch base bucket, one event will go to streaming-topic-create-order and the other will go to streaming-topic-update-order.</p><pre>{<br>    &quot;name&quot;: &quot;test-couchbase-source&quot;,<br>    &quot;config&quot;: {<br>        &quot;name&quot;: &quot;test-couchbase-source&quot;,<br>        &quot;connector.class&quot;: &quot;com.couchbase.connect.kafka.CouchbaseSourceConnector&quot;,<br>        &quot;tasks.max&quot;: &quot;2&quot;,<br>        &quot;couchbase.topic&quot;: &quot;streaming-topic-create-order&quot;,<br>        &quot;couchbase.seed.nodes&quot;: &quot;127.0.0.1&quot;,<br>        &quot;couchbase.bootstrap.timeout&quot;: &quot;10s&quot;,<br>        &quot;couchbase.bucket&quot;: &quot;orders&quot;,<br>        &quot;couchbase.username&quot;: &quot;***&quot;,<br>        &quot;couchbase.password&quot;: &quot;****&quot;,<br>        &quot;key.converter&quot;: &quot;org.apache.kafka.connect.storage.StringConverter&quot;,<br>        &quot;couchbase.source.handler&quot;: &quot;com.couchbase.connect.kafka.handler.source.RawJsonSourceHandler&quot;,<br>        &quot;value.converter&quot;: &quot;org.apache.kafka.connect.converters.ByteArrayConverter&quot;,<br>        &quot;couchbase.event.filter&quot;: &quot;com.couchbase.connect.kafka.filter.AllPassFilter&quot;,<br>        &quot;couchbase.stream.from&quot;: &quot;SAVED_OFFSET_OR_BEGINNING&quot;,<br>        &quot;couchbase.compression&quot;: &quot;ENABLED&quot;,<br>        &quot;couchbase.flow.control.buffer&quot;: &quot;16m&quot;,<br>        &quot;couchbase.persistence.polling.interval&quot;: &quot;100ms&quot;<br>    }<br>}</pre><ul><li>Creating and Managing Connectors</li></ul><p>Connectors are created using HTTP Rest API. Kafka Connect recommends using HTTP REST API as best practice. Following curl commands show how you can manage connectors</p><ul><li>Create a connector</li></ul><pre>curl -X POST -H &quot;Content-Type: application/json&quot; - data @test-couchbase-source.json http://localhost:8083/connectors</pre><ul><li>Check status of connector</li></ul><pre>curl http://localhost:8083/connectors/test-couchbase-source/status</pre><ul><li>List all connectors</li></ul><pre>curl http://localhost:8083/connectors</pre><ul><li>Get config of connector</li></ul><pre>curl http://localhost:8083/connectors/test-couchbase-source/config</pre><ul><li>Delete connector</li></ul><pre>curl -X DELETE localhost:8083/connectors/test-couchbase-source</pre><h4><strong>Filter Documents</strong></h4><p>Many times, we’ll have a requirement to filter and send only a subset of events to the Kafka. In this case, we only want to create events to go to streaming-topic-create-order and update events to go to streaming-topic-update-order. In order to achieve this, write a custom <a href="https://github.com/couchbase/kafka-connect-couchbase/blob/master/examples/custom-extensions/src/main/java/com/couchbase/connect/kafka/example/CustomFilter.java">filter</a> that can read the contents of data streamed from Couchbase. Based upon the content decide whether we want to filter out the event. Build a jar out of it and plug it into the Couchbase lib folder. Couchbase Kafka Connector has a provision to use custom filter under the attribute name couchbase.event.filter</p><p>Following is an example that shows a filter class written for Couchbase Source Connector</p><pre>import com.couchbase.connect.kafka.filter.Filter;<br>import com.couchbase.connect.kafka.handler.source.DocumentEvent;<br>import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode;<br>import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.ObjectMapper;<br>import org.slf4j.Logger;<br>import org.slf4j.LoggerFactory;<br>import java.io.IOException;<br><br>public class ExampleFilter implements Filter {<br>private static final Logger LOGGER = LoggerFactory.getLogger(ExampleFilter.class);<br>private static final String VALUE = &quot;create&quot;;<br>private static final ObjectMapper MAPPER = new ObjectMapper();<br><br>@Override<br>public boolean pass(DocumentEvent document) {<br>    byte[] content = document.content();<br>    JsonNode doc = MAPPER.readTree(content);<br>    var value = doc.get(&quot;type&quot;);<br>    var shouldPass = value.asText().equals(VALUE);<br>    if (shouldPass) {<br>        return true;<br>    }<br>        return false;<br>    }<br>}</pre><p><strong>Partition key for Kafka event</strong></p><p>We can write events into Kafka topics and specify an attribute as a partition key. We can achieve that in Kafka connect as well. In order to achieve this use Simple Message Transforms(SMT) of Kafka Connect. Single Message Transformations (<a href="https://docs.confluent.io/platform/current/connect/transforms/overview.html">SMTs</a>) are applied to messages as they flow through Connect. SMTs transform inbound messages after a source connector has produced them, but before they are written to Kafka. SMTs transform outbound messages before they are sent to a sink connector.</p><p>There are several pre-defined transforms. Use <a href="https://docs.confluent.io/platform/current/connect/transforms/extractfield.html">ExtractField</a> to extract the key and use that to to set the message key. For example, consider the following Couchbase doc</p><pre>{<br>&quot;id&quot;: 3006,<br>&quot;type&quot;: &quot;create&quot;,<br>&quot;name&quot;: &quot;A dummy order&quot;<br>}</pre><p>To extract a field id from the message and set the value as key in the Kafka message, add the following configuration for Couchbase Source Connector</p><pre>&quot;transforms&quot;: &quot;deserializeJson,valueToKey,extractKey&quot;,<br>&quot;transforms.deserializeJson.type&quot;: &quot;com.couchbase.connect.kafka.transform.DeserializeJson&quot;,<br>&quot;transforms.valueToKey.type&quot;: &quot;org.apache.kafka.connect.transforms.ValueToKey&quot;,<br>&quot;transforms.valueToKey.fields&quot;: &quot;id&quot;,<br>&quot;transforms.extractKey.type&quot;: &quot;org.apache.kafka.connect.transforms.ExtractField$Key&quot;,<br>&quot;transforms.extractKey.field&quot;: &quot;id&quot;</pre><p></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8f57bc2f769" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reliable Messaging: A Guide to Transactional Outbox and Kafka Connect]]></title>
            <link>https://medium.com/@sharathk4u/reliable-messaging-a-guide-to-transactional-outbox-and-kafka-connect-9a7cbb3271db?source=rss-4adaef7a22c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a7cbb3271db</guid>
            <category><![CDATA[kafka-connect]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[sofware-engineering]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[SHARATH K]]></dc:creator>
            <pubDate>Sun, 02 Feb 2025 18:56:52 GMT</pubDate>
            <atom:updated>2025-02-02T19:06:50.732Z</atom:updated>
            <content:encoded><![CDATA[<p>Many distributed systems are now relying heavily on event driven architecture. In event driven architecture it is not uncommon to see a database write operation and a corresponding event intended for a downstream system for further processing or a data lake for analytics. However, maintaining consistency across the database and the messaging system is an interesting problem to solve.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*uvVRZwxfPDr82Fsxf2LnEA.png" /></figure><h3>Transaction Outbox Pattern</h3><p>Transaction outbox pattern is a pattern that can be used to solve the problem of reliably sending messages to another process when the message broker and the database are transactionally consistent. The transaction outbox pattern is a two-step process:</p><p>1. When a transactional change is made to the database, also insert a row into an outbox table that describes the event that must be sent because of the change.</p><p>2. Periodically scan the outbox table and send any outstanding messages to the message broker. Delete the message from the outbox table after it has been successfully sent.</p><h3><strong>Kafka Connect</strong></h3><p>Kafka Connect is a tool for reliably stream data between Apache Kafka and various other data systems. It has the fault tolerance and elastic design that we are familiar with Kafka. It allows us to define, what is called a connector to move data in and out of Kafka.</p><ol><li>Source connector : This allows us to collect data from a source system which can be application servers, database tables or other messaging systems.</li><li>Sink Connector : This delivers data to a downstream system which can be Elasticsearch, Hadoop or other database systems.</li></ol><p>Kafka Connect was introduced in Kafka 0.9. These connectors are maintained either by a community or confluent or its partners.</p><h4><strong>Kafka Connect Architecture</strong></h4><p>The three major components of Kafka Connect are Connectors, Workers and Tasks. Workers are instances that are responsible for running the tasks. Kafka Connect cluster will have multiple instances of workers running. Connectors can be a source or a sink and are responsible for handling a set of tasks. Tasks are the custom components that are responsible for getting data in and out of Kafka.</p><p>A high level architecture diagram is as below. We have two connectors — one for create flow and another for update flow. There are multiple tasks for each connector.</p><figure><img alt="Kafka Connect Architecture" src="https://cdn-images-1.medium.com/max/975/1*Qb2DZplFPrOi6FV-q3eqlQ.png" /></figure><h3>Connecting the dots…</h3><p>The second step in transaction outbox pattern can be achieved in multiple ways.</p><ul><li>One of the ways is to use a scheduler that runs periodically and checks for any outstanding messages in the outbox table and sends them to the downstream system.</li><li>Another way is to use a CDC(Change Data Capture) tool that can be used to capture the changes in the database and send them to the downstream system. This is where Kafka Connect fits into the equation. Kafka connect is supported by a wide range of databases as you can see <a href="https://docs.confluent.io/platform/current/connect/supported.html">here</a>. Depending upon where the outbox table is hosted, we can define our source connector to publish message to the Kafka topic in near real time. The specifics of the implementation can be found in Part 2 <a href="https://medium.com/@sharathk4u/reliable-messaging-implementation-of-transactional-outbox-and-kafka-connect-e8f57bc2f769">here</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a7cbb3271db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reactive Programming in Java — Introduction]]></title>
            <link>https://medium.com/@sharathk4u/reactive-programming-in-java-introduction-f146bfc6052f?source=rss-4adaef7a22c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f146bfc6052f</guid>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[introduction]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[SHARATH K]]></dc:creator>
            <pubDate>Sun, 17 May 2020 09:40:28 GMT</pubDate>
            <atom:updated>2020-05-17T09:40:28.165Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reactive Programming in Java — Introduction</h3><figure><img alt="Reactive libraries" src="https://cdn-images-1.medium.com/max/795/1*md8_jueLlx7XG-hSIrGHwA.jpeg" /></figure><p>Though I have been hearing about reactive programming for the last few years, I didn’t get to work on it until last year. When I initially started writing code the reactive way, a lot of things were unclear for me. When I searched the internet, there were a lot of interrelated things around the word <em>reactive</em> and it can be a bit confusing at times. So I thought of putting a few points out there that helped me so that anybody in the same situation will find this useful. First let us try understand the various terms around reactive programming that comes up when we try to read about them.</p><ul><li><strong>Reactive Programming</strong> : is another programming paradigm just like Procedural Programming or Object Oriented Programming. Reactive Programming is a declarative programming paradigm that deals with data stream and manipulation of data and was out there as early as 1970&#39;s.</li><li><strong>Reactive Manifesto</strong> : Talks about the guiding principles for Reactive Systems or Applications that meet the demands of the modern world(Read 2010&#39;s). The pillars of this manifesto are Responsive, Resilient, Elastic and Message Driven. This was first published in 2013. Reactive Programming doesn’t ensure Reactive Systems.</li><li><strong>Reactive Streams :</strong> With multiple projects like Project Reactor and RxJava coming up to serve the needs of high performant, scalable applications it was time to reach a common consensus. Reactive Streams was the answer to that. Reactive Stream is nothing but a specification or standard like JPA or JDBC. It provides a set of interfaces, methods and protocols that is needed to achieve the goal of reactive programming. This was released in 2015 and is also part of JDK9.</li><li><strong>RxJava :</strong> is a Java VM implementation of ReactiveX, a library for composing asynchronous and event-based programs by using observable sequences. The initial release was in 2014 and was the one of the first step in the adoption of reactive programming in Java. RxJava 2.x with support for Reactive Streams was released in 2016.</li><li><strong>Project Reactor :</strong> was another step in the direction of reactive programming that happened in Pivotal. The initial milestone version of project reactor was released as early as 2013. Reactor 2.x build on top of reactive streams was released in 2015.</li><li><strong>Spring :</strong> which is one of the most popular framework for java development announced it will start providing support for reactive streams from Spring 5 on wards. Spring 5 was subsequently released in 2017. Since Spring is also developed by Pivotal, the uptake of reactor was nothing surprising.</li></ul><h4>What is Reactive Programming</h4><p>Though reactive programming as a programming paradigm has been around for some time, the rising popularity of micro services architecture, the need for high amount of data to be processed and the advent of multi core processors pressed the need for a speedy adoption in Java. Java was not inherently reactive and over the years support for asynchronous requests (Servlet 3.0) and non-blocking I/O (Servlet 3.1) were added. An architectural change was necessary for it to be reactive. Thanks to RxJava and Project Reactor, the java community is now better prepared than ever to handle the situation.</p><p>In its simplest form, reactive programming means handling</p><ul><li><strong>Asynchronous </strong>communication helps in decoupling systems and making them more resilient.</li><li><strong>Stream of Data </strong>is unlike your normal data processing where you get a set of data and you play around with it. Instead it is a like a stream of water that flows, where in multiple streams merge to make a bigger stream, or split into multiple streams, get filtered for purity, blocked using dams to produce electricity and so on. But it never stops.</li><li><strong>With Non Blocking I/O </strong>which is nothing new and was introduced in J2SE1.2 and popularized by nodejs. In this we are moving away from the thread per connection approach. It simply means instead of tying a thread to a request and letting it hang there while waiting for the request on some side processing, use it for processing another request. This will help in increasing the scalability and responsive by using a smaller number of threads to handle a large number of requests.</li><li><strong>And Back-Pressure</strong> or flow control is an important aspect of reactive programming. When we have systems of varying capacity a fast upstream system can really choke a slow down stream systems and bring it down. In such scenarios it is very important to have a feedback mechanism that can tell the upstream system to slow down the stream of events. This will help the system in becoming more resilient.</li></ul><h4>Why Reactive Programming</h4><p>While the concept of reactive programming has been around for a long time, why is it gaining more popularity. Is it another fad that everyone is jumping into the bandwagon or does it actually matter?</p><ul><li><strong>More Data : </strong>Internet being more accessible through mobile phones, Iot that handles millions of devices etc has resulted in large amount of data that needs to be processed.</li><li><strong>More Users : </strong>Compared to 2000’s, now we have more users and scalability becomes all the more important. Moving away from the thread per request has helped in scaling up much more easily.</li><li><strong>Efficient Resource Utilization</strong> : With multi core processors being the norm, efficient utilization of all the cores becomes important.</li><li><strong>Microservices, Cloud and Containerization : </strong>has helped in making distributed applications movement grow stronger. Designing for failure, decoupling the applications and scaling them independently are the core traits of these movement which is nicely complemented by reactive programming.</li></ul><h4>When to use Reactive Programming</h4><p>Like anything new or shiny some of us have the tendency to use them in our projects irrespective of the need and later regretting that decision. So it is very important to know when and where using reactive programming makes the most sense.</p><ul><li><strong>Big Data :</strong> Projects where you have a large amount of data and playing around and manipulating data is more important.</li><li><strong>Stream of events :</strong> Projects where you have a live stream of events and need to respond to them where the amount of events are not predetermined.</li><li><strong>Microservices Composition :</strong> where in you have a web service, that calls a number of other services depending upon the scenarios and eventually compose an output from all of these is a nice fit with lot of IO happening.</li></ul><h4>Important points to consider</h4><ul><li>For a java developer, when first starting with reactive programming it can be a bit difficult to wrap your head around it. Because it requires a change in mindset and will require some time time to get comfortable with it. Don’t give up, you are not alone.</li><li>Reactive stream is supported from Java7 onwards, but its not particularly useful without the features introduced in Java8(where reactive stream is still available as a separate library). Reactive Stream is part of JDK from JDK9 onwards.</li><li>Before starting with reactive programming, it is important that you are very much comfortable with the features introduced in Java 8 like lambda expressions and functional interfaces like Function, Predicate, Consumer etc. Don’t start with reactive programming unless you are thorough in Java 8.</li><li>Once you start with reactive programming make sure that you don’t write blocking code (eg : future.get()), have exception bubbles (try..catch..finally) or synchronized blocks.</li><li>Reactive programming needs a reactive server like netty or undertow to run it the right way.</li><li>While you debug your reactive program, the flow can confuse you as it will go through the entire line code once for evaluation and only when the subscriber triggers the actual flow of execution will start.</li><li>If you are using MDC(to store trace id and other stuffs) for your logging, be prepared for a few surprises. MDC is per thread while in reactive programming there is no guarantee that a single thread will handle a request end to end. So we need to use MDC along with reactive context to handle this scenario.</li><li>As you become more comfortable in reactive programming libraries, there will be a tendency to overuse the libraries, with chaining and sub chaining. Remember, making spaghetti code is way more easier in reactive programming. So KISS(Keep It Simple and Stupid) is all the more important. Time to time review the code that you have written and think how you can simplify it further.</li></ul><p>I hope all of the above points will help a bit in understanding about the reactive programming terms in java and you are better placed to get started with programming in one of the reactive frameworks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f146bfc6052f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>