1
00:00:00,637 --> 00:00:02,561
- [Narrator] Hi and
welcome back to the course.

2
00:00:02,561 --> 00:00:03,949
In this video we're going to look at

3
00:00:03,949 --> 00:00:07,282
what exactly is Heroku and how it works.

4
00:00:09,379 --> 00:00:11,860
Heroku, as I've mentioned,
is a web service

5
00:00:11,860 --> 00:00:16,073
that runs your code and
allows other people to see it.

6
00:00:16,073 --> 00:00:18,204
So you can give it your Flask applications

7
00:00:18,204 --> 00:00:20,592
and it can run your Flask apps,

8
00:00:20,592 --> 00:00:24,461
and it makes them available
for others to interact with.

9
00:00:24,461 --> 00:00:26,832
When you run the Flask
app in your computer,

10
00:00:26,832 --> 00:00:30,999
other people can't access it,
log in, and make requests.

11
00:00:32,242 --> 00:00:34,484
However, when you run them on Heroku,

12
00:00:34,484 --> 00:00:36,591
other people can do that because Heroku

13
00:00:36,591 --> 00:00:40,884
gives them a URL and address
that others can access.

14
00:00:40,884 --> 00:00:43,685
Generally, allowing
that, giving other people

15
00:00:43,685 --> 00:00:45,917
a URL that they can access,

16
00:00:45,917 --> 00:00:48,628
is called hosting,
essentially, so you can host,

17
00:00:48,628 --> 00:00:51,986
for example, word press sites,
you can host Flask apps,

18
00:00:51,986 --> 00:00:54,819
you can host static websites, etc.

19
00:00:55,897 --> 00:00:59,196
Heroku can be used to
host Flask applications.

20
00:00:59,196 --> 00:01:01,241
It can also be used to
host many other things,

21
00:01:01,241 --> 00:01:04,040
so you're not limited to just that.

22
00:01:04,040 --> 00:01:08,040
It can host Ruby apps,
it can host Go apps, etc.

23
00:01:09,163 --> 00:01:11,884
Heroku works with dynos,

24
00:01:11,884 --> 00:01:16,079
and this here a picture of
a dyno, and what a dyno is

25
00:01:16,079 --> 00:01:18,412
is very similar to a server.

26
00:01:20,351 --> 00:01:22,846
A server is something
that can put your code on,

27
00:01:22,846 --> 00:01:25,211
and then run your code
and make it available

28
00:01:25,211 --> 00:01:29,277
for other people, and a dyno
does exactly the same thing.

29
00:01:29,277 --> 00:01:32,397
A dyno is Heroku's version of a server.

30
00:01:32,397 --> 00:01:35,314
However, it's not quite a computer.

31
00:01:37,236 --> 00:01:40,825
It is something called a virtual machine.

32
00:01:40,825 --> 00:01:44,017
So when you run your application,

33
00:01:44,017 --> 00:01:45,763
you application doesn't have control

34
00:01:45,763 --> 00:01:47,860
of the computer in which it is running.

35
00:01:47,860 --> 00:01:50,491
It only has control of the virtual system

36
00:01:50,491 --> 00:01:55,058
that has been created
specifically for that dyno.

37
00:01:55,058 --> 00:01:56,991
Now that means that there
are a couple of limitations

38
00:01:56,991 --> 00:01:58,764
in terms of what we can do.

39
00:01:58,764 --> 00:02:02,134
And also, because when we
use a dyno, we tell Heroku

40
00:02:02,134 --> 00:02:06,752
what Flask application to
run, and then it does that.

41
00:02:06,752 --> 00:02:11,307
We're limited also in running
other things simultaneously.

42
00:02:11,307 --> 00:02:13,025
For example, something
we might be interested

43
00:02:13,025 --> 00:02:16,405
in running simultaneously
alongside our Flask app

44
00:02:16,405 --> 00:02:19,854
is a way of improving
performance of our app

45
00:02:19,854 --> 00:02:22,316
by adding a caching layer.

46
00:02:22,316 --> 00:02:26,117
We cannot do that in Heroku, for example.

47
00:02:26,117 --> 00:02:28,031
However, what we can do
is we can tell Heroku

48
00:02:28,031 --> 00:02:30,088
to run our Python our app,

49
00:02:30,088 --> 00:02:32,014
and also we will have to tell it

50
00:02:32,014 --> 00:02:35,259
to run something called uWSGI.

51
00:02:35,259 --> 00:02:36,676
UWSGI is a way of

52
00:02:39,000 --> 00:02:41,965
serving your flask application.

53
00:02:41,965 --> 00:02:46,215
Although the Flask application
has a serving layer,

54
00:02:46,215 --> 00:02:50,473
that's how we access it using
postman or our web server.

55
00:02:50,473 --> 00:02:53,861
It's not the best, and also it is limited

56
00:02:53,861 --> 00:02:56,921
in what it can interact with.

57
00:02:56,921 --> 00:03:01,177
By running uWSGI, which is
another Python library, on top,

58
00:03:01,177 --> 00:03:05,338
we're going to make our Flask
app a lot more flexible.

59
00:03:05,338 --> 00:03:07,234
We're going to look at
exactly what that means

60
00:03:07,234 --> 00:03:08,824
and how to do all this

61
00:03:08,824 --> 00:03:10,574
in the coming videos.

62
00:03:11,572 --> 00:03:14,580
Okay, so this is what
our dyno is going to run.

63
00:03:14,580 --> 00:03:17,392
It's going to run the
Python app, the Flask app,

64
00:03:17,392 --> 00:03:22,329
which includes Flask-RESTful
and Flask-SQLAlchemy and so on,

65
00:03:22,329 --> 00:03:25,762
and it's also going to run uWSGI.

