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 Hands-On Projects Made Easy
Recommended Book

Visual Studio 2026 Hands-On Projects Made Easy

Build Real C# and .NET 10 Applications with Step-by-Step Screenshots, Databases, APIs, Testing, Deployment, and AI Tools