SlideShare a Scribd company logo
Using Kafka in your
python application
Oleksandr Tarasenko
EVO Pay / EVO.company
Using Kafka in your python application - Python fwdays 2020
Using Kafka in your python application - Python fwdays 2020
Agenda
● intro to kafka
● kafka and other solutions
● kafka + python
● EVO solutions with kafka
4
WHY?
5
What is Apache Kafka
A Distributed Streaming Platform
● Publish & Subscribe
● Process streams
● Store data
6
Using Kafka in your python application - Python fwdays 2020
What is Apache Kafka
A Distributed Streaming Platform
● Publish & Subscribe
● Process streams
● Store data
● Queues ?
8
Using Kafka in your python application - Python fwdays 2020
Using Kafka in your python application - Python fwdays 2020
Kafka vs ???
11
Kafka vs ???
● kafka vs rabbitmq
● kafka vs nsq
● kafka vs jms
● kafka vs nuts
● kafka vs pulsar
● kafka vs rest ?
● kafka vs akka ??
12
Using Kafka in your python application - Python fwdays 2020
Apache Kafka good in
● Event sourcing
● Stream processing
● Messaging
● Log aggregation
● Activity tracking
● ...
14
Kafka Ecosystem
https://cwiki.apache.org/confluence/display/KAFKA/Ecosystem
Kafka Ecosystem
https://cwiki.apache.org/confluence/display/KAFKA/Ecosystem
Stream processing
Packaging
Distributions
Kafka connect
Hadoop integration
Database integration
Metrics
Management consoles
Logging
AWS integration
Kafka Camel Integration
Packing and Deployment
+
Kafka in python world
● kafka-python
● confluent-kafka-python
● pykafka
● aiokafka
● faust*
18
Kafka in python world
● kafka-python (sync)
● confluent-kafka-python (sync)
● pykafka (dead)
● aiokafka (async)
● faust* (async)
19
kafka-python
https://github.com/dpkp/kafka-python
https://kafka-python.readthedocs.io/
● pythonic
● work with old kafka versions
kafka-python
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='localhost:1234')
...
for product_data in some_data_source:
producer.send('product_topic', product_data)
future = producer.send('product_topic', b'product_data')
result = future.get(timeout=60)
producer.flush()
…
producer.send('product_topic', key=b'product_category_id', value=b'product_data')
21
kafka-python
from kafka import KafkaConsumer
consumer = KafkaConsumer('product_topic')
for msg in consumer:
print(msg)
...
consumer = KafkaConsumer('product_topic', group_id='discount_product_group')
for msg in consumer:
print(msg)
22
confluent-kafka-python
https://github.com/confluentinc/confluent-kafka-python
https://docs.confluent.io/current/clients/confluent-kafka-python/index.html
● librdkafka
● faster
● thread safe
confluent-kafka-python
from confluent_kafka import Producer
p = Producer({'bootstrap.servers': 'localhost:1234'})
def delivery_report(err, msg):
if err is not None:
print('Message delivery failed: {}'.format(err))
else:
print('Message delivered to {} [{}]'.format(msg.topic(), msg.partition()))
for data in some_data_source:
p.poll(0)
p.produce('product_topic', data.encode('utf-8'), callback=delivery_report)
p.flush()
24
confluent-kafka-python
from confluent_kafka import Consumer
c = Consumer({
'bootstrap.servers': 'localhost:1234',
'group.id': 'discount_product_group',
'auto.offset.reset': 'earliest'
})
c.subscribe(['product_topic'])
while True:
msg = c.poll(1.0)
if msg is None:
continue
if msg.error():
print("Consumer error: {}".format(msg.error()))
continue
print('Received message: {}'.format(msg.value().decode('utf-8')))
c.close() 25
aiokafka
https://github.com/aio-libs/aiokafka
https://aiokafka.readthedocs.io/en/stable/
● aio-libs
● async/await model
● based on kafka-python
● ukrainian developers
aiokafka
from aiokafka import AIOKafkaProducer
import asyncio
loop = asyncio.get_event_loop ()
async def send_one():
producer = AIOKafkaProducer (
loop=loop, bootstrap_servers ='localhost:1234' )
await producer.start()
try:
await producer.send_and_wait("product_topic" , b"product_data" )
finally:
await producer.stop()
loop.run_until_complete (send_one())
27
aiokafka
from aiokafka import AIOKafkaConsumer
import asyncio
async def consume():
consumer = AIOKafkaConsumer (
'product_topic' , 'other_topic',
loop=loop, bootstrap_servers ='localhost:1234' ,
group_id ="discount_product_group" )
await consumer.start()
try:
async for msg in consumer:
print("consumed: ", msg.topic, msg.partition, msg.offset,
msg.key, msg.value, msg.timestamp)
finally:
await consumer.stop()
loop.run_until_complete (consume())
28
faust
https://github.com/robinhood/faust
https://faust.readthedocs.io/en/latest/
● python 3.6+, async/await
● like framework
● standalone
● kafka streams
● celery*
faust
import faust
app = faust.App('myapp', broker='kafka://localhost:1234')
class Product(faust.Record):
product_id: str
price: int
@app.agent(value_type=Product)
async def product(products):
async for product in products:
print(f'Product for {product.product_id}: {product.price}')
30
faust
import faust
class Product(faust.Record):
product_id: str
price: int
app = faust.App('hello-app', broker='kafka://localhost:1234')
topic = app.topic('hello-topic', value_type=Product)
@app.agent(topic)
async def example_source(products):
async for product in products:
print(f'Hello from {product.product_id} to {product.price}')
@app.timer(value_type=1.0)
async def example_producer(app):
await example_source.send(
value=Product(product_id='123zxc', price=100),
)
if __name__ == '__main__':
app.main()
31
Example 1 - Products indexation
Example scheme with python-kafka
Example scheme with python-kafka
Example scheme with python-kafka
Example scheme with python-kafka
Example scheme with python-kafka
Example scheme with python-kafka
Example scheme with python-kafka
Example scheme with python-kafka
Example scheme with python-kafka
Example scheme with python-kafka
Example 2 - Delivery data stream
Example scheme with aiokafka + faust
Example scheme with aiokafka + faust
Example scheme with aiokafka + faust
Example scheme with aiokafka + faust
Example scheme with aiokafka + faust
Example scheme with aiokafka + faust
Example scheme with aiokafka + faust
Example scheme with aiokafka + faust
Thank you :)
Q/A

