Chapter 1. Introduction

This book aims to help you enter the exciting new world of serverless development. By the end of the book, you’ll know how to use Apache OpenWhisk to write serverless functions and how to call them from applications. You’ll see how to create powerful new services by combining existing actions into sequences, as well as how they can be automated with triggers.

What Is Serverless?

The technical industry is rife with terms that sometimes bear little to no resemblance to what they supposedly represent. Serverless is the latest example of this. Many people object to the term because servers are always involved with anything hosted on the internet. Of course, if we can get over the fact that the cloud isn’t literally a few thousand feet over our heads, we can move to accept this new term as well.

It’s best to think of serverless as not the lack of servers, but the lack of server management. Serverless is best described as the ability to deploy your apps without worrying about provisioning and managing a server. This could be seen as a natural outgrowth of the cloud and virtual servers.

Virtual servers greatly improved our lives by allowing developers to add (and remove) servers with the click of a button. Suddenly, you didn’t have to ask permission, or wait around, to put your application online. As awesome as this was, it came with some drawbacks.

Servers require maintenance. They have to be locked down. They have to be set up with the appropriate amount of RAM and disk space. They also have to be running to actually do anything. While that’s obvious, it’s easy to forget that you’re paying for a server to run all day, every day, even when the app in question isn’t actually being used.

This is where serverless truly shines. Instead of provisioning an entire server, you can take the logic that comprises your application and simply deploy it as is. You can think of this as “Function as a Service.” This greatly simplifies the process of getting what you need online and ready to be used. You no longer need to worry about setting up a web server or figuring out how to route a particular request to a particular piece of logic. Instead, you deploy that logic (a function) and the serverless provider handles everything else.

Best of all, your costs can go way down. Instead of a server running constantly, the serverless platform fires up your code when requested. When your code isn’t being used, nothing is running. You pay for your usage and nothing more! While every platform has it’s own pricing model, your costs in general will be far less.

If you think this sounds compelling, you aren’t alone. Many of the biggest tech companies now offer serverless as a product offering. Amazon led the way with AWS Lambda, the oldest and most mature serverless platform. Google has Cloud Functions, and Microsoft has Azure Functions. In this book, we’ll be focusing on IBM Cloud Functions, a serverless solution created by IBM based on Apache OpenWhisk.

Serverless Use Cases

It is (most likely) simpler to work with serverless and certainly cheaper, but what are some use cases where serverless shines? Here are just a few examples.

APIs for CRUD

CRUD, or Create/Read/Update/Delete, refers to how people typically work with content. Given you have a set of data, your app may need to perform CRUD as part of its functionality. In the past, APIs for this would be built in a server-side application and handle passing calls back and forth between a frontend and a backend storage system. Serverless is great for these simple proxies by reducing the amount of overhead you need to support the APIs.

Rewriting APIs

One of the cooler things you can do with serverless is build an API that rewrites another API. Imagine an API that only returns XML. You could use serverless to build a proxy that transforms it to JSON. Imagine an API that returns useful information, but also a lot of data your clients don’t need. You could use your API to simply remove the unwanted data.

Slow background work

Anything that is slow (comparatively) will typically be handled by a process running in the background on a scheduled basis. Examples of this include image processing (such as optimizing and resizing), log processing, or simply handling uploaded files. Serverless is a great way to build these background utilities.

Who Is This Book For?

This book is for the developer who works on the backend, creating services to support frontend clients. Those clients could be basic websites or more modern progressive web apps. They can also be mobile apps written using hybrid technologies like Apache Cordova, or fully native apps written in Java or Swift. This book is for anyone who has had to set up an environment, a web server, and other tools just to build an API, and would love to see a much simpler way of standing up services.

Apache OpenWhisk supports multiple languages, but this book focuses on JavaScript for working with serverless. You do not need to be a JavaScript expert in order to work with the examples. If you know nothing at all about JavaScript and want to quickly get up to speed, or just want to brush up on your knowledge, I highly recommend bookmarking the MDN Web Docs, seen in Figure 1-1. Formally known as “MozDevNet,” this site contains both guides and reference materials to all things web related.

Figure 1-1. MDN Web Docs website

There are absolutely no editor or web browser requirements to complete this book. Use the editor and browser that works best for your development. I used Visual Studio Code and highly recommend it.

Getting the Source

You can find the complete source for the code samples in this book on GitHub at https://github.com/cfjedimaster/developing-serverless-applications-code. If you have a Git client installed on your system, simply pull a copy of the repository. If you don’t, use the Clone or download button to get a zip of the files.

Get Developing Serverless Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.