<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Minaz Inamdar</title>
    <description>The latest articles on DEV Community by Minaz Inamdar (@inamdarminaz).</description>
    <link>https://dev.to/inamdarminaz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F956144%2F303e26a1-1d69-42ed-9e94-30aeb37b0061.jpg</url>
      <title>DEV Community: Minaz Inamdar</title>
      <link>https://dev.to/inamdarminaz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/inamdarminaz"/>
    <language>en</language>
    <item>
      <title>Distributed Systems Patterns</title>
      <dc:creator>Minaz Inamdar</dc:creator>
      <pubDate>Mon, 17 Jun 2024 02:45:53 +0000</pubDate>
      <link>https://dev.to/inamdarminaz/distributed-systems-patterns-3om6</link>
      <guid>https://dev.to/inamdarminaz/distributed-systems-patterns-3om6</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Notes via &lt;a href="https://www.youtube.com/watch?v=nH4qjmP2KEE"&gt;ByteByteGo&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Ambassador Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Pros:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simplifies communication between services.&lt;/li&gt;
&lt;li&gt;Handles load balancing, traffic routing, and retries transparently.&lt;/li&gt;
&lt;li&gt;Promotes decoupling of services.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Cons:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adds an additional layer, which can introduce latency.&lt;/li&gt;
&lt;li&gt;Requires configuration and management overhead.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Applications:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kubernetes uses Envoy as an Ambassador.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2. Circuit Breaker Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Pros:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prevents cascading failures and improves system resilience.&lt;/li&gt;
&lt;li&gt;Enhances fault tolerance by isolating failing components.&lt;/li&gt;
&lt;li&gt;Provides fallback mechanisms to maintain system stability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Cons:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Introduces complexity to manage circuit states.&lt;/li&gt;
&lt;li&gt;May impact performance during high load or transient failures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Applications:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Netflix's Hytrix library.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3. CQRS (Command Query Responsibility Segregation) Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Pros:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Optimizes read and write operations independently.&lt;/li&gt;
&lt;li&gt;Improves scalability and performance for read-heavy workloads.&lt;/li&gt;
&lt;li&gt;Facilitates complex business logic on the write side.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Cons:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increases architectural complexity.&lt;/li&gt;
&lt;li&gt;Requires careful synchronization between command and query models.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4. Event Sourcing Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Pros:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides a complete audit trail of system state changes.&lt;/li&gt;
&lt;li&gt;Enables temporal queries and historical analysis.&lt;/li&gt;
&lt;li&gt;Supports scalability and resilience through immutable event logs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Cons:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increased storage requirements due to storing all events.&lt;/li&gt;
&lt;li&gt;Requires efficient replay mechanisms for state rebuilds.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;5. Leader Election Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Pros:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Establishes a single point of coordination in distributed systems.&lt;/li&gt;
&lt;li&gt;Ensures high availability by quickly electing a new leader.&lt;/li&gt;
&lt;li&gt;Facilitates scalability and fault tolerance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Cons:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adds overhead due to election algorithms and heartbeat mechanisms.&lt;/li&gt;
&lt;li&gt;May introduce latency during leader changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Applications:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apache zookeeper.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;6. Publisher-Subscriber Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Pros:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Supports asynchronous and real-time messaging.&lt;/li&gt;
&lt;li&gt;Decouples publishers from subscribers, improving scalability.&lt;/li&gt;
&lt;li&gt;Facilitates event-driven architectures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Cons:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requires robust message delivery mechanisms to ensure reliability.&lt;/li&gt;
&lt;li&gt;May introduce complexity in managing message ordering and processing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;7. Sharding Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Pros:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Improves scalability by distributing data across multiple nodes.&lt;/li&gt;
&lt;li&gt;Enhances performance for read and write operations by reducing contention.&lt;/li&gt;
&lt;li&gt;Allows horizontal scaling by adding more shards.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Cons:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requires careful shard key selection and management.&lt;/li&gt;
&lt;li&gt;Increases complexity in data distribution and query routing.&lt;/li&gt;
&lt;li&gt;Introduces additional overhead for data rebalancing and maintenance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Applications:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cassandra and MongoDB&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>C# Interfaces</title>
      <dc:creator>Minaz Inamdar</dc:creator>
      <pubDate>Wed, 26 Oct 2022 18:49:08 +0000</pubDate>
      <link>https://dev.to/inamdarminaz/c-interfaces-5g6e</link>
      <guid>https://dev.to/inamdarminaz/c-interfaces-5g6e</guid>
      <description>&lt;h2&gt;
  
  
  Abstraction
&lt;/h2&gt;

&lt;p&gt;What does abstraction mean? In the simplest terms, it means hiding the convoluted implementations and exposing the crucial parts. But is that it?&lt;/p&gt;

