Your HttpClient is Broken: The IHttpClientFactory Playbook
🌐 Making HTTP Requests in .NET: Best Practices When developing API-driven services in .NET, the strategy used for managing HTTP communication is critical to application performance, reliability, and scalability. This document details the modern, recommended approach using IHttpClientFactory . HttpClient vs. IHttpClientFactory in Modern Architectures Historically, developers often instantiated HttpClient directly: C# using var client = new HttpClient(); // Use client to make a request While simple, this pattern is highly problematic in production environments, especially in microservice and high-load architectures. ⚠️ Common Pitfalls of Direct HttpClient Instantiation Pattern Issue Description new HttpClient() in a using block Socket Exhaustion Each new instance allocates a new HttpMessageHandler and potentially a new socket connection. While the HttpClient instance is disposed, the underlying socket may take time to ...