The use cases for serverless frameworks
7 February 2017 | 0
It is easy to be befuddled about “serverless” or “function as a service” architectures. For one, “serverless” is a bit of a misnomer — there are servers, but you don’t have to maintain them. All you do is upload a snippet of code and let the hosting service handle the rest.
But what sorts of applications are suited to this kind of deployment? The answers tend to be the same whether you’re dealing with AWS Lambda or Azure Functions; the designs of those systems all depend on blocks of code triggered by specific actions. Here are five common kinds of apps built out of such pieces.
This is one of the simplest and most direct applications for a serverless architecture: creating REST APIs that return data to be consumed by either another service or by a single-page application.
REST APIs in general are not hard to build. Most of the time, all you need is a basic web framework, a library for rendering data in the format you’re returning (typically JSON), and whatever glue code is needed to talk to the back end from which you’re pulling data. With a serverless architecture, the developer can focus exclusively on writing and deploying the code needed to serve the API, and not be distracted by much else.
Many common functions that need hand-tuning in a REST API, like autoscaling to meet demand, are addressed automatically by serverless frameworks. Plus, the pay-what-you-use model that’s become the staple of cloud pricing means a lightweight, minimally accessed API costs next to nothing to deploy.
This widely adopted mechanism of callbacks over HTTP is a common strategy to implement push, pipes, and plugins — all of which increase the utility of web applications. Serverless frameworks are particularly well suited for webhooks for the same reason they’re useful for creating APIs generally: low overhead, minimal maintenance, automatic scaling. For example, a webhook can be implemented on Azure Functions with Node.js to process SMS messages or phone calls through the Twilio service.
What’s more, most webhook-type actions don’t need a lot of code to get to work. Thus, they’re ideal for the function-oriented approach provided by a lambda-style serverless setup and less likely to outgrow such a delivery mechanism.
Serving static content
Serverless architectures also provide a straightforward method to serve up static content: images, audio, or HTML pages that are not modified by an application. Static assets can be stored on a number of back ends, including an Amazon S3 bucket, and be accelerated through a geolocated cache, such as Cloudflare. (If you are using S3, it is possible to choose Amazon Route 53 to map URLs to specific resources; AWS Lambda itself isn’t even needed for these rudimentary cases.)
Again, the big advantage is that each piece of the puzzle automatically scales to fit demand. It’s also relatively easy to add dynamic functionality over time if needed. However, with this approach, spin-up time for the function might impact performance, so geocaching becomes more useful.
The upside is that each separately served element of the application can scale independently. The downside is that the app has to be implemented as a collection of disparate functions rather than a single unified project, though this should not be much of a hurdle for anyone using modern source control and project management techniques. Also, you will need to implement a front-end framework like React, Angular, or Vue.js — but again, any self-respecting web developer should already have at least one of them.
Background, event-driven apps
Serverless apps run in response to events, but nothing says an event has to be a HTTP request. It could be an event or a message piped in from a cloud service or triggered to run on a schedule — a convenient method to perform passive or low-priority functions. For example, an image uploaded to an S3 bucket could trigger a function that causes the image to be labelled with appropriate metadata, resized, and cropped based on feedback from an image recognition or analysis API.
The most consistent detail about working with serverless frameworks right now is that they involve creating loosely coupled components — microservices, for lack of a better word. If the app you have in mind doesn’t lend itself to being composed in this manner or if you are trying to port a monolithic app that will be difficult to pull apart and rework, do not shoehorn a serverless setup into that role. Build new, little elements, and grow them from there.
IDG News Service