Intro to Deployment: Software Engineering 13 Phase 4 Hybrid

Learning Goals


Key Vocab


Introduction

So far during this phase, we've been working on developing applications and running them locally on our own computers. If we want other folks to be able to interact with our applications, that means we need to deploy them to another computer that's configured to allow requests over the internet, from anywhere in the world!

This process essentially involves:

As a web developer, it's essential to familiarize yourself with the deployment process for a few reasons:

In this lesson, we'll explore the deploying process and identify the things a web server needs in order to host a Flask application.


Defining a Web Server

All web servers share the same common goal: they must be able to handle HTTP requests, and send back a response. The simplest kind of websites are known as static websites Links to an external site., which typically means sites that store all their content in pre-built HTML, JavaScript and CSS files that are saved to the file system and sent back when a client makes a request for that specific file:

static server diagram

Static websites are still quite common on the web; but there's also a large portion of the web that is dynamic Links to an external site.. With dynamic pages, the content returned from an HTTP request isn't derived from just an HTML file, but instead is processed by some code running on the server before it's sent back to the client. All Flask applications are dynamic, since every request needs to be processed by Flask in order to determine the correct response.

dynamic server diagram

Since hosting a server for dynamic websites is a bit more complicated, let's discuss some things a dynamic server needs in order to do its job.


Application Environment

One big consideration for developing any application is: what environments does the application need to run in?

Broadly speaking, application environments are split into three categories:

Other environments you may use when building an application are a QA (quality assurance, for manual testing of features) environment and a staging environment (a preview of the production environment, usually used as the last stage before deploying a new feature). These are standard for larger teams.

Take a moment to think about all the things that are required to run a Flask application in your local development environment. When you're working on a lab, what setup is needed so that you can type python app.py in the terminal, and view your website in the browser?

For starters, there's your environment setup: you could be running on OSX, or WSL, or Linux; you'll need to have a recent version of Python installed; you'll need Git for version control; and a few other system dependencies.

There are also all of your application dependencies: the code specific to your Flask app that needs to run. That includes the Flask library itself as well as all the other libraries in your Pipfile.

You'll also need some kind of database to persist all your data. It's helpful to think of the database in isolation from the rest of your application, as a kind of resource that's available to your Flask app; ideally, even if your Flask app goes down for some reason, your database shouldn't go down with it!

A note on databases: for the labs in this phase, we've been using SQLite as a lightweight database. It's great for quick development, but it doesn't scale well to larger applications. We'll be using PostgreSQL for our database moving forward. More on that later!

Since all of these elements are required in order to run our application, whatever system we choose to deploy our code on will need to be able to handle a similar environment setup. Let's explore some options.


Deploying Options

When it comes to deciding which platform to use to host our deployed applications, there are a number of options, each of which comes with some tradeoffs. For Flask in particular, a few popular choices are:

One thing these services all have in common: they all have the ability to easily configure an environment to run our Flask applications in. These services own the hardware (the physical servers and networking infrastructure) that your code will run on, but they also have configurable containers Links to an external site. with resources dedicated to run your code.

These containers are what makes it possible to quickly and easily set up a new production environment that has all the functionality needed to run your site:

There are a lot of considerations when it comes to choosing a platform for deploying your application, such as:

For now, since we're deploying our very first Flask projects, we're going to prioritize cost and ease of use to decide on a platform, and use Render for deploying in the coming lessons.

Render Links to an external site. is first and foremost a Platform as a Service (PaaS), which means they manage the hardware your code runs on as well as the software environment, with an aim of making it as simple as possible to take the code from your machine and run it on theirs. Render also has a free tier for developers to try out the service at no cost.

, AWS's Elastic Beanstalk Links to an external site. and Digital Ocean's App Platform Links to an external site. are also Platform as a Service options as well, so you're welcome to try them out for future projects if you're interested in exploring other options.

The downside to PaaS options is that they tend to cost more in the long run as your application scales up, since you're not only paying for the hardware your code runs on, you're also paying for the platform maintenance and security. They also tend to make it more challenging to fine-tune the environment in a way that is optimal for your specific application, rather than all applications running on their service.

The upside is that compared to handling that configuration ourselves, using Render will make it much easier to get our app up and running in a production environment on a server.


Conclusion

The end goal of developing web applications is to share them with the world, and deploying is the crucial last step in this process! As a developer, it's important to equip yourself with the knowledge of what it takes to deploy a website so you can evaluate the available options and choose the right one for your project.

In the coming lessons, we'll go through that deployment process with a couple of applications of varying complexity so you can build the confidence to deploy your own projects independently.


Check For Understanding

Before you move on, make sure you can answer the following questions:

How does having an understanding of the deployment process help you as a developer?

Deployment is necessary to make applications available to users.

As fun as local development and seed data can be, they do not allow others to use your product and view data that reflects its use.

What are the advantages and disadvantages of using a Platform as a Service (PaaS) to deploy a Flask app?

PaaS solutions reduce maintenance time and streamline deployment.

PaaS solutions may limit custom functionality and can get expensive.

Resources

Powered by Forestry.md