Last reviewed: November 24, 2026 (UTC and Asia/Shanghai). Official references were retrieved November 24, 2026 at 00:10 UTC.

Direct answer

Measure idle Amazon SQS polling before changing an AI worker’s concurrency. Start with the NumberOfEmptyReceives CloudWatch metric and an application counter for all ReceiveMessage calls. Then replace tight short polling with long polling, use a WaitTimeSeconds value up to the documented 20-second maximum, and set the HTTP response timeout above that wait. Compare empty receives with visible backlog, message age, and model-attempt records.

This separates two costs that are often mixed together. An empty SQS receive is transport overhead; it is not proof that an AI request happened. A successful model call, a retry, or a duplicate delivery needs its own attempt record and usage reconciliation. Long polling can reduce empty SQS responses and request volume, but it does not authorize or suppress model calls by itself.

Who this is for

This guide is for platform engineers and FinOps owners running direct SQS consumers that dispatch AI work. It is especially useful when a worker loops continuously, the queue is quiet for long periods, and the team sees request growth without a matching increase in completed jobs. The examples use a standard queue and a controlled application adapter. A Lambda SQS event source mapping has its own polling and batching controls; do not assume an SDK setting in a separate consumer changes Lambda’s behavior.

No AWS queue, deployment, authenticated model request, or billing experiment was run for this article. The configuration steps below are an operator plan derived from current AWS references. Validate them in a disposable queue and compare observed metrics before changing production capacity.

Key takeaways

  • Count ReceiveMessage calls, empty calls, messages received, and model attempts as separate quantities.
  • Every SQS API action belongs in request accounting, so a quiet consumer can create request volume even when no AI work is admitted.
  • Long polling waits for a message or the wait limit, reducing empty and false-empty responses compared with short polling.
  • NumberOfEmptyReceives is a tuning signal; use application counters and billing evidence before treating it as an invoice total.
  • More consumers can increase idle request pressure. Scale from backlog and age, not from an empty-loop rate alone.

Contract details to verify

Count each receive before calculating savings

The Amazon SQS pricing page says that every SQS API action counts as a request. A request can carry up to 10 messages and a total payload of 1 MiB, while payload chunks are metered in 64 KiB units. For an empty ReceiveMessage, there is no message payload to process, but the receive action still belongs in the request count. The exact regional rate, free-tier eligibility, and account-wide usage must come from the pricing page and the account’s billing evidence.

Start with a ledger that distinguishes the receive operation from the work it may unlock:

receive_call_id | queue | received_count | empty | message_ids | model_attempts | outcome

Do not divide SQS requests by model requests and call the result an efficiency rate. One message can be rejected before dispatch, processed without a model call, or produce more than one model attempt after an application retry. Conversely, a single receive can return multiple messages. The join key for cost review should be a message or business-work identifier, not just a polling invocation.

For a planning estimate, calculate the avoidable request component separately:

billable_empty_receives = max(0, empty_receive_calls - remaining_free_tier_requests)
avoidable_sqs_cost = billable_empty_receives / 1,000,000 * regional_price_per_million

This is a budgeting equation, not a promise about an invoice. Include other SQS actions, payload metering, FIFO or fair-queue rates where applicable, and any cross-service costs in the final estimate. Keep the model-side estimate and usage record separate; the DynamoDB write-cost guide shows the same principle for durable usage evidence.

Replace a tight empty loop with long polling

The SQS short- and long-polling reference describes short polling as an immediate response, even when no message is found. Long polling waits until a message is available or the specified wait expires, and AWS documents a maximum wait of 20 seconds. It can reduce empty responses and false-empty responses, which is why the setting belongs in a cost-control review as well as a latency review.

For a direct consumer, make the wait explicit and request a bounded batch:

aws sqs receive-message --queue-url "$QUEUE_URL" --wait-time-seconds 20 --max-number-of-messages 10

The queue attribute ReceiveMessageWaitTimeSeconds can provide a default for consumers that do not set a per-call wait. Inspect the actual requests emitted by every consumer, because a code path that explicitly sends WaitTimeSeconds=0 can reintroduce short polling. Asking for 10 messages is a maximum, not a guarantee that 10 arrive; process the returned records independently and preserve each record’s disposition.

