{"canonical_url":"https://engineer.company/glossary/serverless/","content_markdown":"# serverless\n\n## What it is\n\nServerless is a way of running code in which the team writes and deploys the\napplication and a provider runs, scales and maintains the machines underneath\nit. The CNCF Serverless Working Group's whitepaper, which uses the longer name\nserverless computing, describes it as the idea of building and running\napplications without anyone on the team having to manage a server.\n\nThe name overstates the case, and the whitepaper says so in plain words:\n“Servers are still required to run a serverless platform.” The servers still\nexist, and so does operations work. What changes is who does it. The team no\nlonger chooses machine sizes, installs the operating system, patches it or\ndecides how many copies to run. It hands over code or a container image and a\ndescription of when that code should run.\n\nThe whitepaper divides the field into two parts. Functions-as-a-service, or\nFaaS, is event-driven computing: small pieces of logic that run in response to\nsomething happening. The thing that starts a function is called a trigger, and\nit is usually the result of an event such as an incoming HTTP request or a\nchange in a database. Backend-as-a-service, or BaaS, is the other part:\nthird-party services, reached through an API, that replace whole parts of an\napplication's functionality. Functions are expected to be stateless and\nshort-lived, so the BaaS side is where the state lives.\n\nTwo products show the range. AWS Lambda describes itself as a serverless compute\nservice that runs code without provisioning or managing servers, and its\noriginal form is the event function: a handler plus a trigger. Azure Container\nApps calls itself a service that runs application containers while the provider\noperates the infrastructure. The first takes a function, the second takes a\nwhole container, and both leave the machines to the provider.\n\n## Why it matters\n\nThe billing model is the first reason teams look at it. The whitepaper describes\nserverless pricing as pay-as-you-go, charging only for the time code is running,\nwith no charge when nothing is running. Lambda bills an event function per\nrequest plus the execution time it uses, measured in gigabyte-seconds. A service\nthat is busy for an hour a day pays for that hour, not for a server waiting\nthrough the other twenty-three.\n\nThe second reason is scaling in both directions. Lambda creates and destroys\nexecution environments as traffic rises and falls, and the whitepaper describes\nfunctions whose instances drop to zero when there is no work. Microsoft notes\nthat Container Apps scales on HTTP traffic, events, or CPU and memory load, and\nthat most applications can scale to zero.\n\nThe third reason is the work that leaves the team's hands. AWS lists server\nmaintenance, capacity provisioning, scaling and patching among the jobs Lambda\ndoes for you. For a small team, those are the chores that fill a week without\nshipping anything, and with a serverless platform they become the provider's\nresponsibility.\n\nThe whitepaper's use cases show where this fits best: reacting to database\nchanges, processing sensor input from devices, handling streams of data, and\nshort scheduled tasks of the kind that would otherwise be a cron job.\nMicrosoft's list for Container Apps adds API endpoints, background processing\njobs and microservices.\n\nThe same whitepaper also warns that serverless may look the most economical\noption at first, and asks teams to weigh the full range of costs before\ncommitting. Per-use billing rewards work that is bursty and idle most of the\ntime. Work that keeps a machine busy around the clock is a different\ncalculation, and debugging, which the whitepaper says can be harder than on IaaS\nor PaaS offerings, is a cost too.\n\n## What it looks like in practice\n\nAWS's documentation for Python handlers has an example that receives an order,\nwrites a text receipt and stores it in an Amazon S3 bucket. A shortened version\nof it looks like this:\n\n```python\nimport os\n\nimport boto3\n\n# Runs in the Init phase, once per execution environment.\ns3_client = boto3.client(\"s3\")\n\n\ndef lambda_handler(event, context):\n    order_id = event[\"Order_id\"]\n    bucket_name = os.environ.get(\"RECEIPT_BUCKET\")\n    receipt_content = (\n        f\"OrderID: {order_id}\\n\"\n        f\"Amount: ${event['Amount']}\\n\"\n        f\"Item: {event['Item']}\"\n    )\n    key = f\"receipts/{order_id}.txt\"\n    s3_client.put_object(Bucket=bucket_name, Key=key, Body=receipt_content)\n    return {\"statusCode\": 200, \"message\": \"Receipt processed successfully\"}\n```\n\nThe handler takes exactly two arguments. The event carries the data to process,\nand a JSON event arrives as a Python dictionary, so this one expects input of\nthe following shape:\n\n```json\n{\"Order_id\": \"12345\", \"Amount\": 199.99, \"Item\": \"Wireless Headphones\"}\n```\n\nThe context carries information about the invocation itself. If the file is\ncalled `lambda_function.py`, the handler is named\n`lambda_function.lambda_handler`, which is the default the Lambda console gives\na new function. The bucket name comes from an environment variable rather than\nfrom the code, which is how AWS recommends passing operational settings, and the\ncode holds no credentials: Lambda supplies them to the SDK through environment\nvariables of its own.\n\nThe placement of the client matters. For on-demand event functions without\nSnapStart or Managed Instances, Lambda runs an execution environment through\nthree phases: Init, Invoke and Shutdown. Code outside the handler runs once,\nduring Init, and AWS limits the initial Init attempt to 10 seconds. The handler\nthen runs for each event, within the function's timeout. When an environment is\nreused for the next event, which AWS calls a warm start, the client created\nduring Init is still there and is not built again.\n\nServerless does not have to mean functions. On this site, the portfolio entry on\n[provisioning an Azure estate as code](/portfolio/provisioned-azure-infrastructure-as-code/)\nlists two services, `api` and `www`, deployed to Azure Container Apps, with\ntheir container images kept in the project's own Azure Container Registry.\nMicrosoft calls Container Apps a serverless platform for containers, so those\ntwo services are where that estate is serverless. Every environment is described\nby one set of Bicep templates that take parameters, which is why the entry can\ntreat a new environment as a pull request.\n\nGoing the other way can be the right call too. The entry on\n[reviewing infrastructure and moving workloads off AWS](/portfolio/a-tenth-of-the-cloud-bill-and-nothing-lost/)\nstarts from an AWS setup sized far beyond what the business used and still\ncarrying services nobody needed. The unused services were removed, the remaining\ncapacity was adjusted, and the workloads moved off AWS. Serverless billing is\none way to stop paying for idle capacity; reviewing and removing unused\ninfrastructure is another. A comparison of the real load and costs would be\nneeded to decide which costs less; the entry records changes rather than a\nlike-for-like cost ratio.\n\n## Where it goes wrong\n\nMost serverless failures come from treating a function like a small server that\nis always on, which it is not.\n\n**Cold starts add delay to some requests.** When no environment is ready, Lambda\nhas to download the code, set up an environment and run the Init code before the\nhandler sees the event. AWS says cold starts typically affect under 1% of\ninvocations and last from under 100 milliseconds to over a second, that they are\nmore common in development and test functions, and that the Init time is billed.\nThe fix is to keep Init small, importing only what the function needs and\nloading rarely used objects lazily. Where a delay matters, provisioned\nconcurrency keeps a chosen number of environments initialised in advance.\n\n**State kept inside the environment leaks or disappears.** Each invocation runs\nindependently, and an environment may or may not be reused. AWS also replaces\nenvironments every few hours for runtime updates, even under constant traffic,\nand a reset after a crash or a timeout does not clear the `/tmp` directory. Data\nfrom one event can therefore surface during another, or vanish without warning.\nThe fix is to keep user data and events out of the environment altogether, and\nto put anything that must persist in a database or storage service.\n\n**The same event is processed twice.** A function can receive duplicate events,\nand AWS's best-practice list asks for idempotent code that validates each event\nand handles a duplicate the same way as the original. In the example above the\nreceipt key is derived from the order id, so a second run overwrites the same\nobject instead of creating a second receipt. Any side effect that cannot be\nrepeated safely, such as sending an email or charging a card, needs its own\nrecord of what was already done.\n\n**Hard limits end the work mid-way.** For event functions outside Lambda Managed\nInstances, an invocation can run for at most 900 seconds, or 15 minutes. A\nsynchronous request and a buffered synchronous response are each limited to 6\nMB, an asynchronous request to 1 MB, and environment variables to 4 KB in total.\nExceeding a limit is an error rather than a slowdown. The fix is to design\naround the limits from the start: split long jobs into steps, keep large data in\nstorage and pass a reference to it, and move work that does not fit to a\ncontainer platform or a virtual machine.\n\n**Concurrency runs out before traffic does.** Lambda's default quota is 1,000\nconcurrent executions per Region, while API Gateway's default allows 10,000\nrequests per second, so the front door can accept more requests than the\nfunctions behind it can run. New accounts start with reduced concurrency and\nmemory quotas, which AWS raises automatically based on usage. The fix is to\nrequest an increase before launch and to load test at the expected peak.\n\n**A function that triggers itself runs up the bill.** A function that invokes\nitself, or starts a process that invokes it again, can produce a flood of\ninvocations, and every one is billed. AWS's advice is to avoid recursive\ninvocations, and if an unexpected volume appears, to set the function's reserved\nconcurrency to `0` at once, which throttles all invocations until the code is\nfixed.\n\n**The programming model ties you to one platform.** The whitepaper names the\nplatform's programming model, its event and messaging interface and its BaaS\nofferings as sources of lock-in. The fix is to keep the business logic in\nordinary functions that the handler only calls, and to prefer platforms such as\nContainer Apps that run a standard container image from any registry when moving\nlater is a real possibility.\n\n## Further reading\n\n- [CNCF Serverless Whitepaper v1.0](https://github.com/cncf/wg-serverless/tree/master/whitepapers/serverless-overview)\n  — the working group's definitions of serverless, FaaS and BaaS, and drawbacks.\n- [What is AWS Lambda?](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)\n  — what Lambda manages for you, its function types and its billing model.\n- [Define Lambda Event Function handler in Python](https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html)\n  — the receipt example in full, handler naming and the code best practices.\n- [Understanding the Lambda execution environment lifecycle](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html)\n  — the Init, Invoke and Shutdown phases, cold starts and environment reuse.\n- [Lambda quotas](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html)\n  — concurrency, memory, timeout and payload limits, and how to raise them.\n- [Azure Container Apps overview](https://learn.microsoft.com/en-us/azure/container-apps/overview)\n  — Microsoft's serverless platform for containers and how it scales to zero.\n\n\u003chttps://engineer.company/glossary/serverless/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"What serverless means, which work the provider takes over, how a function is written, started and billed, and the limits that catch teams out.","formats":{"gemtext":"https://engineer.company/glossary/serverless/index.gmi","gopher":"https://engineer.company/glossary/serverless/gophermap","html":"https://engineer.company/glossary/serverless/","json":"https://engineer.company/glossary/serverless/index.json","markdown":"https://engineer.company/glossary/serverless/index.md","pdf":"https://engineer.company/glossary/serverless/index.pdf"},"kind":"page","language":"en","title":"What is serverless?","url":"https://engineer.company/glossary/serverless/","version":1}