Flask in Production with Nginx - Microservices
Explore how to deploy Flask applications in a production environment using Docker with Nginx as a proxy server and Gunicorn as the WSGI server. Understand microservice architecture, secure communication with self-signed certificates, load distribution with replicas, and resource management for robust app performance.
We'll cover the following...
Getting exposure to production systems before starting on any project will definitely give you a positive feeling and confidence. This lesson is all about how the app looks like in production.
There are n number of ways an app can be deployed in production, but the idea behind is the same: using an architecture which can survive the load.
Type
git logand checkout the commit 327b245bbd4392d3dee40a24457c3ed44a1ef5b9 ( Flask in Production with Nginx - Microservices) for code related to this lesson.
Production code explanation
You will see a lot of changes in this version of the code. Let’s list them one by one.
Docker level
- New Nginx service
- Read-only mounting of the file system
- Resources limitation
App level
- New wsgi server
gunicorninstead of flask server.
The Gunicorn “Green Unicorn” is a Python web server gateway interface HTTP server. It is a pre-fork worker model ported from Ruby’s Unicorn project. The Gunicorn server is broadly compatible with a number of web frameworks, simply implemented, light on server resources and fairly fast
All these changes will make our app stable and robust. Adding extra replicas of services leads to a better distribution of load received by the app. Let’s see the detailed explanation of every change we have done in this version.