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

2.1 KiB

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

  • Shared Kafka Seek-on-retry helper used by all scoring / indexing / notification consumers
  • NotificationPublisher: Seek + delay on transient failure (same as scorers)
  • Unit tests for Seek-retry behavior; keep PoisonPillGuard tests green
  • RabbitMQ prefetchCount: 1 on Escalation, ClinicalSync, DischargeSummary, LocalEscalation
  • DataLakeOptions.MaxBufferedEvents + pause/skip buffer when at cap after failed flush
  • 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).