đ¤Building a Telegram bot with Apache Kafka and ksqlDB
Robin Moffatt
@rmoff
Slide 2
Slide 3
Whereâs my nearest carpark with available spaces?
Slide 4
How many spaces are available in this car park?
Slide 5
đĄTell me when a car park with spaces is available
Slide 6
đHow does occupancy vary over time?
Slide 7
Slide 8
Telegram
@rmoff
Slide 9
Donât just tell meâŚ
show me!
Demo code: https://rmoff.dev/carparks
Slide 10
carparks
HTTP Kafka
@rmoff
Slide 11
What are the key pieces of the design? @rmoff
Slide 12
Event Driven Alerts carparks
HTTP Kafka
@rmoff
Slide 13
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
Slide 14
A schema⌠carparks
HTTP
@rmoff
Slide 15
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
Slide 16
My kingdom for a schema! 2020-10-14,12:28,Broadway,1132,921
âtsâ: â2020-10-14T12:28 UTC+1â, ânameâ: âBroadwayâ, âcapacityâ: 1132, âemptyâ: 921 } âŚ
@rmoff
Slide 17
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
Slide 18
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
Streaming Integration with Kafka Connect Amazon S3
Google BigQuery
Sinks
Tasks
Workers
Kafka Connect Kafka Brokers
@rmoff
Slide 22
Streaming Integration with Kafka Connect Amazon S3
syslog
Google BigQuery
Tasks
Workers
Kafka Connect Kafka Brokers
@rmoff
Slide 23
Streaming Analytics
@rmoff
Slide 24
Why build it this way?
@rmoff
Slide 25
Events @rmoff
Slide 26
Streams of Events
@rmoff
Slide 27
We want to react to them as they happen @rmoff
Slide 28
We want to build state from a stream of events @rmoff
Slide 29
We want to provide the latest data in our analytics @rmoff
Slide 30
Apache Kafka - an Event Streaming Platform Producer
Connectors
Consumer
The Log
Connectors
Streaming Engine @rmoff
Slide 31
Why Kafka?
@rmoff
Slide 32
Distributed, Immutable, Event Log
Old
New
Events are added at the end of the log @rmoff
Slide 33
Consumers can seek to any point
Read to offset & scan Old
New
@rmoff
Slide 34
Data is not deleted once read
New
Old
Sally is here
Scan
@rmoff
Slide 35
Consumers are independent of each other
New
Old
Fred is here
Scan
Sally is here
Scan
@rmoff
Slide 36
Consumers can be added later Rick is here
Scan
New
Old
Fred is here
Scan
Sally is here
Scan
@rmoff
Slide 37
Stream Processing with ksqlDB Source stream
@rmoff
Slide 38
Stream Processing with ksqlDB Source stream
@rmoff
Slide 39
Stream Processing with ksqlDB Source stream
@rmoff
Slide 40
Stream Processing with ksqlDB Source stream
Analytics
@rmoff
Slide 41
Stream Processing with ksqlDB Source stream
Applications / Microservices @rmoff
Slide 42
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
Slide 43
Under the covers of ksqlDB Photo by
@rmoff on
Slide 44
Kafka cluster consume
produce
ksqlDB
@rmoff
Slide 45
JVM
Kafka cluster consume
produce
ksqlDB
Kafka Streams
RocksDB
@rmoff
Slide 46
Slide 47
k &
^ Kafka
Fully Managed as a Service
B D l q s
Slide 48
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
on Photo by
Want to learn more? CTAs, not CATs (sorry, not sorry)
@rmoff
Slide 57
Try it out for yourself https://rmoff.dev/carparks
Slide 58
s e l c i t r a eep-dive
D ⢠⢠⢠⢠â˘
ka? f a K e ds h c n a e r p T A d s i e lat e R What . s v g min a e per r e t e S K t o n o e Z v E ut o h t i w fka a a K k f n a i K s : e t f ante KRa r a u G & ns o i t c a s n a Tr ge a r o t S & ng Processi tals n e m a d Fun
⢠⢠⢠⢠â˘
e c n a m r o f r Kafka Pe a k f a K e v i t ms e t s y S Cloud-na e s ba a t a D g n Streami fka a K e h c a p ls a n Testing A r e t n I s fkaâ a K e r o l Exp
⢠⢠⢠⢠â˘
Over 10
Apache K afka 101 Kafka Co nnect 10 1 Kafka Str eams 101 ksqlDB 1 01 Inside ks qlDB
hours of ⢠⢠⢠â˘
f ree cou
rses
Spring F ramewo rk and K Building afka Data Pip elines wi Event So th Kafka urcing w ith Kafka Data Me sh 101
Plus: Hands-on Quick Starts and Client Language Guides + Event Streaming Patterns + More
fl
developer.con uent.io
Slide 59
OF
F2 00
$200 USD off your bill each calendar month for the rst three months when you sign up https://rmoff.dev/ccloud
RM
Free money! (additional $200 towards your bill đ )
Fully Managed Kafka as a Service fl
fl
fi