Files
vigilcare-clinical/docs/performance/phase-41-correctness-backpressure.md
Trent 68a2ab3204
CI / changes (push) Successful in 17s
CI / frontend (push) Skipped
CI / backend (push) Successful in 15m10s
Fix Kafka retry seek, bound buffers, and cut hot-path CPU/memory waste (Phases 41–44).
Stop consumers from committing past failed offsets, harden Rabbit/DataLake/gateway backpressure, dispose JsonDocument/MinIO correctly, and batch expensive DB/HTTP paths. Track progress in docs/performance.
2026-11-30 21:32:43 +08:00

48 lines
2.1 KiB
Markdown

# Phase 41 — Correctness & Backpressure
| Field | Value |
|-------|-------|
| Status | Complete |
| Audit findings | 1, 2, 3, 7 |
| Depends on | Docs roadmap |
## Goal
Stop silent Kafka message loss, make RabbitMQ channel use safe under concurrency, and hard-cap DataLake / gateway buffers so outages produce lag instead of OOM or unbounded disk growth.
## What exists
- Kafka consumers use `PoisonPillGuard` and log “will retry” but do not `Seek` after transient failure
- Escalation / clinical sync / discharge / local escalation use `prefetchCount: 5` with shared `IModel`
- `DataLakeWriterService` retains failed partition buffers while continuing to consume
- `BufferedSyncWriter.Enqueue` has no depth limit
## What to build
- [x] Shared Kafka Seek-on-retry helper used by all scoring / indexing / notification consumers
- [x] NotificationPublisher: Seek + delay on transient failure (same as scorers)
- [x] Unit tests for Seek-retry behavior; keep PoisonPillGuard tests green
- [x] RabbitMQ `prefetchCount: 1` on Escalation, ClinicalSync, DischargeSummary, LocalEscalation
- [x] `DataLakeOptions.MaxBufferedEvents` + pause/skip buffer when at cap after failed flush
- [x] Gateway sync buffer max depth (config) with reject when full (`SYNC_BUFFER_FULL`)
## Key files
- `VigilCareClinicalAPI/Infrastructure/PoisonPillGuard.cs`
- `VigilCareClinicalAPI/BackgroundServices/*ScoringService.cs`, `EsIndexerService.cs`, `NotificationPublisherService.cs`
- `VigilCareClinicalAPI/DataLake/DataLakeWriterService.cs`, `DataLakeOptions.cs`
- Rabbit workers under `BackgroundServices/Notifications/` and Ward `LocalEscalationWorkerService`
- `VigilCare.WardGateway/Services/BufferedSyncWriter.cs`
## Acceptance criteria
- Transient failure re-seeks to the same offset until success or intentional poison skip
- Rabbit workers with former prefetch 5 now use prefetch 1
- Forced MinIO / central outage: buffers plateau at configured caps
- Affected unit tests green
## Verification notes
- Added `KafkaConsumerRetry` + unit tests for Seek vs poison Commit.
- Consumers wired to helper; Rabbit prefetch set to 1; DataLake/Gateway caps configured (50_000 default).