If you're thinking of deploying a whole server, think of whether you could create a FaaS application instead.
It’s easier than ever to “spin up” or deploy your own server to support your business. Of course, it’s not exactly your own server, the actual hardware and base configuration is controlled by the Amazons, Googles, Microsofts, and IBMs of the world.
However, you get to put your own software on there without worrying about where the server is located, the utility bills, replacement costs, etc. Now, we can even avoid configuring our servers and scaling our applications with Functions as a Service (FaaS).
So what exactly is FaaS? FaaS is a computing service that uses a serverless architecture approach. Serverless applications have “some amount of server-side logic [that] is still written by the application developer but, unlike traditional architectures, is run in stateless compute containers that are event-triggered, ephemeral, and fully managed by a 3rd party” (Serverless Architectures).
So let’s break that down and go over a simple scenario of using a FaaS, in this case Google’s Firebase Cloud Functions, which we have been using at Leverege.
Let’s say that Nicole is a homeowner whose basement is often flooded, so she wants to install a sensor that will notify her when the water level is too high. I sell Nicole a water level sensor solution which will text her when the water level is too high.
However, I don’t want to run a server all year round to listen for a sensor alert – rain is unpredictable and seasonal. Instead, I decide to use Google’s FaaS, Firebase Cloud Function, which will run only when needed to reduce costs.
So how does it work?
If the water level sensor detects the water is too high, then it can send an “event” to Cloud Functions. So then Cloud Functions receives the event, and starts up my serverless text message function. Notice that the text message function was not already running and was “event-triggered.” Also, Google started up my function and is executing it on their servers, so I don’t have to manage it. While FaaS is called “serverless,” it’s serverless for the consumer, not the FaaS vendor who still has to run servers.
Next, my text message function processes the event and sends Nicole the appropriate text message. After the function execution is completed (the text message was sent), my text message function is terminated.
All of this takes at most a tenth of a second from the time the event was sent from the water level sensor. This process happens every time the water level sensor sends an event, so the text message function is “ephemeral”, or only lasting for a short period of time.
A FaaS application can be thought of as a math function (see below). The input is an event, the output is the result of the function. Like a math function, a FaaS application is essentially “stateless”, it has no knowledge of anything except its inputs and is unable to hold an internal state.
Below is a quick bulleted list of pros and cons of FaaS from Mike Roberts’ article. The pros and cons can give you a good idea of what type of applications are best used for FaaS. Afterwards, we’ll go over more things that are specific to Google’s Firebase Cloud Functions.
Firebase Cloud Functions are Google’s implementation of FaaS. Cloud Functions have numerous benefits specific to being a part of the Google Cloud Platform. From our experience, the three big benefits of Cloud Functions specifically are the following:
Firebase Cloud Functions are written in Javascript and Typescript. Javascript is easily the most popular language on the web these days. On GitHub, the amount of Javascript pull requests is the largest at 2.3 million, the next highest is Python at 1 million.
Typescript is “used in almost four times as many pull requests as last year” (GitHub). Furthermore, deploying Cloud Functions is very easy, it only takes two terminal commands, firebase use <project name> and firebase deploy –only functions.
Firebase is a very popular database product that works perfectly with the simple stateless Cloud Functions. It’s fast to deploy and is quick for real-time data which is essential for many IoT applications.
Firestore is Google’s new document database implementation which is currently in beta. Firestore allows for easier querying than Firebase and scales better. If you want to read about the differences between these two database implementations, check out Cloud FireStore, Firebase’s More Scalable Older Brother.
One of the really cool things I saw was Google Analytics for Firebase Triggers. If a conversion event is logged in Google Analytics, a Cloud Function can be triggered. For example, if a customer buys something in-app, which generates a conversion event, then a Cloud Function could send an email thanking them.
This Cloud Function could be easily and quickly changed based off of promotions or campaigns your company is running. That type of ease and flexibility is really powerful. Cloud Functions and Google Cloud Platform products are only going to get more integrated with each other, which is really exciting.
FaaS is not for all applications, but it is definitely useful and here to stay. Whenever you are thinking of deploying a whole server, think of whether you could create a FaaS application instead. Personally, Firebase Cloud Functions have worked well for my team and me, so give that a try if you’re looking to use FaaS.