<?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 Bottle Company on Medium]]></title>
        <description><![CDATA[Stories by Bottle Company on Medium]]></description>
        <link>https://medium.com/@rihammisuk?source=rss-1e8014bce288------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tJrLEla10NUmcPoWoRzLXA.jpeg</url>
            <title>Stories by Bottle Company on Medium</title>
            <link>https://medium.com/@rihammisuk?source=rss-1e8014bce288------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:31:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rihammisuk/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[Caching in .NET 8 in simple terms]]></title>
            <link>https://medium.com/@rihammisuk/caching-in-net-8-in-simple-terms-b1eda9b19d43?source=rss-1e8014bce288------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1eda9b19d43</guid>
            <dc:creator><![CDATA[Bottle Company]]></dc:creator>
            <pubDate>Mon, 02 Sep 2024 07:09:38 GMT</pubDate>
            <atom:updated>2024-09-02T07:09:38.317Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGdhoFOdx_0HUM5Xy4uLpQ.jpeg" /></figure><p>Caching is a technique used to make your applications faster by storing data temporarily so it can be accessed quickly. Think of it like keeping a favorite book close by instead of going to the library every time you want to read it. In .NET 8, caching has some cool features that can help you improve your app’s performance. Let’s break down what caching is, why it’s useful, and how you can use it easily in your .NET 8 applications.</p><h4>Why is Caching Important?</h4><p>When your application needs to fetch data, it might take a while because it has to go to a database or perform complex calculations. If you do this often, your app can become slow. Caching helps by saving that data in a fast-access spot, so the next time your app needs it, it can get it quickly without doing the heavy lifting again. This makes your app faster and lessens the load on your server.</p><h4>Types of Caching in .NET 8</h4><p>.NET 8 provides different ways to use caching, depending on what your app needs. Let’s go through the main ones:</p><h3><strong>In-Memory Caching</strong></h3><p><strong>What It Is:</strong><br>In-memory caching stores data directly in the application’s memory (RAM). It’s the fastest caching method because the data is kept close to the app.</p><p><strong>When to Use It:</strong><br>This is best for smaller applications or apps running on a single server where data doesn’t need to be shared between servers.</p><p><strong>How It Works:</strong></p><ul><li>You save data with a unique key (like a label).</li><li>When you need the data, you check if it’s in the cache using that key.</li><li>If it’s there, you use it (cache hit). If not, you fetch it from the source, store it in the cache, and then use it (cache miss).</li></ul><p><strong>Simple Example:</strong></p><pre>// Step 1: Configure services to use in-memory caching<br>services.AddMemoryCache();<br><br>// Step 2: Use the cache in your code<br>public class MyService<br>{<br>    private readonly IMemoryCache _cache;<br><br>    // Constructor to inject the cache<br>    public MyService(IMemoryCache cache)<br>    {<br>        _cache = cache;<br>    }<br><br>    // Method to get data<br>    public MyData GetData(string key)<br>    {<br>        // Check if the data is already in the cache<br>        if (!_cache.TryGetValue(key, out MyData data))<br>        {<br>            // If not, fetch the data (this is the expensive operation)<br>            data = FetchDataFromDatabase();<br><br>            // Store the data in the cache for 10 minutes<br>            _cache.Set(key, data, TimeSpan.FromMinutes(10));<br>        }<br><br>        // Return the data, either from the cache or freshly fetched<br>        return data;<br>    }<br>}</pre><h3><strong>Distributed Caching</strong></h3><p><strong>What It Is:</strong><br>Distributed caching stores data in a central cache that can be accessed by multiple servers. This is useful for applications running on multiple servers or in the cloud.</p><p><strong>When to Use It:</strong><br>Use distributed caching for large applications where different parts of the app need to share cached data.</p><p><strong>How It Works:</strong></p><ul><li>The cache is stored in a system like Redis, SQL Server, or another central service.</li><li>All servers or instances of your app can access this cache, keeping everything in sync.</li></ul><p><strong>Simple Example (Using Redis):</strong></p><pre>// Step 1: Configure services to use Redis for distributed caching<br>services.AddStackExchangeRedisCache(options =&gt;<br>{<br>    options.Configuration = &quot;localhost:6379&quot;; // Address of the Redis server<br>});<br><br>// Step 2: Use the distributed cache in your code<br>public class MyService<br>{<br>    private readonly IDistributedCache _cache;<br><br>    // Constructor to inject the cache<br>    public MyService(IDistributedCache cache)<br>    {<br>        _cache = cache;<br>    }<br><br>    // Async method to get data<br>    public async Task&lt;MyData&gt; GetDataAsync(string key)<br>    {<br>        // Try to get the data from the cache<br>        var cachedData = await _cache.GetStringAsync(key);<br>        if (cachedData == null)<br>        {<br>            // If not in the cache, fetch it (this is the expensive operation)<br>            var data = FetchDataFromDatabase();<br><br>            // Convert data to JSON and store in cache for 10 minutes<br>            await _cache.SetStringAsync(key, JsonConvert.SerializeObject(data), new DistributedCacheEntryOptions<br>            {<br>                AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)<br>            });<br><br>            return data;<br>        }<br><br>        // Convert cached JSON back to MyData and return it<br>        return JsonConvert.DeserializeObject&lt;MyData&gt;(cachedData);<br>    }<br>}</pre><h3><strong>Output Caching</strong></h3><p><strong>What It Is:</strong><br>Output caching saves the final output of a web request (like an HTML page) so it can be served quickly to other users without regenerating it.</p><p><strong>When to Use It:</strong><br>Output caching is perfect for web pages or API responses that don’t change often and are accessed frequently.</p><p><strong>How It Works:</strong></p><ul><li>The first time a page or API endpoint is accessed, the output is generated and stored in the cache.</li><li>Subsequent requests use the cached output, skipping the logic behind it.</li></ul><p><strong>Simple Example:</strong></p><pre>// Step 1: Configure services for output caching<br>services.AddOutputCache(options =&gt;<br>{<br>    options.AddBasePolicy(builder =&gt;<br>        builder.Expire(TimeSpan.FromMinutes(10))); // Cache for 10 minutes<br>});<br><br>// Step 2: Apply output caching to a controller or action<br>[OutputCache(Duration = 600)] // Cache this action&#39;s output for 600 seconds (10 minutes)<br>public IActionResult MyPage()<br>{<br>    // Generate and return the page content<br>    return View();<br>}</pre><h3>Best Practices for Caching</h3><p><strong>Use the Right Type of Cache:</strong></p><ul><li>Use in-memory caching for single-server apps.</li><li>Use distributed caching for apps that run on multiple servers.</li></ul><p><strong>Set Expiration Times:</strong></p><ul><li>Always set a time limit for how long data should stay in the cache. This ensures the cache stays up-to-date.</li></ul><p><strong>Cache Only What’s Necessary:</strong></p><ul><li>Don’t cache everything — focus on data that’s slow to retrieve or calculate and is frequently needed.</li></ul><p><strong>Monitor Cache Performance:</strong></p><ul><li>Keep an eye on how often your cache is being used (cache hits) versus how frequently it’s not (cache misses). This helps you fine-tune your caching strategy.</li></ul><p><strong>Handle Cache Failures Gracefully:</strong></p><ul><li>If the cache fails, make sure your app can still work by falling back to fetching the data directly from the source.</li></ul><h4>Conclusion</h4><p>Caching in .NET 8 is a powerful way to make your applications faster and more efficient. By storing frequently accessed data in a quick-to-reach spot, you can reduce your app&#39;s time fetching or calculating information. Whether building a small app or a large, scalable system, caching can help you improve performance and handle more users smoothly. Just remember to use the right type of caching for your situation, set expiration times, and monitor how it’s working to get the best results.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1eda9b19d43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker commands in simple terms]]></title>
            <link>https://medium.com/@rihammisuk/docker-commands-in-simple-terms-536ed345be81?source=rss-1e8014bce288------2</link>
            <guid isPermaLink="false">https://medium.com/p/536ed345be81</guid>
            <dc:creator><![CDATA[Bottle Company]]></dc:creator>
            <pubDate>Sun, 30 Jun 2024 06:49:59 GMT</pubDate>
            <atom:updated>2024-06-30T06:58:06.892Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-gd112IeeJ8guXvIF3c-fg.png" /></figure><p>While the list I provided covers many commonly used Docker commands, Docker has a vast command set, and some more specialized commands and options can be utilized. Here’s a more comprehensive list, including some additional commands that can be useful:</p><h3>Basic Docker Commands</h3><ul><li><strong>docker version</strong>: Show the Docker version information.</li><li><strong>docker info</strong>: Display system-wide information about Docker.</li></ul><h3>Image Management Commands</h3><ul><li><strong>docker pull &lt;image&gt;</strong>: Pull an image from a registry.</li><li><strong>docker push &lt;image&gt;</strong>: Push an image to a registry.</li><li><strong>docker build -t &lt;name&gt; &lt;path&gt;</strong>: Build an image from a Dockerfile.</li><li><strong>docker images</strong>: List all images.</li><li><strong>docker rmi &lt;image&gt;</strong>: Remove one or more images.</li><li><strong>docker tag &lt;source_image&gt; &lt;target_image&gt;</strong>: Tag an image into a repository.</li><li><strong>docker history &lt;image&gt;</strong>: Show the history of an image.</li><li><strong>docker save -o &lt;path&gt; &lt;image&gt;</strong>: Save an image to a tar archive.</li><li><strong>docker load -i &lt;path&gt;</strong>: Load an image from a tar archive.</li></ul><h3>Container Management Commands</h3><ul><li><strong>docker run &lt;image&gt;</strong>: Run a new container from an image.</li><li><strong>docker create &lt;image&gt;</strong>: Create a new container from an image but do not start it.</li><li><strong>docker start &lt;container&gt;</strong>: Start one or more stopped containers.</li><li><strong>docker stop &lt;container&gt;</strong>: Stop one or more running containers.</li><li><strong>docker restart &lt;container&gt;</strong>: Restart a running container.</li><li><strong>docker kill &lt;container&gt;</strong>: Kill a running container.</li><li><strong>docker rm &lt;container&gt;</strong>: Remove one or more containers.</li><li><strong>docker pause &lt;container&gt;</strong>: Pause all processes in a container.</li><li><strong>docker unpause &lt;container&gt;</strong>: Unpause all processes in a container.</li><li><strong>docker exec &lt;container&gt; &lt;command&gt;</strong>: Run a command in a running container.</li><li><strong>docker attach &lt;container&gt;</strong>: Attach local standard input, output, and error streams to a running container.</li><li><strong>docker logs &lt;container&gt;</strong>: Fetch the logs of a container.</li><li><strong>docker inspect &lt;container|image&gt;</strong>: Return low-level information on Docker objects.</li><li><strong>docker top &lt;container&gt;</strong>: Display the running processes of a container.</li><li><strong>docker cp &lt;container&gt;:&lt;path&gt; &lt;local_path&gt;</strong>: Copy files/folders between a container and the local filesystem.</li><li><strong>docker commit &lt;container&gt; &lt;new_image&gt;</strong>: Create a new image from a container&#39;s changes.</li><li><strong>docker diff &lt;container&gt;</strong>: Inspect changes to files or directories on a container’s filesystem.</li></ul><h3>Network Management Commands</h3><ul><li><strong>docker network ls</strong>: List all networks.</li><li><strong>docker network inspect &lt;network&gt;</strong>: Display detailed information on one or more networks.</li><li><strong>docker network create &lt;network&gt;</strong>: Create a new network.</li><li><strong>docker network connect &lt;network&gt; &lt;container&gt;</strong>: Connect a container to a network.</li><li><strong>docker network disconnect &lt;network&gt; &lt;container&gt;</strong>: Disconnect a container from a network.</li><li><strong>docker network rm &lt;network&gt;</strong>: Remove one or more networks.</li></ul><h3>Volume Management Commands</h3><ul><li><strong>docker volume ls</strong>: List all volumes.</li><li><strong>docker volume inspect &lt;volume&gt;</strong>: Display detailed information about one or more volumes.</li><li><strong>docker volume create &lt;volume&gt;</strong>: Create a new volume.</li><li><strong>docker volume rm &lt;volume&gt;</strong>: Remove one or more volumes.</li></ul><h3>Docker Compose Commands</h3><ul><li><strong>docker-compose up</strong>: Build, (re)create, start, and attach to containers for a service.</li><li><strong>docker-compose down</strong>: Stop and remove containers, networks, images, and volumes.</li><li><strong>docker-compose build</strong>: Build or rebuild services.</li><li><strong>docker-compose start</strong>: Start existing containers for a service.</li><li><strong>docker-compose stop</strong>: Stop running containers without removing them.</li><li><strong>docker-compose restart</strong>: Restart containers.</li><li><strong>docker-compose ps</strong>: List containers.</li><li><strong>docker-compose exec &lt;service&gt; &lt;command&gt;</strong>: Execute a command in a running container.</li><li><strong>docker-compose logs</strong>: View output from containers.</li><li><strong>docker-compose pull</strong>: Pull service images.</li><li><strong>docker-compose scale &lt;service&gt;=&lt;number&gt;</strong>: Set number of containers for a service (deprecated in favor of up --scale).</li><li><strong>docker-compose config</strong>: Validate and view the Compose file.</li></ul><h3>Docker Swarm Commands (for orchestration)</h3><ul><li><strong>docker swarm init</strong>: Initialize a swarm.</li><li><strong>docker swarm join</strong>: Join a node to a swarm.</li><li><strong>docker swarm leave</strong>: Remove a node from a swarm.</li><li><strong>docker node ls</strong>: List nodes in the swarm.</li><li><strong>docker service create &lt;options&gt; &lt;image&gt;</strong>: Create a new service.</li><li><strong>docker service ls</strong>: List services.</li><li><strong>docker service rm &lt;service&gt;</strong>: Remove a service.</li><li><strong>docker service ps &lt;service&gt;</strong>: List tasks of a service.</li><li><strong>docker stack deploy -c &lt;compose-file&gt; &lt;stack&gt;</strong>: Deploy a new stack or update an existing stack.</li><li><strong>docker stack ls</strong>: List stacks.</li><li><strong>docker stack ps &lt;stack&gt;</strong>: List the tasks in the stack.</li><li><strong>docker stack services &lt;stack&gt;</strong>: List the services in the stack.</li><li><strong>docker stack rm &lt;stack&gt;</strong>: Remove the stack.</li></ul><h3>Cleanup Commands</h3><ul><li><strong>docker system prune</strong>: Remove unused data.</li><li><strong>docker container prune</strong>: Remove all stopped containers.</li><li><strong>docker image prune</strong>: Remove unused images.</li><li><strong>docker volume prune</strong>: Remove unused volumes.</li><li><strong>docker network prune</strong>: Remove unused networks.</li></ul><p>These commands cover a wide range of Docker functionality, including container lifecycle management, networking, volumes, image management, and more advanced orchestration with Docker Swarm. For more detailed information on each command and additional options, you can refer to the official Docker documentation.</p><p><a href="https://docs.docker.com/"></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=536ed345be81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(Back-of-the-Envelope Calculations for a Messaging System like WhatsApp) in simple terms]]></title>
            <link>https://medium.com/@rihammisuk/for-whatsapp-back-of-the-envelope-calculations-in-simple-terms-9a617130a163?source=rss-1e8014bce288------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a617130a163</guid>
            <dc:creator><![CDATA[Bottle Company]]></dc:creator>
            <pubDate>Mon, 13 May 2024 10:54:16 GMT</pubDate>
            <atom:updated>2024-07-09T12:56:52.236Z</atom:updated>
            <content:encoded><![CDATA[<p>Back-of-the-envelope calculations are a useful method for making quick, rough estimates using simple assumptions and basic arithmetic. Let’s apply this method to estimate the load, database storage, cache size, and bandwidth requirements for a messaging platform like WhatsApp. These calculations will help us understand the scale and resource requirements for such a system.</p><p>To make these estimates more relatable, let’s use a single real-world context: the daily operations of WhatsApp.</p><h3>Load Estimates</h3><p>Load estimates involve understanding the volume of requests and interactions a system like WhatsApp needs to handle.</p><h4>Assumptions for Load Estimates:</h4><ul><li><strong>Total Monthly Active Users (MAU):</strong> 2 billion</li><li><strong>Average Daily Usage per User:</strong> 30 minutes</li><li><strong>Messages Sent/Received per User per Day:</strong> 50</li></ul><p><strong>Real-World Context:</strong> Imagine the entire user base of WhatsApp, which includes over 2 billion people worldwide, actively using the platform. If each person sends and receives 50 messages daily, we need to handle a colossal volume of messaging traffic.</p><h4>Calculations for Load Estimates:</h4><p><strong>Daily Active Users (DAU):<br></strong>DAU=MAU × 1/30<br>DAU=2billion× 1/30 ≈ 66.67million users/day</p><p><strong>Total Messages Sent/Received per Day:</strong><br>Total Messages per Day=DAU×Messages per User per Day<br>Total Messages per Day=<br>66.67million users/day×50messages/user/day≈3.33billion messages/day</p><p>Handling 3.33 billion messages a day is equivalent to each WhatsApp user sending and receiving messages constantly throughout the day, reflecting the global scale and continuous activity on the platform.</p><h3>Database Storage Estimate</h3><p>We are estimating the database storage required based on the volume of messages and media shared.</p><h4>Assumptions for Database Storage Estimate:</h4><ul><li><strong>Average Message Size:</strong> 200 dKB</li><li><strong>Percentage of Messages Containing Media:</strong> 30%</li><li><strong>Average Media File Size:</strong> 2 MB</li></ul><p><strong>Real-World Context:</strong> WhatsApp messages can range from simple text to multimedia content. Each text message is around 200 KB, while media messages (photos, videos, etc.) are significantly larger. Given that 30% of messages contain media, storage needs escalate quickly.</p><h4>Calculations for Database Storage Estimate:</h4><p><strong>Daily Data Storage for Messages:<br></strong>Daily Data Storage for Messages=Total Messages per Day×Average Message Size<br>Daily Data Storage for Messages=<br>3.33billion messages/day×200KB/message = 666.67terabytes/day</p><p><strong>Daily Data Storage for Media:<br></strong>Daily Data Storage for Media=<br>Percentage of Media Messages×Total Messages per Day×Average Media Size<br>Daily Data Storage for Media =<br>0.30×3.33billion messages/day×2MB/message = 2petabytes/day</p><p>To put 2 petabytes into perspective, it’s equivalent to storing around 500,000 DVDs worth of media content every single day.</p><h3>Cache Estimate</h3><p>Estimating the cache size required based on the database storage and access patterns.</p><h4>Assumptions for Cache Estimate:</h4><ul><li><strong>Cache-to-Database Storage Ratio:</strong> 20%</li></ul><p><strong>Real-World Context:</strong> WhatsApp employs caching to speed up access to frequently used data, such as recent messages and media, reducing the load on its databases and improving user experience.</p><h4>Calculations for Cache Estimate:</h4><p><strong>Daily Cache Size:<br></strong>Daily Cache Size=Database Storage×Cache-to-Database Storage Ratio<br>Daily Cache Size=<br>(666.67terabytes/day+2terabytes/day)×20% ≈ 133.33terabytes/day</p><p>This is akin to having the most frequently accessed data from over 26,000 high-definition movies readily available for fast access.</p><h3>Bandwidth Estimates</h3><p>Estimating the required bandwidth for handling message transfers and media uploads/downloads.</p><h4>Assumptions for Bandwidth Estimate:</h4><ul><li><strong>Average Message Transfer Size:</strong> 500 KB</li><li><strong>Percentage of Media Uploads:</strong> 30%</li><li><strong>Average Media Upload/Download Size:</strong> 2 MB</li></ul><p><strong>Real-World Context:</strong> The bandwidth requirements reflect the need to transfer vast amounts of data daily. Every text message, photo, and video sent or received on WhatsApp consumes bandwidth, making it essential to estimate these needs accurately.</p><h4>Calculations for Bandwidth Estimate:</h4><p><strong>Daily Bandwidth for Messages:<br></strong>Daily Bandwidth for Messages=<br>Total Messages per Day×Average Message Transfer Size<br>Daily Bandwidth for Messages=<br>3.33billion messages/day×500KB/message = 1.665petabytes/day</p><p><strong>Daily Bandwidth for Media:<br></strong>Daily Bandwidth for Media=<br>Percentage of Media Uploads×Total Messages per Day×Average Media Size<br>Daily Bandwidth for Media=<br>0.30×3.33billion messages/day×2MB/message=2petabytes/day</p><p>Managing 3.665 petabytes of data per day is like streaming about 1.83 million hours of HD video daily.</p><h3>Queries Per Second (QPS)</h3><p>To calculate the Queries Per Second (QPS) for a system like WhatsApp, we can estimate the rate at which messages are sent and received based on user activity.</p><h4>Assumptions:</h4><ul><li><strong>Monthly Active Users (MAU):</strong> 2 billion</li><li><strong>Daily Active Users (DAU):</strong> Assuming 10% of MAU (daily engagement)</li><li><strong>Messages Sent/Received per User per Day:</strong> 50</li></ul><p><strong>Real-World Context:</strong> QPS is similar to how many checkout transactions a cashier can handle in a second at a busy supermarket, scaled up to a global messaging service.</p><h4>Estimating Daily Active Users (DAU):</h4><p>DAU=MAU×Daily Engagement Rate<br>DAU=2billion×0.10=200million users/day</p><p><strong>Estimating Total Messages Sent/Received Per Day:<br></strong>Total Messages/Day=DAU×Messages/User/Day<br>Total Messages/Day=200million users/day×50messages/user/day=10billion messages/day</p><h4>Calculating Queries Per Second (QPS):</h4><p>Assuming a uniform distribution of message activity throughout the day, we can estimate the Queries Per Second (QPS) as follows:</p><p>QPS= (Total Messages/Day) / 24 hours × 3600 seconds/per hour<br>QPS=<br> (10 billion messages per day) / (86400 seconds/per day) ≈ 115,741QPS</p><p>This is like managing over 115,000 transactions per second, similar to how a global stock exchange handles trades.</p><h3>Summary</h3><p><strong>Load Estimates:</strong></p><ul><li><strong>Daily Active Users:</strong> Approximately 66.67 million users/day</li><li><strong>Total Messages per Day:</strong> Approximately 3.33 billion messages/day</li></ul><p><strong>Database Storage Estimate:</strong></p><ul><li><strong>Daily Data Storage for Messages:</strong> Approximately 666.67 terabytes/day</li><li><strong>Daily Data Storage for Media:</strong> Approximately 2 petabytes/day</li></ul><p><strong>Cache Estimate:</strong></p><ul><li><strong>Daily Cache Size:</strong> Approximately 133.33 terabytes/day</li></ul><p><strong>Bandwidth Estimates:</strong></p><ul><li><strong>Daily Bandwidth for Messages:</strong> Approximately 1.665 petabytes/day</li><li><strong>Daily Bandwidth for Media:</strong> Approximately 2 petabytes/day</li></ul><h3>Additional Considerations</h3><p>To further refine these estimates, consider the following:</p><ul><li><strong>Peak Load vs. Average Load:</strong> Messaging activity is not uniformly distributed throughout the day. Peak times can significantly affect load estimates and require systems to be designed for high availability and resilience.</li><li><strong>User Engagement Variability:</strong> Different user segments (e.g., age groups, geographic regions) may have varying levels of engagement. Analyzing these patterns can provide more accurate load estimates.</li><li><strong>Compression and Storage Optimization:</strong> Implementing efficient message and media compression techniques can significantly reduce storage and bandwidth requirements.</li><li><strong>Scalability and Redundancy:</strong> Ensure the system is scalable and has redundancy built in to handle failures and maintenance without affecting user experience.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a617130a163" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Factory method for designing pattern in simple terms]]></title>
            <link>https://medium.com/@rihammisuk/factory-method-for-designing-pattern-in-simple-terms-fe20f3a19503?source=rss-1e8014bce288------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe20f3a19503</guid>
            <dc:creator><![CDATA[Bottle Company]]></dc:creator>
            <pubDate>Thu, 28 Mar 2024 07:21:51 GMT</pubDate>
            <atom:updated>2024-03-28T07:21:51.442Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*1lDD7vavamqLcOZWVcxxUg.jpeg" /></figure><p>Imagine you have a pizza restaurant. You order pizza by specifying the type of pizza you want (e.g., Margherita, Pepperoni, Veggie). You don’t need to know how each pizza is made; you just order the type you want, and the restaurant gives you the finished pizza.</p><p>In software design, the Factory Pattern works similarly. Instead of directly creating objects in your code, you use a factory to create objects based on certain criteria or parameters. You tell the factory what type of object you need, and it gives you the object ready to use. This way, you don’t have to worry about the details of object creation; the factory handles it for you.</p><p>So, the Factory Pattern is like ordering pizza from a restaurant: you specify what you want, and the factory (or restaurant) takes care of making it for you.</p><p>Let’s delve into a practical example to understand the uses of the Factory Method pattern:</p><h3>Example: Document Processors</h3><p>Consider a scenario where you’re developing a document processing application. You have different types of documents such as Word documents, PDFs, and spreadsheets, each requiring its own processing logic.</p><h4>Problem Statement:</h4><p>You want to design a system where clients can create documents without being concerned about the specific implementation details of each document type.</p><h4>Solution using Factory Method pattern:</h4><pre>using System;<br><br>// Document interface<br>public interface Document<br>{<br>    void Open();<br>    void Save();<br>}<br><br>// Concrete document classes<br>public class WordDocument : Document<br>{<br>    public void Open()<br>    {<br>        Console.WriteLine(&quot;Opening a Word document.&quot;);<br>    }<br><br>    public void Save()<br>    {<br>        Console.WriteLine(&quot;Saving a Word document.&quot;);<br>    }<br>}<br><br>public class PDFDocument : Document<br>{<br>    public void Open()<br>    {<br>        Console.WriteLine(&quot;Opening a PDF document.&quot;);<br>    }<br><br>    public void Save()<br>    {<br>        Console.WriteLine(&quot;Saving a PDF document.&quot;);<br>    }<br>}<br><br>// Factory interface<br>public interface DocumentFactory<br>{<br>    Document CreateDocument();<br>}<br><br>// Concrete factory classes<br>public class WordDocumentFactory : DocumentFactory<br>{<br>    public Document CreateDocument()<br>    {<br>        return new WordDocument();<br>    }<br>}<br><br>public class PDFDocumentFactory : DocumentFactory<br>{<br>    public Document CreateDocument()<br>    {<br>        return new PDFDocument();<br>    }<br>}<br><br>class Program<br>{<br>    static void Main(string[] args)<br>    {<br>        // Using Word Document Factory<br>        DocumentFactory wordFactory = new WordDocumentFactory();<br>        Document wordDocument = wordFactory.CreateDocument();<br>        wordDocument.Open(); // Outputs: Opening a Word document.<br>        wordDocument.Save(); // Outputs: Saving a Word document.<br><br>        // Using PDF Document Factory<br>        DocumentFactory pdfFactory = new PDFDocumentFactory();<br>        Document pdfDocument = pdfFactory.CreateDocument();<br>        pdfDocument.Open(); // Outputs: Opening a PDF document.<br>        pdfDocument.Save(); // Outputs: Saving a PDF document.<br>    }<br>}</pre><p>In this code:</p><ul><li>We define the Document interface representing common behavior for all document types.</li><li>Concrete document classes WordDocument and PDFDocument implement the Document interface with their specific Open() and Save() methods.</li><li>We define the DocumentFactory interface with a CreateDocument() factory method.</li><li>Concrete factory classes WordDocumentFactory and PDFDocumentFactory implement the DocumentFactory interface, each creating instances of its respective document type.</li><li>In the Main method, we demonstrate how to use different factory instances to create and work with Word and PDF documents without need to know their specific implementation details.</li></ul><p>Let’s break down the advantages and disadvantages of the Factory Design Pattern using the example of Document Processors:</p><h3>Advantages:</h3><ol><li>Encapsulation:</li></ol><ul><li>Explanation: The Factory Pattern encapsulates the creation logic of different document types within specialized factory classes, hiding the details from client code.</li><li>Example: You have a DocumentFactory interface with a method CreateDocument(), and concrete factory classes (WordDocumentFactory, PDFDocumentFactory) implementing this interface to create instances of specific document types.</li></ul><ol><li>Flexibility:</li></ol><ul><li>Explanation: It allows for flexible creation of document objects by providing an interface for creating documents, enabling subclasses or implementing classes to alter the type of documents that will be created.</li><li>Example: If you need to add support for a new document type (e.g., SpreadsheetDocument), you can create a new factory class (SpreadsheetDocumentFactory) without changing the existing client code.</li></ul><ol><li>Code Reusability:</li></ol><ul><li>Explanation: The Factory Pattern promotes code reusability by centralizing object creation logic, making it easy to reuse across different parts of the codebase.</li><li>Example: The same DocumentFactory interface and concrete factory classes can be reused in multiple parts of the application where document creation is required.</li></ul><ol><li>Decoupling:</li></ol><ul><li>Explanation: It promotes loose coupling between client code and object creation logic, making the system easier to maintain and modify.</li><li>Example: Client code interacts with the DocumentFactory interface, abstracting away the details of how different types of documents are created.</li></ul><h3>Disadvantages:</h3><ol><li>Complexity:</li></ol><ul><li>Explanation: Introducing factory classes and interfaces may add complexity to the codebase, especially for simple object creation scenarios.</li><li>Example: If your application only needs to create one type of document, using a factory pattern may introduce unnecessary overhead and complexity.</li></ul><ol><li>Abstraction Overhead:</li></ol><ul><li>Explanation: Creating separate factory classes/interfaces for every document type may lead to an overhead in terms of code volume and maintenance.</li><li>Example: If you have many different types of documents, each requiring its own factory class, it may result in a lot of boilerplate code.</li></ul><ol><li>Overhead for Small Projects:</li></ol><ul><li>Explanation: For small projects or simple document creation scenarios, using the Factory Pattern may introduce unnecessary overhead and complexity.</li><li>Example: If you’re building a small application that only needs to create a few types of documents, using a Factory Pattern may be overengineering.</li></ul><p>In summary, while the Factory Design Pattern offers advantages such as encapsulation, flexibility, code reusability, and decoupling, it may also introduce complexity and overhead, especially in small or simple projects. It’s essential to consider the specific requirements and scale of the project before deciding to use the Factory Pattern.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe20f3a19503" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Singleton design pattern in simple terms]]></title>
            <link>https://medium.com/@rihammisuk/singleton-design-pattern-in-simple-terms-4aa89e401310?source=rss-1e8014bce288------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aa89e401310</guid>
            <dc:creator><![CDATA[Bottle Company]]></dc:creator>
            <pubDate>Wed, 27 Mar 2024 12:07:08 GMT</pubDate>
            <atom:updated>2024-03-27T12:07:08.495Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3jj3HItkvcCE3sOaMlUgoQ.jpeg" /></figure><h3>What’s a Singleton?</h3><p>Imagine you have a special toy box that can only hold one toy at a time. No matter how many times you try to put another toy inside, it always keeps the first one you put in.</p><h3>How Does It Work?</h3><ol><li>Special Box (Class): The Singleton is like that special toy box. It’s a special class in your computer program that can only have one instance (or copy) of itself.</li><li>Only One Toy (Instance): Just like the toy box only holds one toy, the Singleton class only allows one instance of itself to exist.</li><li>Secret Key (Private Constructor): The Singleton class has a secret door (or private constructor) that only it can use. This door stops other parts of the program from making more copies of the Singleton.</li><li>Special Key to Open (Static Method): To get inside the special toy box, you need a special key. Similarly, to access the Singleton instance, you use a special method provided by the class. This method always gives you the same instance every time you ask for it.</li><li>No Clones Allowed (Thread Safety): The Singleton makes sure that no other parts of the program can make copies of itself, especially if many parts are trying to do it at the same time.</li></ol><h3>Example:</h3><p>Let’s say you have a magical candy machine (the Singleton). It can only give out one candy at a time, and it always gives out the same type of candy.</p><pre>using System;<br><br>// Special class that ensures only one instance of itself exists<br>public class MagicalCandyMachine<br>{<br>    // The single instance of the MagicalCandyMachine class<br>    private static MagicalCandyMachine instance;<br><br>    // Secret door that prevents direct creation of instances<br>    private MagicalCandyMachine() { }<br><br>    // Special method to get the single instance of MagicalCandyMachine<br>    public static MagicalCandyMachine GetInstance()<br>    {<br>        // If there&#39;s no instance yet, create one<br>        if (instance == null)<br>        {<br>            instance = new MagicalCandyMachine(); // Creation of the instance<br>        }<br>        return instance;<br>    }<br><br>    // Method to get candy from the magical candy machine<br>    public void GetCandy()<br>    {<br>        Console.WriteLine(&quot;Here&#39;s your magical candy!&quot;); // Output message<br>    }<br>}<br><br>class Program<br>{<br>    static void Main(string[] args)<br>    {<br>        // Get the single instance of MagicalCandyMachine<br>        MagicalCandyMachine candyMachine1 = MagicalCandyMachine.GetInstance();<br>        <br>        // Since we&#39;re getting the instance again, it should be the same instance as before<br>        MagicalCandyMachine candyMachine2 = MagicalCandyMachine.GetInstance();<br><br>        // Confirm that both references point to the same instance<br>        Console.WriteLine(object.ReferenceEquals(candyMachine1, candyMachine2)); // Output: True<br><br>        // Call the method to get candy from the magical candy machine<br>        candyMachine1.GetCandy(); // Output: Here&#39;s your magical candy!<br>    }<br>}</pre><h3>Explanation:</h3><ol><li>MagicalCandyMachine Class:</li></ol><ul><li>This is our special class that ensures only one instance of itself exists.</li><li>It has a private constructor, meaning no one outside the class can create new instances directly.</li></ul><ol><li>instance Field:</li></ol><ul><li>This static field holds the single instance of the MagicalCandyMachine class.</li></ul><ol><li>GetInstance() Method:</li></ol><ul><li>This static method is responsible for providing access to the single instance of the class.</li><li>It checks if an instance already exists. If not, it creates one.</li><li>It returns the existing instance or the newly created one.</li></ul><ol><li>GetCandy() Method:</li></ol><ul><li>This method represents some functionality of the class. In this example, it simply outputs a message.</li></ul><ol><li>Main Method:</li></ol><ul><li>Here, we demonstrate how to use the Singleton pattern.</li><li>We get two references (candyMachine1 and candyMachine2) to the same instance using the GetInstance() method.</li><li>We confirm that both references point to the same instance by comparing their references.</li><li>We call the GetCandy() method to demonstrate the functionality of the class.</li></ul><h3>Summary:</h3><p>The Singleton pattern ensures that only one instance of a class exists throughout the program’s execution. It achieves this by providing a static method to access the single instance and a private constructor to prevent direct instantiation. This pattern is useful when you need precisely one instance of a class to coordinate actions across the system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aa89e401310" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mediator design pattern in simple terms]]></title>
            <link>https://medium.com/@rihammisuk/mediator-design-pattern-in-simple-terms-e0ddfeaad04d?source=rss-1e8014bce288------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0ddfeaad04d</guid>
            <dc:creator><![CDATA[Bottle Company]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 07:47:36 GMT</pubDate>
            <atom:updated>2024-03-25T07:49:54.442Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is the Mediator Pattern?</h3><p>Imagine you have a group of friends planning a surprise party for another friend. Each person in the group has a specific role: someone is in charge of decorations, someone else handles food, another person is responsible for music, and so on. Instead of everyone talking to each other directly about every little detail, they communicate through a central coordinator, let’s say the “party planner”.</p><h3>How Does it Work?</h3><ol><li>Central Coordinator (Mediator): In our example, the “party planner” is like a mediator. This person doesn’t do all the tasks themselves but helps coordinate who does what. They know what each person is responsible for and can relay messages between them.</li><li>Individuals (Components): Each friend has a specific responsibility (like decorations, food, music). They don’t need to know every detail about what the others are doing. Instead, they tell the party planner what they need or what they’ve done, and the planner passes along relevant information to others.</li><li>Communication: Instead of friends talking directly to each other about every detail (which can get chaotic), they communicate through the party planner. For example, if the music person needs more speakers, they tell the planner, who then informs the person in charge of equipment.</li></ol><h3>Benefits:</h3><ul><li>Decoupling: Friends don’t need to know every detail about what others are doing. They focus on their own tasks and trust the party planner to handle communication.</li><li>Organization: By having a central coordinator, communication is streamlined. There’s less confusion, and everyone knows where to go for updates or to ask questions.</li></ul><h3>Example:</h3><ul><li>Real-world: In software development, different parts of a program (like user interface, database access, and business logic) often need to communicate. Instead of direct communication between them, the Mediator pattern can be used. For instance, a “chatroom” mediator can manage communication between users in a chat application.</li><li>Party Planner Example: Suppose Alice is in charge of decorations, Bob is handling food, and Charlie is managing music. Instead of Alice talking directly to Bob about food details or Charlie about music choices, they tell everything to the party planner, who relays messages between them.</li></ul><p>Let’s implement a simplified version of the Mediator pattern using C# and .NET Core. We’ll create a scenario where different components (friends) communicate through a central mediator (the party planner).</p><pre>using System;<br>using System.Collections.Generic;<br><br>// Mediator interface<br>public interface IPartyPlanner<br>{<br>    void RegisterParticipant(Participant participant);<br>    void SendMessage(Participant sender, string message);<br>}<br><br>// Concrete Mediator<br>public class PartyPlanner : IPartyPlanner<br>{<br>    private List&lt;Participant&gt; participants = new List&lt;Participant&gt;();<br><br>    public void RegisterParticipant(Participant participant)<br>    {<br>        participants.Add(participant);<br>    }<br><br>    public void SendMessage(Participant sender, string message)<br>    {<br>        Console.WriteLine($&quot;[{sender.Name}]: {message}&quot;);<br>        foreach (var participant in participants)<br>        {<br>            if (participant != sender)<br>            {<br>                participant.ReceiveMessage(message);<br>            }<br>        }<br>    }<br>}<br><br>// Participant interface<br>public abstract class Participant<br>{<br>    protected IPartyPlanner partyPlanner;<br>    public string Name { get; }<br><br>    public Participant(IPartyPlanner partyPlanner, string name)<br>    {<br>        this.partyPlanner = partyPlanner;<br>        Name = name;<br>    }<br><br>    public void Send(string message)<br>    {<br>        partyPlanner.SendMessage(this, message);<br>    }<br><br>    public abstract void ReceiveMessage(string message);<br>}<br><br>// Concrete Participant<br>public class Friend : Participant<br>{<br>    public Friend(IPartyPlanner partyPlanner, string name) : base(partyPlanner, name) { }<br><br>    public override void ReceiveMessage(string message)<br>    {<br>        Console.WriteLine($&quot;[{Name} received]: {message}&quot;);<br>    }<br>}<br><br>// Example usage<br>class Program<br>{<br>    static void Main(string[] args)<br>    {<br>        IPartyPlanner partyPlanner = new PartyPlanner();<br><br>        // Create participants<br>        var alice = new Friend(partyPlanner, &quot;Alice&quot;);<br>        var bob = new Friend(partyPlanner, &quot;Bob&quot;);<br>        var charlie = new Friend(partyPlanner, &quot;Charlie&quot;);<br><br>        // Register participants with the party planner (mediator)<br>        partyPlanner.RegisterParticipant(alice);<br>        partyPlanner.RegisterParticipant(bob);<br>        partyPlanner.RegisterParticipant(charlie);<br><br>        // Communication through the party planner<br>        alice.Send(&quot;Hi everyone! Let&#39;s plan the party.&quot;);<br>        bob.Send(&quot;Sure, I&#39;ll take care of food arrangements.&quot;);<br>        charlie.Send(&quot;I&#39;ll handle the music!&quot;);<br><br>        // Output:<br>        // [Alice]: Hi everyone! Let&#39;s plan the party.<br>        // [Bob received]: Hi everyone! Let&#39;s plan the party.<br>        // [Charlie received]: Hi everyone! Let&#39;s plan the party.<br>        // [Bob]: Sure, I&#39;ll take care of food arrangements.<br>        // [Alice received]: Sure, I&#39;ll take care of food arrangements.<br>        // [Charlie received]: Sure, I&#39;ll take care of food arrangements.<br>        // [Charlie]: I&#39;ll handle the music!<br>        // [Alice received]: I&#39;ll handle the music!<br>        // [Bob received]: I&#39;ll handle the music!<br>    }<br>}</pre><p>In this example:</p><ul><li>IPartyPlanner is the mediator interface, defining methods for registering participants and sending messages.</li><li>PartyPlanner is the concrete mediator that manages communication between participants.</li><li>Participant is the abstract class representing participants who communicate through the mediator.</li><li>Friend is a concrete participant class.</li><li>In the Main method, we create participants (Alice, Bob, and Charlie), register them with the party planner, and then simulate communication by having them send messages through the party planner.</li></ul><p>This example demonstrates how the Mediator pattern can be applied to facilitate communication between different components in a system.</p><h3>Summary:</h3><p>The Mediator pattern is like having a central coordinator (the mediator) who helps manage communication between different parts of a system. Instead of parts talking directly to each other, they communicate through the mediator, which simplifies communication and reduces dependencies.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0ddfeaad04d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>