The case for Functional Programming and Serverless Architecture
Increasing options
Sometimes a new computing architecture is so radical, so compelling, it is hard to see it’s value and roadmap from the start. Think of Infrastructure as a Service (IaaS) — “in their data centre, not yours” albeit virtualized, and also Platform as a Service (PaaS), similarly with greater abstraction, and significantly, easier scalability. The value, from the start, was business value: Business has driven the adoption of IaaS and PaaS.
SaaS — Off the virtual shelf
The pinnacle from the business viewpoint has been Software as a Service (SaaS): Why run your own email, calendar and office services if a vendor will do that at a reasonable cost? That’s why I recommend Google Business Services (G Suite) to small business and start-ups. Why run any infrastructure at all if you can outsource it at a reasonable cost? Reliability probably should not be the reason; Information Security might be, but security architectures are evolving where the service provider never has your data in a form they can decrypt, government interference notwithstanding.
PaaS — Build Your Own
However, if you are building your own application or service, what are your options? You could embrace the infrastructure challenge and go for IaaS, and accept the attendant infrastructure cost of ownership; Alternatively, you could base your entire project on technology at a sufficient level of abstraction that the infrastructure challenge vanishes and base your entire project on technology at a sufficient level of abstraction that infrastructure is not a concern of yours.
Caveat Emptor — Trade Abstraction for Control
But be careful: It’s great that you will not be managing infrastructure, someone else will be — keeping security patches up to date and leveraging off experienced availability architecture, but if you choose a closed-system, ‘Everything-as-a-service” monolithic provider such as ServiceNow, be aware that you don’t have options on how that architecture develops, or to revert to hosting your own technology — that is the case with ServiceNow at least. You are taken along for the ride wherever they go, with the attendant costs: You are a disciple, whether you like it or not.
PaaS — Does it have an Image Problem?
I think that PaaS might have an image problem: Folk get that IaaS means no more data centre to manage; They get that SaaS reduces 3rd-party application procurement and management, but PaaS, as a development platform concept, I don’t think has been selling as well. The compelling concept of the infrastructure challenge vanishing, while still providing a flexible, scalable platform can be improved. Enter ‘serverless’:
The ‘Serverless’ Option
There is another PaaS option that is gaining traction, “Serverless” architectures. It is intrinsically linked with functional programming — what a surprise that this 1960s programming language approach finds such application at this time in history. There’s one more infrastructure trick with serverless, not only is the infrastructure virtualized, abstracted and managed by the cloud provider, but it’s spun up on demand and billed on resource usage(CPU, memory, NW bandwidth). Now one can envision architecture solutions with no mind to the underlying infrastructure configuration, provisioning, scaling, or administration. This abstraction is referred to as ‘Serverless’, and I think it will continue to prosper. You don’t need to know when, or for how long, the underlying VM or container (aka “server”) was up, and you don’t care, it’s not what you get billed for: It’s not so much server-”less” as server-”don’t-care”.
The Progress of Functional Programming
Functional programming found application in the area of developing super-resilient services for the telco industry, such as the Open Telecom’ Platform (OTP) and the Erlang functional programming language. Sometimes it is hard to appreciate it, but if you reduce and simplify, you often improve: That has been the case with safer language subsets such as the MISRA-C for the Motor Industry, and it turns out that if you remove data mutability (assignment), then you benefit in many ways, including, importantly, with multiple threads of execution. With this, and their focus on OTP’s manageability, Erlang/OTP became a great platform for reliable, scalable applications, and the Elixir language, based on the Erland/OTP platform, has provided a more approachable, useful language than Erlang. The application area now is much greater than Telecom — anywhere where you need reliability, even embedded systems, and the web application framework, Phoenix, built on Elixir OTP, provides a platform for super-resilient, scalable, and efficient web-apps.
FaaS — Function as a Service — “Serverless Architecture”
To spin the infrastructure up and down sufficiently indiscriminately to provide this “serverless” service, again you need to reduce and simplify to improve. This is achieved by having the service constrained to be a function, in the functional programming sense of a function. Amazon’s FaaS is ‘Lambda’. For a service to operate on-demand it is convenient to have the services defined as functions, and these functions tied to either APIs or events. Scaling multiple threads of execution benefits; Latency of infrequently executed code suffers, perhaps too much for some applications.
Concept Scalability — Complete Applications
This serverless architecture begs the question, “How far can (should) we take this”? For starters, serverless architecture and functional programming are Turing Complete — it’s possible to develop application entirely in them, but (i) should we, and (ii) will we? I think in the near term we will see applications where they fit best — back-end services, data processing, some, or some component of, web-apps, even chatbots and voice recognition services. Will they be entirely hosted on a serverless platform? Perhaps, if the fit is good enough.
Concept Scalability — Similar Services
AWS have other non-compute services that are analogous to the compute serverless service Lambda, and other vendors provide a similar FaaS to Lambda.
- AWS S3 — Simple Storage service — Charged for MB/month + bandwidth usage + get/put rate. In a similar way, you don’t need to know the underlying infrastructure configuration, provisioning, scaling, or administration. Compare that with provisioning and maintaining your own storage service. Also, with S3, if your application hardly ever uses this resource, you will hardly ever receive bills for using it even though it is continuously available.
- AWS Dynamo DB — NoSQL Service — Can be billed for on throughput or storage amount, but otherwise is a similar business prospect to AWS S3.
- Google Could Functions — Is a Google FaaS serverless offering.
- IBM Blue OpenWhisk — Is IBM’s FaaS offering. Similarly “it costs nothing when not in use”, has node.js, python and java interfaces. It is open source, so you can develop your own infrastructure before deployment if you like that way.
- Microsoft Azure Functions — The Microsoft FaaS Service.
Conclusion
I believe FaaS Cloud Services will become a compelling proposition as a platform of choice for the development of services, microservices or otherwise, that fit the functional paradigm because there is (i) no infrastructure to manage, (ii) no fees when the service isn’t being used and (iii) there is scalability and reliability to be had at a reasonable cost. It may even lead to greater adoption of this programming approach where reliability and scalability are critical.
For mission-critical, high-performance applications, I believe the Phoenix/ Elixir / Erlang OTP is an excellent choice: I’ve developed complete services and applications in Elixir and Phoenix and found it strangely compelling and surprisingly efficient and powerful. There’s already great tooling, and application support should continue to grow.
Resources
- “Functional Programming Application and Implementation” by Peter Henderson — Great early book on functional programming using Lispkit Lisp — https://www.amazon.com/Functional-Programming-Application-Implementation-Henderson/dp/0133315797
- Serverless Ops — A Beginners Guide to AWS Lambda and beyond — Free eBook http://www.oreilly.com/webops-perf/free/serverless-ops.csp
- Functional Programming is probably not what you think — Online article — https://dzone.com/articles/functional-programming-is-not-what-you-probably-th
- Serverless Architectures — Another great online article — https://martinfowler.com/articles/serverless.html
- Good YouTube Video on AWS Serverless Architectures — https://www.youtube.com/watch?v=AcGv3qUrRC4
- Elixir Language and OTP — http://elixir-lang.org/getting-started/mix-otp/supervisor-and-application.html
- Wikipedia on Cloud Computing — https://en.wikipedia.org/wiki/Cloud_computing#Service_models
- Wikipedia on Serverless Computing — https://en.wikipedia.org/wiki/Serverless_computing
- Wikipedia on Turing Completeness — https://en.wikipedia.org/wiki/Turing_completeness