← back to blog
WINbackend4min readmin

SentinelAI v1: building an AIOps & automated incident diagnosis copilot in .NET 10

How I designed the first complete version of SentinelAI: event-driven ingestion with SQS, PII sanitization, fingerprint deduplication, Polly-protected AI RCA, CQRS and observability.

Matheus Nunes PereiraSoftware Engineer

When an error spikes in production, the problem is rarely a lack of data. The problem is noise: dozens of repeated stack traces, personal data leaking into exception messages, alerts arriving from different tools, and nobody knowing fast enough what broke and why.

That was the motivation behind the first version of SentinelAI, an AIOps and automated incident diagnosis copilot built in .NET 10.

Architecture in 4 pieces

From day one, I avoided putting everything inside a synchronous monolith. When a target application is experiencing an error spike, the last thing the event collector should do is block waiting on a database or an LLM.

POST /api/v1/events Webhooks Publish Long Polling PII + Fingerprint RCA + Polly CQRS Read + MTTR /metrics /metrics /metrics SampleTarget.Api Sentinel.Ingest.Api :5000 Grafana / CloudWatch SNS AWS SQS + DLQ Sentinel.Diagnostic.Worker PostgreSQL + Dapper Ollama / Heuristic Sentinel.Query.Api :5200 Prometheus Grafana :3000

Each service has a single responsibility:

  1. Sentinel.Ingest.Api (:5000): a lean write/ingestion entry point. It accepts native events (POST /api/v1/events) and external webhooks (Grafana and AWS CloudWatch/SNS via IAlertAdapter), validates the basics, and publishes to SQS without touching PostgreSQL.
  2. Sentinel.Diagnostic.Worker: consumes the queue in the background, runs PII sanitization, computes a deterministic fingerprint, deduplicates the incident in PostgreSQL via Dapper, generates a Root Cause Analysis (RCA) with Microsoft.Extensions.AI, and triggers notifications.
  3. Sentinel.Query.Api (:5200): a dedicated CQRS read API. It filters incidents by service, severity, and status, serves event timelines + RCA, and resolves incidents while calculating MTTR (resolved_at - first_seen_at).
  4. Sentinel.SampleTarget.Api (:5100): a demo target API instrumented with Sentinel.Client and OpenTelemetry, including a simulated checkout flow for realistic failure testing.

Design decisions that mattered

1. Privacy before AI (PII sanitization)

Sending raw exceptions to an LLM or storing them directly in a database is a fast way to leak sensitive data. Before persisting any event or building a diagnosis prompt, CompositePiiSanitizer redacts patterns such as emails, tax IDs, and credentials.

2. Deduplication over alert fatigue

A database timeout during a traffic spike produces hundreds of identical exceptions in seconds. IncidentFingerprinter computes a deterministic hash from service, environment, exception type, and endpoint. In PostgreSQL, IncidentRepository groups open occurrences by incrementing occurrence_count instead of flooding operators with duplicate incidents.

3. Resilience around AI (Polly + Fallback)

Local LLMs (Ollama) or external providers can become slow or unavailable. Diagnosis in the worker is wrapped in a Polly resilience pipeline (timeout, retry, circuit breaker) with a heuristic fallback — if AI fails, incidents are still recorded, deduplicated, and tracked.

4. True CQRS and input adapters

Before

Coupled flow

  • Ingestion and queries sharing the same service
  • Only proprietary event payloads supported
  • Docker infra + manual dotnet run for every service
After

Modular v1

  • Ingest.Api only enqueues; Query.Api only reads and resolves (MTTR)
  • IAlertAdapter unifying Sentinel.Client, Grafana, and CloudWatch SNS
  • Multi-stage Dockerfiles for the full stack in docker compose up -d
Evolution of responsibility boundaries

End-to-end flow

  1. A checkout request fails

    in SampleTarget.Api due to a payment gateway timeout, with customer email and document in the error message.
  2. Sentinel.Client captures the exception asynchronously

    (without blocking the HTTP response) and ships it to Ingest.Api.
  3. Ingest.Api enqueues to SQS

    the exact same pipeline used by alerts arriving from Grafana and CloudWatch webhooks.
  4. Diagnostic.Worker processes the event

    scrubs PII, computes the fingerprint, deduplicates repeated occurrences in PostgreSQL, and stores the JSON RCA.
  5. Query.Api exposes the incident

    with timeline, severity, and root cause, allowing resolution via PATCH /api/v1/incidents/{id}/resolve and MTTR tracking in /stats.

What I learned building v1

  • Separating reads from writes pays off early: keeping Ingest.Api free of database dependencies simplifies scaling, testing, and fault isolation.
  • Day-zero observability avoids blind debugging: exposing /metrics via OpenTelemetry across all three APIs and wiring Prometheus + Grafana immediately surfaced request rates and 5xx spikes during load tests.
  • Testcontainers integration tests build real confidence: validating SQL, JSONB, deduplication, and MTTR math against a real PostgreSQL 16 container catches issues in-memory mocks hide.

The full source code is available on GitHub at matpdev/SentinelAI.

In this post
Written by Matheus Nunes PereiraSoftware Engineer. Distributed systems, real-time telemetry and software that talks to hardware. If you have a problem like that, let’s talk.Software Engineer

Distributed systems, real-time telemetry and software that talks to hardware. If you have a problem like that, let’s talk.