Libraries as a Service for Serverless Platforms

Dragos Dascalita Haut is a project lead for Adobe I/O with a fantastic international team based in Romania, India, and his hometown of San Jose. Together, they work on scaling Adobe’s APIs using a distributed serverless platform.

In his talk at Serverless NYC Meetup, called ‘Libraries as a Service,’ Dascalita Haut explored the idea of annotating libraries to make them directly deployable in serverless environments. Usually, a library needs to first be embedded into a service, compiled, then deployed somewhere, before becoming consumable. Since serverless platforms emphasize the reusability of a function as a deployable unit, he asked the question, “what if we could annotate libraries with enough metadata information to make them directly deployable in serverless environments?”

Experimenting with Libraries in a Serverless Environment

Dascalita came up with this idea after experimenting with passport.js, a Node.js library used for authenticating users in a web application. He was able to write a small adapter that would allow passport.js to be deployed as a function and registered with an HTTP endpoint in OpenWhisk, an Open Source serverless runtime. With OpenWhisk, multiple actions can be composed together to create a workflow. He created three actions for the login functionality: the credentials, storing access, and encryption. After chatting with some colleagues about this experiment, the idea of ‘libraries as a service’ came to be.

“If we have libraries that could be annotated in a way that a serverless environment understands and is able to deploy them, then these libraries come alive, when needed, automatically,” said Dascalita Haut.

Though he used OpenWhisk for annotations in his experiment, Dascalita Haut said this technique can be applied to other platforms. “In principle, I can provide a signature for my main function that would work the same way in Azure, AWS, Lambda or OpenWhisk.”

The Pros and Cons of Annotating Libraries

Dascalita Haut also talked about some of the advantages of annotating libraries for a serverless platform, such as being able to avoid having to integrate the same functionality into different microservices. In serverless it’s available and scalable, which simplifies the maintenance. The library can be updated once and every composition that uses it will benefit from it.

Other advantages include code reuse, which helps to bring your projects to market faster, and makes it possible to share functionality that others can use in their compositions without sharing the source code. You can also deploy them in multiple serverless solutions.

“When you build a library, you can also build it in a way that the same functionality for an individual library could be deployed in multiple providers at the same time, using some descriptor. Like a serverless YAML file or OpenWhisk YAML file that allows you to get the exact code and deployed in the environment that you want,” said Dascalita Haut.

While there are many advantages there are also some things to keep in mind. Dascalita suggests not putting everything into a single function. “In some cases it may not be straightforward to write a generic signature for your function that would work exactly the same in all platforms such as AWS, Google Cloud Functions, or Azure. Why? Because there might be dependencies that make sense just in a single environment,” he said.

But he also cautions against using too many functions and going too granular, to avoid a latency penalty.

The Future of Libraries as A Service

The takeaway that Dascalita Haut was hoping to give the audience at his talk was to get people thinking about writing functions that can be deployed by someone else in any serverless environment. He poses the question, “If I’m a developer thinking about writing a library and I want to share the library, will I put a little extra effort in to make the library deployable in this serverless environment?”

It may be a little more effort in the beginning, but making libraries directly deployable in a serverless environment can go a long way in making your code more efficient and reusable.

Dragos Dascalita Haut

To learn more about Dragos Dascalita Haut’s talk, check out his slides and code samples on SlideShare.