Q: You have an SQS queue triggering a Lambda function to encode massive video files. Sometimes a video takes 8 minutes to encode. You randomly notice the exact same video being encoded simultaneously by two different Lambda functions. Why?
The SQS Visibility Timeout is misconfigured.
Want to master this scenario in a live sandbox? Stephane Maarek's AWS Certified DevOps Engineer Professional Masterclass on Udemy covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "In our AWS cloud environment, we managed high-traffic microservices where this exact scenario occurred. The interviewer is testing: SQS Visibility Timeout.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Production Solution & Architecture
The SQS Visibility Timeout is misconfigured. When a Lambda polls SQS, the message doesn't delete immediately; it becomes "invisible" to other consumers for the duration of the Visibility Timeout (default 30 seconds). Because the video encode takes 8 minutes, the 30-second timeout expires mid-encode. SQS assumes the first Lambda quietly crashed, making the message instantly visible again. A second Lambda picks up the identical message and starts encoding it. *Fix:* You must increase the SQS Visibility Timeout to be strictly greater than the maximum theoretical runtime of the Lambda function (e.g., set it to 10 minutes, or 600 seconds).
- Immediate Triage: The SQS Visibility Timeout is misconfigured.
- Run targeted verification commands before modifying configuration.
- Automate permanent guardrails (CI check, alerts, IaC policy) to prevent recurrence.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Subscribing an Amazon SQS queue to an SNS topic without attaching an explicit queue access policy when configuring queue triggering Lambda
SNS lacks permission to write to SQS by default; without an IAM resource policy granting
sqs:SendMessageto the topic ARN, messages drop silently. -
Confusing standard SQS queues with FIFO queues regarding strict ordering and deduplication when configuring queue triggering Lambda
Standard SQS provides at-least-once delivery with best-effort ordering; strict FIFO ordering requires
MessageGroupIdand deduplication IDs. -
Using short polling instead of SQS long polling (
WaitTimeSeconds: 20) in high-volume consumers when configuring queue triggering Lambda Short polling queries single partition subsets and returns empty responses, dramatically inflating AWS API billing and consumer CPU usage. -
Failing to monitor
ApproximateNumberOfMessagesVisibleandApproximateAgeOfOldestMessagein CloudWatch when configuring queue triggering Lambda Queue depth and message age are primary SLI signals for consumer backlog saturation, far superior to consumer CPU utilization.