66
00:03:25,762 --> 00:03:29,360
The uWSGI app or library
is going to interact

67
00:03:29,360 --> 00:03:32,061
with our Flask app in
order to make it available

68
00:03:32,061 --> 00:03:33,561
for others to use.

69
00:03:35,162 --> 00:03:38,262
So our Heroku app is going to
look essentially like this.

70
00:03:38,262 --> 00:03:40,817
We're gonna have a big box,
which is our Heroku app,

71
00:03:40,817 --> 00:03:44,431
and that is going to be
composed of a single dyno.

72
00:03:44,431 --> 00:03:47,157
The Heroku app in addition
can also have other things

73
00:03:47,157 --> 00:03:49,691
such as configuration properties.

74
00:03:49,691 --> 00:03:53,590
For example, we can configure
what database we want to use.

75
00:03:53,590 --> 00:03:57,407
We can use SQLite, we can
also use Postgres from iSQL.

76
00:03:57,407 --> 00:04:02,163
We can also configure things
like where the logs appear.

77
00:04:02,163 --> 00:04:05,778
Whenever our application
crashes, we can put some logging,

78
00:04:05,778 --> 00:04:08,215
some printing out to
the console somewhere.

79
00:04:08,215 --> 00:04:10,924
We can decide where that
is, we can do things like

80
00:04:10,924 --> 00:04:15,176
setting up a bunch of other
configuration parameters.

81
00:04:15,176 --> 00:04:18,007
And in addition, the
Heroku apps are not limited

82
00:04:18,007 --> 00:04:19,960
to just limited to running a single dyno,

83
00:04:19,960 --> 00:04:23,661
but they can also run many
other dynos a the same time.

84
00:04:23,661 --> 00:04:27,265
As you can see all these dynos
run exactly the same code,

85
00:04:27,265 --> 00:04:29,698
and that means that for
example, as an example,

86
00:04:29,698 --> 00:04:33,166
each dyno can deal with one
user, if we run six dynos

87
00:04:33,166 --> 00:04:35,878
we can deal with six users simultaneously.

88
00:04:35,878 --> 00:04:37,541
This is a bit of an oversimplification,

89
00:04:37,541 --> 00:04:40,749
don't worry, each dyno
can deal with many users,

90
00:04:40,749 --> 00:04:42,521
but of course if you have six,

91
00:04:42,521 --> 00:04:46,631
that's six times more users you
can deal with, more or less.

92
00:04:46,631 --> 00:04:49,630
All of these dynos can interact
with the same database,

93
00:04:49,630 --> 00:04:51,632
so data can be shared between them,

94
00:04:51,632 --> 00:04:54,600
and overall, this
increased number of dynos

95
00:04:54,600 --> 00:04:58,417
would just make your app go
faster and be more available.

96
00:04:58,417 --> 00:05:00,922
However, you will have to pay if you want

97
00:05:00,922 --> 00:05:03,284
to increase the number of dynos,

98
00:05:03,284 --> 00:05:05,730
so that's a limitation there.

99
00:05:05,730 --> 00:05:08,788
Also, Heroku is great for security

100
00:05:08,788 --> 00:05:12,166
because Heroku enables
Secure Sockets Layer for us,

101
00:05:12,166 --> 00:05:13,666
so we don't have to do anything.

102
00:05:13,666 --> 00:05:15,842
SSL is automatically enabled,

103
00:05:15,842 --> 00:05:18,706
and what SSL does is it
allows the communication

104
00:05:18,706 --> 00:05:21,107
between yourself, the
client, and the server,

105
00:05:21,107 --> 00:05:23,191
which is Heroku, to be encrypted,

106
00:05:23,191 --> 00:05:26,336
so all of your users, all
of your REST API users,

107
00:05:26,336 --> 00:05:28,793
are going to see encrypted communication

108
00:05:28,793 --> 00:05:31,289
going to the server, which
is great, for example,

109
00:05:31,289 --> 00:05:34,341
when we're sending passwords
and things like that.

110
00:05:34,341 --> 00:05:37,645
That's just so nobody else
can snoop on that information

111
00:05:37,645 --> 00:05:40,228
and read it if it is encrypted.

112
00:05:41,977 --> 00:05:45,317
So as a conclusion, Heroku is
a distributed hosting service,

113
00:05:45,317 --> 00:05:48,803
which means each dyno is
separate from the others.

114
00:05:48,803 --> 00:05:50,677
And each server is called a dyno,

115
00:05:50,677 --> 00:05:52,195
and it runs your application.

116
00:05:52,195 --> 00:05:55,904
And also, the free tier
gives you one dyno,

117
00:05:55,904 --> 00:05:57,567
which is what I mentioned earlier,

118
00:05:57,567 --> 00:05:59,413
but you have limited running hours,

119
00:05:59,413 --> 00:06:02,079
so you cannot run the dyno continuously.

120
00:06:02,079 --> 00:06:04,412
It goes to sleep every now and then,

121
00:06:04,412 --> 00:06:07,726
and then it takes a few
seconds to start up again,

122
00:06:07,726 --> 00:06:10,160
so we'll look into exactly what that means

123
00:06:10,160 --> 00:06:11,953
in the next few videos.

124
00:06:11,953 --> 00:06:14,252
And also its got a good security profile

125
00:06:14,252 --> 00:06:17,342
due to SSL being enabled by default.

126
00:06:17,342 --> 00:06:18,706
So that's it for this video,

127
00:06:18,706 --> 00:06:21,543
a quick intro to what Heroku
is and how it's gonna run,

128
00:06:21,543 --> 00:06:25,586
and now we're gonna work on
deploying our app to Heroku.

129
00:06:25,586 --> 00:06:28,253
I'll see you in the next video.