More Related Content

What's hot (20)

PDF
AWS 클라우드 기반 게임 아키텍처 사례 - AWS Summit Seoul 2017
Amazon Web Services Korea
 
PPTX
Introduction to Microsoft Power Platform (PowerApps, Flow)
Sam Fernando
 
PDF
HAProxy TCP 모드에서 내부 서버로 Source IP 전달 방법
Young D
 
PDF
Salesforce.com Org Migration Overview
Shell Black
 
PDF
Configure, price and quote (CPQ) platform - Right information
Right Information
 
PDF
Event Driven-Architecture from a Scalability perspective
Jonas Bonér
 
PDF
Glpi 9.2-presentation
alexandre delaunay
 
PDF
GPPB2020 - Milan - Power BI dataflows deep dive
Riccardo Perico
 
PDF
5 Critical Steps to Clean Your Data Swamp When Migrating Off of Hadoop
Databricks
 
PDF
게임서비스를 위한 ElastiCache 활용 전략 :: 구승모 솔루션즈 아키텍트 :: Gaming on AWS 2016
Amazon Web Services Korea
 
PDF
[AIS 2018] [Team Tools_Advanced] Confluence 100배 활용하기 - 커브
Atlassian 대한민국
 
PDF
Deep Dive into Building Streaming Applications with Apache Pulsar
Timothy Spann
 
PPTX
Design Pattern - Chain of Responsibility
Mudasir Qazi
 
PPTX
How EnerKey Using InfluxDB Saves Customers Millions by Detecting Energy Usage...
InfluxData
 
PDF
Refactoring for Domain Driven Design
David Berliner
 
PPTX
Nginx Reverse Proxy with Kafka.pptx
wonyong hwang
 
PDF
Design by contract(계약에의한설계)
Jeong-gyu Kim
 
PDF
[236] 카카오의데이터파이프라인 윤도영
NAVER D2
 
PDF
[226]NAVER 광고 deep click prediction: 모델링부터 서빙까지
NAVER D2
 
PPTX
Developer group introduction & Salesforce overview
Sujesh Ramachandran
 
AWS 클라우드 기반 게임 아키텍처 사례 - AWS Summit Seoul 2017
Amazon Web Services Korea
 
Introduction to Microsoft Power Platform (PowerApps, Flow)
Sam Fernando
 
HAProxy TCP 모드에서 내부 서버로 Source IP 전달 방법
Young D
 
Salesforce.com Org Migration Overview
Shell Black
 
Configure, price and quote (CPQ) platform - Right information
Right Information
 
Event Driven-Architecture from a Scalability perspective
Jonas Bonér
 
Glpi 9.2-presentation
alexandre delaunay
 
GPPB2020 - Milan - Power BI dataflows deep dive
Riccardo Perico
 
