-
Notifications
You must be signed in to change notification settings - Fork 128
/
kafka.slide
267 lines (161 loc) · 7.46 KB
/
kafka.slide
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
# Cloud Native Kafka for Gophers
A guide for using Kafka & Strimzi in Golang
11 Nov 2024
Tags: golang, go, kafka, strimzi
Aykut Bulgu <[email protected]>
Red Hat, Inc. | System Craftsman
https://www.systemcraftsman.com
@SystemCraftsman
## About Me
.image ./kafka/images/back_to_the_engineering.png _ 700
## About Me
.code ./kafka/aboutme.yaml
## Gophers
.image ./common/fiveyears.jpg _ 900
.caption _Gopher(s)_ by [[https://instagram.com/reneefrench][Renee French]]
## Apache Kafka
//Section title
## What is Apache Kafka?
.image ./kafka/images/kafka.png _ 600
Apache Kafka is a distributed system designed for streams. It is built to be an horizontally-scalable, fault-tolerant, commit log, and allows distributed data streams and stream processing applications.
## What is Apache Kafka?
* Developed at LinkedIn back in 2010, open sourced in 2011
* Designed to be fast, scalable, durable and highly available
* Distributed by design
* Data partitioning (sharding)
* High throughput
* Ability to handle huge number of consumers
## Apache Kafka Ecosystem
* **Kafka Core**
* Broker
* Producer API, Consumer API, Admin API
* Management tools
* Kafka Connect
* Kafka Streams API
* Mirror Maker / Mirror Maker 2
* REST Proxy for bridging HTTP and Kafka
* Schema Registry
## Apache Kafka Concepts - Brokers & HA
.image ./kafka/images/brokers_ha_1.png _ 800
## Apache Kafka Concepts - Brokers & HA
.image ./kafka/images/brokers_ha_2.png _ 1000
## Apache Kafka Concepts - Producers
.image ./kafka/images/producers.png _ 900
## Apache Kafka Concepts - Consumers
.image ./kafka/images/consumers.png _ 900
## Apache Kafka Use Cases
Real time ...
* Messaging
* Activity Tracking
* Stream Processing
* Data Integration
* Metrics
* Log aggregation
## Cloud Native Kafka: Strimzi
//Section title
## Cloud Native Kafka: Strimzi
.image ./kafka/images/strimzi_def.png _ 700
## Why Strimzi? Why run Kafka on Kubernetes?
* Simplified Deployment and Management
* Scalability and Flexibility
* High Availability and Fault Tolerance
* Infrastructure Agnostic
* Operational Efficiency
* Seamless Integration with Other Kubernetes Ecosystem Tools
* Developer Productivity
## Kubernetes Native Kafka: Strimzi
.image ./kafka/images/strimzi_arch.png _ 700
## A Quick Peek to a Kafka Cluster on Kubernetes
The Strimzi operator and a pre-created Kafka cluster is running on our local Kubernetes cluster, in the `default` namespace.
.play ./kafka/code/show_operator_state.go /START OMIT/,/END OMIT/
Let's have a quick look at the Kafka cluster called `kafka-cluster` by using [Strimzi Kafka CLI](https://github.com/SystemCraftsman/strimzi-kafka-cli). Another way is to use YAMLs and `kubectl`.
.play ./kafka/code/show_strimzi_cluster.go /START OMIT/,/END OMIT/
## The Golang Side
//Section title
## Using Strimzi Kafka with Golang
.image ./kafka/images/gopher_kafka_cook.png _ 600
.caption _Image_from:_https://medium.com/trendyol-tech/batch-processing-with-confluent-kafka-go-707790e7d563_
## Golang Kafka Clients
Some popular Kafka libraries for Go:
* **Sarama** by Shopify
* **Confluent Kafka Go**
* **kafka-go** by Segment
* **Franz-go** by Twilio
* **Goka** by Lovoo
## Sarama
* One of the most widely used Go clients for Kafka, developed by Shopify. Now under IBM maintenance.*
* Supports Kafka producers and consumers, including synchronous and asynchronous processing.
* Provides configuration options for message retries, compression, and partition handling.
* It’s suitable for both high-level consumers (like consumer groups) and lower-level (partition) consumers.
.caption [*] _https://github.com/IBM/sarama/issues/2461_
Command for including the library:
.code ./kafka/code/sarama_producer.go /START1 OMIT/,/END1 OMIT/
## Sarama - Producer
.code ./kafka/code/sarama_producer.go /START2 OMIT/,/END2 OMIT/
## Sarama - Consumer
.code ./kafka/code/sarama_consumer.go /START OMIT/,/END OMIT/
## Confluent Kafka Go
* Developed by Confluent, it’s a Go wrapper around the C/C++ library `librdkafka`.
* Provides advanced features for Kafka, including exactly-once semantics, which are not available in Sarama.
* Ideal for enterprise-grade applications with a need for high throughput, low latency, and Confluent-specific capabilities.
* Well-integrated with the Confluent platform and its features like Schema Registry.
Command for including the library:
.code ./kafka/code/confluent_producer.go /START1 OMIT/,/END1 OMIT/
## Confluent Kafka Go - Producer
.code ./kafka/code/confluent_producer.go /START2 OMIT/,/END2 OMIT/
## Confluent Kafka Go - Consumer
.code ./kafka/code/confluent_consumer.go /START OMIT/,/END OMIT/
## kafka-go
* Built by Segment, it’s a pure Go implementation of the Kafka protocol.
* Suitable for applications needing a simpler API without depending on `librdkafka`.
* Offers key functionalities like producer, consumer, and reader abstractions, with support for batching, compression, and automatic topic creation.
* Supports distributed applications, such as multi-partition reading and writing.
Command for including the library:
.code ./kafka/code/kafka_go_producer.go /START1 OMIT/,/END1 OMIT/
## kafka-go - Producer
.code ./kafka/code/kafka_go_producer.go /START2 OMIT/,/END2 OMIT/
## kafka-go - Consumer
.code ./kafka/code/kafka_go_consumer.go /START OMIT/,/END OMIT/
## franz-go
* A recent library developed by Twilio that also provides a pure Go Kafka client.
* Focuses on high-performance and ease of use with support for consumer groups, transactions, and connection pooling.
* Supports Kafka 2.0+ features, including better handling of Kafka protocol updates.
* Franz-go can be a good alternative to `kafka-go` for its modern approach and robust documentation.
Command for including the library:
.code ./kafka/code/franz_go_producer.go /START1 OMIT/,/END1 OMIT/
## franz-go - Producer
.code ./kafka/code/franz_go_producer.go /START2 OMIT/,/END2 OMIT/
## franz-go - Consumer
.code ./kafka/code/franz_go_consumer.go /START OMIT/,/END OMIT/
## Goka
* Goka is a Go library specifically designed for building stream processing applications with Kafka.
* Unlike general-purpose Kafka clients, Goka is more focused on implementing concepts from Kafka Streams, making it a great choice if you're working on stateful stream processing in Go.
## Demo
//Section title
## The Coffee Shop
.image ./kafka/images/coffeeshop.jpg _ 800
[https://github.com/RedHatTraining/AD482-ToT-CoffeeShop](https://github.com/RedHatTraining/AD482-ToT-CoffeeShop)
## The Coffee Shop - History
.image ./kafka/images/coffeeshop_history_sync.png _ 700
## The Coffee Shop - History
.image ./kafka/images/coffeeshop_history_async.png _ 700
## The Coffee Shop - Simplified
.image ./kafka/images/coffeeshop_arch_diagram.png _ 1000
## Creating the Topic
Run the following Strimzi CLI command to create the topic on your Strimzi cluster:
.play ./kafka/code/create_topic.go /START OMIT/,/END OMIT/
Topic details:
.play ./kafka/code/view_topic.go /START OMIT/,/END OMIT/
Open the IDE for the rest of the demo:)
.play ./kafka/code/open_ide.go /START OMIT/,/END OMIT/
## Source of the Demo
.image ./kafka/images/demo_qr_code.png _ 400
[https://github.com/SystemCraftsman/coffeeshop-kafka-go-demo](https://github.com/SystemCraftsman/coffeeshop-kafka-go-demo)
## MISC
// Section title
## Golang Present Library
.image ./kafka/images/present.png _ 700
[https://pkg.go.dev/golang.org/x/tools/present](https://pkg.go.dev/golang.org/x/tools/present)
## GoKonf - November 23rd
.image ./kafka/images/go_konf.jpeg _ 700
[https://gokonf.com/](https://gokonf.com/)