Kafka as a Platform: the Ecosystem from the Ground Up Robin Moffatt | #BudapestData | @rmoff

$ whoami • Robin Moffatt (@rmoff) • Senior Developer Advocate at Confluent (Apache Kafka, not Wikis 😉) • Working in data & analytics since 2001 • Oracle ACE Director (Alumnus) http://rmoff.dev/talks · http://rmoff.dev/blog · http://rmoff.dev/youtube @rmoff | #BudapestData | @confluentinc

EVENTS @rmoff | #BudapestData | @confluentinc

EVENTS @rmoff | #BudapestData | @confluentinc

EVENTS n o i t a c fi i Not • e g n a h c e t a t S •

Human generated events A Sale A Stock movement @rmoff | #BudapestData | @confluentinc

Machine generated events IoT Networking Applications @rmoff | #BudapestData | @confluentinc

EVENTS are EVERYWHERE @rmoff | #BudapestData | @confluentinc

EVENTS y r e v ^ are POWERFUL @rmoff | #BudapestData | @confluentinc

K V

LOG @rmoff | #BudapestData | @confluentinc

K V

K V

K V

K V

K V

K V

K V

Immutable Event Log Old New Events are added at the end of the log @rmoff | #BudapestData | @confluentinc

TOPICS @rmoff | #BudapestData | @confluentinc

Topics Clicks Orders Customers Topics are similar in concept to tables in a database @rmoff | #BudapestData | @confluentinc

PARTITIONS @rmoff | #BudapestData | @confluentinc

Partitions Clicks p0 P1 P2 Messages are guaranteed to be strictly ordered within a partition @rmoff | #BudapestData | @confluentinc

PUB / SUB @rmoff | #BudapestData | @confluentinc

PUB / SUB @rmoff | #BudapestData | @confluentinc

Producing data Old New Messages are added at the end of the log @rmoff | #BudapestData | @confluentinc

partition 0 … partition 1 producer … partition 2 … Partitioned Topic

try (KafkaProducer<String, Payment> producer = new KafkaProducer<String, Payment>(props)) { for (long i = 0; i < 10; i++) { final String orderId = “id” + Long.toString(i); final Payment payment = new Payment(orderId, 1000.00d); final ProducerRecord<String, Payment> record = new ProducerRecord<String, Payment>(“transactions”, payment.getId().toString(), payment); producer.send(record); } } catch (final InterruptedException e) { e.printStackTrace(); }

Producing to Kafka - No Key Time Partition 1 Partition 2 Partition 3 Messages will be produced in a round robin fashion Partition 4 @rmoff | #BudapestData | @confluentinc

Producing to Kafka - With Key Time Partition 1 A Partition 2 B hash(key) % numPartitions = N Partition 3 C Partition 4 D @rmoff | #BudapestData | @confluentinc

Producers partition 0 … partition 1 producer … partition 2 … Partitioned Topic • A client application • Puts messages into topics • Handles partitioning, network protocol • Java, Go, .NET, C/C++, Python • Also every other language

PUB / SUB @rmoff | #BudapestData | @confluentinc

Consuming data - access is only sequential Read to offset & scan Old New @rmoff | #BudapestData | @confluentinc

Consumers have a position of their own Old New Sally is here @rmoff | Scan #BudapestData | @confluentinc

Consumers have a position of their own Old New Fred is here Sally is here Scan @rmoff | Scan #BudapestData | @confluentinc

Consumers have a position of their own Rick is here Scan Old New Fred is here Sally is here Scan @rmoff | Scan #BudapestData | @confluentinc

try (final KafkaConsumer<String, Payment> consumer = new KafkaConsumer<>(props)) { consumer.subscribe(Collections.singletonList(TOPIC)); while (true) { ConsumerRecords<String, Payment> records = consumer.poll(100); for (ConsumerRecord<String, Payment> record : records) { String key = record.key(); Payment value = record.value(); System.out.printf(“key = %s, value = %s%n”, key, value); } } }

partition 0 … partition 1 … partition 2 … Partitioned Topic consumer A

partition 0 … consumer A partition 1 … partition 2 … Partitioned Topic consumer B