Long polling changes the idle request pattern, not the business decision to call a model. A message should still pass freshness, authorization, input validation, and budget admission immediately before the outbound AI request. If the queue is empty, the consumer should record an empty receive and wait again—not manufacture a synthetic job or call the model to keep the worker busy.

Align the network timeout with the receive contract

The ReceiveMessage API reference defines WaitTimeSeconds as the period that the call waits for a message. It also warns that the HTTP response timeout should be longer than that value. A client timeout shorter than the long-poll wait turns an intended idle wait into a network error, which can create a rapid retry loop and erase the request reduction.

Set a response timeout with explicit margin for connection setup and normal network variance. Record the configured wait, client timeout, retry count, and queue name in sanitized configuration evidence. Do not copy authorization headers, signed URLs, message bodies, or raw provider responses into routine logs.

Measure idle poll pressure alongside backlog

The Amazon SQS CloudWatch metrics reference defines NumberOfEmptyReceives as the number of ReceiveMessage API calls that returned no messages. It also exposes NumberOfMessagesReceived, ApproximateNumberOfMessagesVisible, and ApproximateNumberOfMessagesNotVisible. AWS notes that SQS metrics can be approximate because of its distributed architecture, so use them for trends and tuning and reconcile material spend with billing data.

Add an application-side total receive counter so the team can calculate a rate rather than inspect an isolated count:

empty_receive_rate = empty_receive_calls / total_receive_calls
messages_per_receive = messages_received / total_receive_calls

Review those values with backlog and age in the same time window. The following interpretations are useful starting hypotheses:

SignalLikely issueFirst action
High empty receives, no visible backlogPollers are checking too often for intermittent workEnable long polling, then reduce idle consumers or use a bounded wake-up policy
High empty receives, visible backlog remainsConsumers may be reading the wrong queue, timing out, or using an unsuitable polling pathVerify queue identity, request settings, client timeout, visibility, and consumer errors
Low empty receives, backlog and age riseWorkers are busy or underprovisionedMeasure processing latency and safe concurrency before adding poll loops
Low empty receives, model attempts rise faster than messagesApplication retries or duplicate delivery are creating extra AI workReconcile attempt identities and delivery outcomes; do not infer from receive count

As an illustrative planning case, eight consumers making one short-poll call per second can issue 691,200 receive calls in a day, or 20,736,000 in a 30-day month, before counting sends, deletes, visibility changes, or payload units. A 20-second long poll on an empty queue changes the idle call cadence dramatically, but the actual result depends on arrivals, connection behavior, scaling, and client retries. Measure the before-and-after window instead of claiming the theoretical maximum as realized savings.

Operator workflow

  1. Freeze the baseline. For one queue, record total receives, empty receives, messages received, visible and not-visible backlog, oldest message age, consumer count, configured wait, client timeout, and AI attempts for at least a representative busy and quiet period.
  2. Separate direct consumers from managed mappings. Inventory SDK workers, container pollers, scheduled jobs, and Lambda event source mappings. Apply this direct-consumer procedure only where the application owns the ReceiveMessage call.
  3. Change one control. Enable a long-poll wait, keep batch size and processing behavior stable, and deploy first to a disposable or low-risk consumer. Do not combine a polling change with a concurrency increase if you need to attribute the result.
  4. Watch the timeout path. Confirm the HTTP response timeout exceeds the wait and that transport retries do not run faster than the intended wait. Alert on receive errors separately from empty receives.
  5. Protect AI admission. On each non-empty record, check the business deadline, source revision, authorization, and remaining allowance before making an AI call. Store the message ID, work ID, attempt ID, and cost state without storing sensitive content.
  6. Reconcile the window. Compare SQS request metrics, application counters, queue backlog, and returned model usage. Attribute SQS request savings to the polling change; attribute model savings or increases to admission, retries, and workload volume.

Use the Lambda SQS batch-retry guide when the same workload is delivered through Lambda. Its partial-batch-response control addresses replayed completed records, which is a different failure mode from an idle direct poller.

