Three approaches to deploying a web application (Part 3)

Example of application: a webscraping program of press articles with sentiment analysis.

Imagine: Your webscraping project is finally finished! Or almost... You now have an application capable of extracting online press articles and then performing sentiment analysis on their content. You have solved all the compatibility issues between NLP libraries in your virtual environment. Your parsing approach is robust, the sentiment analysis holds up and you are satisfied with the visual output.

How to make the world benefit from your invention? On the web of course!

Between a program developed on a local machine and a secure web service accessible to the world, there are a number of steps to consider. The term "deployment" refers to the process required to put an application into service, also called a web service. There are many approaches to deploying a web service. In this series of articles, we will present 3 scenarios:


In this series of articles, we will present 3 scenarios:

Scenario 1: From-scratch approach

Scenario 2: Docker approach

Scenario 3: Serverless approach


Scenario 3: serverless approach


What is serverless computing?

Serverless computing is a computing service that does not require the user to manage the underlying server capacity. The provision, maintenance and scaling of the servers is handled by the cloud service provider (CSP).

 “There is no such thing as the cloud, it's just someone else's computer”

Cloud computing is just an expression to refer to computing services that are delivered over the internet. Behind a cloud service, there are always real computers, processors, networks and other hardware running in a data center somewhere around the world. For instance, Azure relies on hundreds of independent data centers located in more than 60 “regions”, themselves divided into multiple availability regions for business continuity purposes. 

Likewise, when an application is running on a serverless tool, it does not mean that it runs without any server. It just means that cloud users don’t need to worry about those servers. 

Serverless computing is similar to PaaS or “platform as a service”. In the PaaS service model, the responsibility of the cloud service provider is not limited to hardware provision, maintenance and security. Instead, the CSP also takes care of the operating system, the middleware, security patches or more, depending on the type of service. 

As such, PaaS differs from “infrastructure as a service” or IaaS, where users simply rent hardware and are responsible for everything else. In IaaS, the CSP only guarantees the proper functioning of the hardware, its maintenance and security. A virtual machine (VM) is an example of IaaS.



Why use serverless computing?

The first benefit of serverless computing is simply a benefit of PaaS itself: simplicity. Users only need to provide the application code as well as the configuration for deployment. On the contrary, deploying a service on a virtual machine requires significantly more maintenance for the cloud user. 

The second benefit, and certainly not the least, is elasticity. Elasticity simply means a service can scale up when demand increases and shrinks when demand decreases. Serverless tools can grow their capacity according to the incoming traffic without human intervention. 



Serverless tools examples



AWS lambda

Azure Functions

Google Cloud Functions



Deployment scenario

Serverless tool: Azure Function

Code editor: VSCode 

OS: Ubuntu

Language: Python

Install the Azure extension or the Azure Function extension on VSCode

  • In the Azure section, create a new workspace locally (click Add and Create Function, then follow the instructions to select the function name, runtime, etc.)

  • This action will generate the Azure Function boilerplate code, including: 

    • The json configuration files,

    • The git, .gitignore and .funcignore files

    • A virtual environment folder named .venv 

    • The function folder containing the __init__.py (the application code goes there)

  • At this moment, a simple demo application should be inside the __init__.py file, test it using the VSCode debugger (shortcut F5)

  • Once the application is launched, you can see it in your browser

  • Replace the code in the __init__.py with your actual application - in this case the web scraping and sentiment analysis application - don’t forget to include whatever additional files your application requires like modules or serialized models. 

  • Install all the required dependencies and make sure the application runs well locally

  • Create a requirements.txt at the root of your application and populate it with the required dependencies. You can use the following command:  pip freeze > requirements.txt 

  • Pro tip: make sure only the dependencies your application needs to run are installed in the virtual environment. No more, no less. 

  • Start the debugger again with F5 

  • Make sure the application runs properly: you can copy and paste the application URL to Postman and test it with a few requests

  • Go back to the Azure extension and select the Azure Subscription where you want to create your Function. Create the Function

  • Select the workspace that you created earlier and click Deploy

  • The deployment can take a few minutes to complete

  • Go to the newly created Azure Function where the application is now deployed and copy the function URL to a browser. And voilà! Your application is now deployed. 

In short, the serverless approach allows you to deploy a web application without having to manage the servers on which the application runs. The management of the servers is outsourced to the cloud service provider. Serverless solutions are characterized by their simplicity of use and their elasticity. Elasticity means that an application has the ability to adapt its computational resources according to the incoming traffic. 


This article concludes the series of articles on deployment.