Architektur

Function as a Service (FaaS)

Function as a Service
Carsten Wiesbaum
Carsten Wiesbaum

In the last few years lightweight and flexible technologies and architectures become the predominant approach for enterprise applications. Besides Microservices, Function as a Service (FaaS) or Serverless Programming is a commonly discussed topic. Some see FaaS as an addition to today’s lightweight architectures, others see it as next step within the evolution of Cloud and IT.

Throughout the last few months I had many interesting discussions regarding FaaS and recognized that many people have problems to understand underlying concepts and identify useful use cases. As result I want to share my thoughts about this topic within a blog series.

Within this article I want to share my understanding of FaaS and why I, as an architect, see it as valuable addition to solve certain problems. To support my argument, I will present an example using a technology most people would not expect when reading about FaaS. In the second article I will reuse my example and show an implementation using Oracle’s fn project, an open source FaaS platform. Finally, in the third article I want to show how to combine fn project functions to solve more complex problems.

Functional Programming

First of all, let us talk about functions. In my opinion functions have the following basic characteristics:

  • Clearly defined input
  • Clearly defined action which they execute based on the input
  • Clearly defined output
  • Are idempotent, meaning using the same input several times results to the same output each time I execute the function

Let us explain these characteristics using an example. Within the example we use the following data structure as input:

As one can see it is a simple JSON-Array containing generated records about persons and some kind of bookings. For this example, we have a line-based text file with 1000 records. Let us assume we want to identify all persons which bought a specific product. In order to identify the records, we want to use a function to which we provide the file and a product name (input) and expect to get all records which contain this product (output). Good news, such a function already exists on most Unix like systems!

In the example above the Unix filter command grep is used in order to fulfil our requirement. We pass the search string Barcadi Raspberry and the JSON text file as input. The filter command returns two lines and will always return the same result as long as the input stays the same:

Now let us assume Marketing approached us with the requirement to be able to search customers which ordered a specific product and get an email list for those customers in order to start a targeted marketing campaign. Taking the list of two records (IDENTIFIED_CUSTOMERS.json) above we can easily create this list for marketing using the same Unix filter command:

It is also possible to directly combine both functions using the | symbol:

This way we just have to execute one command in order to fulfil the stakeholder requirement.

Pipelines and Filters

The underlying architecture on which Unix shell commands are build is Pipelines and Filters. Within this architectural pattern multiple filter programs are combined using pipelines which simply connect each standard output stream to the next filter program’s standard input stream.

Pipelines and Filters

From my point of view two aspects of this architecture and programming style are very interesting:

  1. Each filter program has one purpose and fulfils it as perfect as possible
  2. Complex problems are solved by combining multiple filters using pipelines

Using this approach, it is possible to solve quite complex data processing tasks just using a few filter commands within the Unix shell. As an architect the simplicity and flexibility aspects are the most interesting characteristics of FaaS and why I see it as valuable addition to many architectural solutions. The commands we use every day within shells are the best example how functions in context of FaaS could look like and what kind of problems they are able to solve.

Within the next article I will use Oracle’s fn project to solve the same requirement and show how FaaS platforms work in general.

Further Reading

Oracle fn project – Oracle’s open FaaS Platform
Mockaroo – Test data generator (free up to 1000 records)
Wikipedia article regarding filter applications
Source Code Examples on GitHub.com