Full Web Apps with FastAPI Transcripts
Chapter: Course conclusion and review
Lecture: Deployment

Login or purchase this course to watch this video and the rest of the course contents.
0:00 After we were happy with our app and we got it built and running,
0:03 it was time to put it on the Internet,
0:05 and we decided Nginx plus Gunicorn would be a great way to deploy our
0:09 FastAPI web application. Nginx is by far one of the most popular front
0:14 end web servers that handles things like static files,
0:17 it handles SSL, and you know,
0:20 upgrades requests to things like HTTP2, all sorts of cool stuff that's happening over there.
0:25 It will be the front line server that our clients actually talk to.
0:29 But when it comes to running,
0:30 our Python code, our FastAPI code,
0:33 we're gonna do that, managed by Gunicorn. We already saw that Uvicorn,
0:37 which comes from Gunicorn,
0:39 is how we were, we've been running our app so far,
0:42 and we're gonna continue to use that in production,
0:44 but not just by running it,
0:46 but by having a bunch of them that Gunicorn can manage.
0:49 So it's gonna spin off 5, 10,
0:52 who knows how many makes the most sense for your server and the number of requests
0:55 you're getting, but multiple numbers of your process as if you had started it just on
1:00 the command line multiple times. And then when a request comes in,
1:04 Nginx is gonna figure out where it goes.
1:06 If it's a Python request, it hits Gunicorn and says,
1:09 hey, drive one of these Uvicorn worker processes
1:13 that's not busy. Well, this one,
1:15 it's not busy, it can handle a request.
1:17 Another request comes in, says here,
1:18 this one's not busy this time.
1:20 Now then maybe those two are busy,
1:21 another request comes in, it picks this other one this next time.
1:25 And this is generally how our web application works.
1:27 We saw that setting up Gunicorn to run,
1:30 we had a special config file to do that as
1:33 a systemd service. And then we have a special config file to set up
1:38 Nginx, and then we also had a whole script to actually build out
1:41 the Ubuntu server just the way we wanted it.
1:44 It might be a lot to take in at the beginning,
1:46 but if you go through it a few times,
1:47 you'll figure out what the important parts are to pay attention to, and the rest,
1:51 you'll just copy and paste; and remember,
1:53 this script goes there and then we're good to go.
1:55 Not too bad. So good luck running your app in production.