<?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: M Nouman Berlas</title>
    <description>The latest articles on DEV Community by M Nouman Berlas (@noumanberlas).</description>
    <link>https://dev.to/noumanberlas</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4005344%2Fde51c1cf-d1fc-48ed-867b-4bf4194d8267.png</url>
      <title>DEV Community: M Nouman Berlas</title>
      <link>https://dev.to/noumanberlas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/noumanberlas"/>
    <language>en</language>
    <item>
      <title>HttpClient Socket Exhaustion</title>
      <dc:creator>M Nouman Berlas</dc:creator>
      <pubDate>Sat, 27 Jun 2026 13:00:21 +0000</pubDate>
      <link>https://dev.to/noumanberlas/httpclient-socket-exhaustion-3fln</link>
      <guid>https://dev.to/noumanberlas/httpclient-socket-exhaustion-3fln</guid>
      <description>&lt;p&gt;🔥 Your .NET API is Slowly Dying (And You Don't Even Know It)&lt;/p&gt;

&lt;p&gt;Last month, our production system started timing out randomly. No errors. No warnings. Just... slow death.&lt;br&gt;
After 3 sleepless nights and diving through 60+ microservices, I found the culprit:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
var client = new HttpClient(); // This single line&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Here's what was happening:&lt;br&gt;
Every HTTP call was creating a NEW TCP socket. Under load, we exhausted the system's connection pool. Requests started queuing. Response times went from 200ms to 30+ seconds.&lt;/p&gt;

&lt;p&gt;The Silent Killer:&lt;br&gt;
• ✅ Your code compiles fine&lt;br&gt;
• ✅ Your tests pass&lt;br&gt;
• ✅ It works in dev/staging&lt;br&gt;
• ❌ It crashes in production under real load&lt;/p&gt;

&lt;p&gt;The Fix That Saved Our SLA:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
// In Startup.cs&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;code&gt;services.AddHttpClient("MyService", client =&amp;gt; {&lt;br&gt;
    client.Timeout = TimeSpan.FromSeconds(120);&lt;br&gt;
})&lt;/code&gt;&lt;br&gt;
&lt;code&gt;.ConfigurePrimaryHttpMessageHandler(() =&amp;gt; new SocketsHttpHandler {&lt;br&gt;
    PooledConnectionLifetime = TimeSpan.FromMinutes(2),&lt;br&gt;
    PooledConnectionIdleTimeout = TimeSpan.FromMinutes(5),&lt;br&gt;
    MaxConnectionsPerServer = 20,&lt;br&gt;
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// In your service&lt;br&gt;
public class MyService {&lt;br&gt;
    private readonly IHttpClientFactory _clientFactory;    &lt;br&gt;
    public MyService(IHttpClientFactory clientFactory) {&lt;br&gt;
        _clientFactory = clientFactory;&lt;br&gt;
    }    &lt;br&gt;
    public async Task&amp;lt;string&amp;gt; GetDataAsync() {&lt;br&gt;
        var client = _clientFactory.CreateClient("MyService");&lt;br&gt;
        // Use the client&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The Results: &lt;br&gt;
📊 95% reduction in connection failures &lt;br&gt;
⚡ 40% improvement in throughput &lt;br&gt;
💰 Prevented potential revenue loss from timeouts&lt;/p&gt;

&lt;p&gt;The Lesson:&lt;br&gt;
IHttpClientFactory isn't just a "best practice" - it's a production survival tool.&lt;br&gt;
Microsoft documented this in 2018, but I still see this anti-pattern EVERYWHERE.&lt;br&gt;
Have you been bitten by socket exhaustion? &lt;/p&gt;

&lt;p&gt;Share your battle story in comments 👇&lt;/p&gt;

&lt;p&gt;#performance #dotnet #csharp #softwareengineering #productionissues #microservices #debugging #azure #performanceoptimization #lessonslearned #techleadership&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
      <category>networking</category>
      <category>performance</category>
    </item>
    <item>
      <title>Battle Stories Series</title>
      <dc:creator>M Nouman Berlas</dc:creator>
      <pubDate>Sat, 27 Jun 2026 12:40:11 +0000</pubDate>
      <link>https://dev.to/noumanberlas/battle-stories-series-2c50</link>
      <guid>https://dev.to/noumanberlas/battle-stories-series-2c50</guid>
      <description>&lt;p&gt;I will be writing about the real world instances that I have witnessed during my career from production issues. For almost all of the I have to spend the night figuring out the real cause and end up having to go through the team post mortem.&lt;br&gt;
Love to hear about your production experiences as well. The first story to be followed soon :)&lt;/p&gt;

</description>
      <category>performance</category>
    </item>
  </channel>
</rss>
