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.
Each service has a single responsibility:
Sentinel.Ingest.Api(:5000): a lean write/ingestion entry point. It accepts native events (POST /api/v1/events) and external webhooks (GrafanaandAWS CloudWatch/SNSviaIAlertAdapter), validates the basics, and publishes to SQS without touching PostgreSQL.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) withMicrosoft.Extensions.AI, and triggers notifications.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).Sentinel.SampleTarget.Api(:5100): a demo target API instrumented withSentinel.Clientand 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
Coupled flow
- Ingestion and queries sharing the same service
- Only proprietary event payloads supported
- Docker infra + manual
dotnet runfor every service
Modular v1
Ingest.Apionly enqueues;Query.Apionly reads and resolves (MTTR)IAlertAdapterunifyingSentinel.Client, Grafana, and CloudWatch SNS- Multi-stage Dockerfiles for the full stack in
docker compose up -d
End-to-end flow
A checkout request fails
inSampleTarget.Apidue to a payment gateway timeout, with customer email and document in the error message.Sentinel.Client captures the exception asynchronously
(without blocking the HTTP response) and ships it toIngest.Api.Ingest.Api enqueues to SQS
the exact same pipeline used by alerts arriving from Grafana and CloudWatch webhooks.Diagnostic.Worker processes the event
scrubs PII, computes the fingerprint, deduplicates repeated occurrences in PostgreSQL, and stores the JSON RCA.Query.Api exposes the incident
with timeline, severity, and root cause, allowing resolution viaPATCH /api/v1/incidents/{id}/resolveand MTTR tracking in/stats.
What I learned building v1
- Separating reads from writes pays off early: keeping
Ingest.Apifree of database dependencies simplifies scaling, testing, and fault isolation. - Day-zero observability avoids blind debugging: exposing
/metricsvia OpenTelemetry across all three APIs and wiring Prometheus + Grafana immediately surfaced request rates and5xxspikes 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.