Consuming From Kafka - Multiple Consumers C1 Partition 1 Partition 2 Partition 3 C2 Partition 4 @rmoff | #BudapestData | @confluentinc

Consuming From Kafka - Grouped Consumers CC1 1 CC1 1 Partition 1 Partition 2 Partition 3 C2 Partition 4 @rmoff | #BudapestData | @confluentinc

CONSUMERS CONSUMER GROUP COORDINATOR CONSUMER GROUP

Consuming From Kafka - Grouped Consumers Partition 1 Partition 2 Partition 3 C1 C2 C3 C4 Partition 4 @rmoff | #BudapestData | @confluentinc

Consuming From Kafka - Grouped Consumers Partition 1 Partition 2 Partition 3 C1 C2 C3 3 Partition 4 @rmoff | #BudapestData | @confluentinc

Consuming From Kafka - Grouped Consumers Partition 1 C1 Partition 2 Partition 3 C2 C3 Partition 4 @rmoff | #BudapestData | @confluentinc

Consumers partition 0 … partition 1 … consumer A consumer A consumer A partition 2 … Partitioned Topic consumer B • A client application • Reads messages from topics • Horizontally, elastically scalable (if stateless) • Java, Go, .NET, C/C++, Python, everything else

BROKERS and REPLICATION @rmoff | #BudapestData | @confluentinc

Leader Partition Leadership and Replication Follower Partition 1 Partition 2 Partition 3 Partition 4 Broker 1 Broker 2 @rmoff Broker 3 | #BudapestData | @confluentinc

Leader Partition Leadership and Replication Follower Partition 1 Partition 1 Partition 1 Partition 2 Partition 2 Partition 2 Partition 3 Partition 3 Partition 3 Partition 4 Partition 4 Partition 4 Broker 1 Broker 2 Broker 3 @rmoff | #BudapestData | @confluentinc

Leader Partition Leadership and Replication Follower Partition 1 Partition 1 Partition 1 Partition 2 Partition 2 Partition 2 Partition 3 Partition 3 Partition 3 Partition 4 Partition 4 Partition 4 Broker 1 Broker 2 Broker 3 @rmoff | #BudapestData | @confluentinc

Photo by Raoul Droog on Unsplas DEMO @rmoff | #BudapestData | @confluentinc

So far, this is Pretty good @rmoff | #BudapestData | @confluentinc

So far, this is Pretty good but I’ve not finished yet… @rmoff | #BudapestData | @confluentinc

Streaming Pipelines Amazon S3 RDBMS HDFS @rmoff | #BudapestData | @confluentinc

Evolve processing from old systems to new Existing New App <x> App RDBMS @rmoff | #BudapestData | @confluentinc

Streaming Integration with Kafka Connect syslog Sources Kafka Connect @rmoff | Kafka Brokers #BudapestData | @confluentinc

Streaming Integration with Kafka Connect Amazon Sinks Google Kafka Connect @rmoff | Kafka Brokers #BudapestData | @confluentinc

Streaming Integration with Kafka Connect Amazon syslog Google Kafka Connect @rmoff | Kafka Brokers #BudapestData | @confluentinc

