title: "Streaming Data with Kafka" sub_title: A quick introduction author: Viktor Gamov theme: name: catppuccin-mocha override: footer: style: template right: "{current_slide} / {total_slides}" height: 2
Why Streaming?
Every business is becoming a real-time business.
Batch processing means hours of delay. Event streaming means milliseconds.
Let's see how Apache Kafka makes this possible.
What is Kafka?
- Producers send events to topics
- Consumers read events from topics
- Brokers store and replicate the data
- Events are immutable and ordered within a partition
Architecture
%%{init: {'theme': 'dark'}}%%
flowchart LR
subgraph Producers
P1[App 1]
P2[App 2]
end
subgraph Kafka["Kafka Cluster"]
B1[(Broker 1)]
B2[(Broker 2)]
B3[(Broker 3)]
B1 <--> B2
B2 <--> B3
end
subgraph Consumers
C1[Analytics]
C2[Search Index]
end
P1 --> B1
P2 --> B2
B1 --> C1
B3 --> C2
Demo Time
Producer Code
import org.apache.kafka.clients.producer.*;
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
Producer<String, String> producer =
new KafkaProducer<>(props);
producer.send(new ProducerRecord<>(
"my-topic", "key", "value"
));
producer.close();
Data Model
direction: right
topics: Topics {
shape: sql_table
id: int {constraint: primary_key}
name: varchar
partitions: int
}
messages: Messages {
shape: sql_table
id: bigint {constraint: primary_key}
topic_id: int {constraint: foreign_key}
key: bytea
value: bytea
}
topics.id <-> messages.topic_id
Summary
Kafka enables real-time data streaming at scale.
Thank you!
Questions?