Lesson 3 of 6 AWS Lambda

Controlling Lambda Concurrency and Cold Starts

This lesson explains how Lambda scales by running more execution environments in parallel, and how concurrency settings protect other functions and downstream systems and remove cold starts where latency matters.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how Lambda scales.
  • Distinguish reserved concurrency, provisioned concurrency and SnapStart.

How Lambda scales

Lambda scales by running more copies of a function at the same time. Concurrency is the number of requests in progress at once, roughly the number of requests per second multiplied by the average duration in seconds; a function receiving 100 requests per second that each take half a second needs about 50 concurrent executions.

By default, an account has a quota of 1,000 concurrent executions per Region, shared by all functions, which can be raised. Each function can add up to 1,000 concurrent executions every 10 seconds. Beyond these limits, synchronous invocations are throttled with HTTP 429 errors, while asynchronous events are queued and retried.

Fill in the value

Concurrency

Exam skills 3.2.2 · 2.1.2

Work out the concurrency a function needs.

Log in to try this activity Interactive activities are free with an account.

Concurrency controls

Lambda offers three controls related to concurrency and start-up. Reserved concurrency both guarantees and caps a function's concurrency. It ensures that a critical function always has capacity, stops one busy function from using the whole account quota, and limits a function that writes to a database with few connections. It costs nothing.

Provisioned concurrency keeps a number of execution environments initialised, so requests that they serve have no cold start. It is charged while configured, so it suits latency-sensitive APIs with predictable traffic. SnapStart, for Java, Python and .NET, resumes new environments from a snapshot taken after initialisation, so cold starts are much shorter, at lower cost than keeping environments warm. The following table summarises the controls.

ControlEffectUse for
Reserved concurrencyGuarantees and caps a function's concurrencyProtecting a downstream database, or stopping one function using the whole quota
Provisioned concurrencyKeeps environments initialised, removing cold starts; charged while configuredLatency-sensitive APIs with predictable traffic
SnapStartResumes new environments from a snapshot (Java, Python, .NET)Cheaper reduction of cold-start time

Provisioned concurrency can be scheduled or scaled with Application Auto Scaling, for example raised before a known daily peak.

The following diagram shows reserved concurrency dividing the account's concurrency, with the other two controls below.

Lambda concurrency controls. Reserved concurrency carves a guaranteed and capped share out of the account's concurrency, for example so a function that writes to a database with few connections cannot exceed it, while other functions share the unreserved pool. Provisioned concurrency keeps environments initialised, so requests they serve have no cold start.
The shares are illustrative. Reserved concurrency limits how many copies run; provisioned concurrency decides how many start warm.
Sort into groups

Which concurrency control?

Exam skills 3.2.4 · 4.4.6

Choose the concurrency control for each requirement.

Log in to try this activity Interactive activities are free with an account.
Worked example

One function starving the others

During a promotion, a public sign-up function scales to 950 concurrent executions, and the critical checkout function in the same account is throttled.

SettingEffect
Reserved concurrency of 200 on checkoutCheckout can always run 200 environments
Reserved concurrency of 300 on sign-upSign-up can never take more than 300
Provisioned concurrency of 50 on checkoutNo cold starts at checkout
Request a higher account quotaMore headroom for growth

Reserved concurrency both guarantees and caps, so the two functions can no longer interfere with each other.

Check yourself

What does provisioned concurrency do?

Show answer

It keeps a number of execution environments initialised, so requests up to that level avoid cold starts.

Exam Tips

Remember for the exam

  • To eliminate cold-start latency, use provisioned concurrency.
  • To protect a database from too many concurrent functions, use reserved concurrency.
  • To stop one function consuming the account's whole concurrency quota, set reserved concurrency on it.
  • For Java functions with slow start-up, use SnapStart.