Lesson 22 of 40 Architecture Expert 65 min

Microservices Architecture

Design and implement a microservices system with service discovery, API gateways, event-driven communication, and distributed tracing.

Part 1: Service Communication Patterns

PatternUse WhenTechnology
SynchronousImmediate response neededgRPC, HTTP
Async MessagingDecouple servicesAzure Service Bus, RabbitMQ
Event StreamingEvent log, replayApache Kafka, Azure Event Hub

Part 2: Yarp API Gateway

// appsettings.json - YARP config
{
  "ReverseProxy": {
    "Routes": {
      "orders-route": {
        "ClusterId": "orders-cluster",
        "Match": { "Path": "/api/orders/{**catch-all}" }
      }
    }
  }
}

Part 3: Resilience with Polly v8

builder.Services.AddHttpClient<OrderClient>()
  .AddResilienceHandler("pipeline", pipeline =>
  {
    pipeline.AddRetry(new() { MaxRetryAttempts = 3 });
    pipeline.AddCircuitBreaker(new() { FailureRatio = 0.5 });
    pipeline.AddTimeout(TimeSpan.FromSeconds(10));
  });

Part 4: OpenTelemetry Distributed Tracing

builder.Services.AddOpenTelemetry()
  .WithTracing(b => b
    .AddAspNetCoreInstrumentation()
    .AddEntityFrameworkCoreInstrumentation()
    .AddOtlpExporter());

// Traces appear in Aspire Dashboard / Jaeger / Zipkin
VISUAL STUDIO 2026 MADE EASY
Recommended Book

VISUAL STUDIO 2026 MADE EASY

Build real applications with C#, VB.NET, Python, JavaScript, C++, and .NET 10. A practical companion for mastering Visual Studio 2026 step by step.