Serverless

FaaS

Escrito por Darjus Kazakevic · revisado el

Functions that the cloud runs per event, scales from zero and bills per call.

In serverless, or Functions as a Service (FaaS), you deploy single functions, not servers. The platform runs a function when an event arrives: an HTTP request, a queue message, a file upload or a timer. AWS Lambda, Google Cloud Functions and Azure Functions work this way. The platform starts copies under load and stops them all when idle.

You pay per request and per millisecond of run time, so idle costs nothing. The limits are real. A cold start can add from about 100 ms to several seconds to the first call. Lambda stops any function after 15 minutes. And your code depends on one provider's events and services.

En esencia — Write one stateless handler per job and let the platform run a copy per event; you stop running servers and accept cold starts, time limits and lock-in.

Cuándo recurrir a él

Recurre a él cuando

  • Spiky or low traffic, where paying nothing when idle saves money
  • Event glue: webhooks, file uploads, queue jobs and scheduled tasks
  • A small team that wants to ship features without running servers

Reconsidéralo cuando

  • Steady high traffic, where a reserved server costs less
  • Latency-critical paths that cannot accept cold-start delays
  • Jobs that run longer than the time limit (15 minutes on Lambda)

How it works

Event-triggered functions
You deploy one handler per job. It runs only when its trigger fires: an HTTP call, a queue message, a new file in S3, or a schedule.
Stateless and short-lived
A copy may be reused for the next call or destroyed at any time. Anything that must survive goes to a managed store, such as DynamoDB, Redis or S3.
Scale from zero
The platform runs one copy per concurrent request, up to an account limit, and none when idle. Lambda's default limit is 1,000 concurrent copies per region, and you can ask AWS to raise it.
Pay per use
You pay per request plus memory × duration. Idle is free, but steady high traffic can cost more than a server.
Cold starts
When no warm copy exists, the platform must load your code first. Large packages and heavy runtimes make this slower; provisioned concurrency keeps copies warm for a fee.

Working with the platform

Keep functions small and stateless
One trigger, one job, nothing kept between calls. The platform's scaling and billing assume copies you can throw away at any moment.
Protect what sits behind the functions
1,000 parallel copies can open 1,000 database connections. Put a queue in front, use a connection proxy such as RDS Proxy, or cap the function's reserved concurrency.
Design for cold starts
Keep packages small and initialise clients once, outside the handler. Keep latency-critical paths warm with provisioned concurrency, or run them on servers.
Check the cost curve before you commit
Estimate the bill at your steady load and compare it with a server. In 2023, Prime Video moved a video-monitoring tool from Step Functions and Lambda to ECS and cut its cost by over 90%.

Errores habituales

  • A traffic spike that opens thousands of database connections and takes the database down
  • Keeping data in a global variable and losing it when the copy is recycled
  • Hundreds of tiny functions with no tracing, so no one can follow a request
  • Ignoring the bill until a steady, busy endpoint costs more than a server