Look Ma, No Code! { “connector.class”: “io.confluent.connect.jdbc.JdbcSourceConnector”, “connection.url”: “jdbc:mysql://asgard:3306/demo”, “table.whitelist”: “sales,orders,customers” } @rmoff | #BudapestData | @confluentinc

Extensible Connector Transform(s) @rmoff | Converter #BudapestData | @confluentinc

hub.confluent.io @rmoff | #BudapestData | @confluentinc

Single Kafka Connect node S3 Task #1 JDBC Task #1 JDBC Task #2 Kafka Connect cluster Worker Worker Offsets Config Status @rmoff | #BudapestData | @confluentinc

Kafka Connect - scalable and fault-tolerant S3 Task #1 JDBC Task #1 Kafka Connect cluster JDBC Task #2 Worker Worker Offsets Config Status @rmoff | #BudapestData | @confluentinc

Automatic fault tolerance S3 Task #1 JDBC Task #1 JDBC Task #2 Kafka Connect cluster Worker Worker Offsets Config Status @rmoff | #BudapestData | @confluentinc

K V

K V

K V

K V

K V ? s i h t s ’ t a h w … t i a W

How do you serialise your data? JSON Avro Protobuf Schema JSON CSV @rmoff | #BudapestData | @confluentinc

APIs are contracts between services {user_id: 53, address: “2 Elm st.”} Profile service Quote service {user_id: 53, quote: 580} @rmoff | #BudapestData | @confluentinc

But not all services {user_id: 53, address: “2 Elm st.”} Profile service Quote service {user_id: 53, quote: 580} @rmoff | #BudapestData | @confluentinc

And naturally… {user_id: 53, address: “2 Elm st.”} Profile service Quote service Profile database @rmoff Stream processing | #BudapestData | @confluentinc

Schemas are about how teams work together {user_id: 53, timestamp: 1497842472} new Date(timestamp) Profile service Quote service Profile database Stream processing create table ( user_id number, timestamp number) @rmoff | #BudapestData | @confluentinc

Things change… {user_id: 53, timestamp: “June 28, 2017 4:00pm”} Profile service Quote service Profile database @rmoff Stream processing | #BudapestData | @confluentinc

Moving fast and breaking things {user_id: 53, timestamp: “June 28, 2017 4:00pm”} Profile service Quote service Profile database @rmoff Stream processing | #BudapestData | @confluentinc

Lack of schemas – Coupling teams and services 2001 2001 Citrus Heights-Sunrise Blvd Citrus_Hghts 60670001 3400293 34 SAC Sacramento SV Sacramento Valley SAC Sacramento County APCD SMA8 Sacramento Metropolitan Area CA 6920 Sacramento 28 6920 13588 7400 Sunrise Blvd 95610 38 41 56 38.6988889 121 16 15.98999977 -121.271111 10 4284781 650345 52 @rmoff | #BudapestData | @confluentinc

Serialisation & Schemas JSON Avro Protobuf Schema JSON CSV @rmoff | #BudapestData | @confluentinc

Serialisation & Schemas JSON Avro Protobuf Schema JSON CSV 👍 👍 👍 😬 https://qconnewyork.com/system/files/presentation-slides/qcon_17_-_schemas_and_apis.pdf @rmoff | #BudapestData | @confluentinc

Schemas Schema Registry Topic producer … consumer

n a y l l Actua ! c i p o t l a n r e t in Schemas Schema Registry Topic producer … consumer

Producers contain serializers props.put(“key.serializer”, “org.apache.kafka.serializers.StringSerializer”); props.put(“value.serializer”, “io.confluent.kafka.serializers.KafkaAvroSerializer”); props.put(“schema.registry.url”, “http://schema-registry:8081”); … producer<String, LogLine> producer = new KafkaProducer<String, LogLine>(props); @rmoff | #BudapestData | @confluentinc

partition 0 consumer A … consumer A partition 1 … consumer A partition 2 … consumer B Partitioned Topic @rmoff | #BudapestData | @confluentinc

consumer A consumer A consumer A @rmoff | #BudapestData | @confluentinc

} “reading_ts”: “2020-02-14T12:19:27Z”, “sensor_id”: “aa-101”, “production_line”: “w01”, “widget_type”: “acme94”, “temp_celcius”: 23, “widget_weight_g”: 100 Photo by Franck V. on Unsplash { @rmoff | #BudapestData | @confluentinc

Streams of events Time @rmoff | #BudapestData | @confluentinc

Stream Processing Stream: widgets Stream: widgets_red @rmoff | #BudapestData | @confluentinc

Stream Processing with Kafka Streams Stream: widgets final StreamsBuilder builder = new StreamsBuilder() .stream(“widgets”, Consumed.with(stringSerde, widgetsSerde)) .filter( (key, widget) -> widget.getColour().equals(“RED”) ) .to(“widgets_red”, Produced.with(stringSerde, widgetsSerde)); Stream: widgets_red @rmoff | #BudapestData | @confluentinc

Streams Application Streams Application Streams Application @rmoff | #BudapestData | @confluentinc

Stream Processing with ksqlDB Stream: widgets ksqlDB CREATE STREAM widgets_red AS SELECT * FROM widgets WHERE colour=’RED’; Stream: widgets_red @rmoff | #BudapestData | @confluentinc

} “reading_ts”: “2020-02-14T12:19:27Z”, “sensor_id”: “aa-101”, “production_line”: “w01”, “widget_type”: “acme94”, “temp_celcius”: 23, “widget_weight_g”: 100 Photo by Franck V. on Unsplash { @rmoff | #BudapestData | @confluentinc

SELECT * FROM WIDGETS WHERE WEIGHT_G > 120 { SELECT COUNT(*) FROM WIDGETS GROUP BY PRODUCTION_LINE } “reading_ts”: “2020-02-14T12:19:27Z”, “sensor_id”: “aa-101”, “production_line”: “w01”, “widget_type”: “acme94”, “temp_celcius”: 23, “widget_weight_g”: 100 Photo by Franck V. on Unsplash SELECT AVG(TEMP_CELCIUS) AS TEMP FROM WIDGETS GROUP BY SENSOR_ID HAVING TEMP>20 CREATE SINK CONNECTOR dw WITH ( Object store, ‘connector.class’ = ‘S3Connector’, data warehouse, ‘topics’ = ‘widgets’ RDBMS …); @rmoff | #BudapestData | @confluentinc

Stream Processing with ksqlDB Source stream @rmoff | #BudapestData | @confluentinc

Stream Processing with ksqlDB Source stream @rmoff | #BudapestData | @confluentinc

Stream Processing with ksqlDB Source stream @rmoff | #BudapestData | @confluentinc

Stream Processing with ksqlDB Source stream Analytics @rmoff | #BudapestData | @confluentinc

Stream Processing with ksqlDB Source stream Applications / Microservices @rmoff | #BudapestData | @confluentinc

Stream Processing with ksqlDB …SUM(TXN_AMT) GROUP BY AC_ID AC _I D= 42 BA LA NC AC E= _I 94 D= .0 42 0 Source stream Applications / Microservices @rmoff | #BudapestData | @confluentinc

ksqlDB or Kafka Streams? @rmoff | #BudapestData | @confluentinc Photo by Ramiz Dedaković on Unsplash

Standing on the Shoulders of Streaming Giants ksqlDB Powered by Ease of use ksqlDB UDFs Kafka Streams Powered by Producer, Consumer APIs Flexibility @rmoff | #BudapestData | @confluentinc

Photo by Raoul Droog on Unsplas DEMO @rmoff | #BudapestData | @confluentinc

Summary @rmoff | #BudapestData | @confluentinc

@rmoff | #BudapestData | @confluentinc

K V @rmoff | #BudapestData | @confluentinc

K V @rmoff | #BudapestData | @confluentinc

The Log @rmoff | #BudapestData | @confluentinc

Producer Consumer The Log @rmoff | #BudapestData | @confluentinc

Producer Consumer Connectors The Log @rmoff | #BudapestData | @confluentinc

Producer Consumer Connectors The Log Streaming Engine @rmoff | #BudapestData | @confluentinc

Apache Kafka Producer Consumer Connectors The Log Streaming Engine @rmoff | #BudapestData | @confluentinc

EVENTS are EVERYWHERE @rmoff | #BudapestData | @confluentinc

EVENTS y r e v ^ are POWERFUL @rmoff | #BudapestData | @confluentinc

Free Books! https://rmoff.dev/budapestdata @rmoff | #BudapestData | @confluentinc

60 DE VA DV $50 USD off your bill each calendar month for the first three months when you sign up https://rmoff.dev/690 Free money! (additional $60 towards your bill 😄 ) Fully Managed Kafka as a Service * Limited availability. Activate by 11th September 2020. Expires after 90 days of activation. Any unused promo value on the expiration date will be forfeited.

Learn Kafka. Start building with Apache Kafka at Confluent Developer. developer.confluent.io

Confluent Community Slack group cnfl.io/slack @rmoff | #BudapestData | @confluentinc

@rmoff #BudapestData #EOF rmoff.dev/talks