You are the engineer on call. Two tickets have come in against the order pipeline — an SQS FIFO queue feeding a Lambda consumer — plus one theory from the platform team.
Your job is triage and a minimal fix — not a rewrite.
OPS-882 — opened by Ama (Support)
Customers are getting their order confirmation email twice.
On a normal quiet day it is maybe one order in fifty. Nobody would have noticed except one of them replied to complain.
On a bad day it is not one in fifty. Tuesday morning we sent just over 400 confirmation emails for 51 orders. Tuesday was also the morning the payments provider was flapping, if that is relevant.
OPS-884 — opened by Dev (Ops)
When one order jams, everything stops. Not that customer's orders — everything, for every customer, in every region, until somebody goes into the console and purges the message by hand. We did it twice last week.
Second thing, and I do not understand it: our dead-letter queue has never had a single message in it. Not one, since we deployed in March. Orders definitely fail. Where are they going?
Comment on OPS-884 from Marcus (Platform), yesterday
This is a concurrency ceiling, nothing more. We have
reservedConcurrency: 2on the consumer, which is absurd for a queue this size. Take it to 50 and both of these tickets go away — the backlog will clear faster than a jam can build up. I can raise the PR this afternoon.
serverless.yml (the parts that matter):
service: order-pipeline
provider:
name: aws
runtime: nodejs22.x
region: eu-west-1
functions:
consumeOrders:
handler: src/consumer.handler
timeout: 120
memorySize: 1024
reservedConcurrency: 2
events:
- sqs:
arn: !GetAtt OrdersQueue.Arn
batchSize: 10
resources:
Resources:
OrdersQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: orders.fifo
FifoQueue: true
ContentBasedDeduplication: false
VisibilityTimeout: 30
MessageRetentionPeriod: 345600
OrdersDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: orders-dlq.fifo
FifoQueue: true
MessageRetentionPeriod: 1209600
RedrivePolicy:
deadLetterTargetArn: !GetAtt OrdersQueue.Arn
maxReceiveCount: 5
src/producer.ts:
import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
import { randomUUID } from "node:crypto";
import type { Order } from "./types";
const sqs = new SQSClient({});
const QUEUE_URL = process.env.ORDERS_QUEUE_URL!;
/**
* Publish an order for downstream processing. FIFO, because finance need
* an order's events to arrive in the order they happened.
*/
export async function publishOrder(order: Order): Promise<void> {
await sqs.send(
new SendMessageCommand({
QueueUrl: QUEUE_URL,
MessageBody: JSON.stringify(order),
MessageGroupId: "orders",
MessageDeduplicationId: randomUUID(),
})
);
}
src/consumer.ts:
import type { SQSEvent, SQSRecord } from "aws-lambda";
import { chargeCard } from "./payments";
import { reserveStock } from "./inventory";
import { sendConfirmationEmail } from "./email";
import { logger } from "./logger";
import type { Order } from "./types";
/**
* One order, end to end. Typically 400ms–1.5s. The payment provider's p99 is a
* lot worse than that — several seconds — and reserveStock retries internally.
*/
async function processOrder(order: Order): Promise<void> {
await chargeCard(order);
await reserveStock(order);
await sendConfirmationEmail(order);
logger.info("order processed", { orderId: order.id });
}
export async function handler(event: SQSEvent): Promise<void> {
logger.info("batch received", { count: event.Records.length });
for (const record of event.Records as SQSRecord[]) {
const order = JSON.parse(record.body) as Order;
await processOrder(order);
}
logger.info("batch complete", { count: event.Records.length });
}
A table, one row per reported symptom. There are three — treat the empty dead-letter queue as its own row.
| # | Symptom | Verdict | Cause |
|---|---|---|---|
| 1 | Duplicate confirmation emails | ||
| 2 | One bad order stops the whole pipeline | ||
| 3 | Dead-letter queue is always empty |
Verdict is exactly one of REAL or NOT A BUG. Cause is one line. If a symptom has more than one independent cause in this configuration, say so and name each — one of these does, and a single cause is a partial answer.
One paragraph on Marcus's concurrency proposal. Would raising reservedConcurrency to 50 change any of the three symptoms? Be specific about the mechanism, not the intent.
For each symptom you marked REAL:
Do not give me the whole file back. Minimal changes, reviewable in a diff.
At most two further defects nobody has reported, each one you can quote a line for.
If there is nothing else worth raising, write exactly Nothing else.
Every claim should be checkable against the files above or against documented AWS behaviour you can state precisely. If a fix depends on a specific documented rule about how these services interact, give the rule and the number — I am going to look it up. A confident diagnosis of a problem this configuration does not have costs you more than missing one it does.
| # | Symptom | Verdict | Cause |
|---|---|---|---|
| 1 | Duplicate confirmation emails | REAL | src/consumer.ts fails the entire SQS batch when any record fails, so successful messages in that batch are returned to the queue and reprocessed/emailed again. |
| 2 | One bad order stops the whole pipeline | REAL | Two independent causes: (a) src/producer.ts publishes every order to the same FIFO MessageGroupId: "orders", so one bad message blocks the only group; (b) the main OrdersQueue has no DLQ because the redrive policy is on OrdersDLQ, so the bad message never moves out automatically. |
| 3 | Dead-letter queue is always empty | REAL | serverless.yml puts the RedrivePolicy on OrdersDLQ targeting OrdersQueue, instead of putting it on OrdersQueue targeting OrdersDLQ. |
Raising reservedConcurrency to 50 would not change any of the three symptoms. For FIFO queues, Lambda processes messages in order per message group, and effective concurrency is bounded by the number of distinct message groups. Since every message is published with MessageGroupId: "orders", there is only one group, so only one batch can make progress at a time regardless of available concurrency. The duplicate emails come from whole-batch retries when the handler throws, not from a concurrency ceiling. The empty DLQ is caused by the redrive policy being on the wrong queue. So Marcus’s change would only remove a ceiling that is not the current bottleneck.
In src/consumer.ts, this is wrong:
export async function handler(event: SQSEvent): Promise<void> {
logger.info("batch received", { count: event.Records.length });
for (const record of event.Records as SQSRecord[]) {
const order = JSON.parse(record.body) as Order;
await processOrder(order);
}
logger.info("batch complete", { count: event.Records.length });
}
Replace it with:
export async function handler(event: SQSEvent): Promise<{ batchItemFailures: { itemIdentifier: string }[] }> {
logger.info("batch received", { count: event.Records.length });
const batchItemFailures: { itemIdentifier: string }[] = [];
const failedGroups = new Set<string>();
for (const record of event.Records as SQSRecord[]) {
const groupId = record.attributes?.MessageGroupId ?? record.messageId;
if (failedGroups.has(groupId)) {
batchItemFailures.push({ itemIdentifier: record.messageId });
continue;
}
try {
const order = JSON.parse(record.body) as Order;
await processOrder(order);
} catch (err) {
logger.error("order failed", { messageId: record.messageId, err });
batchItemFailures.push({ itemIdentifier: record.messageId });
failedGroups.add(groupId);
}
}
logger.info("batch complete", { count: event.Records.length, failures: batchItemFailures.length });
return { batchItemFailures };
}
Why: this tells the SQS event source mapping to delete the successful messages and only retry the failed/unprocessed ones, rather than returning the whole batch to the queue when one record throws.
In src/producer.ts, this is wrong:
MessageGroupId: "orders",
Replace it with:
MessageGroupId: order.id,
Why: each order gets its own FIFO message group, so a poisoned message blocks only that order’s group while preserving per-order ordering.
This symptom also needs the same serverless.yml redrive fix as Symptom 3 below; otherwise the bad message still never leaves OrdersQueue automatically.
In serverless.yml, this is wrong:
OrdersDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: orders-dlq.fifo
FifoQueue: true
MessageRetentionPeriod: 1209600
RedrivePolicy:
deadLetterTargetArn: !GetAtt OrdersQueue.Arn
maxReceiveCount: 5
Remove the RedrivePolicy block from OrdersDLQ, and add this equivalent block to OrdersQueue:
OrdersQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: orders.fifo
FifoQueue: true
ContentBasedDeduplication: false
VisibilityTimeout: 30
MessageRetentionPeriod: 345600
RedrivePolicy:
deadLetterTargetArn: !GetAtt OrdersDLQ.Arn
maxReceiveCount: 5
Why: a redrive policy must be on the source queue, not on the dead-letter queue. This makes failed messages move to OrdersDLQ after maxReceiveCount failed receives.
src/producer.ts line MessageDeduplicationId: randomUUID(), defeats FIFO deduplication because ContentBasedDeduplication is false and every send gets a fresh ID. If publishOrder is ever called twice for the same order, the second send is not deduplicated. Use a deterministic ID derived from the order or event, not a random UUID.