Volume 4 · Chapter 10 — .NET Distributed Systems and Microservices Architecture

Observability and Production Operations

Goutham Mayaluri 9 min read .NETC#ILMicroservicesObservability

10.1 Introduction

Observability is the ability to understand a system’s internal state from its external outputs - logs, metrics, and traces. In distributed systems it is not optional, because a single business operation flows through many independent services and traditional single-process debugging cannot follow it. The three pillars work together: metrics say something is wrong, traces say where, and logs say why - correlated by a shared trace id. (Volume 7 and Volume 11 develop observability in depth.)

10.2 The Three Pillars

Metricsare aggregated numbers (request rate, error rate, latency percentiles, saturation) that tell you something is wrong and how bad.Tracesfollow one request across services as a tree of timed spans, localizing where the time or failure is.Logsare structured, detailed events that explain the cause. Together, correlated by a trace/correlation id, they make a distributed system diagnosable.

sequenceDiagram
  autonumber
  participant GW as Gateway (trace start)
  participant Cust as Customer Service
  participant Pay as Payment Service
  participant DB as Database
  GW->>Cust: request (traceparent: t1)
  Cust->>Pay: call (traceparent: t1)
  Pay->>DB: query (traceparent: t1)
  DB-->>Pay: rows
  Pay-->>Cust: result
  Note over GW,DB: One trace id t1 links every span into a single latency waterfall

10.3 Structured Logging and Correlation

Structured logging records events as machine-readable fields (not plain strings), and the single most valuable field is a correlation/trace id that ties every log line of one request together across services - so a single query returns the whole story of a failing request wherever it ran. Structured logs feed dashboards, alerts, and correlation.


// Structured logging with correlation - queryable fields, not strings.
_logger.LogInformation("Payment {PaymentId} for {Amount} completed in {Ms}ms",
    paymentId, amount, elapsedMs);   // TraceId is attached automatically via OpenTelemetry

10.4 OpenTelemetry and Distributed Tracing

OpenTelemetry provides vendor-neutral instrumentation for metrics, traces, and logs, with context propagation (the W3Ctraceparentheader) that stitches every service’s spans into one trace. This is how you see that a 900 ms request spent 820 ms in a downstream call. It exports to backends like Application Insights, Prometheus/Grafana, or Jaeger.


builder.Services.AddOpenTelemetry()
    .WithTracing(t => t.AddAspNetCoreInstrumentation().AddHttpClientInstrumentation().AddOtlpExporter())
    .WithMetrics(m => m.AddAspNetCoreInstrumentation().AddRuntimeInstrumentation().AddOtlpExporter());

10.5 Health, Alerting, and Troubleshooting

Health checks (liveness for “restart me if wedged,” readiness for “route traffic when able”) let orchestrators and load balancers act correctly. Alerts should fire on user-facing symptoms and SLO burn rate, not noisy low-level causes, to avoid alert fatigue. And troubleshooting follows the funnel: from customer impact to metrics (localize) to traces (find the failing span) to logs by trace id (explain), to root cause.

Senior Interview Question

Why are logs alone insufficient for a distributed system?

Logs are detailed but local and unaggregated, and in a distributed system a single business operation flows through many independent services, so logs alone can’t give you the system-level picture or follow a request end to end. Concretely: logs from one service tell you what happened in that service, but a request that touches the gateway, a customer service, a payment service, and a database produces separate log streams in each, and correlating them by timestamp across services to reconstruct one request’s journey is slow, error- prone, and often impossible at scale - you can’t easily see the whole path or where in it the failure or latency occurred. Logs also don’t give you aggregated, system-level signals: to know the overall error rate, latency trend, or throughput - “is something wrong, and how bad?” - you need metrics, which are aggregated numeric time series, not millions of individual log lines. And to see where in a multi-service request the time went or the failure happened, you need distributed tracing, which follows one request as a tree of timed spans across services, tied together by a shared trace id, so you can see, for example, that 90% of a slow request’s time was spent in one downstream call. That’s why observability rests on three complementary pillars: metrics tell you something is wrong and how severe (the “what/how much”), traces localize where in the distributed flow the problem is (the “where”), and logs explain the detailed cause (the “why”) - and they work together, correlated by a trace/correlation id so that from a metric alert you jump to the relevant trace and then to the exact log lines for that request across all services. Relying on logs alone leaves you blind to aggregate behavior and unable to follow cross-service causality, which is exactly what breaks down when a single operation spans many services - hence you need metrics and distributed tracing alongside structured, correlated logs to understand and debug a distributed system. The senior insight is that distributed systems require correlated, cross-service observability (metrics + traces + logs tied by a trace id), not just per-service logging, because the behavior you care about emerges from the interaction of many services and no single service’s logs can show it.

Principal Engineer Question

How do you design production observability for an enterprise microservices platform?

