Exploring Serverless computing and Implementation of Function as a Service in a Local Private Cloud

Rietesh Amminabhavi
Nov 2 · 4 min read

The Code for Flask web app, Dockerfiles and the pre trained model can be obtained from my GitHub repo here.

For Enterprise level there are various Server-less computing platforms such as AWS Lambda, Google Functions and Azure Functions. If you are looking for an open source project then OpenFaas is the right fit.

Motivation behind this project was to learn and understand What is Server-less computing? How does it work. What is Function as a service(FaaS)? and What is Event driven computing?

Timeline/How we got to Server-less:

DIAY=Do It All Yourself, CaaS=Container as a service (Source)

What is Server-less and Function as a Service(FaaS)?

source

The Traditional 3 tier architecture consisted of Database layer, Application layer and Presentation layer. This was Do it all Yourself stage all the layers had to be built maintained and deployed all by yourself. Server-less computing separates these layers, As a developer the only focus is on Application layer other layers are taken care by a Server-less platform. The server-less platform perform all the deployment tasks (networking, dependencies, maintenance, etc.) automatically behind the scenes. These other layers can be called whenever needed similar to APIs. We can think of it as when you call compute then you are essentially using Infrastructure as a service. All the entities of a Traditional server are separated in server-less architecture like Database, Compute, Networking etc.

FaaS has become synonym for server-less computing. For a developer a FaaS platform helps him to focus on writing functions used in building the app. The rest of the job is done by the platform itself like managing dependencies, configurations,deployment and scaling. The app is broken down into several functions and these functions are grouped and maintained by a gateway thus transforming all the backend into an API service.

Event driven computing

The execution of the code/function is triggered by an event these events can be of various type like HTTP, storage or by an IOT device. This execution results in a output these can again be a trigger for another function or just the output to be rendered back to the user. These synchronous execution is coded by the developer while developing the app, Event-driven computing breaks the contract and frees all the parts involved in the sequence.

My Setup

I have a VMware workstation with VMware ESXi hypervisor which consists of two servers. I have a client or developers machine which is connected to internet and also to an internal network with my host as the DHCP server.

Overview
ESXi management center

Docker Swarm:

The servers with Hostname Server and Server1 are in a swarm with server as a managing node and server1 as a worker node. I have built an image (babadook4535/server)from the GitHub repo and pushed it into docker hub using a droplet from Digital ocean. I pull the images onto the Server create a local registry and create a service named catsdogsAPI. These service runs on the swarm and has an API endpoint on /cats-dogs/ the code can be found below.

To learn how to get started with Docker swarm click. The output after creating the service and publishing the port 80 is as follows

We can test the successful deployment of the service by using curl on either of the servers.

Next we go onto the Developers machine and Create a Flask web app, The Developer writes the Functions here for this demonstration he writes a function to hit the API endpoint at our servers which expects a POST request at /cats-dogs/, Finally he hosts this website using an Apache web server, The code for Developers app can be found below

The entire workflow can be visualized as follows

As a client when I visit the website at 192.168.56.103 an HTTP event is triggered, the app takes in a image and the function is fetched and called the execution happens at one of the servers and a result is returned which can finally be rendered to the client in the last step.

In action on a client machine

Further Improvements:

  1. Implementing Load Balancing with NGINX
  2. An Auto scaling script
  3. Removing Docker swarm and Implementing Kubernetes
  4. Implementing Prometheus for monitoring
  5. Implementing something similar to Function watchdogs to monitor the functions

Rietesh Amminabhavi

Written by

Network security enthusiast | Student @ IITG https://rietesh.github.io

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade