WEBVTT

1
00:00:00.550 --> 00:00:02.850
<v ->Real quickly, let's talk about message cues as well.</v>

2
00:00:02.850 --> 00:00:05.930
It's also potentially a useful tool in your tool chest for

3
00:00:05.930 --> 00:00:07.903
solving a system design problem.

4
00:00:09.220 --> 00:00:11.680
So message queues are a way to deal with some specific

5
00:00:11.680 --> 00:00:13.070
scaling problems.

6
00:00:13.070 --> 00:00:15.960
The idea here is that it's a mechanism for decoupling

7
00:00:15.960 --> 00:00:18.640
producers and consumers of data.

8
00:00:18.640 --> 00:00:21.630
So it's sort of a buffer we can use to make sure that things

9
00:00:21.630 --> 00:00:24.120
don't get backed up in a larger system.

10
00:00:24.120 --> 00:00:26.290
So with a message queue in place,

11
00:00:26.290 --> 00:00:28.790
if your consumers of data get backed up a little bit,

12
00:00:28.790 --> 00:00:31.180
you don't have quite enough capacity there, it's okay.

13
00:00:31.180 --> 00:00:32.260
You're not going to lose data.

14
00:00:32.260 --> 00:00:34.440
It might sit in that message queue for a while,

15
00:00:34.440 --> 00:00:36.300
and it might take a little bit longer to process,

16
00:00:36.300 --> 00:00:38.250
but at least you're not going to lose it, right?

17
00:00:38.250 --> 00:00:39.360
It's going to be somewhere safe,

18
00:00:39.360 --> 00:00:42.010
waiting to be processed when you can get to it.

19
00:00:42.010 --> 00:00:45.770
An example of an implementation is the Amazon SQS service,

20
00:00:45.770 --> 00:00:47.330
or Simple Queue Service.

21
00:00:47.330 --> 00:00:49.670
If you want to just use an off the shelf, you know,

22
00:00:49.670 --> 00:00:51.380
cloud based solution,

23
00:00:51.380 --> 00:00:55.080
SQS is an example of a single-consumer message queue.

24
00:00:55.080 --> 00:00:58.970
So in SQS, there is only one consumer associated

25
00:00:58.970 --> 00:01:01.100
with a given publisher of data.

26
00:01:01.100 --> 00:01:02.330
However, there's also the idea

27
00:01:02.330 --> 00:01:04.650
of pub/sub or published subscribe,

28
00:01:04.650 --> 00:01:06.920
where you can actually have messages published

29
00:01:06.920 --> 00:01:10.670
by your servers and multiple consumers

30
00:01:10.670 --> 00:01:13.240
can then get that data back out from it,

31
00:01:13.240 --> 00:01:15.260
through that message queue.

32
00:01:15.260 --> 00:01:16.430
So what's an example of this?

33
00:01:16.430 --> 00:01:17.420
You know, let's say I have a bunch

34
00:01:17.420 --> 00:01:19.010
of web servers out there that are

35
00:01:19.010 --> 00:01:21.210
generating orders or something, right?

36
00:01:21.210 --> 00:01:22.621
And those orders need to get set to sent

37
00:01:22.621 --> 00:01:24.870
to some other system for further processing

38
00:01:24.870 --> 00:01:27.310
and fraud detection and validation.

39
00:01:27.310 --> 00:01:29.750
What happens if my systems that do fraud detection get

40
00:01:29.750 --> 00:01:30.720
backed up, right?

41
00:01:30.720 --> 00:01:32.170
Do I just throw those orders away?

42
00:01:32.170 --> 00:01:33.270
No, that would be bad.

43
00:01:33.270 --> 00:01:36.700
You know, I don't want to leave money lying on the table or

44
00:01:36.700 --> 00:01:38.090
give my customer a bad experience

45
00:01:38.090 --> 00:01:39.670
when they're trying to give me money.

46
00:01:39.670 --> 00:01:41.340
Instead, I'd have some sort of a message queue

47
00:01:41.340 --> 00:01:42.173
in between these two

48
00:01:42.173 --> 00:01:44.570
systems so that if the consumers,

49
00:01:44.570 --> 00:01:45.710
I need to process that data,

50
00:01:45.710 --> 00:01:46.970
do get backed up,

51
00:01:46.970 --> 00:01:48.250
it'll sit in the queue until

52
00:01:48.250 --> 00:01:50.520
it can actually get caught up again.

53
00:01:50.520 --> 00:01:53.910
And again, there are single consumer systems like SQS,

54
00:01:53.910 --> 00:01:55.730
and then there are pubs subsystems where you can have

55
00:01:55.730 --> 00:01:59.360
multiple consumers for a given publisher that subscribed to

56
00:01:59.360 --> 00:02:01.190
a given message queue.

57
00:02:01.190 --> 00:02:03.430
Now this is a little bit different from streaming data.

58
00:02:03.430 --> 00:02:05.900
So when we talk about streaming data,

59
00:02:05.900 --> 00:02:07.420
like in the context of Kafka

60
00:02:07.420 --> 00:02:10.310
or Spark Streaming or things like that,

61
00:02:10.310 --> 00:02:11.480
those are generally in the context

62
00:02:11.480 --> 00:02:13.370
of real time massive data that just needs

63
00:02:13.370 --> 00:02:14.280
to be routed from one

64
00:02:14.280 --> 00:02:16.200
system quickly to another.

65
00:02:16.200 --> 00:02:17.830
Technically systems like Kafka

66
00:02:17.830 --> 00:02:20.460
and Spark Streaming can be used as a message queue,

67
00:02:20.460 --> 00:02:23.700
but message queues tend to be a little bit more

68
00:02:23.700 --> 00:02:24.920
single-threaded if you will.

69
00:02:24.920 --> 00:02:26.860
Okay, so it's meant more as a buffer

70
00:02:26.860 --> 00:02:28.760
between two systems and not as

71
00:02:28.760 --> 00:02:31.850
mechanism for piping torrents of data

72
00:02:31.850 --> 00:02:33.500
between them necessarily.

73
00:02:33.500 --> 00:02:35.750
And speaking of Apache Spark,

74
00:02:35.750 --> 00:02:37.100
let's talk about that next.

