<?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 Berkay Yalçın on Medium]]></title>
        <description><![CDATA[Stories by Berkay Yalçın on Medium]]></description>
        <link>https://medium.com/@berkayyalcin?source=rss-990b4c847684------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YQiZPX6wUhw23lny.</url>
            <title>Stories by Berkay Yalçın on Medium</title>
            <link>https://medium.com/@berkayyalcin?source=rss-990b4c847684------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 04:43:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@berkayyalcin/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[Your .NET Microservices Will Fail: A Guide to Building Resilient and Observable Systems]]></title>
            <link>https://medium.com/@berkayyalcin/your-net-microservices-will-fail-a-guide-to-building-resilient-and-observable-systems-847bb1bb6dd7?source=rss-990b4c847684------2</link>
            <guid isPermaLink="false">https://medium.com/p/847bb1bb6dd7</guid>
            <category><![CDATA[circuit-breaker]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[polly]]></category>
            <dc:creator><![CDATA[Berkay Yalçın]]></dc:creator>
            <pubDate>Fri, 18 Jul 2025 22:08:04 GMT</pubDate>
            <atom:updated>2025-07-18T22:08:04.714Z</atom:updated>
            <content:encoded><![CDATA[<h3>Your .NET Microservices Will Fail: A Guide to Building Resilient and Observable Systems</h3><h3>Stop building “happy path” applications. Let’s dive into Polly and OpenTelemetry to create .NET 8 systems that can survive the chaos of the real world.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ABMEyvbhOpQi0lJALSZPg.jpeg" /></figure><p>There’s a fundamental truth every software architect eventually learns: <strong>everything fails.</strong> The network is unreliable, services crash, databases time out. A junior developer tries to prevent all failures. A senior developer anticipates them.</p><p>For years, we’ve built robust monoliths. But as we move to the distributed world of microservices, a failure in one small service can trigger a catastrophic domino effect, bringing down the entire system.</p><p>So, how do we build systems that don’t just work, but know how to gracefully fail and tell us exactly what went wrong?</p><p>In this guide, we’ll move beyond basic CRUD and explore the two pillars of production-ready systems, using a real .NET 8 Flight Booker microservice project as our example:</p><ol><li><strong>Resiliency ⛈️:</strong> Teaching our services to survive temporary failures using <strong>Polly</strong>.</li><li><strong>Observability 🕵️‍♂️:</strong> Giving ourselves the tools to understand <em>why</em> and <em>how</em> failures happen using <strong>Serilog</strong>, <strong>OpenTelemetry</strong>, and <strong>Seq</strong>.</li></ol><h3>Pillar 1: Resiliency — Surviving the Storm with Polly</h3><p>In our Flight Booker system, the Booking.API needs to call the Search.API to validate a flight before creating a booking. It’s a direct, synchronous HTTP call.</p><p>But what if the Search.API is restarting and is down for just 3 seconds? The booking request fails. The user gets an error. Game over.</p><p>This is where <strong>Polly</strong>, the .NET resilience and transient-fault-handling library, becomes your best friend. It allows you to wrap your operations in powerful “resilience policies.”</p><h3>The “Try, Try Again” Policy: Retry</h3><p>The simplest and most effective policy is the Retry pattern. Don’t fail on the first attempt. Wait a bit and try again.</p><p>Integrating this with IHttpClientFactory in the Booking.API&#39;s Program.cs is incredibly clean:</p><pre>// In Booking.API&#39;s Program.cs<br><br>builder.Services<br>    .AddHttpClient(&quot;SearchService&quot;, client =&gt; { /* ... */ })<br>    .AddPolicyHandler(GetRetryPolicy());<br><br>static IAsyncPolicy&lt;HttpResponseMessage&gt; GetRetryPolicy()<br>{<br>    // If the request fails, wait 1s, then 2s, then 4s before the next retry.<br>    return HttpPolicyExtensions<br>        .HandleTransientHttpError() // Handles 5xx, 408, or network issues<br>        .WaitAndRetryAsync(3, retryAttempt =&gt; TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),<br>            onRetry: (outcome, timespan, retryAttempt, context) =&gt;<br>            {<br>                Console.WriteLine($&quot;--&gt; Retrying... Attempt: {retryAttempt}, Wait: {timespan.TotalSeconds}s&quot;);<br>            });<br>}</pre><p>With this simple addition, our Booking.API is now resilient to temporary glitches in the Search.API.</p><h3>The “Smart Fuse” Policy: Circuit Breaker</h3><p>But what if the Search.API is completely down? Retrying a few times is good, but hammering a dead service indefinitely will just consume resources and create more problems.</p><p>This is where the <strong>Circuit Breaker</strong> pattern comes in. Like an electrical fuse, it “trips” after a certain number of consecutive failures.</p><pre>// Chaining the Circuit Breaker policy AFTER the Retry policy<br>builder.Services<br>    .AddHttpClient(&quot;SearchService&quot;, client =&gt; { /* ... */ })<br>    .AddPolicyHandler(GetRetryPolicy())<br>    .AddPolicyHandler(GetCircuitBreakerPolicy()); // New policy<br><br>static IAsyncPolicy&lt;HttpResponseMessage&gt; GetCircuitBreakerPolicy()<br>{<br>    // After 5 consecutive failures...<br>    return HttpPolicyExtensions<br>        .HandleTransientHttpError()<br>        .CircuitBreakerAsync(5, TimeSpan.FromSeconds(30),<br>            onBreak: (result, timespan) =&gt; {<br>                Console.WriteLine(&quot;--&gt; Circuit is now open! No requests for 30s.&quot;);<br>            },<br>            onReset: () =&gt; {<br>                Console.WriteLine(&quot;--&gt; Circuit is closed. Back to normal.&quot;);<br>            });<br>}<br></pre><p>Now, if the Search.API fails 5 times in a row, the circuit breaker opens. For the next 30 seconds, any attempt to book a flight will fail <em>instantly</em> without even making an HTTP call, protecting our Booking.API from a failing dependency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*1HQ64iECZpANnFlnMan0Cw.jpeg" /></figure><h3>Pillar 2: Observability — Seeing Inside the Chaos</h3><p>So, our system is now more resilient. But when a failure eventually happens, how do we debug it? Sifting through plain text logs from 5 different services is a nightmare.</p><p>This is where <strong>Observability</strong> comes in. Our goal is simple: when a user reports an error, we want to be able to find every single log entry, across every single service, related to their specific request in seconds.</p><h3>The Tools: Serilog &amp; OpenTelemetry</h3><ul><li><strong>Serilog:</strong> A structured logging library. Instead of writing plain text like &quot;Booking failed&quot;, it writes searchable JSON: {&quot;Timestamp&quot;: &quot;...&quot;, &quot;Level&quot;: &quot;Error&quot;, &quot;Message&quot;: &quot;Booking failed&quot;, &quot;FlightId&quot;: &quot;...&quot;}</li><li><strong>OpenTelemetry:</strong> The industry standard for distributed tracing. When a request first enters our system at the <strong>ApiGateway</strong>, OpenTelemetry assigns it a unique <strong>TraceId</strong>. This TraceId is then automatically passed along in the headers of every subsequent internal HTTP call and message queue event.</li></ul><h3>The Control Tower: Seq</h3><p>All our services are configured to send their structured logs to <strong>Seq</strong>, a centralized log server built for this purpose. When we put these two concepts together, magic happens.</p><p>Every log entry from every service, written by Serilog, is now automatically enriched with the TraceId from OpenTelemetry.</p><p>Imagine a user gets an error while booking. They give you a rough time. You open Seq and find their initial request log from the ApiGateway. You copy the TraceId. Then, you filter all logs in your entire system by that one TraceId.</p><p>The result is a perfectly ordered, chronological story of that one request’s journey through your entire microservice ecosystem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*A6RSxKkH86vx3jbVRaF4xw.jpeg" /></figure><p>By embracing resiliency with <strong>Polly</strong>, you build systems that can survive failures. By embracing observability with <strong>Serilog and OpenTelemetry</strong>, you build systems where failures are no longer mysteries, but diagnosable events.</p><p>Stop coding for the happy path. Start building for reality. That’s the mark of a senior engineer.</p><p><strong>Resources:</strong></p><ul><li><a href="https://github.com/App-vNext/Polly">Polly — .NET Resilience and Transient-Fault-Handling Library</a></li><li><a href="https://opentelemetry.io/docs/instrumentation/net/">OpenTelemetry .NET</a></li><li><a href="https://serilog.net/">Serilog — Structured Logging for .NET</a></li><li><a href="https://datalust.co/seq">Seq — Centralized Logging for .NET</a></li><li><a href="https://microsoft.github.io/reverse-proxy/">YARP — A Reverse Proxy for .NET</a></li><li><a href="https://masstransit.io/">MassTransit — Distributed Application Framework for .NET</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=847bb1bb6dd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>