Function invocation

Also known as: invocation

On this page 7

Function invocation is a single execution of a serverless function in response to an event, an HTTP request or a direct API call. In Serverless architectures within the Cloud subject, the invocation is the basic unit of work, scaling and billing: the platform receives an event, finds or creates an execution environment, runs the handler code once and returns or discards the result.

Every invocation carries an event payload and a context object that describes the request, the remaining time and the identity of the caller. Understanding how invocations are routed, retried and metered is essential for designing reliable, cost-efficient systems on platforms such as AWS Lambda, Azure Functions or Google Cloud Run.

How a function invocation is processed

A function invocation follows a fixed lifecycle that the platform manages on behalf of the developer. A front-end router authenticates the request, checks concurrency limits and then assigns the event to an available execution environment, which is usually a lightweight virtual machine or container sandbox.

If no warm environment exists, the platform must download the code package, start the runtime and run initialization code, a delay known as a cold start. When a warm environment is available, the handler starts within milliseconds. After the handler returns, the environment is frozen and may be reused for later invocations, which is why global variables and open connections sometimes survive between calls.

The following table summarizes the main phases of a single invocation and what each phase costs in time.

PhaseWhat happensTypical duration
RoutingAuthentication, throttling check, placement1-10 ms
Environment initSandbox start and code download (cold only)100 ms to several seconds
Runtime initLanguage runtime and global code run10 ms to seconds
Handler executionBusiness logic processes the eventMilliseconds to the timeout
Freeze or teardownEnvironment paused for reuse or recycledNot billed in most models
Phases of a serverless invocation

Synchronous, asynchronous and stream-based invocation

Serverless platforms offer three invocation models, and the choice determines who waits for the result and who handles errors. In a synchronous invocation, the caller holds the connection open and receives the response or error directly, as with an API gateway request. In an asynchronous invocation, the platform places the event in an internal queue, immediately acknowledges receipt and runs the function later.

Stream and queue polling forms a third model. Here the platform runs a poller that reads batches of records from a message queue or data stream and invokes the function with each batch. Ordering, batch size and checkpointing then become part of the design.

ModelTypical sourcesError handlingCaller waits
SynchronousHTTP endpoints, SDK callsCaller must retryYes
AsynchronousStorage events, notificationsPlatform retries, then dead-letterNo
Poll-basedQueues, data streamsBatch retried until success or expiryNo
Comparison of invocation models

A function trigger defines which source starts the invocation, while the invocation model defines the delivery semantics. The two concepts are related but distinct: one trigger type, such as an object upload, always maps to one invocation model on a given platform.

Retries, idempotency and delivery guarantees

Most asynchronous and poll-based invocations offer at-least-once delivery, which means the same event can invoke the function more than once. Duplicates arise from automatic retries after errors, from timeouts where the work actually finished, and from rare internal redeliveries.

The standard defense is an idempotent handler: the function records a unique event identifier, often in a key-value store with a conditional write, and skips work it has already completed. Without idempotency, a retried payment or email invocation can charge or notify a customer twice.

  • Dead-letter queues capture events that fail after the final retry so that they can be inspected and replayed.
  • Retry limits and maximum event age stop a failing event from consuming resources indefinitely.
  • Partial batch responses in stream processing let the function report only the failed records instead of reprocessing the whole batch.
  • Exponential backoff spaces retries out and reduces pressure on struggling downstream systems.

Concurrency, limits and billing per invocation

Each execution environment handles one invocation at a time on classic function-as-a-service platforms, so ten simultaneous requests require ten environments. Concurrency is therefore roughly the request rate multiplied by the average duration. A function receiving 200 requests per second with a 250 ms duration needs about 50 concurrent environments.

Some container-based services, including Google Cloud Run, allow multiple concurrent requests per instance, which changes the cost profile and requires thread-safe code. Billing generally combines a per-request charge with a compute charge measured in GB-seconds, rounded to the millisecond on most current platforms.

The table below lists the main limits that shape invocation design; exact values differ by provider and change over time, so they should be confirmed in current documentation.

LimitTypical rangeDesign consequence
Maximum durationSeconds to 15 minutes, longer for container servicesLong jobs must be split or moved
Payload sizeAbout 256 KB async to 6-32 MB syncLarge data passed by reference
Account concurrencyOften 1,000 by default, raisableThrottling under traffic spikes
Memory allocation128 MB to about 10 GBCPU usually scales with memory
Common invocation limits and their effect

Provisioned concurrency keeps a set number of environments initialized ahead of demand, which removes cold starts for those invocations at the price of a continuous hourly charge. The opposite behavior, scale to zero, eliminates idle cost but exposes the first invocation after a quiet period to initialization latency.

Common mistakes in invocation design

Many production incidents in serverless systems trace back to misunderstood invocation semantics rather than to faulty business logic. The following table pairs frequent symptoms with their usual cause and a practical fix.

SymptomLikely causeFix
Duplicate records or emailsRetries without idempotencyStore and check event identifiers
Sudden 429 throttling errorsConcurrency limit reachedReserve concurrency or buffer with a queue
Runaway costsRecursive invocation loopSeparate input and output resources
Timeouts under loadSlow downstream dependencyShorter timeouts, circuit breakers
Latency spikes after idle timeCold startsLighter packages or provisioned concurrency
Invocation problems, causes and fixes

A particularly costly error is the recursive invocation loop, where a function writes to the same bucket or queue that triggers it. Some providers now detect and stop such loops, but careful resource separation remains the reliable safeguard.

In everyday language

A function invocation is one run of a small piece of code in the cloud. Think of a vending machine: nothing happens until someone presses a button, and then the machine performs exactly one action. In serverless computing, the button press is an event, such as a file upload or a web request, and the action is the function running once.

The provider takes care of the machines and starts as many copies as needed. It charges only for each run and the time it takes. One lesson matters most. The same event can sometimes press the button twice, so good functions give the same result when repeated.

Seen in the real world

An online retailer processes product photos uploaded by sellers. Each upload to object storage triggers an asynchronous invocation of an image-resizing function configured with 1,024 MB of memory and a 30-second timeout. On a normal day the function runs about 40,000 times, with an average duration of 400 ms.

During a seasonal sale, uploads jump to 150 per second, and concurrency rises to roughly 60 environments without any server changes. An early version wrote resized images back into the source bucket and briefly caused a recursive loop; the team moved outputs to a separate bucket and added an idempotency check keyed on the object version. The result was stable processing at a few dollars per day and no duplicate thumbnails, even when the platform retried failed invocations.