Full Web Apps with FastAPI Transcripts
Chapter: Deploying FastAPI on Linux with gunicorn and nginx
Lecture: Surveying some hosting options
0:00 I often get asked: where should I host my web app?
0:03 my Python web app? People either ask me that after taking one of my courses
0:06 or they'll ask me how to do that because of the podcast or something along
0:10 those lines, and I have one answer that I typically give.
0:14 But I want to talk about the spectrum of the options here because not everyone fits
0:18 into the same bucket. So at the, probably easiest to get started and certainly easiest
0:24 to operate, we have these platform as a service type of hosting environments for Python
0:30 web applications. So Heroku has been hosting many web applications as a platform as
0:36 a service, and they have great Python support.
0:39 So what does platform as a service means? It means you'll do something like point,
0:44 you know, connect Heroku to a GitHub repository,
0:47 if that repository has a requirements.txt or other Python indicators right at the top,
0:52 it will automatically determine that it needs to run under Python.
0:55 You add a file to say
0:57 here's the execute command, and it'll just go on, create
1:00 a server, set it up, make sure it runs.
1:02 You push a new thing to that
1:04 GitHub repo, you'll grab it,
1:06 redeploy it with zero downtime, all of those kinds of things.
1:09 So this is super helpful, but you don't have as much control here,
1:13 right? You've got to fit into their ecosystem.
1:15 You want to use a database?
1:16 Great, you're probably using their hosted database,
1:18 which is not that cheap, honestly,
1:20 depends on where that money is coming from and what you're doing.
1:23 But it's not nearly as cheap is doing it yourself,
1:25 that's for sure. So Heroku is actually,
1:28 if you're very unsure about working with things like running and maintaining Linux servers and virtual
1:34 machines and stuff, Heroku or other platforms as a service are a really good idea
1:38 to get started. My favorite place for hosting is Digital Ocean,
1:43 and in fact, at the time of the recording,
1:45 all of the infrastructure for Talk Python Training runs over at Digital Ocean.
1:50 We've got about eight servers there,
1:52 and we do all sorts of interesting things with them to make all of our
1:55 APIs, our APPS and our web app and whatnot go. Digital
1:58 Ocean just launched something like a platform as a service that Heroku has, called their app
2:04 platform. So you might consider using that, Python is definitely supported
2:07 there. What I use is just their, what they call droplets.
2:10 This is their virtual machines you can go create. Notice,
2:13 starting at $5 a month. So for literally $5 a month,
2:17 we could get this python FastAPI
2:19 up and running, no problem.
2:21 We have a lot of database requirements?
2:23 Maybe we've gotta add a dedicated database server.
2:26 If it's very, very lightweight,
2:28 maybe we could actually put it on the same server. Anyway,
2:30 it's quite cheap to get started.
2:32 Linode is also really good,
2:34 and they're comparable to Digital Ocean in that they have hosting of like these droplets,
2:40 these virtual machines. They don't call them droplets,
2:42 but same idea. They also both Digital Ocean and Linode have kubernetes clouds or
2:48 clusters, if you want to run Docker.
2:50 I'm not necessarily recommending that, but it's you know,
2:53 if that's the way you wanna go,
2:54 they both have great support for that.
2:56 Also, notice up at the top here, this URL talkpython.fm/linode
2:59 If you do want to go to Linode, use that and you'll get
3:04 $20 off, get a $20 credit towards your account.
3:07 Not gonna change the world
3:08 and I, it just lets them know that I'm sending people over.
3:11 I don't actually get paid, this is just part of their sponsorship of the podcast.
3:14 But, you know, it'll give you guys a little bit off
3:16 so go ahead and use that if you feel like it.
3:18 Next up, we've got a couple of the big ones.
3:20 We've got a AWS. Now, AWS is amazing,
3:23 I use AWS services for various things,
3:25 like generating transcripts, the first pass
3:28 of transcripts for the courses. Delivering some of the video content and things like
3:31 that. But I don't host my service there.
3:34 I think AWS is massively complicated and massively expensive. To run that $5 VM
3:40 we saw over at Digital Ocean or the similar one at Linode,
3:43 how much does it cost? About %50 - $60 a month for exactly the same thing.
3:47 Yeah, and the thing is,
3:49 it's super, super complicated because AWS runs extremely large scale applications,
3:57 things like Netflix and so on.
3:59 So all the tooling is really dialed in for these advanced use cases,
4:03 which means the simple case is not so simple.
4:07 But there is a simple, simplified version of AWS,
4:10 if you guys are over there,
4:11 it's called Amazon Lightsail. And to run that $60 server over a normal AWS,
4:16 you can get it for $3.50 on lightsail. Go figure,
4:20 it's very weird the fact that they have these two things,
4:22 but they do and my theory is that this is a direct response to Digital Ocean
4:28 and Linode, and it's a very similar and simple way of creating things,
4:32 so you might consider it. Again,
4:34 I'm, I'm sticking with Digital Ocean.
4:36 We also have Microsoft Azure, they let you run web apps as VMs,
4:39 they let you run web apps as a platform as a service
4:42 as well. So those are the hosting places that I would first go look at
4:46 If I was hosting my stuff on the Internet.
4:49 If I was was trying to take this FastAPI
4:50 we built, put it somewhere that has good data centers, has good reputations, has good pricing,
4:56 at least you know, excluding the bare VMs that say AWS and Azure.
5:03 But the, one of the uniform
5:04 things about this, all of them,is that they're gonna ultimately run on Linux.
5:08 So final thing, we're really in this chapter gonna just focus on getting our
5:14 FastAPI running on an Ubuntu virtual machine in the cloud. We're gonna actually
5:19 create it on Digital Ocean, but that's just like a few clicks in some web app.
5:23 And then, you know, you won't even know what server,
5:26 what host you're on. You're just gonna log into the server remotely and do a
5:30 bunch of steps. So really,
5:31 what we're gonna do is figure out where we're gonna run our Ubuntu virtual
5:34 machine and on the platforms as a service,
5:36 even when you're not directly interacting with that server,
5:40 you really are running on some kind of Linux machine the vast majority of the time.
5:44 So understanding what's going on under the covers is probably a good idea anyway