Calculate the avoidable cost without hiding work

Report four separate rows in the cost review: SQS receive requests, other SQS API actions, accepted AI attempts, and recovery or duplicate AI attempts. For each row, show the time window, unit, source of the count, and whether the number is measured, estimated, or pending reconciliation. A lower empty-receive count is useful only if backlog service level and accepted work remain healthy.

If the queue was empty because upstream producers stopped, long polling may lower request overhead while leaving business throughput unchanged. If the queue was empty because consumers were pointed at the wrong queue, long polling can hide the symptom without repairing delivery. If messages were present but model attempts were missing, adding pollers may increase spend before the admission bug is fixed. Treat the metrics as evidence for a decision, not as an automatic scaling instruction.

Verification before rollout

  • Exercise an empty queue and confirm the consumer waits rather than issuing a tight sequence of receives.
  • Publish one message during the wait and confirm it is returned, processed, and accounted for under its message and work IDs.
  • Force a client timeout and verify the retry path respects the bounded policy instead of reverting to a short-poll storm.
  • Compare NumberOfEmptyReceives with the application counter and inspect discrepancies before relying on a dashboard-only calculation.
  • Verify that no model call occurs for an empty receive and that a redelivered message follows the existing attempt and duplicate controls.
  • Review a busy window as well as an idle window; a setting that saves requests while starving a deadline-sensitive queue is not a successful cost control.

Failure modes

The queue is configured for long polling but the client overrides it. Inspect the serialized ReceiveMessage request and SDK defaults. A queue attribute is not evidence that every caller uses it.

The HTTP client times out at 10 seconds while SQS waits 20. The consumer sees errors before SQS can return the intended result and may retry rapidly. Set the response timeout above the wait with network margin.

The team treats an empty response as proof that the system is idle. Delays, visibility, distributed timing, or a different queue can explain the observation. Check backlog, age, consumer identity, and producer activity.

The team adds consumers to improve latency without pricing the idle case. Each direct consumer can add receive pressure when no work is available. Set a capacity floor and ceiling from backlog and service objectives.

SQS request savings are reported as AI API savings. They are different meters. Reconcile model usage and retry evidence separately, then report the combined workload cost with both components visible.

A direct-consumer setting is applied to a Lambda mapping. Managed event-source polling and partial-batch behavior need their own configuration and verification. Do not claim a Lambda improvement from a container worker’s metrics.

Sources checked

Four distinct official primary references were reachable with HTTP 200 during live research on November 24, 2026 UTC:

These are maintained technical references for an evergreen operations task, not evidence of a new product release or a specific account price. The rate, free-tier treatment, and observed savings still need to be checked in the account and region where the queue runs.

FAQ

Is a 20-second wait always the right setting?

No. It is the documented maximum, not a universal latency target. Start with the business deadline, connection limits, and consumer model. A shorter wait may be appropriate for a latency-sensitive queue; a longer wait is often useful for intermittent work when the client timeout is aligned.

Does long polling eliminate empty responses?

No. AWS documents rare empty responses even when a queue contains messages, particularly with a low wait value, and network or timeout failures remain possible. Track the observed rate and investigate unexpected empties rather than treating zero as a requirement.

Does lowering empty receives lower CometAPI spend?

Not directly. It lowers SQS request pressure when polling was the waste. Model spend changes only when the polling path was also creating or retrying AI work. Keep provider usage, attempt identity, and SQS request evidence in separate ledger fields.

Should every receive ask for 10 messages?

The API allows a bounded maximum, but the response can contain fewer messages. Choose a batch size that fits processing time, visibility, memory, and failure handling. Do not turn a transport batch into an assumption that all records will produce the same model work.

Reader next step

Instrument one direct consumer for a quiet window and a busy window. Capture total receives, empty receives, messages per receive, backlog age, client timeout, and model attempts. Apply long polling in a controlled environment, then re-run the same comparison and keep the SQS and AI rows separate. If Lambda owns the polling path, move to the SQS batch-retry guide instead of extrapolating from this direct-consumer workflow.