AWS Lambda 00:00:01 The first thumbnail after a quiet morning The school photographer uploads the morning's first photo. A function must make its thumbnail. The code is deployed, but assume no suitable initialized environment is available. Trace what this request pays for before the handler can touch the image. The function exists as code. There is no environment. The front end checks permission and concurrency. No environment is free, so a microVM starts and the code is loaded. The runtime initializes and module-level setup runs for this environment. Imports and client creation can contribute noticeably to the first request's latency. The handler runs and writes logs. After the invocation, the environment may be frozen and later reused or reclaimed. Initialization can construct reusable clients. Later eligible invocations may reuse their environment, but that reuse is opportunistic. Keep durable image state and completion records outside the process. 00:01:00 A slow database can multiply concurrency The photo service receives a hundred requests a second, and each lasts half a second. Under steady load that is about fifty simultaneously running invocations. Now change duration while leaving arrivals alone. 100 a second at half a second needs 50 environments. Three times the traffic needs 150. Normal traffic, but each call now lasts 4 seconds: 400. At three hundred requests a second and four seconds each, the estimate reaches twelve hundred. In this example it exceeds the assumed regional quota of one thousand. At four seconds per request, that same hundred per second requires about four hundred concurrent invocations. Compare demand with the actual account and function limits, and with the capacity of the database behind them. 00:01:47 Follow an asynchronous failure to its destination A separate function receives photo events by asynchronous invocation and its handler throws an error. The caller's initial acceptance does not certify that the thumbnail has been produced. The handler raises an error. With the illustrated default behavior for a function error, another attempt follows after roughly a minute. Two minutes after that. It fails again. After the configured retries are exhausted, the configured on-failure destination can receive an invocation record. Arrange a way to inspect and recover the original work. Lambda's asynchronous delivery settings differ from a synchronous caller or a queue event-source mapping. Bound event age and retries, and configure a failure destination when failed work must be examined. 00:02:31 Four valid photos and one broken record Now let a queue event-source mapping read five messages. One photo record is malformed. Reprocessing the other four on every retry would waste resources and might repeat their effects. The mapping reads five messages. They become invisible in the queue. It calls the function and waits for the answer. Message 3 cannot be parsed. The function notes its id and goes on. For this standard queue example, the mapping can delete the successful messages. The failed one can reappear after its visibility timeout. A configured redrive policy can eventually move the repeatedly failing message to a dead-letter queue. With partial batch responses enabled, report the failed message identifier and handle individual records carefully. Make successful side effects idempotent because queue delivery can still repeat. Preserve any ordering requirements of the chosen queue. 00:03:32 Protect the photographer's database The school announces a new album and hundreds of function environments open database connections. Watch the downstream pool before celebrating the number of functions that started. Forty environments hold forty connections. Two hundred environments use every connection the database allows. Errors cause retries, and retries add load. Here the design caps the function's concurrency and places a connection proxy in front of the database. Validate the resulting backend connection count under the actual transaction pattern. Use an appropriate concurrency cap and connection management for the database workload. A proxy can reuse backend connections where supported; it cannot create database throughput. Rehearse one burst and one slow query before promising that every photo will finish promptly.