<?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 Vibhor Pareek on Medium]]></title>
        <description><![CDATA[Stories by Vibhor Pareek on Medium]]></description>
        <link>https://medium.com/@vibskant?source=rss-81063df4ba27------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9JkMjN6rLdeJo7BB.jpg</url>
            <title>Stories by Vibhor Pareek on Medium</title>
            <link>https://medium.com/@vibskant?source=rss-81063df4ba27------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 11:03:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vibskant/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[Composite Pattern Java]]></title>
            <link>https://medium.com/javarevisited/composite-pattern-java-93dc840def6c?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/93dc840def6c</guid>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[design-pattern-in-java]]></category>
            <category><![CDATA[composite-pattern]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Mon, 02 Sep 2024 12:16:23 GMT</pubDate>
            <atom:updated>2024-09-03T15:40:46.426Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Composite pattern is a structural design pattern aims at defining the structure of group of objects in a hierarchy. The pattern can be applied where you see a group of object sharing a tree like pattern or relationship between them like file-&gt;directories, employee in department which can further drill deep down and have child departments, mostly nodes in a tree structure.</p><p>The pattern is extensively used where :</p><ul><li>Application need to aggregate data across the tree structure.</li><li>Client treats each object in an hierarchy uniformly.</li><li>Keep client contract simple &amp; promotes uniformity.</li></ul><p><strong>Terminologies</strong></p><ul><li><em>Component</em> : Interface for objects in the composition.</li><li><em>Leaf : </em>Leaf object in composition with no children. Defines behavior via implementing component interface.</li><li><em>Composite : </em>Object containing child component. Defining relation between components and defines behavior for components having children.</li></ul><p>In this article, we will dig deep into an example possibly a problem of LLD design and solve it via composite pattern.</p><h3>Problem</h3><p>Lets say you need a design a music player where you can add songs to a playlist &amp; play . To demonstrate the application of composite pattern, I am keeping a playlist and multiple songs added as part of LLD design.</p><p><strong>Implementation</strong></p><ol><li>Defining a base component interface as below.</li></ol><pre>public interface Playable {<br>     void play();<br>}</pre><p>2. Defining Leaf component which is song object in our case. Leaf object also defines a behavior which is play [Song to be played.]</p><pre>public class Song implements Playable{<br><br>    private final String title;<br>    private final String artist;<br>    private final String album;<br><br>    public Song(String title,String artist,String album) {<br>        this.title = title;<br>        this.artist = artist;<br>        this.album = album;<br>    }<br><br>    @Override<br>    public void play() {<br>        System.out.println(&quot;Playing song! : &quot; + title + &quot; &quot; + artist + &quot; &quot; + album);<br>    }<br>}</pre><p>3. Defining composite object which is playlist in our case &amp; containing songs to be played by the playlist. Below code has list of songs contained by composite object Playlist.</p><pre>public class Playlist implements Playable{<br><br>    private final String name;<br>    private final List&lt;Playable&gt; songList;<br><br>    public Playlist(String name) {<br>        this.name = name;<br>        this.songList = new ArrayList&lt;&gt;();<br>    }<br><br>    @Override<br>    public void play() {<br>        System.out.println(&quot;Playing the playlist : &quot; + name);<br>        songList.forEach(Playable::play);<br>    }<br><br>    public void add(Playable song) {<br>        //Adding to the playlist<br>        this.songList.add(song);<br>        System.out.println(&quot;Added to the playlist -&gt;&quot; + name);<br>    }<br><br>    public void remove(Playable song) {<br>        this.songList.remove(song);<br>    }<br><br>}</pre><p>4. Reaching here, we are almost done. Now we need to see the invoker in action as below.</p><pre>public class Invoker {<br>    public static void main(String [] args) {<br><br><br>        Playable song1 = new Song(&quot;Song-A&quot;,&quot;Artist-A&quot;,&quot;Album-A&quot;);<br>        Playable song2 = new Song(&quot;Song-B&quot;,&quot;Artist-B&quot;,&quot;Album-B&quot;);<br>        Playable song3 = new Song(&quot;Song-C&quot;,&quot;Artist-C&quot;,&quot;Album-C&quot;);<br><br>        Playlist playlist = new Playlist(&quot;Vibhor&#39;s Playlist&quot;);<br>        playlist.add(song1);<br>        playlist.add(song2);<br>        playlist.add(song3);<br><br>        playlist.play();<br><br>    }<br>}<br><br>//Playing the playlist : Vibhor&#39;s Playlist<br>//Playing song! : Song-A Artist-A Album-A<br>// Playing song! : Song-B Artist-B Album-B<br>//Playing song! : Song-C Artist-C Album-C</pre><p>4. Keeping it till here only, you can also add/extend Music Player class and invoke playlist in the class. Hope you got the the detailed explanation about composite pattern.</p><h3>Conclusion</h3><ol><li>The composite pattern structures the hierarchy consisting of individual and composite objects &amp; can handle complex hierarchy as well.</li><li>Clients treats basic and composite objects uniformly through a component interface which makes client code simple.</li><li>Adding new components is easy and client can focus on aggregated functionality provided by composite object. This also promotes loose coupling in code &amp; adheres to ‘O’ in SOLID principles.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93dc840def6c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/composite-pattern-java-93dc840def6c">Composite Pattern Java</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[Iterator Design Pattern Java]]></title>
            <link>https://medium.com/javarevisited/iterator-design-pattern-java-f0d5a33e3262?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0d5a33e3262</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[design-pattern-in-java]]></category>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[iterator-pattern]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Sat, 22 Jun 2024 09:33:34 GMT</pubDate>
            <atom:updated>2024-08-30T15:28:05.113Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>The iterator design pattern is a behavioral design pattern in GOF patterns. Whenever you want to iterate over a collection or group of objects, you will always think of <em>iterator pattern [Traverse in a defined manner]. </em>It hides the necessary implementation from client and just iterates over it reducing complexity on client side.</p><p>The idea is to take the responsibility for access and traversal out of the actual[aggregator] object and give it to iterator object defining a custom traversal [logic in any direction/ forward/backward or any custom logic]<br>It satisfies Open Closed Principle &amp; helps to provide decoupling of classes.<br>You will find actual implementation in java.util package for List iterators/ Map iterators to quantify the above arguments.<br>Enough of the talking lets look at the Code in depth.</p><h3>Problem</h3><p>Lets take a simple traversal for a library, where in you will traverse a list of books present in the library. I am keeping the class simple, you can have any custom logic based on shelf where book is placed or keep shelves array as input &amp; define your logic.</p><h3>Implementation</h3><ol><li><strong><em>Iterator Interface</em></strong></li></ol><p>The interface defines key operations which will be implemented by concrete iterators.</p><pre>public interface Iterator {<br><br>boolean hasNext(); // Do you have a next element to traverse ?<br>Object next(); // Give me the element ?<br><br>}</pre><p>2. <strong><em>Concrete Iterator</em></strong></p><p>Concrete implementation of the above interface.<br>It takes a List&lt;Book&gt; as an argument in constructor and defines the actual traversal logic</p><pre>import java.util.List;<br><br>public class BookIterator implements Iterator{<br><br>    private final List&lt;Book&gt; bookList;<br><br>    private int position;<br><br>    public BookIterator(List&lt;Book&gt; bookList) {<br>        this.bookList = bookList;<br>        position = 0;<br>    }<br><br><br>    @Override<br>    public boolean hasNext() {<br>        return position &lt; bookList.size();<br>    }<br><br>    @Override<br>    public Object next() {<br>        Book book =  bookList.get(position);<br>        position++;<br>        return book;<br>    }<br>}</pre><p>3. <strong><em>Aggregator Interface</em></strong></p><p>Interface defining the iterator we want to use for the traversal logic and in the actual concrete aggregator class, we will return the exact concrete implementation of iterator which is our <em>BookIterator.</em></p><pre>public interface Aggregate {<br><br>    Iterator getIterator();<br><br>}</pre><p><strong><em>4. Concrete Aggregator Class</em></strong></p><pre>public class ConcreteAggregator implements Aggregate{<br><br>    public List&lt;Book&gt; bookList;<br><br>    public ConcreteAggregator(List&lt;Book&gt; bookList) {<br>        this.bookList = bookList;<br>    }<br><br>    @Override<br>    public Iterator getIterator() {<br>        return new BookIterator(bookList);<br>    }<br>}</pre><p><strong><em>5. Client Class</em></strong></p><p>Lets look at how client class makes a call to Concrete Aggregator and does not bother about traversal logic but in turn gives responsibility to iterator to traverse.</p><pre>public class Client {<br><br>    public static void main(String[] args) {<br>        Book book1 = Book.builder().bookName(&quot;Book1&quot;).bookType(&quot;SCIFI&quot;).bookId(&quot;1&quot;).build();<br>        Book book2 = Book.builder().bookName(&quot;Book2&quot;).bookType(&quot;HORROR&quot;).bookId(&quot;2&quot;).build();<br>        Book book3 = Book.builder().bookName(&quot;Book3&quot;).bookType(&quot;FICTION&quot;).bookId(&quot;3&quot;).build();<br>        Book book4 = Book.builder().bookName(&quot;Book4&quot;).bookType(&quot;PSYCHOLOGY&quot;).bookId(&quot;4&quot;).build();<br><br>        //create a list;<br>        List&lt;Book&gt; bookList = new ArrayList&lt;&gt;();<br>        bookList.add(book1);<br>        bookList.add(book2);<br>        bookList.add(book3);<br>        bookList.add(book4);<br><br><br>        Aggregate aggregate = new ConcreteAggregator(bookList);<br><br>        // Get Book Iterator via polymorphism<br>        Iterator iterator = aggregate.getIterator();<br><br>        while(iterator.hasNext()) {<br>            System.out.println( &quot;Getting book : &quot; + iterator.next().toString());<br>        }<br><br><br>    }<br>}<br><br>// Output :<br><br>// Getting book : Book(bookId=1, bookName=Book1, bookType=SCIFI)<br>// Getting book : Book(bookId=2, bookName=Book2, bookType=HORROR)<br>// Getting book : Book(bookId=3, bookName=Book3, bookType=FICTION)<br>// Getting book : Book(bookId=4, bookName=Book4, bookType=PSYCHOLOGY)</pre><h3>Conclusion</h3><ul><li><strong>Decoupling</strong> <strong>&amp; Code Reusability</strong>: We have decoupled classes with iterator and aggregator here. You can have multiple implementation and attach different iterators to aggregate object.</li><li><strong>Abstraction </strong>: The iterator pattern hides the underlying data structure of a collection.</li><li><strong>Good Control</strong>: The iterator pattern lets you control the iteration process. For instance, you can choose to skip certain elements in a collection, something that’s hard to do with standard loops.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0d5a33e3262" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/iterator-design-pattern-java-f0d5a33e3262">Iterator Design Pattern Java</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[Service Locator Factory Pattern]]></title>
            <link>https://medium.com/javarevisited/service-locator-factory-pattern-7bb9e835b709?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bb9e835b709</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[service-locator-pattern]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Tue, 10 Jan 2023 05:11:12 GMT</pubDate>
            <atom:updated>2024-08-31T15:22:08.928Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Service Locator Factory pattern helps you to locate services at runtime based on certain criteria. In this article, I will be mainly focusing on spring provided service locator pattern &amp; its implementation. There are many ways to implement service locator pattern but spring service locator pattern helps you to avoid boiler plate code &amp; implement it efficiently &amp; quickly.</p><p>From Martin Fowler’s article talking about locator pattern : <br><em> “The basic idea behind a service locator is to have an object that knows how to get hold of all of the services that an application might need. So a service locator for this application would have a method that returns a ‘service’ when one is needed.”</em></p><h3>Problem Statement</h3><p>Let’s take a simple example of a payment system where you have different payment processors like Visa/Amex/MasterCard. These payment processors have different methods to pay. We need to build a controller that calls the appropriate method based on type provided by client. Let’s try to understand &amp; build a very basic code structure around it. Before that, we will take a look at the components involved in locator pattern.</p><blockquote>Components</blockquote><ul><li><strong>Client:</strong> Consumer that requires the service at runtime.</li><li><strong>Service Locator:</strong> Service locator is responsible for returning the service on-demand to the client. It abstracts the lookup or creation of the service.</li><li><strong>Initial Context:</strong> It creates, registers and caches the service. This is the starting point of the lookup and creation.</li><li><strong>Service Factory:</strong> The service factory provides lifecycle management for the service with support to create, lookup, or remove a service.</li><li><strong>Service:</strong> Concrete implementation of the service desired by the client.</li></ul><h3>Implementation</h3><ol><li>Let’s start with building the generic interface for our payment processor as below :</li></ol><pre>public interface PaymentProcessor {<br>    public void pay();<br>}</pre><p>2. Concrete implementation of interface PaymentProcessor with Visa. In the below class, we have specified the name as “Visa” for the component.</p><pre>@Slf4j<br>@Component(&quot;Visa&quot;)<br>public class VisaPaymentProcessor implements PaymentProcessor{<br><br><br><br>    @Override<br>    public void pay() {<br>        log.info(&quot;Paying through Visa Network!&quot;);<br>    }<br>}</pre><p>3. Concrete implementation of interface PaymentProcessor with Amex. In the below class, we have specified the name as “Amex” for the component.</p><pre>@Slf4j<br>@Component(&quot;Amex&quot;)<br>public class AmexPaymentProcessor implements PaymentProcessor{<br><br><br>    @Override<br>    public void pay() {<br>            log.info(&quot;Paying through Amex Network!&quot;);<br>    }<br>}</pre><p>4. Now let’s write service locator interface. It has a method which takes a type as input param &amp; returns a PaymentProcessor type as below :</p><pre>public interface PaymentRegistry {<br><br>    public PaymentProcessor findProcessor(String type);<br><br>}</pre><p>5. Using the above service locator interface, I will now add it to the spring factory bean config to use this as service locator interface.</p><pre>@Configuration<br>public class ServiceLocatorConfig {<br><br> @Bean(&quot;paymentRegistry&quot;)<br> public FactoryBean&lt;?&gt; getBean() {<br>  ServiceLocatorFactoryBean bean = new ServiceLocatorFactoryBean();<br>  bean.setServiceLocatorInterface(PaymentRegistry.class);<br>  return bean;<br> }<br><br>}</pre><p>6. Sample controller to test our changes</p><pre>@RestController<br>@RequestMapping(&quot;/payment-service&quot;)<br>@Slf4j<br>public class TestController {<br><br>    @Autowired<br>    private PaymentRegistry paymentRegistry;<br><br><br>  @GetMapping(&quot;/v1/pay&quot;)<br>  public void payViaProcessor(@RequestParam String type) {<br>      log.info(&quot;Paying thru type : {} &quot;, type );<br>       paymentRegistry.findProcessor(type).pay();<br>  }<br>}</pre><h4>Output</h4><pre>http://localhost:8080/payment-service/v1/pay?type=Visa</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkU9vpu9hXczz0qP5F3BPQ.png" /><figcaption>Image Visa Type</figcaption></figure><pre>http://localhost:8080/payment-service/v1/pay?type=Amex</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTYDNQjdo3LMOI1bAViD0A.png" /><figcaption>Image Amex Type</figcaption></figure><h3>Take Aways</h3><ul><li>The pattern helps you to remove tight coupling making it complaint to Open Closed Principle.</li><li>Removal of boiler plate code to build caches &amp; factory of services since spring takes care of it for you :)</li></ul><p>Happy Learning! ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bb9e835b709" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/service-locator-factory-pattern-7bb9e835b709">Service Locator Factory Pattern</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[Strategy Design Pattern (Java)]]></title>
            <link>https://vibskant.medium.com/strategy-design-pattern-java-391e4b87831a?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/391e4b87831a</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[strategy-pattern]]></category>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Wed, 13 Apr 2022 11:58:21 GMT</pubDate>
            <atom:updated>2022-04-13T11:58:21.697Z</atom:updated>
            <content:encoded><![CDATA[<p>Behavioural Design Pattern in Java</p><p><strong>Introduction</strong></p><p>Strategy pattern is a behavioural design pattern which helps you to decide on choosing type of algorithm from a set of algorithms during runtime. Java Collections.sort() method uses strategy pattern to determine what type of comparator to be passed during runtime and acts accordingly. Hope this has given little bit of insight on strategy pattern.</p><p><strong>Where can we apply Strategy Pattern</strong></p><p>This is one of the most asked questions in an interview to a senior developer/tech lead/architect while doing a low level design problem. Answer is pretty straightforward, you have a set of predefined algorithms to choose which can be encapsulated in a new class/implementation, allowing the caller/client to decide on what algorithm to use at runtime.</p><p><strong>Code</strong> <strong>Walkthrough</strong></p><p>Let’s take a simple example of sorting numbers with different strategies. We are now creating an interface defining sort function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2Ig4AtUH_iM_WBvY.png" /></figure><p>Interface defining Strategy</p><p>Let’s try to implement concrete classes defining different strategies:</p><ol><li>Merge Sort Strategy</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MYBq6ZJ9cH5k-ShE.png" /><figcaption>Concrete Class 1</figcaption></figure><p>2. Quick Sort Strategy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k7HdVFCVQcTGuUqS.png" /><figcaption>Concrete Class 2</figcaption></figure><p>Ah! pretty simple, now how do client call and decide runtime behaviour for the class ? Let’s create a context class and set the context determining your implementation as follows :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lNjdVpJlqqVPnoYW.png" /><figcaption>Context Class</figcaption></figure><p>We have now reached the end of implementation, let’s try calling it and see :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ehCP37nL_PA0s4o7.png" /><figcaption>Client Class</figcaption></figure><p>Hope you have understood the usage of Strategy Pattern :) Keep Learning !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=391e4b87831a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Distributed Load Testing at Scale]]></title>
            <link>https://vibskant.medium.com/distributed-load-testing-at-scale-2a3f70d257d1?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a3f70d257d1</guid>
            <category><![CDATA[jmeter]]></category>
            <category><![CDATA[load-testing]]></category>
            <category><![CDATA[distributed-load-testing]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Mon, 18 Oct 2021 04:39:22 GMT</pubDate>
            <atom:updated>2021-10-18T16:29:07.866Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Introduction</strong></h4><p>Load testing is an important part of non functional testing activity to determine the system bottleneck in terms of variety of factors like cpu, memory, network bandwidth, read/write latencies, response times &amp; plethora of other metrics. This not only helps you to make your system deal with large number of concurrent users but also help you to determine the how much resources your current infra supports and autoscaling policies in case of intermittent spikes. As you add more and more virtual users/threads into the system, you need to have more load generators and don&#39;t want to choke load generators for resources.</p><h4>Problem Statement</h4><p>If you quickly want to load test your backend systems , you would probably spin up jmeter or bring up gatling container and start testing with your scripts. This is okay for any small system or even a fairly large systems but the problem arrives when you want to load test with a million users and need to horizontally scale your load generators. Here&#39;s what at …, we are trying to solve :</p><p>- <em>Provide a infrastructure or tooling to carry out load tests without worrying about scale of virtual users.<br>- Realtime Visualisation of the tests triggered.<br>- Running any number of load tests concurrently.<br>- Summary &amp; Detailed Reporting at the end of tests.<br>- CI-CD gating with performance tests.<br>- Inbuilt Profiler to profile your pods on k8s.<br>- Cloud Native/ VM &amp; BYOVM for load generation.<br>- Load Tool agnostic solution : Teams at … uses different tools &amp; scripts.<br>- We at …. , have built a tool to solve the above challenges and are. continuously improving it to adhere to the changing tech trends.</em></p><h4>Architecture Diagram</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LfpYEMHSo64LkJ6ir9OeCw.png" /><figcaption>Architecture Diagram</figcaption></figure><p>At … , our system for load tool consists of the below components :</p><ul><li><strong>User Interface</strong>, we provide teams to trigger their tests via UI which asks information from user in terms of git url for the load scripts &amp; few other configurations.</li><li><strong>Scripts &amp; Config Files</strong>, Users are asked to build out global &amp; tool agnostic json file where in he/she can provide all the load related configs like duration of tests/api endpoints/ramp ups/virtual users. We have a strict schema &amp; has to be followed by the users.</li><li><strong>Validator Component/Service</strong>, This component takes care of validation of user scripts and configs which helps us to verify scripts &amp; configuration for any schema or data validation. This is an entry point to our backend system which is triggered via UI.</li><li><strong>Worker</strong>, This is our main component which is responsible for triggering load test runs, determining the number of executors as well as creation of executors on different load gen clusters. For each test triggered we instantiate a worker until the test is completed.</li><li><strong>Executors</strong>, are baked in containers of load tools like jmeter/gatling or any other load tools and are responsible to run load tests, send data points to time series database for aggregation at the end of the test.</li><li><strong>Reporting Service</strong>, is responsible to aggregate data points across executors and build final report which is sent to user via slack &amp; email configured. Executors push data points to kairos database and final reports are pushed to a no sql database.</li><li><strong>Visualisation</strong>, We also provide live reporting for each test triggered via our UI with an embedded Grafana, where user can come and see the progress of the test triggered.</li><li><strong>Metadata Service</strong>, We also keep test runs for different teams/projects onboarded to our load tool.</li><li><strong>CI-CD Integration</strong>, We also provide custom plugin of the tool to be integrated to our in house ci-cd platform and can be used to gate deployments based on user defined parameters.</li><li><strong>Pod Profiler</strong>, is responsible for providing pod suggestions during daily &amp; holiday peak to the application teams.</li><li><strong>Kafka Integration Jars</strong>, we also provide ways to load test kafka producers &amp; samplers using our custom jars which can be included as part of configs while doing a kafka load test.</li><li><strong>Helper Service</strong> [Job Service] provides support of creating executors &amp; workers at runtime across different clusters in k8s.</li></ul><h4>Tool Usage &amp; Statistics</h4><p><em>At …, application teams are constantly doing load tests of the backend systems and the tool is used by more than 1000+ teams.<br>~ runs on our load tool during holiday period spanned over a month.<br>~ new projects were onboarded.</em></p><h4>Road Ahead</h4><ul><li>Working towards enabling new load tools like locust as of now we support jmeter &amp; gatling.</li><li>Making reporting &amp; analysis more intelligent using machine learning &amp; data science.</li><li>Addition of JVM profiling as part of tool to provide one stop solution for all.</li><li>Constantly working on improvements towards providing users with low latency &amp; high throughput scalable load tool.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a3f70d257d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Cloud Stream — Functional Programming!]]></title>
            <link>https://vibskant.medium.com/spring-cloud-stream-functional-programming-19c398e435ac?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/19c398e435ac</guid>
            <category><![CDATA[event-based-architecture]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-cloud-stream]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Mon, 27 Sep 2021 07:12:20 GMT</pubDate>
            <atom:updated>2021-09-27T07:38:15.920Z</atom:updated>
            <content:encoded><![CDATA[<h3>Spring Cloud Stream — Functional Programming!</h3><h4>Spring cloud stream with functional programming.</h4><h3>Introduction</h3><p>This story talks about using spring cloud stream and building binder agnostic event application using spring boot with functional programming. You might have used annotations while using spring cloud to define bindings channels[INPUT/OUTPUT], stream listeners which is now deprecated, I will not go into details of that but will mainly focus on building application with Functional Style. We will be using kafka as broker to publish messages &amp; subscribe to those messages.</p><h4>Functional Programming Style</h4><ul><li>Producing value to a binder with functional programming - we use <strong>suppliers</strong> to provide value and the spring cloud framework binds these function names to produce messages to the broker[for our case i.e kafka]</li><li>Processor uses <strong>Function&lt;T,R&gt;</strong> to take messages produced and processes it to another topic.</li><li>Consumer i.e <strong>Consumers </strong>take those messages and perform actions required.</li></ul><h4>Deep Dive into Code</h4><ul><li>Our supplier is as follows :</li></ul><pre>@Bean<br>public Supplier&lt;Flux&lt;Integer&gt;&gt; randomProducer() {<br>    return ()-&gt;Flux.<em>interval</em>(Duration.<em>ofSeconds</em>(5)).map(value-&gt;random.nextInt(500 - 1) + 1).log();<br>}</pre><p>Above supplier produces random values every 5 secs between 0 to 500.</p><ul><li>We will also use a processor to basically process messages via Function&lt;T,R&gt; as shown below :</li></ul><pre>@Bean<br>public Function&lt;Flux&lt;Integer&gt;,Flux&lt;Integer&gt;&gt; evenProcessor() {<br>    return integerFlux -&gt; integerFlux.map(this::getEvenNumber).log();<br>}</pre><p>Above function takes the produced message and checks if it is a even number take it else returns 0. Sample implementation for the even check :</p><pre>private int getEvenNumber(int i){<br><br>    if(i%2 == 0)<br>        return i;<br><br>    else<br>        return 0;<br><br>}</pre><ul><li>Finally our consumer which is a plain consumer prints the values to console as follows :</li></ul><pre>@Bean<br>public Consumer&lt;Flux&lt;Integer&gt;&gt; numberConsumer() {<br>    return System.<em>out</em>::println;<br>}</pre><p>If you want to look at the whole code, click on the <a href="https://github.com/vibskant007/spring-cloud-stream"><strong>github link</strong></a></p><h4>Configuration</h4><ul><li>Application yml contains configs defined as function names along with in &amp; out bindings [in being reading from &amp; out being produced to ]</li><li>It also contains destinations to read &amp; produce messages to topic names.</li><li>And last but not the least specifying binder details which in our case is kafka.</li></ul><pre>server:<br>  port: 9002<br><br><br>spring:<br>  cloud:<br>    stream:<br>      function:<br>        definition: randomProducer;evenProcessor;numberConsumer<br><br>      bindings:<br>        randomProducer-out-0:<br>          destination: numbers<br>        evenProcessor-in-0:<br>          destination: numbers<br>        evenProcessor-out-0:<br>          destination: even<br>        numberConsumer-in-0:<br>          destination: even<br>      kafka:<br>        binder:<br>          brokers: localhost:9092<br>          auto-create-topics: true</pre><h4>Final Words</h4><p>Spring cloud stream provide an easy way to integrate and build event based applications which helps you to focus only on business requirements.</p><p>Functional programming with cloud streams keeps our life very simple and just focus on writing and integrating via configs unlike remembering &amp; searching for annotations :)</p><p>Keep Writing &amp; reading ! Thank you :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19c398e435ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Template Pattern- Deep Dive(Java)]]></title>
            <link>https://vibskant.medium.com/template-pattern-deep-dive-java-164249d3090b?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/164249d3090b</guid>
            <category><![CDATA[template-patterns]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Fri, 02 Jul 2021 09:09:25 GMT</pubDate>
            <atom:updated>2021-07-02T09:09:25.669Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>Template pattern is another behavioral design pattern which helps you to define a skeleton of steps to be performed for an algorithm. This pattern is mostly used where you see same steps being repeated and where template pattern comes to rescue to help you define loose coupling &amp; single responsibility across your classes.</p><p><strong>Problem Statement</strong></p><p>Let’s take a simple use case where in you want to achieve below steps.</p><ul><li>Extract data from databases/files/cloud storages.</li><li>Parse data according to your defined strategy.</li><li>Generate report from the parsed data.</li><li>Store reports again back to some data store.</li></ul><p>As you can see above steps can be duplicated if we are trying to extract data from files/databases or any cloud storage.</p><p>If we follow template pattern, we will be able to structure our codebase and achieve loose coupling &amp; srp, irrespective of any new storage which can get added in future.</p><p><strong>Deep Dive</strong></p><ul><li>Let’s try to define template for our steps which will involve an abstract class as shown below containing abstract steps which needs to implemented by concrete classes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t45eolAnS4Xm0W1CvFINuQ.png" /><figcaption>Template Abstract Class</figcaption></figure><ul><li>Now building concrete classes would be piece of cake now . Here is our Database class which implements above methods as below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x9PQEnhVT78EzGMohkZ0WQ.png" /><figcaption>Concrete Class-1</figcaption></figure><p>Similarly, another class for file report generator is as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ts8xtzGJYqeLiyuiKR6yMg.png" /><figcaption>Concrete Class-2</figcaption></figure><p>We are done now and looking at the below client call seems so simple and classy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ilRY4KG5MoPrgN67nz1ZYw.png" /><figcaption>Client Class</figcaption></figure><p><strong>Take-Aways</strong></p><ol><li>Your template method should be final so that implementing class can’t override and change the order of steps.</li><li>You should mark all methods abstract which derived classes must implement.</li></ol><p>Next time, while building a feature just think about steps being duplicated in your code and certain task is achieved via sequential steps. BOOM apply template and thank the creator later :) Happy Coding !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=164249d3090b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Command Design Pattern (Java)]]></title>
            <link>https://vibskant.medium.com/command-design-pattern-java-d91b82d270c7?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/d91b82d270c7</guid>
            <category><![CDATA[command-pattern]]></category>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Sat, 20 Feb 2021 09:17:07 GMT</pubDate>
            <atom:updated>2021-02-20T12:47:57.536Z</atom:updated>
            <content:encoded><![CDATA[<h3>Implementing Command Design Pattern (Java)</h3><p>Behavioural Design Pattern</p><p><strong>Introduction</strong></p><p>Command design pattern another category of behavioural design pattern is used to abstract actions as commands. The command pattern helps you to build concrete command classes over an interface, separating actions or commands incorporated into your receiver . Let’s look at details of terminologies used in the pattern and design classes.</p><p><strong>Terminologies</strong></p><p><em>Receiver</em> : This is actual implementation of commands and receiver is responsible to execute the command.</p><p><em>Command Interface</em> : Interface declaring and abstracting the operation.</p><p><em>Concrete Command Classes</em> : Implementing above interface and have reference to receiver to execute the operation.</p><p><em>Invoker</em> : Takes command object to execute the operation.</p><p><strong>Code Walkthrough</strong></p><p>Let’s consider a simple example of invoking rest service, which has different methods implemented like GET/PUT/POST/PATCH &amp; DELETE. Considering these methods as commands , how do I write my classes ?</p><p>Firstly, I will build my receiver class which has actual implementation of commands in our case i.e GET &amp; POST</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KWSQjQVrT-KA8PH2qMlIIQ.png" /><figcaption>Receiver Class</figcaption></figure><p>OK! Now I have receiver class implemented. Let’s try to create an interface defining the operation which will have an execute method to be implemented by concrete command classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zzT_iGT9BX4bdVTOvN-KYg.png" /><figcaption>Command Interface</figcaption></figure><p>Concrete GET Command Class :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5rFQOVLISITSJQQW-qqjCA.png" /><figcaption>Concrete Command Class-1</figcaption></figure><p>Concrete POST Command Class :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rR1QINugqi_nKa0AF176vg.png" /><figcaption>Concrete Command Class-2</figcaption></figure><p>In each of the above command classes, I am passing a reference of receiver for executing the command/action or business logic.</p><p>Lastly, Invoker class which will just set command at runtime taking command interface as a reference :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zAmEBjH4aEcUjIs7gBe_7g.png" /><figcaption>Invoker Class</figcaption></figure><p>All done! Let’s see them in action from a client class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OMQFIskn-mLi1Svk8j1g7Q.png" /><figcaption>Client Class</figcaption></figure><p><strong>Take Aways &amp; Advantages</strong></p><ul><li>This way you can also implement other methods like PUT/PATCH and call them at runtime with just setting the command object.</li><li>Makes our code scalable, easy to understand as well as loose coupled which is open to extension and closed for modification :)</li></ul><p>Hope you have enjoyed reading the article! Keep learning :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d91b82d270c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Load Testing Design & Implementation[Part -1]]]></title>
            <link>https://vibskant.medium.com/load-testing-design-implementation-part-1-fb5954d5a858?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb5954d5a858</guid>
            <category><![CDATA[gatling]]></category>
            <category><![CDATA[performance-engineering]]></category>
            <category><![CDATA[jmeter]]></category>
            <category><![CDATA[load-testing]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Wed, 17 Feb 2021 08:10:35 GMT</pubDate>
            <atom:updated>2021-02-21T09:07:51.726Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>In this era of build and deliver fast, load testing has become an important part of software engineering and often as one of the key component in performance engineering. Mostly as a developer, we tend to think more on functionality and correctness of code and overlook the performance aspects. This leads to increased issues either in QA/Stage or Prod environments.</p><p>So, how should load testing be included ? Should it be a part of CI-CD process or carried out on performance env (an exact replica of production env)? Answer is both. You should have both as part of your delivery process and carry out activity on a performance env.</p><p><strong>Why Load Testing?</strong></p><p>We often see slowness in our application/service or website as we see a sudden spike of users in our system. Why is that? Have you looked at the resource usages at your instance/system level and tried to figure out the root cause? If you look closely, you will see some erratic behaviour either at cpu usage, memory consumption, database call latencies etc. Here are some of the important stats needs to be looked from an application standpoint :</p><ol><li>Response time which includes your client side as well as server latencies(average/90th percentile/95th percentile/99th percentile)</li><li>Throughput of your system measured in terms of amount of work done per unit time i.e TPS/RPS.</li><li>Success &amp; Error percentage.</li><li>CPU &amp; Memory usage during the test.</li><li>Network usage.</li></ol><p>There are other things as well to be looked for number of database connections &amp; datastore latencies during the read and write operations. So, it’s important to measure &amp; monitor all of the above resources and their latency fluctuation over time. Load testing helps you to achieve and mimic exact load of users and prepare for the scale required!</p><p><strong>How to do Load Test &amp; Which tool to use?</strong></p><p>There are many tools in the market and often people get confused which one to use, here is a distinction among tools for performance in market based on varying criteria’s :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XjPzweRsFFyGHMkFF_SMxQ.png" /><figcaption>Image from Internet</figcaption></figure><p>It totally depends on which language you are comfortable in and protocols you are looking to test out. <strong>JMeter</strong> is the winner in terms of wider community reach with plethora of plugins available and acceptance of tool over the geography but I personally like <strong>Gatling</strong> as it provides you control over script creation, vast DSL support in scala and readable report in html format. Overall Gatling is lighter in terms of resource utilisation and lighter as compared to threads in JMeter. Here’s the detail on the gatling site for more info.</p><p><strong>Gatling’s architecture is asynchronous as long as the underlying protocol, such as HTTP, can be implemented in a non blocking way. This kind of architecture lets us implement virtual users as messages instead of dedicated threads, making them very resource cheap.</strong></p><p><strong>Script creation</strong> is one of the major part of performance testing but what most people make mistake is in understanding user behaviours. Ideal way is to understand user journeys for your application i.e create paths for user journeys and separate them based on functionality. One such example would be in an e-commerce application:</p><ol><li>Few users would be logging in and viewing a product/product details/pricing.</li><li>Few users login-&gt;buy product-&gt;cart -&gt;checkout-&gt;payment</li><li>Few users signup-&gt;login-&gt;view pages</li></ol><p>.</p><p>.</p><p>n.</p><p>Similar to that there might be n paths you want to have virtual users in your system and do read/write/update operations during the whole load period. It is also important to have a previous year stats for one of the peak event while understanding user journeys and add a 5–10% increase of users while creating test plan for load. I will not go into details of writing load scripts as it varies based on tool &amp; terminologies pertaining to the tool used.</p><p><strong>Distributed Load Testing </strong>As you add more and more virtual users/threads into the system, you need to have more load generators and don’t want to choke load generators for resources. Let’s try to build &amp; design a distributed Load testing tool and understand the benefits and challenges in the next section! COMING SOON …</p><p>Happy Learning :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb5954d5a858" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Strategy Design Pattern (Java)]]></title>
            <link>https://vibskant.medium.com/strategy-design-pattern-java-6ee2f7f4c297?source=rss-81063df4ba27------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ee2f7f4c297</guid>
            <category><![CDATA[strategy-pattern]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[low-level-design]]></category>
            <dc:creator><![CDATA[Vibhor Pareek]]></dc:creator>
            <pubDate>Tue, 16 Feb 2021 10:52:22 GMT</pubDate>
            <atom:updated>2021-02-16T11:09:55.364Z</atom:updated>
            <content:encoded><![CDATA[<p>Behavioural Design Pattern in Java</p><p><strong>Introduction</strong></p><p>Strategy pattern is a behavioural design pattern which helps you to decide on choosing type of algorithm from a set of algorithms during runtime. Java Collections.sort() method uses strategy pattern to determine what type of comparator to be passed during runtime and acts accordingly. Hope this has given little bit of insight on strategy pattern.</p><p><strong>Where can we apply Strategy Pattern</strong></p><p>This is one of the most asked questions in an interview to a senior developer/tech lead/architect while doing a low level design problem. Answer is pretty straightforward, you have a set of predefined algorithms to choose which can be encapsulated in a new class/implementation, allowing the caller/client to decide on what algorithm to use at runtime.</p><p><strong>Code</strong> <strong>Walkthrough</strong></p><p>Let’s take a simple example of sorting numbers with different strategies. We are now creating an interface defining sort function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XJehOvC2CwACT33MXBQyaQ.png" /><figcaption>Interface defining Strategy</figcaption></figure><p>Let’s try to implement concrete classes defining different strategies:</p><ol><li>Merge Sort Strategy</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ydLD-n_44eI92doT-hYLw.png" /><figcaption>Concrete Class 1</figcaption></figure><p>2. Quick Sort Strategy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iFNZgeginFUts_ofOiduWw.png" /><figcaption>Concrete Class 2</figcaption></figure><p>Ah! pretty simple, now how do client call and decide runtime behaviour for the class ? Let’s create a context class and set the context determining your implementation as follows :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iHvAoLsWiKp1mgbfEdy_Iw.png" /><figcaption>Context Class</figcaption></figure><p>We have now reached the end of implementation, let’s try calling it and see :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tnq6GkdVCobBxtxkuTuM5Q.png" /><figcaption>Client Call</figcaption></figure><p>Hope you have understood the usage of Strategy Pattern :) Keep Learning !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ee2f7f4c297" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>