Modern APIs with FastAPI and Python 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 mean? It means you'll do something like point,
0:44 you know, connect Heroku you 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 and 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, it'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 as 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 API's and our apps and our Web app and whatnot go. Digital
1:58 Ocean just launched something like a platform as a service that Heroku who 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 there, 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 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 a 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 want to go,
2:54 they both have great support for that.
2:56 Also, notice up of the top here this URL "talkpython.fm/linode".
3:00 If you do want to go to Linode,
3:03 use that and you'll get $20 off,
3:05 Get a $20 credit towards your account.
3:07 Not going to 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 have 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 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 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
4:16 AWS, 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 sticking with Digital ocean.
4:36 We also have Microsoft Azure. They let you run Web apps as VM's.
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 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 VM's at say AWS and Azure. But
5:03 one of the uniform things about this,
5:05 all of them, is that they're gonna ultimately run on Linux.
5:08 So final thing, we're really, in this chapter, going to just focus on getting our
5:14 FastAPI running on a 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.