Technology news has been filled lately with case studies of companies and developers taking their code “serverless” and saving time and money in the process. This seems to go against all traditional logic. How can server-side code run without a server? The answer lies in the fact that serverless infrastructure isn’t running without a server as the name implies, but rather the infrastructure is abstracted away.
Serverless infrastructure “allows you to build and run applications and services without thinking about servers.” (https://aws.amazon.com/serverless/). In most cases, your code is deployed into a container which is stateless, lasts only as long as your code is running, and is fully managed by a third party. This means, if you have a script to generate a thumbnail from a given full size image, you simply tell your infrastructure provider that the script is written in Python and then fire a request to the script. They take care of the rest and you only pay for the server while the script is actually running. In this way, serverless architecture can makes the traditional “pay for what you use” model of the cloud even more precise.
If you’re not running servers, how are serverless applications built and delivered? Let’s take our image thumbnail example. We would build the code that can take in an image and generate thumbnail output and upload this into AWS Lambda (one of the more popular serverless providers) and set it as an AWS Lambda Function. For optimal performance, we might want to hook it into S3 for storing the images before and after we run our function. We can run our function through either an API call or by triggering it from another Amazon service, such as S3 or or Amazon SNS (Simple Notification Service). Once our function is triggered, Amazon handles spinning up the infrastructure to run our code to completion, providing us any information on errors along the way. Because Amazon handles the entire environment, no thought has to be given to the infrastructure. This is what makes it serverless. After your code for this task has finished running and all the files are back in the correct place, your server is spun down and you’re only billed for the time your function took to execute.
Because Amazon handles the entire environment, no thought has to be given to the infrastructure. This is what makes it serverless.
As serverless becomes a more popular paradigm, more cloud providers are supporting this infrastructure. Currently, Amazon Web Services has been pushing hard in this space with their Lambda service. In addition, Google offers Cloud Functions and Microsoft has Azure Web Jobs. While these are all similar, the best choice usually depends on which provider you are using for the rest of your infrastructure, as integrations are easier between Amazon products, for example, than trying to bridge an Amazon Service with Azure Web Jobs.
Although the serverless paradigm is very flexible, not every development use case is a good fit. Some workflows would require chaining multiple functions together, which can be difficult given the current state of serverless technology. However, there are definitely some cost savings possible when using serverless architecture instead of having servers running when not in use. Like previously discussed, image processing is one great use case for serverless. Another use case for serverless has been the processing of log files or near-real-time site metrics and operational data. Bustle (https://www.bustle.com/) has used AWS Lambda to process metrics coming in from their site without having to worry about scale. The most important criteria here is that the operations can be run independently and fit into the existing workflow.
The easiest way to get started with serverless is to see if you can identify a piece of your workflow that fits the criteria for a serverless implementation outlined above. Is there any piece of your business processes that can be run independently in the background and can be abstracted enough to not have to worry about server configuration? If so, serverless might be a good fit for you. If you’re not sure, we would love to talk to you about your workflow and chat about the cost savings running on a serverless architecture might bring to your business.