Serverless
Serverless is a cloud model in which the provider runs your code only when an event arrives; in IoT, functions react to device messages and scale to zero.
Photo: Domaintechnik / Unsplash
Serverless is a way of running software in the cloud in which the provider, not the customer, looks after the servers. You upload a small piece of code, a function, and say which event should start it; the provider runs it when the event arrives, adds capacity when many events arrive at once and charges for what was used. AWS describes its Lambda service as running code “without provisioning or managing servers”, with the provider handling maintenance, capacity, scaling and patching. The servers still exist, but the customer never sees or manages them. In IoT, “serverless” usually means using such functions to react to messages from devices.
How does serverless work in an IoT system?
Devices do not talk to functions directly. They keep a connection to a managed message broker, usually over MQTT, and the cloud platform starts a function when a message matches a rule. On Amazon’s cloud, AWS IoT Core receives the message and its rule engine can pass it to a Lambda function; AWS IoT invokes Lambda functions asynchronously, so the device does not wait for the result. On Microsoft’s cloud, Azure IoT Hub exposes device messages as an event stream, and Azure Functions has an IoT Hub trigger that runs a function for each message or batch of messages.
Google Cloud no longer has its own device service: Google IoT Core was retired on 16 August 2023. Teams on Google Cloud connect devices through another IoT platform or a broker they run themselves, forward the messages to Pub/Sub, and use a Pub/Sub trigger to run a Cloud Run function each time a message is published to a topic.
What is serverless used for in IoT?
Mostly for the glue between device messages and the rest of a system. Typical jobs are checking and reformatting an incoming reading, adding metadata such as the device’s location, writing it to a database, sending an alert when a value crosses a threshold, calling a webhook on another service, or starting a firmware update when a device reports an old version. These tasks are short, independent of each other and arrive at irregular times, which is the pattern serverless platforms are built for. A small fleet that reports a few times an hour costs little, because nothing runs between messages; billing on AWS is per request plus the memory and time used.
What are the limits of serverless for IoT?
Time limits, start-up delays, concurrency caps and cost at high, steady volume. Most plans cap how long one run can last: a Lambda function can run for up to 900 seconds (15 minutes), or up to 90 minutes for some kinds of call on the newer Lambda Managed Instances option, and on Azure the legacy Consumption plan allows 5 minutes by default and 10 at most, while the newer Flex Consumption plan defaults to 30 minutes with no fixed maximum.
When no copy of the function is ready, the platform must prepare one first, which is called a cold start. AWS says cold starts typically occur in under 1% of invocations and last from under 100 ms to over 1 second, and that paid options such as provisioned concurrency keep copies ready. For a door lock or an alarm that must react at once, that delay matters.
Scale has a ceiling too. By default an AWS account can run 1,000 Lambda executions at the same time in each region, shared by all its functions; requests above the limit are throttled unless the quota is raised. A whole fleet reconnecting after a power cut can reach that. Finally, a function invoked for every single reading from a large fleet can cost more than a stream processing job that runs all the time, because the per-request charge adds up.
When should you use serverless for IoT, and when not?
Use it for event-driven tasks that are short and come in bursts, and for teams that would rather not run servers. Avoid it for the heavy data path of a large fleet, for long calculations, and for anything that has to keep state or a connection open between messages, since each run starts fresh. The common design is mixed: a managed broker holds the device connections, serverless functions handle rules, alerts and integrations, and a stream processor or database service takes the continuous flow of readings. Logic that must keep working without the internet belongs on the device or a gateway instead, as edge computing. The IoT data pipeline shows where each piece fits, and IoT platforms explained compares the cloud services that provide the broker and rules.
Part of the IoT Glossary. Spotted an error or a missing term? Tell us.