A STAR story for an Azure Service Bus (or similar) backlog with poison messages: queue metrics, throughput maths, dead-letter analysis, safe replay, idempotency and alerting.
Our [invoice queue] on Azure Service Bus grew to [300,000] messages and invoices were [hours] late. I checked two things: throughput maths (arrivals [50/s] vs processing [30/s] with [4] consumers) and the dead-letter queue, which was filling with messages that had hit MaxDeliveryCount. A [schema change upstream] made some messages throw on every attempt; each one was retried [10] times, eating consumer capacity. I shipped a fix that dead-letters non-transient errors immediately, scaled consumers within what [SQL] could take, and replayed the DLQ after fixing the parser, relying on idempotent handlers. Backlog drained in [3 hours], no messages lost. The trade-off: scaling consumers drains faster but can overload the database, so I capped concurrency.
"At [company], our [invoice-processing worker] read from an Azure Service Bus queue. One [Monday] customers reported invoices taking [hours] to appear. The active message count was at [300,000] and the oldest message was [four hours] old. Nobody had been alerted because we only alerted on exceptions, and the worker wasn't crashing.
I looked at two things. First, throughput: about [50] messages a second arriving, and our [four] consumers processing about [30] a second, when normally they did [70]. So capacity had dropped, not just demand going up. Second, the dead-letter queue had [8,000] messages with the reason MaxDeliveryCountExceeded. [An upstream team] had added an optional field with a different date format, our deserialiser threw, and each bad message was retried ten times with a lock-duration wait between attempts. Those retries were eating about half our capacity.
I shipped a small fix the same morning: catch deserialisation and validation errors and dead-letter the message immediately with a clear reason instead of retrying it. Throughput went straight back up. I scaled to [8] consumers, but capped concurrency at what [Azure SQL] could handle. Then I fixed the date parsing, tested it against a sample of the dead letters, and replayed them in batches; our handlers were idempotent on invoice id, so replays were safe. The backlog drained in about [three] hours with nothing lost. Afterwards we added alerts on message age and DLQ count, KEDA scaling on queue length, and a contract test with [the upstream team]. My takeaway: a backlog is a maths problem first, and poison messages are the usual hidden term in the equation."
| Observation | Likely cause |
|---|---|
| Processing rate normal, arrivals up | Capacity: scale consumers or optimise handler |
| Processing rate down, DLQ growing, same message ids retried | Poison messages wasting capacity |
| Processing rate down, handler duration up | Slow downstream (SQL, HTTP) |
| Consumers idle, queue growing | Consumer not running, lock lost, or wrong subscription filter |
| Feature | Role |
|---|---|
MaxDeliveryCount (default 10) |
After N failed deliveries, message moves to DLQ |
DeadLetterMessageAsync(reason, description) |
Explicit dead-lettering for non-transient errors |
| Lock duration / lock renewal | Prevents duplicate processing while working |
MaxConcurrentCalls, prefetch |
Consumer concurrency |
DLQ path queue/$deadletterqueue |
Inspect and resubmit |
Template: [invoice queue] backlog [300k], oldest [4 h]; DLQ [8k] from [date-format change]; immediate dead-lettering restored [70 msg/s] per [4] consumers; replay of DLQ after fix; drained in [3 h]; [0] messages lost.
Checks whether you understand at-least-once messaging, can reason about rates and capacity, separate poison messages from load, and clear a backlog without losing or duplicating work.
Green flags
Red flags
This checks messaging fundamentals (at-least-once delivery, retries, dead-lettering, idempotency) and quantitative thinking (rates, capacity, drain time). It also checks that you protect data: no purging of the DLQ, safe replay.
Backlog growth = arrival rate - processing rate
Processing rate = consumers x concurrency / handler time
Drain time = backlog / (processing rate - arrival rate)
Example: 300,000 backlog; arrivals 50/s; processing after fix 140/s
Drain time = 300,000 / (140 - 50) = ~3,300 s = ~55 min (longer at peak)
Poison messages subtract capacity: each one costs MaxDeliveryCount handler attempts plus waits.
Service Bus peek-lock gives at-least-once delivery. A message is redelivered when the lock expires or the handler abandons it; after MaxDeliveryCount it moves to the DLQ. Because duplicates can happen anyway, handlers must be idempotent (dedupe on a business key, upserts, or an inbox table). That idempotency is what makes DLQ replay safe.
STAR, with the maths as one crisp sentence in the Action. CAR for a short version.
Weak: "we scaled up the workers." Good: found the poison messages. Strong: did the maths, separated poison from capacity, replayed safely. Excellent: added message-age alerting, explicit dead-lettering policy and a contract test with the producer.
Also answers "a time you worked across teams" (the upstream schema change), "a time you used data" (the maths) and "a time you improved monitoring". Non-technical version: "A batch of broken messages kept being retried and clogged the queue; I set them aside, fixed the bug, and processed them once it was safe."
DeadLetterMessageAsync for a validation exception and compare throughput.The handler change: dead-letter non-transient failures at once, let transient ones retry.
using Azure.Messaging.ServiceBus;
namespace Invoicing.Worker;
public sealed class InvoiceProcessor(ServiceBusClient client, IInvoiceService invoices, ILogger<InvoiceProcessor> log)
: BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await using var processor = client.CreateProcessor("invoices", new ServiceBusProcessorOptions
{
MaxConcurrentCalls = 16, // capped at what Azure SQL can absorb
AutoCompleteMessages = false,
PrefetchCount = 32
});
processor.ProcessMessageAsync += async args =>
{
try
{
var message = args.Message.Body.ToObjectFromJson<InvoiceRequested>()
?? throw new InvalidDataException("Empty body");
await invoices.CreateIfNotExistsAsync(message, args.CancellationToken); // idempotent on InvoiceId
await args.CompleteMessageAsync(args.Message, args.CancellationToken);
}
catch (Exception ex) when (ex is JsonException or InvalidDataException)
{
// Non-transient: retrying ten times only wastes capacity.
log.LogWarning(ex, "Dead-lettering {MessageId}", args.Message.MessageId);
await args.DeadLetterMessageAsync(args.Message, "InvalidPayload", ex.Message, args.CancellationToken);
}
// Other exceptions propagate: the message is abandoned and retried up to MaxDeliveryCount.
};
processor.ProcessErrorAsync += args =>
{
log.LogError(args.Exception, "Service Bus error {Source}", args.ErrorSource);
return Task.CompletedTask;
};
await processor.StartProcessingAsync(stoppingToken);
await Task.Delay(Timeout.Infinite, stoppingToken).ContinueWith(_ => { });
await processor.StopProcessingAsync();
}
}
public sealed record InvoiceRequested(Guid InvoiceId, Guid CustomerId, decimal Amount, DateOnly DueDate);
STAR template
S: [Worker] on [Service Bus / RabbitMQ]; [arrival rate]; backlog [N], oldest [age].
T: I [owned / was on call for] clearing it without losing messages.
A: Maths: [arrivals vs processing]; DLQ showed [reason]; [dead-letter immediately]; scaled to [N] within [limit];
fixed [bug]; replayed DLQ (idempotent handlers); added [alerts, KEDA, contract test].
R: Drained in [N h]; [0] lost; no backlog incidents in [period].
Illustrative only: invoice queue, 300k backlog; date-format change upstream; drained in ~3 h.
The senior signal is quantitative reasoning plus data safety: you did the rate maths to separate capacity from failure, protected every message, and fixed the system (dead-letter policy, alerts on age, autoscaling with a cap, a contract with the producer).
How the numbers drove the decisions. Units matter: work in messages per second. Processing had dropped from [70/s] to [30/s] while arrivals were a normal [50/s]: a capacity drop, so scaling first would only have hidden the failing work and pushed more load at SQL. After the dead-letter fix, processing was [140/s] with [8] replicas; at the [50/s] daytime peak that drains [300,000] in about 300,000 / 90 โ [55] minutes, and faster in the evening when arrivals fall to [10/s]. That told me the backlog would clear the same day without more replicas than SQL could take.
Proactive monitoring for queues is what stops the next one: oldest-message age as the customer-facing SLO (for example, 95% of invoices processed within [5] minutes), processing rate versus arrival rate, DLQ count and growth, and failures per message type on a dashboard next to the consumer's dependencies.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Scale consumers (KEDA) | Healthy handler, more load | Downstream pressure, cost | Poison messages or slow downstream |
| Dead-letter non-transient errors | Validation/deserialisation failures | Needs DLQ handling process | Transient errors |
| Optimise handler (batching, fewer round trips) | Handler time dominates | Engineering time | Short-lived spike |
| Replay tool for DLQ | After fix | Must be idempotent | Without root-cause fix |
| Contract tests / schema registry | Cross-team payloads | Coordination | Single-team internal queue |
First I work out which problem I have:
To tell them apart I use Service Bus metrics (incoming, completed, abandoned, dead-lettered), the DLQ's DeadLetterReason and DeadLetterErrorDescription, DeliveryCount, and traces grouped by exception.
Poison messages loop when handlers catch and abandon forever, re-publish failures as new messages, or MaxDeliveryCount is huge. The fix: dead-letter permanent failures immediately, fix the handler or data, then resubmit from the DLQ in batches to an idempotent consumer. Scale consumers only up to the downstream's limit. To prevent it: alerts on oldest message age and DLQ count, plus a poison-message test. The trade-off: dead-lettering early keeps the queue flowing, but someone must own the DLQ.
A queue only grows when the arrival rate is higher than the service rate, so I measure both: incoming versus completed messages per second. Service rate is consumers ร concurrency รท handler time: 4 pods ร 8 concurrent ร (1 รท 0.4 s) is 80 messages/s, and if business hours bring 120/s the backlog grows by 40 every second until the evening. Little's law turns the backlog into a delay customers feel: 400,000 รท 80 โ 83 minutes. Before scaling I find where the 400 ms goes; often it's per-message database round trips or a slow partner call. Scaling out works until the bottleneck moves downstream or ordering caps it; fixing the handler (batching, concurrency, fewer calls) is usually cheaper. I separate poison messages, and alert on oldest-message age, not count.
Three things make a queue worker safe on Kubernetes or Container Apps. Graceful shutdown: on SIGTERM the host cancels stoppingToken. The worker stops receiving and finishes or abandons in-flight messages within HostOptions.ShutdownTimeout, which must be shorter than terminationGracePeriodSeconds. Idempotency: Service Bus peek-lock is at-least-once. A crash, a lock expiry or a shutdown redelivers the message, so the handler records the message id in a processed-messages table in the same transaction as the business change, and passes idempotency keys to the payment provider. Poison messages go to the dead-letter queue after MaxDeliveryCount. Scaling: a KEDA ScaledObject (or a Container Apps scale rule) on queue length adds pods as the backlog grows and scales to zero or a minimum when idle.
The trade-off: more replicas clear backlogs faster but multiply concurrency against downstream systems and break ordering unless you use sessions.
How to tell it (STAR)
**S:** At [company], our [invoice worker] on Azure Service Bus fell [four hours] behind with a backlog of [300,000] messages, and customers noticed before we did. **T:** As [the senior engineer on the team] I needed to clear it without losing or duplicating invoices. **A:** I compared arrival and processing rates and saw our capacity had halved; the dead-letter queue showed why: an upstream format change made some messages fail ten times each. I shipped a change to dead-letter bad payloads immediately, scaled out within what the database could take, fixed the parsing, and replayed the dead letters safely because our handlers were idempotent. Then I added alerts on message age, capped autoscaling, and a contract test with [the upstream team]. **R:** The backlog drained in about [three] hours with [zero] messages lost, and we've had [no] backlog incidents in [N] months.
Last updated 23 Nov 2026.