Listen to this article

Cloud spending continues to climb. Gartner forecasts public cloud services growth of 21.3% in 2026, with the market projected to reach $1.48 trillion by 2029. But more spend does not always mean more value: Flexera’s 2026 State of the Cloud Report estimates that 29% of cloud spend is wasted, the first increase in five years.

While serverless promises that you pay only for what you use, that promise breaks down when workloads spend most of their time waiting.

This is common whenever a workflow depends on an external system, such as document processing, media transformation or third-party data enrichment. Processing times can range from seconds to minutes.

The usual approach is to call an external API from an AWS Lambda function and wait for the answer. Lambda keeps billing while it waits, and the cost grows with every added request.

The root cause is simple: workflow coordination is coupled with application execution. In this blog, we show how to redesign wait-heavy Lambda workflows by separating the two. You will learn when an SQS-based pattern fits, how to handle retries and failures, and when AWS Step Functions or Amazon EventBridge are a better choice.

Where Serverless Savings Quietly Disappear

Consider a global property and casualty insurer that processes more than 100,000 claims a day through mobile apps and service channels. Before a claim is approved for payment, it goes through fraud assessment on a third-party risk scoring platform. The platform analyzes claim history, customer behavior and external fraud intelligence.

Each claim triggers a Lambda function that calls the third-party API and waits. The platform responds asynchronously, so timing varies.

  • Average latency: 20 to 60 seconds.
  • Peak latency: up to two to three minutes for complex claims that need extra verification.
  • Traffic: bursty, especially after severe weather events that generate thousands of claims in a short period.

Lambda stays active for the whole call, so cost follows external latency and not useful work.

Take a smaller example. If external processing takes 45 seconds on average, Lambda stays active for all 45 seconds, even though only a small part is real work. At 10,000 requests a day, that adds up to more than 125 Lambda-hours of mostly idle compute.

The core issue is that coordination, such as waiting and polling, is tightly coupled with compute. That hurts both efficiency and scalability.

Engineering the Wait Out of Your Lambda Bill

At Persistent, we believe waiting should never be billable compute. The fix is a simple but powerful shift. Instead of holding a Lambda function open while an external system works, move coordination to Amazon SQS and limit Lambda to short, purposeful runs. One long-running function becomes a series of short steps coordinated through messages.

Each part has a clear job.

  • Amazon SQS manages coordination, including retry timing and message visibility.
  • Amazon DynamoDB stores workflow state and execution metadata.
  • AWS Lambda runs short activities such as starting a request, checking status and processing results.
  • External systems do the long-running work.

The key insight is that SQS acts as a state parking mechanism. When a message is re-queued with a visibility timeout, it becomes invisible for a while and uses no compute.

Here is what changes:

  • Execution: One long Lambda run becomes several short runs.
  • Waiting: It moves from inside Lambda to the SQS visibility timeout.
  • State: It moves from in-memory context to DynamoDB.
  • Retries: They move from custom application logic to SQS with DynamoDB state tracking.
  • Cost driver: It shifts from external latency to the compute actually performed.
  • Scalability: It no longer depends on concurrent waiting executions, so it scales independently of wait time.

From One Long-running Function to Many Short, Coordinated Steps

The workflow runs as a series of short, stateless executions. Each run handles either a new request or one already in progress.

  • New request: Lambda picks up the message and calls the external API to start processing. The API returns a job identifier. Lambda stores the identifier and status in DynamoDB, then re-queues the message with a visibility timeout, for example 30 seconds. The job starts and nobody waits for it.
  • Request in progress: When the message becomes visible again, Lambda reads the job identifier from DynamoDB and asks the external API for status. If processing is complete, the result goes to Amazon S3, the message is deleted and DynamoDB records the final status. If not, Lambda increments the retry counter and re-queues the message.

The cycle repeats until the job completes or a retry limit is reached. Each run does a small unit of work, progress lives in DynamoDB, visibility timeouts set the polling pace and no compute is held during waits.

Failures need a circuit breaker. Set a maximum retry threshold. Move messages that exceed it to a dead-letter queue, record the failure in DynamoDB and let Amazon CloudWatch raise alerts. Failed requests stay isolated and the rest of the system keeps running.

Not Every Wait Needs a Queue

AWS Step Functions is a fully managed orchestration service. It is the better choice for multi-step workflows with branching or parallel execution, built-in observability and auditability, and complex retry and error handling.

SQS-based coordination solves a different problem. It works best when:

  • The workflow is simple and linear: start, poll, complete.
  • Polling is required because of external system limits.
  • Volume is high and cost matters.
  • Orchestration logic is minimal.

Other AWS patterns may fit better, depending on the external system.

  • Amazon EventBridge suits event-driven integrations where external systems can publish completion events.
  • Amazon API Gateway with callbacks suits external systems that support webhooks or asynchronous notifications.

In practice, you can combine these patterns, each where it fits best.

The Payoff and the Price of Decoupling

For a workload of about 10,000 requests a day with 45-second average external processing, compute can fall from about 125 Lambda-hours to about five to six.* The benefit is greatest when external processing time far exceeds active compute time. Gains can also reach concurrency use, throughput and resilience.

*Actual results vary with memory allocation, polling frequency, request volume, external latency, retry behavior and workload characteristics.

The pattern has trade-offs.

  • State management: You must manage workflow state, idempotency and execution tracking explicitly.
  • Observability: Tracing, monitoring and debugging take extra effort.
  • Ordering: Standard SQS queues do not guarantee strict ordering. FIFO queues help but may reduce throughput.
  • Fit: It works best for simple, linear, polling-driven workflows. For short-lived executions, coordination overhead can outweigh the savings.

Ideas to Take Back to Your Architecture

When execution time follows external latency, long waits quietly drain serverless budgets. Separating coordination from compute fixes that and keeps your workloads scalable and simple to run.

  • Separate coordination from compute to remove idle wait from execution.
  • Use SQS and DynamoDB to externalize state and manage retries.
  • Limit Lambda to short executions that match the actual work.
  • Choose this pattern for simple, high-volume, polling-driven workloads where cost efficiency is critical.

Ready to find the idle time in your workloads? Start by checking where Lambda executions wait on long-running external systems. Any workflow that depends on them is a strong candidate for this pattern.

Connect with Persistent to review your serverless architecture and choose the right coordination approach.

Author Profile

Ajesh Chandra

Aayush Bhansali

Engineering Lead, Persistent Systems

Aayush Bhansali is an Engineering Lead at Persistent Systems and a subject-matter expert in static application security testing (SAST). He leads work at the intersection of application security, agentic AI and AWS cloud engineering, building AI agents that automate and improve how security analysis is developed and delivered. With over five years in application security, he is focused on making secure software delivery faster, more intelligent and easier to scale.