I design observability as a first-class platform capability standardized across every service, so that any request can be followed end to end and any team can diagnose an unfamiliar service, and I anchor it on the three correlated pillars with a shared trace id. Concretely: I standardize on OpenTelemetry across all services for metrics, traces, and logs, with a common instrumentation baseline (automatic ASP.NET Core, HttpClient, database, and messaging instrumentation plus key business metrics) so telemetry is consistent and context propagates across HTTP and messaging boundaries via the W3C traceparent standard - this is what stitches every service’s spans into one trace for a single request, including across async/message hops. Structured logging is mandatory and always includes the trace/correlation id, so logs for a failing request are one query away and can be correlated with its trace. I export to a central backend (Application Insights, or Prometheus/Grafana plus a tracing backend) so metrics, traces, and logs are aggregated and cross-linked in one place rather than siloed per service. I define SLIs and SLOs per service so alerting is symptom- and burn-rate-based - I alert on user-facing symptoms (error rate, latency against budget, SLO burn) rather than noisy low-level causes, to avoid alert fatigue, and I route non-actionable signals to dashboards, with alerts linked to runbooks. Every service ships with baseline RED (rate, errors, duration) dashboards and health checks (liveness for restart decisions, readiness for traffic routing) so orchestrators act correctly and any responder can navigate a service they didn’t build. I ensure correlation ids and tracing survive async and queue boundaries, not just synchronous HTTP, because in an event-driven system much of the flow is asynchronous. I treat telemetry cost and cardinality as a design constraint - sampling traces, keeping high-cardinality data out of metrics - so observability is affordable and not drowned in noise. And I make it a shared standard (often via a shared library) so improvements and fixes roll out everywhere at once, and so teams get correct observability by default rather than each reinventing it. The outcome I aim for is that any engineer can go from “an alert fired” to “this span in this service, here’s the log line” in minutes - following the funnel from metrics (localize) to traces (where) to logs by trace id (why) to root cause - across a system where a single business operation spans many services. And I feed post-incident reviews back in: gaps found become required instrumentation. So enterprise observability is standardized, correlated, cross-service telemetry (OpenTelemetry metrics/traces/logs with a shared trace id and context propagation including across async), centralized and cross-linked, driving symptom-based SLO alerting, with per-service dashboards and health checks, cost/cardinality managed, delivered as a shared platform capability - which is what makes an otherwise opaque distributed system diagnosable and operable, turning multi-hour cross-service investigations into minutes.

10.6 Banking Enterprise Scenario

A banking payment platform sees intermittent transaction failures across a multi-service workflow, where single-process debugging can’t follow the request. The team relies on correlation ids and OpenTelemetry distributed tracing to open a slow/failing transaction’s trace, sees 85% of the time in one downstream span, jumps to that span’s structured logs by trace id, and finds the failing dependency in minutes. SLO burn-rate alerts detected the issue, and correctly-separated liveness/readiness probes kept the degraded dependency out of rotation without restart storms - a distributed system made diagnosable by correlated observability.

Volume 4 Summary and Interview Rapid-Fire

  • Microservices fundamentals and when to use them
  • Service boundary design and database-per-service
  • Domain-driven design and bounded contexts
  • API gateway architecture
  • Inter-service communication and resilience
  • Messaging (queues, topics, DLQs, idempotency)
  • Event-driven architecture and the outbox
  • The saga pattern and compensation
  • Resilience and fault handling
  • Observability and production operations
Rapid-Fire Interview Question

Biggest microservices mistake?

The distributed monolith - services coupled by a shared database, lockstep deploys, or sync chains: all the cost of distribution, none of the independence.

Rapid-Fire Interview Question

Should microservices share a database?

No - database-per-service is the foundation of independence; sharing one couples them into a distributed monolith.

Rapid-Fire Interview Question

Bounded context vs microservice?

A bounded context is a business/model boundary; it usually maps to a microservice, but the mapping is a judgment call, not a rigid law.

Rapid-Fire Interview Question

Business logic in the API gateway?

No - gateways handle routing, auth, rate limiting, and aggregation; business logic belongs in the owning services.

Rapid-Fire Interview Question

REST/gRPC vs messaging?

Sync (REST/gRPC) for immediate responses; async messaging/events for decoupling, resilience, and state-change notifications.

Rapid-Fire Interview Question

Queue vs topic?

Queue = one consumer per message (work distribution); topic = every subscriber gets a copy (event broadcast).

Rapid-Fire Interview Question

Command vs event?

A command is an imperative request to one handler (rejectable); an event is a past-tense fact broadcast to many.

Rapid-Fire Interview Question

Why the outbox pattern?

It makes a state change and its event commit atomically (no lost/phantom events); consumers stay idempotent under at-least-once delivery.

Rapid-Fire Interview Question

Distributed transactions across services?

Avoid 2PC (blocking, coupling); use sagas - local transactions with compensation - plus outbox and idempotency.

Rapid-Fire Interview Question

Why not logs alone in microservices?

They’re per-service and can’t follow one request across many services - you need metrics (what) and traces (where) correlated by a trace id.