🤖Building a Telegram bot with Apache Kafka, Go, and ksqlDB Robin Moffatt @rmoff

Where’s my nearest carpark with available spaces?

How many spaces are available in this car park?

💡Tell me when a car park with spaces is available

📈How does occupancy vary over time?

$ 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

Telegram @rmoff

Don’t just tell me… show me! Demo code: https://rmoff.dev/carparks

carparks HTTP Kafka @rmoff

What are the key pieces of the design? @rmoff

Event Driven Alerts carparks HTTP Kafka @rmoff

K/V Lookups (materialised views) SELECT SPACES_AVAILABLE How many spaces are free at “ FROM CARPARK WHERE NAME=’WESTGATE’; Westgate carpark right now? ksqlDB ” Kafka CARPARK_EVENTS 42 CREATE TABLE CARPARK AS SELECT LATEST(… GROUP BY NAME “ There are 42 spaces free ” @rmoff

A schema… carparks HTTP @rmoff

A schema… 2020-10-14,12:28,Broadway,1132,921 2020-10-14,12:28,Kirkgate Centre,611,474 2020-10-14,12:28,Sharpe Street,98,63 ?! @rmoff

My kingdom for a schema! 2020-10-14,12:28,Broadway,1132,921 2020-10-14,12:28,Kirkgate Centre,611,474 2020-10-14,12:28,Sharpe Street,98,63 😍 { “ts”: “2020-10-14T12:28 UTC+1”, “name”: “Broadway”, “capacity”: 1132, “empty”: 921 } … @rmoff

Applying a schema to streams of data source_topic ksqlDB CREATE STREAM mySource (date VARCHAR , time VARCHAR , name VARCHAR , capacity INT ) WITH (KAFKA_TOPIC=’source_topic’, VALUE_FORMAT=’DELIMITED’); Kafka @rmoff

Applying a schema to streams of data source_topic ksqlDB Kafka derived_topic CREATE STREAM mySource (date VARCHAR , time VARCHAR , name VARCHAR , capacity INT ) WITH (KAFKA_TOPIC=’source_topic’, VALUE_FORMAT=’DELIMITED’); CREATE STREAM myTargetStream WITH (VALUE_FORMAT=’PROTOBUF’, KAFKA_TOPIC=’derived_topic’) AS SELECT * FROM mySource; @rmoff

Integration carparks HTTP Kafka @rmoff

Streaming Integration with Kafka Connect syslog Sources Tasks Workers Kafka Connect Kafka Brokers @rmoff

Streaming Integration with Kafka Connect Amazon S3 Google BigQuery Sinks Tasks Workers Kafka Connect Kafka Brokers @rmoff

Streaming Integration with Kafka Connect Amazon S3 syslog Google BigQuery Tasks Workers Kafka Connect Kafka Brokers @rmoff

Streaming Analytics @rmoff

Why build it this way? @rmoff

Events @rmoff

Streams of Events @rmoff

We want to react to them as they happen @rmoff

We want to build state from a stream of events @rmoff

We want to provide the latest data in our analytics @rmoff

Apache Kafka - an Event Streaming Platform Producer Connectors Consumer The Log Connectors Streaming Engine @rmoff

Why Kafka? @rmoff

Distributed, Immutable, Event Log Old New Events are added at the end of the log @rmoff

Consumers can seek to any point Read to offset & scan Old New @rmoff

Data is not deleted once read New Old Sally is here Scan @rmoff

Consumers are independent of each other New Old Fred is here Scan Sally is here Scan @rmoff

Consumers can be added later Rick is here Scan New Old Fred is here Scan Sally is here Scan @rmoff

Stream Processing with ksqlDB Source stream @rmoff

Stream Processing with ksqlDB Source stream @rmoff

Stream Processing with ksqlDB Source stream @rmoff

Stream Processing with ksqlDB Source stream Analytics @rmoff

Stream Processing with ksqlDB Source stream Applications / Microservices @rmoff

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

Under the covers of ksqlDB Photo by @rmoff on

Kafka cluster consume produce ksqlDB @rmoff

JVM Kafka cluster consume produce ksqlDB Kafka Streams RocksDB @rmoff

k & ^ Kafka Fully Managed as a Service B D l q s

Running ksqlDB - self-managed DEB, RPM, ZIP, TAR downloads http://confluent.io/download Docker images ksqlDB Server confluentinc/ksqldb-server (JVM process) …and many more… @rmoff

Why Kafka? @rmoff

Stream Store Process Integrate @rmoff

Stream Store Process Integrate @rmoff

Stream Store Process Integrate @rmoff

Stream Store Process Integrate @rmoff

Stream Store Process Integrate @rmoff

Flexible, event-driven applications Event-driven alerts Key/Value lookups Streaming ETL @rmoff

on Photo by Want to learn more? CTAs, not CATs (sorry, not sorry) @rmoff

Try it out for yourself https://rmoff.dev/carparks

RM OF F2 00 $200 USD off your bill each calendar month for the first three months when you sign up https://rmoff.dev/ccloud Free money! (additional $200 towards your bill 😄 ) Fully Managed Kafka as a Service * T&C: https://www.confluent.io/confluent-cloud-promo-disclaimer

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

#EOF https://talks.rmoff.net @rmoff

Confluent Community Slack group cnfl.io/slack @rmoff

Further reading / watching https://rmoff.dev/kafka-talks @rmoff