-
Notifications
You must be signed in to change notification settings - Fork 29
/
apache-kafka-essentials.html
382 lines (347 loc) · 15.7 KB
/
apache-kafka-essentials.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Apache Kafka™ Workshop | The Essentials of Apache Kafka™</title>
<meta name="description" content="Apache Kafka™ Workshop | The Essentials of Apache Kafka™">
<meta name="author" content="Jacek Laskowski">
<link rel="stylesheet" href="reveal5/dist/reset.css">
<link rel="stylesheet" href="reveal5/dist/reveal.css">
<link rel="stylesheet" href="reveal5/dist/theme/beige.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="reveal5/plugin/highlight/monokai.css">
<!-- Jacek: custom formatting -->
<link rel="stylesheet" href="revealjs-css/jacek.css">
</head>
<body>
<div class="reveal">
<div class="footer">
<footer style="font-size: small;">
© <a href="https://medium.com/@jaceklaskowski">Jacek Laskowski</a> 2022 / <a
href="https://twitter.com/jaceklaskowski">@JacekLaskowski</a>
</footer>
</div>
<div class="slides">
<section class="intro" data-transition="zoom" id="home">
<p>
<img width="14%" style="background:none; border:none; box-shadow:none;" data-src="images/kafka-logo.png">
<img width="10%" src="images/jacek_laskowski_20201229_200x200.png" style="border: 0">
</p>
<h1 style="font-size: 3.44em;">Apache Kafka</h1>
<h2>The Essentials</h2>
<h4 style="font-size: smaller;">
<a href="https://twitter.com/jaceklaskowski">@jaceklaskowski</a> / <a
href="https://stackoverflow.com/users/1305344/jacek-laskowski">StackOverflow</a> / <a
href="https://github.com/jaceklaskowski">GitHub</a> / <a
href="https://www.linkedin.com/in/jaceklaskowski/">LinkedIn</a>
<br>
The "Internals" Books: <a href="https://books.japila.pl">books.japila.pl</a>
</h4>
</section>
<section id="agenda" data-markdown>
<textarea data-template>
## Agenda
1. [Introduction](#/intro)
1. [Core Concepts of Kafka](#/concepts)
1. [Features of Kafka](#/kafka-features)
1. [Kafka Streams](#/kafka-streams)
1. [Kafka Connect](#/kafka-connect)
1. [ksqlDB](#/ksqldb)
</textarea>
</section>
<section>
<section id="intro" data-markdown>
<textarea data-template>
## Introduction <small>(1 of 2)</small>
**Apache Kafka** is an open source **publish-subscribe messaging system** based on the concept of a **distributed commit log**.
**Messages** (aka **records**) in Kafka are distributed, stored durably and in order, and can be read deterministically.
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Introduction <small>(2 of 2)</small>
**Apache Kafka** is an open source "umbrella" project with the following modules:
* Kafka Core
* Broker
* Producer and Consumer APIs
* Kafka Streams
* Kafka Connect
_From a messaging queue to a distributed streaming platform_
</textarea>
</section>
</section>
<section>
<section id="concepts" data-markdown>
<script type="text/template">
## Core Concepts of Kafka (Core)
* [Records](#/records)
* [Topics](#/topics)
* [Partitions](#/partitions)
* [Replicas and In-Sync Replicas](#/replicas)
* [Offsets](#/offsets)
* [Brokers](#/brokers)
* [Producers](#/producers)
* [Consumers](#/consumers)
* [Retention](#/retention)
</script>
</section>
<section id="records">
<h2>Records</h2>
<ol>
<li><b>Record</b> (aka <b>message</b> or <b>event</b>) is the unit of data in Kafka</li>
<li>Array of bytes (in no particular format)
<ul>
<li><a href="http://avro.apache.org/">Apache Avro</a> as data serialization framework</li>
</ul>
</li>
<li>Record has a <b>key</b> and a <b>value</b>
<ul>
<li>Both could be <b>null</b></li>
</ul>
</li>
<li>Records are categorized into <b>topics</b></li>
</ol>
</section>
<section id="topics">
<h2>Topics</h2>
<ol>
<li>Records are categorized into <b>topics</b>
<ul>
<li>Think a <i>table</i> or a <i>directory</i></li>
</ul>
</li>
<li>Producers publish messages to topics while consumers consume them</li>
<li>Topics are partitioned
<ul>
<li>Namespaces of one or many <b>partitions</b></li>
</ul>
</li>
<li><b>kafka-topics</b> shell script manages Kafka topics</li>
</ol>
</section>
<section id="partitions">
<h2>Partitions</h2>
<ol>
<li>Topics are partitioned into one or more <b>partitions</b></li>
<li>Partitions hold zero, one or many records</li>
<li>Ordered (by offsets) immutable sequence of records</li>
<li>A partition is a single ordered log</li>
<li>Stored durably on disk</li>
<li>Records are added to partitions in <b>append-only</b> fashion</li>
<li>Partitions are replicated among brokers as <b>replicas</b></li>
<li><b>In-sync replicas (ISRs)</b></li>
</ol>
</section>
<section id="replicas" style="font-size: 90%">
<h2>Replicas and In-Sync Replicas</h2>
<ol>
<li><b>Replica</b> is a copy of a partition</li>
<li><b>Replication factor</b> is the number of replicas of a topic
<ul>
<li>There can be one or many replicas</li>
<li>Allows for automatic failover when a broker fails</li>
</ul>
</li>
<li>One replica is the <b>leader</b> while others are <b>followers</b>
<ul>
<li>Leader handles writes from producers, and the followers merely copy the leader's log</li>
</ul>
</li>
<li><b>In-Sync Replica</b> is a replica that has <i>enough</i> records to be considered in <b>partition leader election</b></li>
<li>Use <b>kafka-topics --describe</b> to list the details of a topic (incl. replicas and in-sync replicas)</li>
</ol>
</section>
<section id="offsets">
<h2>Offsets</h2>
<ol>
<li><b>Offset</b> is a unique sequential numerical position of a record (in a partition of a topic)
<ul>
<li>A message in a partition has a unique offset</li>
</ul>
</li>
<li>Offsets start from 0</li>
<li>Offsets are unique per partition only
<ul>
<li>Not across partitions</li>
</ul>
</li>
</ol>
</section>
<section>
<h2>Kafka Topics and Partitions</h2>
<h5>(distributed commit log)</h5>
<img width="70%" style="background:none; border:none; box-shadow:none;" data-src="images/kafka-topic-anatomy.png">
<br>
<small>From <a href="https://kafka.apache.org/documentation">Official Documentation of Apache Kafka</a></small>
</section>
<section>
<h2>Kafka Topics and Partitions <small>(cntd)</small></h2>
<img width="150%" style="background:none; border:none; box-shadow:none;" data-src="images/kafka-partitions.png">
<br>
<small>From <a href="https://www.safaribooksonline.com/library/view/kafka-the-definitive/9781491936153/">Kafka: The Definitive Guide</a></small>
</section>
<section id="brokers">
<h2>Brokers</h2>
<ol>
<li><b>Kafka Broker</b> is a Kafka server that manages records
<ul>
<li>Receives messages, assigns offsets, and commits messages to storage on disk</li>
</ul>
</li>
<li><b>Kafka Cluster</b> consists of one or more brokers
<ul>
<li>Uses Zookeeper as the source of truth</li>
</ul>
</li>
</ol>
</section>
<section id="producers">
<h2>Producers</h2>
<ol>
<li>Kafka clients that publish records to a Kafka cluster</li>
<li>Send messages to topics
<ul>
<li>Can optionally specify partitions</li>
</ul>
</li>
<li><a href="https://kafka.apache.org/27/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html">KafkaProducer</a> API for Java</li>
</ol>
</section>
<section id="consumers">
<h2>Consumers</h2>
<ol>
<li>Kafka clients that consumes records from a Kafka cluster</li>
<li>Subscribe to receive messages from topics</li>
<li>Read messages in the order they were produced
<ul>
<li>Per partition only</li>
</ul>
</li>
<li><a href="https://kafka.apache.org/27/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html">KafkaConsumer</a> API for Java</li>
</ol>
</section>
<section>
<h2>Kafka Producers and Consumers</h2>
<img style="background:none; border:none; box-shadow:none;" data-src="images/kafka-producers-topics-consumers.png">
<small>From <a href="https://www.infoq.com/articles/apache-kafka">Apache Kafka: Next Generation Distributed Messaging System</a></small>
</section>
<section>
<h2>Kafka Producers and Consumers <small>(cntd)</small></h2>
<img width="70%" style="background:none; border:none; box-shadow:none;" data-src="images/kafka-producers-consumers.png">
<small>From <a href="https://kafka.apache.org/documentation">Official Documentation of Apache Kafka</a></small>
</section>
<section id="retention">
<h2>Retention</h2>
<ol>
<li><b>Retention</b> of messages in topics is how long messages are stored in topics
<ul>
<li><i>Durable message retention</i></li>
<li>For some period of time, e.g. 7 days</li>
<li>Until a topic reaches a certain size in bytes, e.g. 1 gigabyte</li>
</ul>
</li>
<li>Once these limits are reached, messages are expired and deleted</li>
<li>Can be selected on a per-topic basis</li>
</ol>
</section>
</section>
<section id="kafka-features">
<h2>Features of Kafka</h2>
<ol>
<li>Thousands of Producers</li>
<li>Thousand of Consumers</li>
<li>Client Independence</li>
<li>High Throughput</li>
<li>Message Persistence</li>
<li>Disk-based Retention</li>
<li>Scalability</li>
<li>High Performance</li>
</ol>
</section>
<section id="kafka-streams" data-markdown>
<textarea data-template>
## Kafka Streams
1. **Kafka Streams** is a client library for stream processing on Kafka
1. Stream and Table Abstractions (over Kafka topics)
1. Elastic, highly scalable, fault-tolerant
1. [Home Page](https://kafka.apache.org/documentation/streams/)
</textarea>
</section>
<section id="kafka-connect" data-markdown>
<textarea data-template>
## Kafka Connect
1. **Kafka Connect** is a framework for a scalable and reliable data streaming between Apache Kafka and other systems
1. A framework for Kafka connectors
1. Distributed and standalone (single process) modes
1. REST interface for connector deployment and management
1. [Home Page](https://kafka.apache.org/documentation/#connect)
</textarea>
</section>
<section id="ksqldb" data-markdown style="font-size: 90%;">
<textarea data-template>
## ksqlDB
1. **ksqlDB** is an open source streaming SQL engine for stream processing on Kafka
1. Interactive SQL interface
1. "KSQL: Query Your Streams Without Writing Code"
1. No need to write code in a programming language like Java or Python
1. SQL layer atop Kafka Streams
* Executing SQL on tables and streams
1. [Home Page](https://ksqldb.io/)
</textarea>
</section>
<section id="recap" data-markdown>
<textarea data-template>
## Recap
1. [Introduction](#/intro)
1. [Core Concepts of Apache Kafka](#/concepts)
1. [Features of Kafka](#/kafka-features)
1. [Kafka Streams](#/kafka-streams)
1. [Kafka Connect](#/kafka-connect)
1. [ksqlDB](#/ksqldb)
</textarea>
</section>
<section style="text-align: left" data-markdown id="questions">
<textarea data-template>
# Questions?
* Read [The Internals of Apache Kafka](https://books.japila.pl/kafka-internals/)
* Read [The Internals of Kafka Streams](https://books.japila.pl/kafka-streams-internals)
* Read [The Internals of ksqlDB](https://books.japila.pl/ksqldb-internals/)
* Follow [@jaceklaskowski](https://twitter.com/jaceklaskowski) on twitter (DMs open)
* Upvote [my questions and answers on StackOverflow](http://stackoverflow.com/users/1305344/jacek-laskowski)
* Contact me at **[email protected]**
</textarea>
</section>
</div>
</div>
<script src="reveal5/dist/reveal.js"></script>
<script src="reveal5/plugin/notes/notes.js"></script>
<script src="reveal5/plugin/markdown/markdown.js"></script>
<script src="reveal5/plugin/highlight/highlight.js"></script>
<script src="reveal5/plugin/zoom/zoom.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
hash: true,
pdf: true,
slideNumber: 'c/t',
showSlideNumber: 'speaker',
// Learn about plugins: https://revealjs.com/plugins/
plugins: [RevealMarkdown, RevealHighlight, RevealNotes, RevealZoom]
});
</script>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-45999426-3', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>