5 Critical Steps to Clean Your Data Swamp When Migrating Off of Hadoop
Databricks
 
게임서비스를 위한 ElastiCache 활용 전략 :: 구승모 솔루션즈 아키텍트 :: Gaming on AWS 2016
Amazon Web Services Korea
 
[AIS 2018] [Team Tools_Advanced] Confluence 100배 활용하기 - 커브
Atlassian 대한민국
 
Deep Dive into Building Streaming Applications with Apache Pulsar
Timothy Spann
 
Design Pattern - Chain of Responsibility
Mudasir Qazi
 
How EnerKey Using InfluxDB Saves Customers Millions by Detecting Energy Usage...
InfluxData
 
Refactoring for Domain Driven Design
David Berliner
 
Nginx Reverse Proxy with Kafka.pptx
wonyong hwang
 
Design by contract(계약에의한설계)
Jeong-gyu Kim
 
[236] 카카오의데이터파이프라인 윤도영
NAVER D2
 
[226]NAVER 광고 deep click prediction: 모델링부터 서빙까지
NAVER D2
 
Developer group introduction & Salesforce overview
Sujesh Ramachandran
 

Similar to Using Kafka in your python application - Python fwdays 2020 (20)

PPTX
Mule soft meetup_chandigarh_#7_25_sept_2021
Lalit Panwar
 
PDF
Big Data Open Source Security LLC: Realtime log analysis with Mesos, Docker, ...
DataStax Academy
 
PDF
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Timothy Spann
 
PPTX
Real-Time Log Analysis with Apache Mesos, Kafka and Cassandra
Joe Stein
 
PPTX
Real-time streaming and data pipelines with Apache Kafka
Joe Stein
 
PDF
Kafka Connect & Streams - the ecosystem around Kafka
Guido Schmutz
 
PDF
ApacheCon NA - Apache Camel K: connect your Knative serverless applications w...
Nicola Ferraro
 
PPTX
Building Stream Processing as a Service
Steven Wu
 
PDF
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
mfrancis
 
PDF
14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...
Athens Big Data
 
PPTX
Being Ready for Apache Kafka - Apache: Big Data Europe 2015
Michael Noll
 
PDF
Python Streaming Pipelines on Flink - Beam Meetup at Lyft 2019
Thomas Weise
 
PDF
Camel Kafka Connectors: Tune Kafka to “Speak” with (Almost) Everything (Andre...
HostedbyConfluent
 
PPT
Kafka Explainaton
NguyenChiHoangMinh
 
PDF
Spark streaming + kafka 0.10
Joan Viladrosa Riera
 
PDF
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Guido Schmutz
 
PDF
Data science online camp using the flipn stack for edge ai (flink, nifi, pu...
Timothy Spann
 
PPTX
Introduction Apache Kafka
Joe Stein
 
PDF
What is Apache Kafka and What is an Event Streaming Platform?
confluent
 
PDF
Codeless pipelines with pulsar and flink
Timothy Spann
 
Mule soft meetup_chandigarh_#7_25_sept_2021
Lalit Panwar
 
Big Data Open Source Security LLC: Realtime log analysis with Mesos, Docker, ...
DataStax Academy
 
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Timothy Spann
 
Real-Time Log Analysis with Apache Mesos, Kafka and Cassandra
Joe Stein
 
Real-time streaming and data pipelines with Apache Kafka
Joe Stein
 
Kafka Connect & Streams - the ecosystem around Kafka
Guido Schmutz
 
ApacheCon NA - Apache Camel K: connect your Knative serverless applications w...
Nicola Ferraro
 
Building Stream Processing as a Service
Steven Wu
 
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
mfrancis
 
14th Athens Big Data Meetup - Landoop Workshop - Apache Kafka Entering The St...
Athens Big Data
 
Being Ready for Apache Kafka - Apache: Big Data Europe 2015
Michael Noll
 
Python Streaming Pipelines on Flink - Beam Meetup at Lyft 2019
Thomas Weise
 
Camel Kafka Connectors: Tune Kafka to “Speak” with (Almost) Everything (Andre...
HostedbyConfluent
 
Kafka Explainaton
NguyenChiHoangMinh
 
Spark streaming + kafka 0.10
Joan Viladrosa Riera
 
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Guido Schmutz
 
Data science online camp using the flipn stack for edge ai (flink, nifi, pu...
Timothy Spann
 
Introduction Apache Kafka
Joe Stein
 
What is Apache Kafka and What is an Event Streaming Platform?
confluent
 
Codeless pipelines with pulsar and flink
Timothy Spann
 
Ad

Recently uploaded (20)

PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Ad

Using Kafka in your python application - Python fwdays 2020