Patterns

Functions for spiky jobs

Run bursty or rare work on a Serverless Function that bills per use and scales from zero, and keep steady load on boxes.

Put work with sharp peaks and long quiet stretches on a Serverless Function, so you pay only while it runs.

Move up when#

  • Traffic is spiky, and boxes sit idle most of the day or fall over at the peak.

  • One endpoint needs its own capacity without a second box to run.

  • The work is short, since a function has a time limit.

The Design#

Drag to pan. Hold Ctrl or Cmd and scroll to zoom.

At 1.50k Users the Simulation solves this Design to Apdex 1.00, p99 237 ms, 0.0% errors and $1.47/s Burn.
WhereSettingValueWhy
Serverless FunctionRuntimegoA Go binary starts cold in a few dozen milliseconds, where a JVM takes seconds. Cold starts are the price of scaling to zero.
DatabaseInstance sizesmallFunctions have no pool to share, so a spike of executions lands on the Database.

Research this Design needs: Serverless, Serverless, Go.

Users call the Function directly, and it calls the Database. There is no App Server. The Function takes its Runtime from your Stack, and the runtime sets how fast it runs and how long a cold start takes.

Why it works#

Nothing stands while it idles, so a quiet hour costs almost nothing. Capacity follows demand up to a concurrency cap, with no Autoscaler to tune and no boxes to boot. A compiled runtime starts cold in a fraction of a second, where a JVM needs seconds, so the language you choose changes the cost of scale to zero.

What it costs#

An environment that sat idle is gone, so the next call pays a cold start. Past the cap the provider throttles and drops the excess. Each execution opens its own database connections, so a spike lands on the Database, and a pooler is worth having. Above a steady share of an equal VM's load, a function costs more than the box. Long work such as an export belongs on a Worker, because a function stops after a fixed time.

In Quorum#

Place a Serverless Function after Serverless, and a runtime Research such as Go for the Runtime. Put a CDN or Cache in front, because every request that reaches a function bills. The glossary has cold start. The next rung scales boxes: Autoscale the compute tier.