SlideShare a Scribd company logo
Using Kafka in your
python application
Oleksandr Tarasenko
EVO Pay / EVO.company
Oleksandr Tarasenko "Using Kafka in your python applications"
Oleksandr Tarasenko "Using Kafka in your python applications"
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
Oleksandr Tarasenko "Using Kafka in your python applications"
What is Apache Kafka
A Distributed Streaming Platform
● Publish & Subscribe
● Process streams
● Store data
● Queues ?
8
Oleksandr Tarasenko "Using Kafka in your python applications"
Oleksandr Tarasenko "Using Kafka in your python applications"
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
Oleksandr Tarasenko "Using Kafka in your python applications"
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

PDF
Brief intro to K8s controller and operator
ODP
Kyua and Jenkins: Testing Framework for BSD
PDF
Deploying .NET applications with the Nix package manager
PDF
Spring Boot to Quarkus: A real app migration experience | DevNation Tech Talk
PDF
An intro to Kubernetes operators
PPTX
Kafka y python
PDF
Hands-on K8s: Deployments, Pods and Fun
PDF
Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...
Brief intro to K8s controller and operator
Kyua and Jenkins: Testing Framework for BSD
Deploying .NET applications with the Nix package manager
Spring Boot to Quarkus: A real app migration experience | DevNation Tech Talk
An intro to Kubernetes operators
Kafka y python
Hands-on K8s: Deployments, Pods and Fun
Serverless, Tekton, and Argo CD: How to craft modern CI/CD workflows | DevNat...

What's hot (19)

PDF
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
PPTX
Using Rally for OpenStack certification at Scale
PPTX
Build a Deep Learning App with Tensorflow & Redis by Jayesh Ahire and Sherin ...
PDF
Reactive database access with Slick3
ODP
Oslo Vancouver Project Update
PDF
12 Factors Kubernetes
PDF
Continuously Deliver Your Kubernetes Infrastructure - KubeCon 2018 Copenhagen
PDF
Integrate Openshift with Cloudforms
PPTX
Make stateful apps in Kubernetes a no brainer with Pure Storage and GitOps
PDF
Paris Container Day 2016 : Retour sur DockerCon 16', faits marquants (Docker)
PDF
Operator SDK for K8s using Go
PDF
client-go: The Good, The Bad and The Ugly
PDF
Scaling i/o bound Microservices
PDF
HKG15-204: OpenStack: 3rd party testing and performance benchmarking
PDF
PDF
Rally: OpenStack Benchmarking
PPTX
How to lock a Python in a cage? Managing Python environment inside an R project
PDF
Presentation security automation (Selenium Camp)
PDF
Paris Container Day 2016 : Cloud de conteneurs, conteneurs dans le cloud, str...
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
Using Rally for OpenStack certification at Scale
Build a Deep Learning App with Tensorflow & Redis by Jayesh Ahire and Sherin ...
Reactive database access with Slick3
Oslo Vancouver Project Update
12 Factors Kubernetes
Continuously Deliver Your Kubernetes Infrastructure - KubeCon 2018 Copenhagen
Integrate Openshift with Cloudforms
Make stateful apps in Kubernetes a no brainer with Pure Storage and GitOps
Paris Container Day 2016 : Retour sur DockerCon 16', faits marquants (Docker)
Operator SDK for K8s using Go
client-go: The Good, The Bad and The Ugly
Scaling i/o bound Microservices
HKG15-204: OpenStack: 3rd party testing and performance benchmarking
Rally: OpenStack Benchmarking
How to lock a Python in a cage? Managing Python environment inside an R project
Presentation security automation (Selenium Camp)
Paris Container Day 2016 : Cloud de conteneurs, conteneurs dans le cloud, str...
Ad

Similar to Oleksandr Tarasenko "Using Kafka in your python applications" (20)

PDF
Python Kafka Integration: Developers Guide
PDF
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
PDF
Developing Realtime Data Pipelines With Apache Kafka
PPTX
Apache Kafka
PPTX
Large scale, distributed and reliable messaging with Kafka
PDF
Developing Real-Time Data Pipelines with Apache Kafka
PPTX
Kafka overview
PDF
PDF
An Introduction to Apache Kafka
PDF
Kafka zero to hero
PDF
Apache Kafka - From zero to hero
PPTX
Real-time streaming and data pipelines with Apache Kafka
PPTX
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
ODP
Introduction to Apache Kafka- Part 2
PPTX
Introduction to Kafka and Event-Driven
PDF
Introduction to Kafka and Event-Driven
PPTX
Kafka tutorial
PPTX
Building an Event Bus at Scale
PDF
Enabling Data Scientists to easily create and own Kafka Consumers | Stefan Kr...
PDF
Enabling Data Scientists to easily create and own Kafka Consumers
Python Kafka Integration: Developers Guide
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Developing Realtime Data Pipelines With Apache Kafka
Apache Kafka
Large scale, distributed and reliable messaging with Kafka
Developing Real-Time Data Pipelines with Apache Kafka
Kafka overview
An Introduction to Apache Kafka
Kafka zero to hero
Apache Kafka - From zero to hero
Real-time streaming and data pipelines with Apache Kafka
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
Introduction to Apache Kafka- Part 2
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-Driven
Kafka tutorial
Building an Event Bus at Scale
Enabling Data Scientists to easily create and own Kafka Consumers | Stefan Kr...
Enabling Data Scientists to easily create and own Kafka Consumers
Ad

More from Fwdays (20)

PDF
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
PDF
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
PPTX
"Computer Use Agents: From SFT to Classic RL", Maksym Shamrai
PPTX
"Як ми переписали Сільпо на Angular", Євген Русаков
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
PDF
"Validation and Observability of AI Agents", Oleksandr Denisyuk
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
PPTX
"Co-Authoring with a Machine: What I Learned from Writing a Book on Generativ...
PPTX
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
PDF
"AI is already here. What will happen to your team (and your role) tomorrow?"...
PPTX
"Is it worth investing in AI in 2025?", Alexander Sharko
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
PDF
"Database isolation: how we deal with hundreds of direct connections to the d...
PDF
"Scaling in space and time with Temporal", Andriy Lupa .pdf
PPTX
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
PPTX
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
PPTX
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
"Computer Use Agents: From SFT to Classic RL", Maksym Shamrai
"Як ми переписали Сільпо на Angular", Євген Русаков
"AI Transformation: Directions and Challenges", Pavlo Shaternik
"Validation and Observability of AI Agents", Oleksandr Denisyuk
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
"Co-Authoring with a Machine: What I Learned from Writing a Book on Generativ...
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
"AI is already here. What will happen to your team (and your role) tomorrow?"...
"Is it worth investing in AI in 2025?", Alexander Sharko
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Database isolation: how we deal with hundreds of direct connections to the d...
"Scaling in space and time with Temporal", Andriy Lupa .pdf
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
sap open course for s4hana steps from ECC to s4
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine Learning_overview_presentation.pptx
Programs and apps: productivity, graphics, security and other tools
sap open course for s4hana steps from ECC to s4
MIND Revenue Release Quarter 2 2025 Press Release
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25-Week II
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Review of recent advances in non-invasive hemoglobin estimation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Oleksandr Tarasenko "Using Kafka in your python applications"