Formerly known as Wikibon
Search
Close this search box.

Using Functional Programming to Build Serverless Cloud Applications

Premise

Functional programming enables developers to produce code that is clear, modular, parallelizable, efficient, maintainable, and portable. Based on a universal model of computation called lambda calculus, functional programming operates on immutable data, relies on stateless event-driven methods, and eschews cross-module dependencies and transition rules. As such, it is well-suited for developing the lightweight microservices from which serverless computing applications are composed.

Analysis

Functional programming is a well-established development paradigm that taken on added importance in the era of serverless computing. By decoupling coding decisions from the management of serving infrastructure, it can accelerate the DevOps pipeline for cloud-native applications.

Functional programming provides an abstraction for developing stateless, event-driven code. In serverless computing environments, it spares developers from having to write the application logic that manages containers, virtual machines, and other back-end microservices runtime environments. And it allows developers to avoid embedding cross-module dependencies, complex transition rules, synchronous function calls, and other heavyweight application logic into their microservices code.

Functional programming should be a core approach for developing serverless computing applications. However, it’s not suited to all cloud-native use cases or other application scenarios. Developers should not consider functional programming for any microservices or other application requirements patterns that involve stateful, procedural, orchestrated, mutable , guaranteed consistent, or tightly coupled interoperability.

For application developers, Wikibon provides the following guidance regarding adoption of functional programming:

  • Identify suitable enterprise use cases for functional programming. This approach supports any use case that involves REST-based publishing of API endpoints, incorporates event-driven application semantics, and/or content serving in request-response interactions. As illustrated by the established use of functional methods in many traditional applications, these need not be limited to cloud-computing use cases.
  • Interface functionally programmed apps to other computing paradigms. Functional programming is suited only to a subset of application semantics. Depending on the application project, developers may need to hybridize functional programming with other approaches to support procedural, orchestrated, mutable, guaranteed consistent, and/or tightly coupled application semantics. Likewise, it might be necessary to hybridize serverless clouds with other clouds, platforms, and runtime execution environments to support the full range of application requirements.

Identify Enterprise Applications Best Suited to Functional Programming

Functional programming is a well-established programming paradigm that long predates cloud computing. It provides an abstraction for simplified development of highly scalable applications, as long as you accept the core constraints of the approach.

Functional methods build microservices and other types of applications through the evaluation of mathematical functions that eschew modifications to program state and application data. Grounded in lambda calculus and traditionally focused on scientific computing, it allows developers to construct application logic through expressions that incorporate values, constants, variables, operators, and other explicit arguments. Within a functional-capable interpreter, the results being computed depend purely on the arguments within the expression passed to it.

As befits the long vintage of functional programming, there are many programming languages in which these expressions may be built. Languages designed for functional programming include Common LispSchemeClojure, Wolfram Language, RacketErlangOCaml, HaskellF#, C#, APL, and Opal. It’s possible to program functional code in some general-purpose languages, such as PerlC++11Java 8C# 3.0Julia, Swift, and Scala, and to script them in frameworks such as Node.js and languages such as PHPJavaScript, Python, Bash, and PowerShell. Within the space of domain-specific languages focused on statistics and data management, support for some functional constructs—such as eschewing of mutable values–is included in R, XQuery, XSLTSQL, and Lex.

The principal criteria for identifying which use cases are best suited to functional programming consist of the following:

  • Do they involve publishing of API endpoints? This involves automatic creation of REST APIs that return data from back-end cloud services in response to programmatic requests (e.g, via HTTP GET). This approach relies on a basic web framework (e.g., js), a library for rendering data in the format being returned (e.g., JSON), and microservices or other code for pulling data from back-end service.
  • Do they involve event-driven application semantics? This involves automated sending of notifications and alerts in response to scheduled triggers or to such unscheduled events such as ingest of messages, files, sensor outputs, and other content, as well as mouse-clicks, key presses, and other user-initiated actions.
  • Do they involve content-serving applications? This involves request-response interactions that return data, images, webpages, streams, and other content not created, modified, or deleted by the requesting applications.

Though this may sound like a narrow list, it includes a vast swath of core applications upon which the digital economy depends. Any of the following applications may be implemented as event-driven, stateless functions over serverless clouds: API publishing, query response, data transformation, data filtering, intelligent caching, web publishing, face and voice recognition, content processing, image processing, stream processing, alerting, and on-the-fly log analysis.

Interface Functionally Programmed Apps to Other Computing Paradigms

As noted above, functional programming is suited only to a subset of application semantics, just as serverless computing environments are not all-purpose computing fabrics.

Within serverless computing environments, functional programming is the basis of what it commonly referred to as “function as a service.”. Serverless environments—such as AWS Lambda, Microsoft Azure Functions, Google Cloud Functions, and IBM Bluemix OpenWhisk–automatically provision, scale, and manage function-specific microservices for diverse use cases. Serverless environments manage microservices on demand through lightweight protocol bindings. The serverless fabric enables speedy functional microservices startup and teardown with minimal overhead and maintenance. They allow developers to create functions in the cloud and run them without having to worry about managing infrastructure.

Depending on the application projects, developers may need to blend functional with other programming approaches and serverless clouds with other execution environments. When they are required, stateful application semantics should be served from an adjacent computing fabric, such as a public, private, hybrid, or edge cloud, that executes code developed in a complementary paradigm known as “imperative programming.” Typically, functional code would need to interface to external stateful programs within use-case scenarios that conform to any of the following interoperability profiles:

  • Procedural: This refers to any program that uses procedure calls, aka routines/subroutines, containing a series of computational steps to be carried out, with any given procedure callable at any point during a program’s execution, including by other procedures or itself.
  • Orchestrated: These programs involve the pre-arranged automated coordination of multi-node data exchanges, execution steps, and state transitions.
  • Mutable: These programs create, revise, and/or delete fields, files, datasets, and other content objects within the context of interprogram communications.
  • Guaranteed consistent: These programs enforce the requirement that database transactions may change affected data only in allowed ways in order to maintain validity and transactional integrity according to clearly defined rules.
  • Tightly coupled: These programs involve any or all of the following levels of conjoined node-to-node interoperation: direct physical links, synchronous communication, strong type systems, complex object trees, central process-logic control, statically bound services, strong OS dependency, and programming-language dependency.

Depending on their programming, application, and IT infrastructure, developers may be able to bridge functional and these other programming environments via API calls, through API gateways, message-oriented middleware, and other approaches. Essentially, standing up a full functional app—spanning serverless and other computing environments—might involve daisy-chaining APIs through a blend of functional and imperative code.

Action Item

Developers should use functional programming to build stateless, event-driven code for deployment into serverless computing environments. As they do so, they should make sure the functional apps play well with the stateful, imperative code that executes elsewhere in their public, private, or hybrid cloud environments.

Article Categories

Book A Briefing

Fill out the form , and our team will be in touch shortly.
Skip to content