サーバーレス関数
リクエストごとにコードを動かし、持つべき箱がありません。待機中はゼロ、起きればコールドスタート、同時実行は1,000です。
このページはまだ日本語に翻訳されていません。
The Serverless Function runs your code per request, with no box of your own, as AWS Lambda, Google Cloud Functions, and Azure Functions do.
When to place it#
Place it when traffic is spiky. It unlocks with Serverless in Series A, for 3,500 ◇, and has no placement cost.
Place it when one endpoint needs its own capacity without a second box.
Skip it for steady load above about 30% utilization of an equal VM, where it costs more than the VM.
Skip it for long
jobwork. That belongs on a Worker behind a Queue.
How it works#
It runs your Service's Stack with no instance type and no size to pick, so the runtime alone decides how fast a request runs and how long a cold start takes. Every request kind comes in and is answered the way an App Server answers it, turned into the backend calls it makes.
It differs from an App Server in three ways:
It bills per use. Nothing stands while it idles. Each request pays a request price plus a price for the GB-seconds its execution ran, and the whole bill lands on the Requests line of the cloud bill. A slow call to the Database makes each execution longer, so the bill rises with the data tier's latency.
It scales from zero to a cap. One execution environment holds one request at a time, so the function serves as many requests a second as 1,000 concurrent executions allow. Past the cap the provider throttles, and the excess is dropped, not queued.
It starts cold. An environment that sat idle is gone, and the next invocation boots a new one. See cold start. The Simulation charges it on a share of requests: nearly all of them at a trickle, almost none under steady load.
Because nothing is resident, a function is cheap at low and spiky volume. Above about 30% steady utilization of an equal VM it costs more than the VM, because the VM's Burn does not grow with the work it does.
How it fails#
The cap. A spike above 1,000 concurrent executions is throttled, and the requests are lost.
Cold starts after a quiet minute. A Java function can pay two seconds before its code runs, while Go and Rust pay 50 ms. A trickle of traffic pays it most often.
Connections. Every concurrent execution opens its own database connections. Without a Connection Pooler, a spike exhausts Postgres.
Duration. A function stops an execution after 15 minutes. An export (
job) runs 4 seconds for each GB the Databases hold, so past 225 GB it fails astimeout. Longjobwork belongs on a Worker behind a Queue, which has no limit.
Instance failure#
Signs: The Serverless Function card goes grey and its callout reads "The host under this VM died. It still bills." Requests sent to it are stranded.
Do now: Select the Node and click Replace. It costs Cash and comes back cold.
Prevent: Run a second copy behind a Load Balancer that skips dead hosts. Load balancing and Health checks unlock them.
Zone outage#
Signs: Every Node in one zone goes grey at once, the Serverless Function with them.
Do now: Nothing brings the zone back sooner. Fail over promotes a Standby, and this Component keeps none, so it ends on its own after at most 120 s.
Prevent: Research Multiple zones and keep a copy of the Component in a second zone.
Region outage#
Signs: One region's board goes grey and the Serverless Function in it goes down.
Do now: Press Fail over on the banner. It needs Multiple zones and a second open region, and starts the Node again in the nearest other region, cold, for the price of a replacement. Otherwise it comes back when the incident ends: 180 sim seconds in the catalog, 60 once the error budget counts.
Prevent: Research Multiple regions, keep a copy in a second region, and add GeoDNS to send users there.
Tips#
ルール#
- 追加のコピーは 1 つ前より 25% 高くなります。
- 売却すると、最後のコピーの価格の 50% が戻ります。
- サイズは 1 つだけです。
- 新しいコピーはコールドスタートで、温まるまで遅いままです。