&lt;p&gt;Well yeah, that's it. Thanks for reading.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28zw4koc37g5d2m4bqpi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28zw4koc37g5d2m4bqpi.png" alt="CoderMan" width="256" height="228"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Object-oriented programming takes inspiration from the real world. The way I think of it is by looking around. Look around you, and come up with three things that you know how to use but do not know how it works internally.&lt;br&gt;
I can name a few, a laptop, a smartphone, and a game controller.&lt;/p&gt;


&lt;h3&gt;
  
  
  Interface
&lt;/h3&gt;

&lt;p&gt;Interface is one way of achieving abstraction, the other being abstract class.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Interfaces will only show the capabilities of a class. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Interfaces have only method declarations, not method implementation 
(Update : they can now have default implementation read more here &lt;a href="https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/default-interface-methods-versions"&gt;Default Interface Method&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;The methods within the interface are always public by default.&lt;/li&gt;
&lt;li&gt;They cannot have fields, but they can have properties. &lt;/li&gt;
&lt;li&gt;Class implementing the interface must provide a definition for the interface's method with the same method signature.&lt;/li&gt;
&lt;li&gt;A single class can implement multiple interfaces. But extending multiple base classes are not allowed (&lt;a href="https://www.programmingwithshri.com/2018/09/what-is-diamond-problem-in-c.html"&gt;The Diamond Problem&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Interface Chaining
&lt;/h4&gt;

&lt;p&gt;When an Interface2 is implementing another Interface1, and class Dummy is implementing Interface2, class Dummy must provide implementation for all the members of both the interfaces.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://replit.com/@inamdarminaz/InterfaceChaning"&gt;https://replit.com/@inamdarminaz/InterfaceChaning&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
namespace InterfaceChaining{

  public interface Interface1
  {
      void Print1();
  }

  public interface Interface2 : Interface1 //chaining inheritance
  {
      void Print2();
  }

public class Dummy : Interface2
{
    // Implement Interface1 and Interface2 all members because Interface2 has chained inheritance from interface1
    public void Print1()
    {
        Console.WriteLine("Interface1.Print1();");
    }

    public void Print2()
    {
         Console.WriteLine("Interface2.Print2();");
    }
}
}


class Program {
  public static void Main (string[] args) {
    InterfaceChaining.Dummy dummy = new InterfaceChaining.Dummy();
    dummy.Print1();
    dummy.Print2();

   // We cannot create instance of an interface.
    //But an interface  reference variable can point to derieved class object.
    InterfaceChaining.Interface1 interface1 = new InterfaceChaining.Dummy();
    interface1.Print1();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explicit Interface
&lt;/h4&gt;

&lt;p&gt;Consider two interfaces (Interface1 and Interface2)  have same method name and signature. If these two interfaces are implemented by a single class then which method will it point to? Interface1's Print() or Interface2's Print()? &lt;/p&gt;

&lt;p&gt;To avoid this confusion, developers use explicit interfaces which will specify which interface's method will be called.&lt;/p&gt;

&lt;p&gt;Let's understand the ambiguity from below code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
namespace ExplicitInterface{

  public interface Interface1
  {
      void Print();
  }

  public interface Interface2
  {
      void Print();
  }

public class Dummy : Interface1, Interface2
{
//Since the below method is implementing both the interfaces
//there won't be an error here. But when this function is called
//from main() which interface method will it point to?

// To avoid abiguity we need to implement Explicit Interface
    public void Print()
    {
        Console.WriteLine("Which interface am I pointing to?");
    }
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This could solved by using explicit interfaces, by following these steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get rid of access modifiers.&lt;/li&gt;
&lt;li&gt;Set the method as "ReturnType InterfaceName.MethodName()"&lt;/li&gt;
&lt;li&gt;Access the methods using interface refrence variables.
&lt;a href="https://replit.com/@inamdarminaz/ExplicitInterfaces"&gt;https://replit.com/@inamdarminaz/ExplicitInterfaces&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public class Dummy : Interface1, Interface2
{
    void Interface1.Print()
    {
        Console.WriteLine("Interface1.Print();");
    }
    void Interface2.Print()
    {
        Console.WriteLine("Interface2.Print();");
    }
}
}


class Program {
  public static void Main (string[] args) {
    //But an interface  reference variable can point to derieved class object.
    ExplicitInterface.Interface1 interface1 = new ExplicitInterface.Dummy();
    interface1.Print();
    ExplicitInterface.Interface2 interface2 = new ExplicitInterface.Dummy();
    interface2.Print();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






</description>
      <category>csharp</category>
      <category>beginners</category>
      <category>interface</category>
    </item>
  </channel>
</rss>
