đ¤Building a Telegram bot with
Apache Kafka, Go, and ksqlDB
Robin Moffatt
@rmoff
Slide 2
Slide 3
Slide 4
Slide 5
Slide 6
Whereâs my nearest carpark with available spaces?
Slide 7
How many spaces are available in this car park?
Slide 8
đĄTell me when a car park with spaces is available
Slide 9
đHow does occupancy vary over time?
Slide 10
$ 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
Slide 11
Slide 12
Telegram
@rmoff
Slide 13
Donât just tell meâŚ
show me!
Demo code: https://rmoff.dev/carparks
Slide 14
carparks
HTTP Kafka
@rmoff
Slide 15
What are the key pieces of the design? @rmoff
Slide 16
Event Driven Alerts carparks
HTTP Kafka
@rmoff
Slide 17
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 18
A schema⌠carparks
HTTP
@rmoff
Slide 19
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 20
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
Slide 21
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 22
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 26
Streaming Integration with Kafka Connect Amazon S3
syslog
Google BigQuery
Tasks
Workers
Kafka Connect Kafka Brokers
@rmoff
Slide 27
Streaming Analytics
@rmoff
Slide 28
Why build it this way?
@rmoff
Slide 29
Events @rmoff
Slide 30
Streams of Events
@rmoff
Slide 31
We want to react to them as they happen @rmoff
Slide 32
We want to build state from a stream of events @rmoff
Slide 33
We want to provide the latest data in our analytics @rmoff
Slide 34
Apache Kafka - an Event Streaming Platform Producer
Connectors
Consumer
The Log
Connectors
Streaming Engine @rmoff
Slide 35
Why Kafka?
@rmoff
Slide 36
Distributed, Immutable, Event Log
Old
New
Events are added at the end of the log @rmoff
Slide 37
Consumers can seek to any point
Read to offset & scan Old
New
@rmoff
Slide 38
Data is not deleted once read
New
Old
Sally is here
Scan
@rmoff
Slide 39
Consumers are independent of each other
New
Old
Fred is here
Scan
Sally is here
Scan
@rmoff
Slide 40
Consumers can be added later Rick is here
Scan
New
Old
Fred is here
Scan
Sally is here
Scan
@rmoff
Slide 41
Stream Processing with ksqlDB Source stream
@rmoff
Slide 42
Stream Processing with ksqlDB Source stream
@rmoff
Slide 43
Stream Processing with ksqlDB Source stream
@rmoff
Slide 44
Stream Processing with ksqlDB Source stream
Analytics
@rmoff
Slide 45
Stream Processing with ksqlDB Source stream
Applications / Microservices @rmoff
Slide 46
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 47
Under the covers of ksqlDB Photo by
@rmoff on
Slide 48
Kafka cluster consume
produce
ksqlDB
@rmoff
Slide 49
JVM
Kafka cluster consume
produce
ksqlDB
Kafka Streams
RocksDB
@rmoff
Slide 50
Slide 51
k &
^ Kafka
Fully Managed as a Service
B D l q s
Slide 52
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 61
Try it out for yourself https://rmoff.dev/carparks
Slide 62
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
Slide 63
Learn Kafka. Start building with Apache Kafka at Confluent Developer. developer.confluent.io
Slide 64
#EOF https://talks.rmoff.net
@rmoff
Slide 65
Confluent Community Slack group
cnfl.io/slack @rmoff
Slide 66
Further reading / watching
https://rmoff.dev/kafka-talks
@rmoff