perf(notification-outbox): bounded parallel delivery within a dispatch sweep (default 4)

This commit is contained in:
Joseph Doherty
2026-07-09 09:41:48 -04:00
parent acd8a6b8b5
commit 6567216e14
4 changed files with 216 additions and 26 deletions
@@ -48,4 +48,23 @@ public class NotificationOutboxOptions
/// Default: 1 minute.
/// </summary>
public TimeSpan DeliveredKpiWindow { get; set; } = TimeSpan.FromMinutes(1);
/// <summary>
/// Maximum number of notifications delivered concurrently within a single dispatch
/// sweep. Delivery is I/O-bound (SMTP / Twilio round trips of seconds each), so a
/// purely sequential sweep caps throughput at ~1/attempt-latency regardless of batch
/// size — an alarm storm queued behind one slow SMTP host would drain far too slowly
/// (arch-review 04). Each concurrent delivery runs on its own DI scope/repository, so
/// there is no shared-DbContext contention. Set to <c>1</c> to preserve the strictly
/// sequential behaviour. Clamped to a minimum of 1 via <see cref="ResolvedMaxParallelDeliveries"/>.
/// Default: 4.
/// </summary>
public int MaxParallelDeliveries { get; set; } = 4;
/// <summary>
/// Resolves the effective delivery parallelism, clamped to at least 1 so a
/// misconfigured <c>0</c>/negative value cannot stall the dispatcher (a zero-count
/// semaphore would deadlock the sweep).
/// </summary>
public int ResolvedMaxParallelDeliveries => MaxParallelDeliveries < 1 ? 1 : MaxParallelDeliveries;
}