<?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 Aditya G Budh on Medium]]></title>
        <description><![CDATA[Stories by Aditya G Budh on Medium]]></description>
        <link>https://medium.com/@adityagb0009?source=rss-e4a089697652------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CsVcfnoKJQl5UpNKI7S9ag.jpeg</url>
            <title>Stories by Aditya G Budh on Medium</title>
            <link>https://medium.com/@adityagb0009?source=rss-e4a089697652------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:16:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adityagb0009/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[TOPIC : Singletone ]]></title>
            <link>https://adityagb0009.medium.com/topic-singletone-eaa83fed7934?source=rss-e4a089697652------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa83fed7934</guid>
            <category><![CDATA[singletone-design-pattern]]></category>
            <dc:creator><![CDATA[Aditya G Budh]]></dc:creator>
            <pubDate>Thu, 25 Jun 2026 06:49:10 GMT</pubDate>
            <atom:updated>2026-06-25T06:49:10.757Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>TOPIC : Singletone 👍</strong></p><p>Q1).What is Singleton?</p><ul><li>Singleton is a creational type of design pattern.</li><li>If we make any class as a singleton there will be only one object at JVM level.</li><li>To make it singleton we should make a constructor as a private.</li><li>In class we have to declare one variable private static Singleton singleton.</li><li>After that we have created one factory method whose return type is Singleton.</li><li>Inside the method we need to check that instance variable is null or not null.</li><li>If null then create new object and return it. If it’s not null, return the existing object.</li><li>In this way we can create singleton design pattern.</li></ul><p>Q2)How to break Singleton?</p><ul><li>Multi Threading :- Using this we can break singleton so to avoid this we can use synchronized block.</li><li>Java Reflection :- Using reflection we can change private constructor to public so to avoid this throw exception in constructor.</li><li>cloning :- Using cloning we can create the duplicate clone object to avoid this throw exception in clone method.</li><li>Sterilization :- During this JVM creates new object to avoid implementing the readResolve() method which return same instance.</li></ul><p>Q4)how to break singleton scope?</p><ul><li>If you don’t want to be class as a scope Singleton then you should write @Bean(prototype) in class.</li></ul><p>Examples:</p><p>import org.springframework.context.annotation.Bean;</p><p>import org.springframework.context.annotation.Configuration;</p><p>import org.springframework.context.annotation.Scope;</p><p>@Configuration</p><p>class AppConfig {</p><p>@Bean</p><p>@Scope(“prototype”)</p><p>public MyService myService() {</p><p>return new MyService();</p><p>}</p><p>}</p><p>Q5)Write the singleton code ?</p><p>import java.util.*;</p><p>public class Main</p><p>{</p><p>public static void main(String[] args) {</p><p>MySingaltone mysingaltone1= MySingaltone.getinstance();</p><p>MySingaltone mysingaltone2= MySingaltone.getinstance();</p><p>MySingaltone mysingaltone13=MySingaltone.getinstance();</p><p>System.out.println(mysingaltone1.hashCode());</p><p>System.out.println(mysingaltone2.hashCode());</p><p>System.out.println(mysingaltone13.hashCode());</p><p>}</p><p>}</p><p>class MySingaltone</p><p>{</p><p>private static MySingaltone mysingaltone;</p><p>private MySingaltone()</p><p>{</p><p>}</p><p>public static MySingaltone getinstance()</p><p>{</p><p>if(mysingaltone== null)</p><p>{</p><p>mysingaltone= new MySingaltone();</p><p>}</p><p>return mysingaltone;</p><p>}</p><p>}</p><p>Q6)What is singleton bean?</p><p>Ans:</p><ul><li>Singleton Bean is a Spring bean for which only one instance is created per Spring IoC container.</li><li>By default, all Spring beans (@Service, @Component, @Repository, @Controller) have singleton scope, and the same object is shared throughout the application.</li></ul><p>Q7) What is the default scope of a Spring Bean?</p><p>Answer: Singleton.</p><h3>Q8) Does Singleton Bean mean only one object in the entire JVM?</h3><p>Answer: No. It means one bean instance per Spring IoC container.</p><p>Q9) What is Singleton Bean and Singleton Scope?</p><ul><li>Singleton Bean means there will be only single object in IOC level.</li><li>By default all the classes are Singleton scope in spring.(classes with Stereotype annotation)</li></ul><p>Q10) What is the default bean scope?</p><p>Ans:Singleton.</p><p>Q11) How do you make a bean prototype instead of Singleton?</p><p>@Service</p><p>@Scope(“prototype”)</p><p>public class UserService {</p><p>}</p><p>Q12) What are the bean scopes in Spring?</p><ul><li>Singleton</li><li>Prototype</li><li>Request</li><li>Session</li><li>Application</li><li>WebSocket</li></ul><p>Q13) Is Singleton Bean thread-safe?</p><p>Answer: Not necessarily.</p><p>Spring creates only one object, but if multiple threads access mutable variables inside it, thread-safety issues can occur.</p><p>Q14) Is Singleton Bean thread-safe?</p><h3>Answer: Not necessarily.</h3><ul><li>Spring creates only one object, but if multiple threads access mutable variables inside it, thread-safety issues can occur.</li></ul><h3>Q15) Why are Spring Services usually Singleton?</h3><h3>Answer: To save memory and improve performance by reusing one object.</h3><h3>Q16) Where are Singleton Beans stored?</h3><h3>Answer: In the Spring IoC Container (ApplicationContext).</h3><p>Q17) What happens when two controllers inject the same service?</p><ul><li>@Autowired</li><li>UserService userService;</li></ul><h3>Both controllers receive the same singleton instance.</h3><h3>Q18) When is a Singleton Bean created?</h3><p>Answer: By default, at application startup (eager initialization).</p><h3>Q19) How do you create a bean lazily?</h3><ul><li>@Lazy</li><li>@Service</li></ul><p>public class UserService {</p><p>}</p><p>The bean is created only when first requested</p><p>Q20) What problem can occur with Singleton Beans?</p><p>Answer: Race conditions and data inconsistency if shared mutable state is used.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa83fed7934" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is IoC (Inversion of Control)?]]></title>
            <link>https://adityagb0009.medium.com/what-is-ioc-inversion-of-control-fc30af0b5fe6?source=rss-e4a089697652------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc30af0b5fe6</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Aditya G Budh]]></dc:creator>
            <pubDate>Sun, 09 Mar 2025 12:08:02 GMT</pubDate>
            <atom:updated>2025-03-09T12:08:02.115Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>IoC (Inversion of Control) is a design principle where the control of object creation and dependency management is transferred from the application to the framework.</li><li>In Spring Boot, IoC is implemented using the Spring IoC Container.</li></ul><h3><strong>Spring IoC Container :</strong></h3><p>The IoC container in Spring is responsible for: Creating and managing objects (beans). Handling dependencies between objects. Configuring and injecting dependencies automatically.</p><h3>Types of IoC Containers in Spring</h3><ol><li><em>BeanFactory</em></li></ol><p>The simplest container that provides basic dependency injection. Uses lazy loading (creates beans only when requested). Example: XmlBeanFactory (deprecated).</p><p>2)<em>ApplicationContext(Recommended)</em></p><p>More advanced than BeanFactory. Supports eager loading (creates beans at startup). Provides additional features like event propagation, declarative bean creation, and AOP.</p><p>3)<em>Common implementations:</em></p><ul><li>AnnotationConfigApplicationContext — for Java-based configuration. ClassPathXmlApplicationContext — for XML-based configuration.</li><li>WebApplicationContext — for web applications</li></ul><h3><strong>How IoC Works in Spring Boot</strong></h3><p>When Spring boot application start then Spring Boot automatically configures an ApplicationContext and scans all the classes who having below annotation.</p><p>-@Component — Generic bean declaration.</p><p>-@Service — Marks a service layer component.</p><p>-@Repository — Marks a repository (DAO) layer component.</p><p>-@Controller / @RestController — Marks a web controller.</p><ul><li>@Bean — Declares a bean inside a @Configuration class.</li><li>then it creates a bean of classes and store in logical memory in form of key and value, this logical memory called as IOC container</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*awOlGYA83gFNtiteZ3_NVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*-Lfwk5oBXz1370I8WhrVaA.png" /></figure><p>Spring Boot scans EmployeeService and MyController automatically. IoC Container creates objects and injects dependencies (@Autowired).</p><blockquote>Conclusion:</blockquote><blockquote>IoC in Spring Boot simplifies dependency management. The Spring IoC container ensures efficient object creation and dependency injection. Using annotations like @Component, @Service, and @Autowired, Spring Boot automatically wires dependencies.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc30af0b5fe6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Caching Strategies]]></title>
            <link>https://adityagb0009.medium.com/caching-strategies-131c7fe47dd9?source=rss-e4a089697652------2</link>
            <guid isPermaLink="false">https://medium.com/p/131c7fe47dd9</guid>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Aditya G Budh]]></dc:creator>
            <pubDate>Mon, 03 Jun 2024 01:44:48 GMT</pubDate>
            <atom:updated>2024-06-03T01:44:48.057Z</atom:updated>
            <content:encoded><![CDATA[<p>Caching is essential for improving application performance by temporarily storing copies of frequently accessed data in a fast-access storage layer, typically in memory. Here are the main caching strategies:</p><h4>a) Write-Around Cache</h4><p>In the write-around caching strategy, data is written directly to the permanent storage, bypassing the cache. This helps reduce the load on the cache for write operations.</p><p><strong>Advantages:</strong></p><ol><li><strong>Faster Write Operations:</strong> Since data is directly written to storage, write performance is improved.</li></ol><p><strong>Disadvantages:</strong></p><ol><li><strong>Slow Read Operations:</strong> Cache misses are more frequent, leading to slower reads as data must be fetched from the slower permanent storage.</li></ol><h4>b) Write-Through Cache</h4><p>In the write-through strategy, data is written to both the cache and the permanent storage simultaneously.</p><p><strong>Advantages:</strong></p><ol><li><strong>No Stale Data:</strong> Ensures data consistency between the cache and the permanent storage.</li><li><strong>High Consistency:</strong> Data in the cache is always up-to-date with the storage.</li></ol><p><strong>Disadvantages:</strong></p><ol><li><strong>Slow Write Operations:</strong> Writing to both cache and storage can slow down write operations.</li></ol><h4>c) Write-Back Cache</h4><p>In the write-back strategy, data is written only to the cache initially. The cache writes the data back to the permanent storage at specified intervals or under certain conditions.</p><p><strong>Advantages:</strong></p><ol><li><strong>Fast Write Operations:</strong> Writes are faster as they are done in the cache first.</li></ol><p><strong>Disadvantages:</strong></p><ol><li><strong>Data Loss Risk:</strong> There is a risk of data loss if the cache fails before the data is written back to storage.</li></ol><h3>Cache Eviction Strategies</h3><p>Eviction strategies determine which data to remove when the cache is full. Common strategies include:</p><ol><li><strong>LRU (Least Recently Used):</strong> Evicts the least recently accessed data first. Requires extra memory to track usage.</li><li><strong>MRU (Most Recently Used):</strong> Evicts the most recently accessed data first.</li><li><strong>LFU (Least Frequently Used):</strong> Evicts the least frequently accessed data first. Needs additional memory to track access frequencies.</li><li><strong>FIFO (First In First Out):</strong> Evicts the oldest data added to the cache.</li><li><strong>LIFO (Last In First Out):</strong> Evicts the most recently added data.</li><li><strong>RR (Random Replacement):</strong> Randomly selects an item to evict. Useful when all data entries have equal importance.</li></ol><h3>Benefits of Caching</h3><ol><li><strong>Improve Application Performance:</strong> Reduces latency for data access.</li><li><strong>Reduce Database Cost:</strong> Offloads read operations from the database.</li><li><strong>Reduce Load on the Backend:</strong> Minimizes database queries.</li><li><strong>Predictable Performance:</strong> Provides consistent response times.</li><li><strong>Eliminate Database Hotspots:</strong> Distributes the read load.</li><li><strong>Increase Read Throughput (IOPS):</strong> Enhances input/output operations per second.</li></ol><h3>Disadvantages of Caching</h3><ol><li><strong>Cost:</strong> Cache memory is expensive and limited in capacity.</li><li><strong>Heavy Pages:</strong> Cache storage can increase the memory footprint of pages.</li><li><strong>Stale Data:</strong> Potential for outdated data if the cache is not updated.</li></ol><h3>Applications of Caching</h3><ol><li><strong>Read-Intensive Applications:</strong> Improves performance in portals, gaming, media sharing, and social networking.</li><li><strong>Database Queries and Web Artifacts:</strong> Speeds up access to frequently used queries, calculations, and web content like HTML, JavaScript, and images.</li><li><strong>In-Memory Data Layers:</strong> Benefits compute-intensive tasks such as recommendation engines and simulations.</li><li><strong>Massive Data Sets:</strong> Enhances real-time access across large server clusters, essential for applications constrained by disk-based storage speed.</li></ol><p>By employing these caching strategies and eviction policies, systems can significantly improve performance and scalability, ensuring a better user experience and efficient resource utilization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=131c7fe47dd9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Synchronous Communication…]]></title>
            <link>https://adityagb0009.medium.com/synchronous-communication-aeccd36c81c9?source=rss-e4a089697652------2</link>
            <guid isPermaLink="false">https://medium.com/p/aeccd36c81c9</guid>
            <category><![CDATA[synchronous-communication]]></category>
            <dc:creator><![CDATA[Aditya G Budh]]></dc:creator>
            <pubDate>Mon, 27 May 2024 02:42:56 GMT</pubDate>
            <atom:updated>2024-05-27T02:44:21.452Z</atom:updated>
            <content:encoded><![CDATA[<p>Suppose you go to a shop to buy something and the vendor tells you to wait for some time till the order gets prepared. Till the order gets prepared , you’ve to wait .It means that you’re blocked until you receive the order. And you cannot leave that place until you get the order. It means that it is like synchronous communication with the vendor.</p><blockquote><strong>What is synchronous communication :</strong>Synchronous communication is the connection between to entities without any interrupt till we met with a fulfilling condition .</blockquote><p>eg: Buying something from ecommerce site and in receiving a timely delivery .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*ck0ZFzL5RJf9xUCrFxHSSQ.png" /></figure><blockquote><strong>How synchronization is achieved ?</strong></blockquote><p>The synchronous call is based on concept of blocking .Till the first request is not met with its fulfilling condition and during that time the second request has to wait.</p><p><strong><em>Following things are required by synchronization connection…</em></strong></p><ol><li>Real-Time Communication</li><li>Consistency</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aeccd36c81c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>