SlideShare a Scribd company logo
Enterprise Wide Publish / Subscribe Models
With Apache Kafka
Johan Louwers – Global Lead Architect
2Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Application
Schema C
Database
Application (backend)
Client Device / Client Application
Schema B
Schema A
UI Rendering Logic
Application Logic
Interface Logic
ExternalSystems
Monolithic Architecture
Still used today
Monolithic Architecture
- Commonly seen in traditional large scale enterprise
deployment
- Not flexible and hard to maintain
- Seen as a dead end
3Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
RESTAPI
Database
(micro)Service(s)
Service B
RESTAPI
Database
(micro)Service(s)
Service A
RESTAPI
Application (backend)
UI Applications & Application Backend Services
API gateway
Microservice Architecture
Decompose the monolith
Microservice Architecture
- Decomposition of the monolith
- Commonly deployed in containers of functions
- Commonly self scaling
- Commonly loosely coupled
- Commonly makes use of REST / gRPC
- Commonly makes use isolated persistence
4Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
RESTAPI
Database
(micro)Service(s)
Service B
RESTAPI
Database
(micro)Service(s)
Service A
RESTAPI
Application (backend)
API gateway
UI Applications & Application Backend Services
Microservice Architecture
Distribute transactions (option 1)
Microservice Architecture
Distributed transactions over multiple services
- UI calls all services involved in a business
transaction
- High changes of inconsistency
- Complex UI logic and hard to maintain
5Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
RESTAPI
Database
(micro)Service(s)
Service B
RESTAPI
Database
(micro)Service(s)
Service A
RESTAPI
Application (backend)
API gateway
UI Applications & Application Backend Services
Microservice Architecture
Distribute transactions (option 2)
Microservice Architecture
Distributed transactions over multiple services
- UI calls initial service for business transaction
- Service propagate transaction to other services
- High level of point 2 point connections
- Complex to add new services
6Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service B
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service A
Subscribe
r
Publisher
RESTAPI
KafkaPub/Sub
Application (backend)
UI Applications
App. Backend
Services
API gateway
Microservice Architecture
Distribute transactions (option 3)
Microservice Architecture
Distributed transactions over multiple services
- UI calls initial service for business transaction
- Service publish event to a Kafka topic
- A topic can be read by every subscriber
- Care about your consumers by not caring
7Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service B
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service A
Subscribe
r
Publisher
RESTAPI
KafkaPub/Sub
Application (backend)
UI Applications
App. Backend
Services
API gateway
Microservice Architecture
Distribute transactions (option 3)
Microservice Architecture
All services are publishers
- “event” : a significant change of state
- Do not share the data, share the event
- CRUD events:
- CREATE & UPDATE : standard
- DELETE : do you really want that?
- READ : on some very specific cases
{
"event": {
"event_topic": "customerdata",
"event_type": "create",
"event_application": "CRMAPAC",
"event_service": "customers",
"event_data_object": "deliveryLocations",
"event_data_location": "https://api.crmapac.acme.com/customers/1264/deliveryLocations/26/",
"classification": {
"classified_gdpr": true,
"classified_internalviews": true,
"classified_publicviews": false,
"classified_privateviews": true
}
}
}
8Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service B
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service A
Subscribe
r
Publisher
RESTAPI
KafkaPub/Sub
Application (backend)
UI Applications
App. Backend
Services
API gateway
from kafka import KafkaProducer
from kafka.errors import KafkaError
producer = KafkaProducer(bootstrap_servers=['broker1:1234'])
# Asynchronous by default
future = producer.send('my-topic', b'raw_bytes')
# Block for 'synchronous' sends
try:
record_metadata = future.get(timeout=10)
except KafkaError:
# Decide what to do if produce request failed...
log.exception()
pass
# Successful result returns assigned partition and offset
print (record_metadata.topic)
print (record_metadata.partition)
print (record_metadata.offset)
# produce keyed messages to enable hashed partitioning
producer.send('my-topic', key=b'foo', value=b'bar')
# encode objects via msgpack
producer = KafkaProducer(value_serializer=msgpack.dumps)
producer.send('msgpack-topic', {'key': 'value'})
# produce json messages
producer = KafkaProducer(value_serializer=lambda m: json.dumps(m).encode('ascii'))
producer.send('json-topic', {'key': 'value'})
# produce asynchronously
for _ in range(100):
producer.send('my-topic', b'msg')
def on_send_success(record_metadata):
print(record_metadata.topic)
print(record_metadata.partition)
print(record_metadata.offset)
def on_send_error(excp):
log.error('I am an errback', exc_info=excp)
# handle exception
# produce asynchronously with callbacks
producer.send('my-topic', b'raw_bytes').add_callback(on_send_success).add_errback(on_send_error)
# block until all async messages are sent
producer.flush()
# configure multiple retries
producer = KafkaProducer(retries=5)
Microservice Architecture
Distribute transactions (option 3)
9Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service B
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service A
Subscribe
r
Publisher
RESTAPI
KafkaPub/Sub
Application (backend)
UI Applications
App. Backend
Services
API gateway
Microservice Architecture
Distribute transactions (option 3)
Microservice Architecture
Services can be a subscriber
- Easily add new services by subscribing to topics
- Kafka topic consumption:
- REST API / Native Kafka client
- PULL/PUSH
- Subscriber defines the required actions on an event
- Subscriber calls publisher server API to obtain data
- Data should never be stored outside the context of
the owning service
- or with care and understanding{
"event": {
"event_topic": "customerdata",
"event_type": "create",
"event_application": "CRMAPAC",
"event_service": "customers",
"event_data_object": "deliveryLocations",
"event_data_location": "https://api.crmapac.acme.com/customers/1264/deliveryLocations/26/",
"classification": {
"classified_gdpr": true,
"classified_internalviews": true,
"classified_publicviews": false,
"classified_privateviews": true
}
}
}
10Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service B
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service A
Subscribe
r
Publisher
RESTAPI
KafkaPub/Sub
Application (backend)
UI Applications
App. Backend
Services
API gateway
from kafka import KafkaConsumer
# To consume latest messages and auto-commit offsets
consumer = KafkaConsumer('my-topic',
group_id='my-group',
bootstrap_servers=['localhost:9092'])
for message in consumer:
# message value and key are raw bytes -- decode if necessary!
# e.g., for unicode: `message.value.decode('utf-8')`
print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
message.offset, message.key,
message.value))
# consume earliest available messages, don't commit offsets
KafkaConsumer(auto_offset_reset='earliest', enable_auto_commit=False)
# consume json messages
KafkaConsumer(value_deserializer=lambda m: json.loads(m.decode('ascii')))
# consume msgpack
KafkaConsumer(value_deserializer=msgpack.unpackb)
# StopIteration if no message after 1sec
KafkaConsumer(consumer_timeout_ms=1000)
# Subscribe to a regex topic pattern
consumer = KafkaConsumer()
consumer.subscribe(pattern='^awesome.*')
# Use multiple consumers in parallel w/ 0.9 kafka brokers
# typically you would run each on a different server / process / CPU
consumer1 = KafkaConsumer('my-topic',
group_id='my-group',
bootstrap_servers='my.server.com')
consumer2 = KafkaConsumer('my-topic',
group_id='my-group',
bootstrap_servers='my.server.com')
Microservice Architecture
Distribute transactions (option 3)
11Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service B
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service A
Subscribe
r
Publisher
RESTAPI
KafkaPub/Sub
Application (backend)
UI Applications
App. Backend
Services
API gateway
External API ServiceExt consumers
Microservice Architecture
Inform the world
Microservice Architecture
Enable the “world” to subscribe as much as possible
- Allow all known services to subscribe to topics
- Allow unknown parties to subscribe to topic via the
external service API
- Ensure both known (internal) and unknown
(external) parties can only access the data in a
secured manner (OAUTH2)
12Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Database
(micro)Service(s)
Service C
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service B
Subscribe
r
Publisher
RESTAPI
Database
(micro)Service(s)
Service A
Subscribe
r
Publisher
RESTAPI
KafkaPub/Sub
Application (backend)
UI Applications
App. Backend
Services
External API ServiceExt consumers
Outbound WebHook
Ext/Int
subscribers
Microservice Architecture
Inform the world
Microservice Architecture
Enable the “world” to subscribe as much as possible
- Do provide the option to subscribe to a webhook
- Push updates to HTTP(S) endpoints
- Prevent aggressive polling
- Allows for notification “spreading”
- Prevent request storms
API gateway
13Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Kafka Pub/Sub
External API ServiceOutbound WebHook
External Consumers
Application 1
(backend)
Application 3
(backend)
Application 2
(backend)
Microservice Architecture
Inform everyone
Microservice Architecture
Simplify the picture
- External and internal consumers
- Provide APIs, native clients and webhooks
- Strive for an event driven architecture
14Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Kafka Pub/Sub
External API ServiceOutbound WebHook
External Consumers
Application 1
(backend)
Application 3
(backend)
Application 2
(backend)
Remember – It is NOT a database
More than pub/sub - KSQL
Kafka, more than pub/sub
Query kafka
- Allow developers to query Kafka
- Stream analytics
- KSQL, a bit more than SQL
- Kafka is NOT a database
- Keep retention costs in mind
15Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
Kafka Pub/Sub
External API ServiceOutbound WebHook
External Consumers
Application 1
(backend)
Application 3
(backend)
Application 2
(backend)
CREATE STREAM pageviews 
(viewtime BIGINT, 
userid VARCHAR, 
gender VARCHAR, 
regionid VARCHAR, 
pageid VARCHAR) 
WITH (KAFKA_TOPIC='pageviews', 
VALUE_FORMAT='DELIMITED');
SELECT regionid, COUNT(*) FROM pageviews 
WINDOW HOPPING (SIZE 30 SECONDS, ADVANCE BY 10 SECONDS) 
WHERE UCASE(gender)='FEMALE' AND LCASE (regionid) LIKE '%_6' 
GROUP BY regionid;
Remember – It is NOT a database
More than pub/sub - KSQL
16Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
DC - A
How to deploy Kafka
Make it high available
Make it High Available
It is harder than you think
- Single DC cluster
- Issues with DC failure
- Stretched DC cluster
- Issues with split brain and CAP theorem
- Cluster per DC
- Issues with topic sync
Kafka node A-
3
Kafka node A-
2
Kafka node A-
1
Kafka node A-
0
DC - B
Kafka node A-
3
Kafka node A-
2
Kafka node A-
1
Kafka node B-
0
DC - A
Kafka node AKafka node 0
DC - B
Kafka node AKafka node 2
DC - A
Kafka node A-
3
Kafka node A-
2
Kafka node A-
1
Kafka node A-
0
DC - B
17Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved.
DC - A
How to get Kafka
Build versus buy versus consume
Kafka provides a high value
It comes with a lot of complexity
- Build (& deploy)
- Invest in a R&D and development
- Invest in (virtual HW)
- You build it you run it
- You know and own everything
- Buy
- High support costs
- Invest in (virtual HW)
- Still requires deep knowledge
- Could require a maintenance partner
- Consume
- Pay-per-use PaaS models
- Most solutions are in the cloud
- Some solutions are private cloud on converged
infra
Kafka node A-
3
Kafka node A-
2
Kafka node A-
1
Kafka node A-
0
DC - B
Kafka node A-
3
Kafka node A-
2
Kafka node A-
1
Kafka node B-
0
DC - A
Kafka node AKafka node 0
DC - B
Kafka node AKafka node 2
DC - A
Kafka node A-
3
Kafka node A-
2
Kafka node A-
1
Kafka node A-
0
DC - B
Thank you
Enterprise wide publish subscribe with Apache Kafka

More Related Content

What's hot (20)

PDF
Machine Learning with Apache Kafka in Pharma and Life Sciences
Kai Wähner
 
PDF
Confluent Platform 5.5 + Apache Kafka 2.5 => New Features (JSON Schema, Proto...
Kai Wähner
 
PDF
Apache Kafka and MQTT - Overview, Comparison, Use Cases, Architectures
Kai Wähner
 
PPTX
The Top 5 Apache Kafka Use Cases and Architectures in 2022
Kai Wähner
 
PDF
IoT Architectures for Apache Kafka and Event Streaming - Industry 4.0, Digita...
Kai Wähner
 
PDF
Apache Kafka in the Transportation and Logistics
Kai Wähner
 
PPTX
Streaming IBM i to Kafka for Next-Gen Use Cases
Precisely
 
PDF
Connected Vehicles and V2X with Apache Kafka
Kai Wähner
 
PDF
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Kai Wähner
 
PDF
Event Streaming CTO Roundtable for Cloud-native Kafka Architectures
Kai Wähner
 
PDF
Simplified Machine Learning Architecture with an Event Streaming Platform (Ap...
Kai Wähner
 
PDF
Mainframe Integration, Offloading and Replacement with Apache Kafka
Kai Wähner
 
PDF
Apache Kafka in the Healthcare Industry
Kai Wähner
 
PDF
Apache Kafka, Tiered Storage and TensorFlow for Streaming Machine Learning wi...
Kai Wähner
 
PDF
Apache Kafka and Blockchain - Comparison and a Kafka-native Implementation
Kai Wähner
 
PDF
Serverless Kafka on AWS as Part of a Cloud-native Data Lake Architecture
Kai Wähner
 
PDF
Confluent Operator as Cloud-Native Kafka Operator for Kubernetes
Kai Wähner
 
PDF
The Rise Of Event Streaming – Why Apache Kafka Changes Everything
Kai Wähner
 
PDF
Apache Kafka as Event Streaming Platform for Microservice Architectures
Kai Wähner
 
PDF
Apache Kafka for Real-time Supply Chain in the Food and Retail Industry
Kai Wähner
 
Machine Learning with Apache Kafka in Pharma and Life Sciences
Kai Wähner
 
Confluent Platform 5.5 + Apache Kafka 2.5 => New Features (JSON Schema, Proto...
Kai Wähner
 
Apache Kafka and MQTT - Overview, Comparison, Use Cases, Architectures
Kai Wähner
 
The Top 5 Apache Kafka Use Cases and Architectures in 2022
Kai Wähner
 
IoT Architectures for Apache Kafka and Event Streaming - Industry 4.0, Digita...
Kai Wähner
 
Apache Kafka in the Transportation and Logistics
Kai Wähner
 
Streaming IBM i to Kafka for Next-Gen Use Cases
Precisely
 
Connected Vehicles and V2X with Apache Kafka
Kai Wähner
 
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Kai Wähner
 
Event Streaming CTO Roundtable for Cloud-native Kafka Architectures
Kai Wähner
 
Simplified Machine Learning Architecture with an Event Streaming Platform (Ap...
Kai Wähner
 
Mainframe Integration, Offloading and Replacement with Apache Kafka
Kai Wähner
 
Apache Kafka in the Healthcare Industry
Kai Wähner
 
Apache Kafka, Tiered Storage and TensorFlow for Streaming Machine Learning wi...
Kai Wähner
 
Apache Kafka and Blockchain - Comparison and a Kafka-native Implementation
Kai Wähner
 
Serverless Kafka on AWS as Part of a Cloud-native Data Lake Architecture
Kai Wähner
 
Confluent Operator as Cloud-Native Kafka Operator for Kubernetes
Kai Wähner
 
The Rise Of Event Streaming – Why Apache Kafka Changes Everything
Kai Wähner
 
Apache Kafka as Event Streaming Platform for Microservice Architectures
Kai Wähner
 
Apache Kafka for Real-time Supply Chain in the Food and Retail Industry
Kai Wähner
 

Similar to Enterprise wide publish subscribe with Apache Kafka (20)

PPTX
Migrate a on-prem platform to the public cloud with Java - SpringBoot and PCF
Roy Braam
 
PPTX
Cloud Native with Kyma
Piotr Kopczynski
 
PPTX
IoT and Event Streaming at Scale with Apache Kafka
confluent
 
PDF
Introduction to Apache Kafka and why it matters - Madrid
Paolo Castagna
 
PDF
Event Mesh Presentation at Gartner AADI Mumbai
Solace
 
PDF
Kafka Vienna Meetup 020719
Patrik Kleindl
 
PDF
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...
confluent
 
PDF
Apache Kafka vs. Traditional Middleware (Kai Waehner, Confluent) Frankfurt 20...
confluent
 
PDF
Fast Data – Fast Cars: Wie Apache Kafka die Datenwelt revolutioniert
confluent
 
PPTX
Keine Angst vorm Dinosaurier: Mainframe-Integration und -Offloading mit Confl...
Precisely
 
PDF
Spark and machine learning in microservices architecture
Stepan Pushkarev
 
PDF
Building Event Driven (Micro)services with Apache Kafka
Guido Schmutz
 
PDF
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)
Kai Wähner
 
PDF
How to Build Streaming Apps with Confluent II
confluent
 
PPTX
Event-Based API Patterns and Practices
LaunchAny
 
PDF
Kubernetes, Istio and Knative - noteworthy practical experience
SAP HANA Cloud Platform
 
PDF
Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...
HostedbyConfluent
 
PDF
Set Your Data In Motion - CTO Roundtable
confluent
 
PPS
Bloomberg API Open Source Development and Solution Providers India
Point Perfect Technology Solutions
 
PDF
apidays LIVE JAKARTA - Event Driven APIs by Phil Scanlon
apidays
 
Migrate a on-prem platform to the public cloud with Java - SpringBoot and PCF
Roy Braam
 
Cloud Native with Kyma
Piotr Kopczynski
 
IoT and Event Streaming at Scale with Apache Kafka
confluent
 
Introduction to Apache Kafka and why it matters - Madrid
Paolo Castagna
 
Event Mesh Presentation at Gartner AADI Mumbai
Solace
 
Kafka Vienna Meetup 020719
Patrik Kleindl
 
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...
confluent
 
Apache Kafka vs. Traditional Middleware (Kai Waehner, Confluent) Frankfurt 20...
confluent
 
Fast Data – Fast Cars: Wie Apache Kafka die Datenwelt revolutioniert
confluent
 
Keine Angst vorm Dinosaurier: Mainframe-Integration und -Offloading mit Confl...
Precisely
 
Spark and machine learning in microservices architecture
Stepan Pushkarev
 
Building Event Driven (Micro)services with Apache Kafka
Guido Schmutz
 
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)
Kai Wähner
 
How to Build Streaming Apps with Confluent II
confluent
 
Event-Based API Patterns and Practices
LaunchAny
 
Kubernetes, Istio and Knative - noteworthy practical experience
SAP HANA Cloud Platform
 
Apicurio Registry: Event-driven APIs & Schema governance for Apache Kafka | F...
HostedbyConfluent
 
Set Your Data In Motion - CTO Roundtable
confluent
 
Bloomberg API Open Source Development and Solution Providers India
Point Perfect Technology Solutions
 
apidays LIVE JAKARTA - Event Driven APIs by Phil Scanlon
apidays
 
Ad

More from Johan Louwers (20)

PDF
Multi Domain REST API routing for Data Mesh based Data Products
Johan Louwers
 
PDF
TClab Dynamic Solar Panel Positioning Systems
Johan Louwers
 
PPTX
Oracle Cloud With Azure DevOps Pipelines
Johan Louwers
 
PPTX
Oracle Cloud native functions - create application from cli
Johan Louwers
 
PPTX
Oracle Labs - research mission & project potfolio
Johan Louwers
 
PPTX
Install Redis on Oracle Linux
Johan Louwers
 
PPTX
Fn project quick installation guide
Johan Louwers
 
PPTX
Oracle python pandas merge DataFrames
Johan Louwers
 
PPTX
import data from Oracle Database into Python Pandas Dataframe
Johan Louwers
 
PDF
Voice assistants for the insurance industry
Johan Louwers
 
PPTX
Industry 4.0 and Oracle Cloud
Johan Louwers
 
PPTX
Docker and microservices - moving from a monolith to microservices
Johan Louwers
 
PDF
Cloud native applications for banking
Johan Louwers
 
PPTX
Conversational retail
Johan Louwers
 
PPTX
Oracle Cloudday security
Johan Louwers
 
PPTX
Oracle Cloudday - the future of retail
Johan Louwers
 
PPTX
Capgemini Oracle Cloud Access Security Broker
Johan Louwers
 
PPTX
Microservices in the oracle cloud
Johan Louwers
 
PPTX
Oracle cloud, private, public and hybrid
Johan Louwers
 
PPTX
RethinkDB on Oracle Linux
Johan Louwers
 
Multi Domain REST API routing for Data Mesh based Data Products
Johan Louwers
 
TClab Dynamic Solar Panel Positioning Systems
Johan Louwers
 
Oracle Cloud With Azure DevOps Pipelines
Johan Louwers
 
Oracle Cloud native functions - create application from cli
Johan Louwers
 
Oracle Labs - research mission & project potfolio
Johan Louwers
 
Install Redis on Oracle Linux
Johan Louwers
 
Fn project quick installation guide
Johan Louwers
 
Oracle python pandas merge DataFrames
Johan Louwers
 
import data from Oracle Database into Python Pandas Dataframe
Johan Louwers
 
Voice assistants for the insurance industry
Johan Louwers
 
Industry 4.0 and Oracle Cloud
Johan Louwers
 
Docker and microservices - moving from a monolith to microservices
Johan Louwers
 
Cloud native applications for banking
Johan Louwers
 
Conversational retail
Johan Louwers
 
Oracle Cloudday security
Johan Louwers
 
Oracle Cloudday - the future of retail
Johan Louwers
 
Capgemini Oracle Cloud Access Security Broker
Johan Louwers
 
Microservices in the oracle cloud
Johan Louwers
 
Oracle cloud, private, public and hybrid
Johan Louwers
 
RethinkDB on Oracle Linux
Johan Louwers
 
Ad

Recently uploaded (20)

PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Python basic programing language for automation
DanialHabibi2
 
July Patch Tuesday
Ivanti
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 

Enterprise wide publish subscribe with Apache Kafka

  • 1. Enterprise Wide Publish / Subscribe Models With Apache Kafka Johan Louwers – Global Lead Architect
  • 2. 2Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Application Schema C Database Application (backend) Client Device / Client Application Schema B Schema A UI Rendering Logic Application Logic Interface Logic ExternalSystems Monolithic Architecture Still used today Monolithic Architecture - Commonly seen in traditional large scale enterprise deployment - Not flexible and hard to maintain - Seen as a dead end
  • 3. 3Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C RESTAPI Database (micro)Service(s) Service B RESTAPI Database (micro)Service(s) Service A RESTAPI Application (backend) UI Applications & Application Backend Services API gateway Microservice Architecture Decompose the monolith Microservice Architecture - Decomposition of the monolith - Commonly deployed in containers of functions - Commonly self scaling - Commonly loosely coupled - Commonly makes use of REST / gRPC - Commonly makes use isolated persistence
  • 4. 4Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C RESTAPI Database (micro)Service(s) Service B RESTAPI Database (micro)Service(s) Service A RESTAPI Application (backend) API gateway UI Applications & Application Backend Services Microservice Architecture Distribute transactions (option 1) Microservice Architecture Distributed transactions over multiple services - UI calls all services involved in a business transaction - High changes of inconsistency - Complex UI logic and hard to maintain
  • 5. 5Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C RESTAPI Database (micro)Service(s) Service B RESTAPI Database (micro)Service(s) Service A RESTAPI Application (backend) API gateway UI Applications & Application Backend Services Microservice Architecture Distribute transactions (option 2) Microservice Architecture Distributed transactions over multiple services - UI calls initial service for business transaction - Service propagate transaction to other services - High level of point 2 point connections - Complex to add new services
  • 6. 6Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C Subscribe r Publisher RESTAPI Database (micro)Service(s) Service B Subscribe r Publisher RESTAPI Database (micro)Service(s) Service A Subscribe r Publisher RESTAPI KafkaPub/Sub Application (backend) UI Applications App. Backend Services API gateway Microservice Architecture Distribute transactions (option 3) Microservice Architecture Distributed transactions over multiple services - UI calls initial service for business transaction - Service publish event to a Kafka topic - A topic can be read by every subscriber - Care about your consumers by not caring
  • 7. 7Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C Subscribe r Publisher RESTAPI Database (micro)Service(s) Service B Subscribe r Publisher RESTAPI Database (micro)Service(s) Service A Subscribe r Publisher RESTAPI KafkaPub/Sub Application (backend) UI Applications App. Backend Services API gateway Microservice Architecture Distribute transactions (option 3) Microservice Architecture All services are publishers - “event” : a significant change of state - Do not share the data, share the event - CRUD events: - CREATE & UPDATE : standard - DELETE : do you really want that? - READ : on some very specific cases { "event": { "event_topic": "customerdata", "event_type": "create", "event_application": "CRMAPAC", "event_service": "customers", "event_data_object": "deliveryLocations", "event_data_location": "https://api.crmapac.acme.com/customers/1264/deliveryLocations/26/", "classification": { "classified_gdpr": true, "classified_internalviews": true, "classified_publicviews": false, "classified_privateviews": true } } }
  • 8. 8Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C Subscribe r Publisher RESTAPI Database (micro)Service(s) Service B Subscribe r Publisher RESTAPI Database (micro)Service(s) Service A Subscribe r Publisher RESTAPI KafkaPub/Sub Application (backend) UI Applications App. Backend Services API gateway from kafka import KafkaProducer from kafka.errors import KafkaError producer = KafkaProducer(bootstrap_servers=['broker1:1234']) # Asynchronous by default future = producer.send('my-topic', b'raw_bytes') # Block for 'synchronous' sends try: record_metadata = future.get(timeout=10) except KafkaError: # Decide what to do if produce request failed... log.exception() pass # Successful result returns assigned partition and offset print (record_metadata.topic) print (record_metadata.partition) print (record_metadata.offset) # produce keyed messages to enable hashed partitioning producer.send('my-topic', key=b'foo', value=b'bar') # encode objects via msgpack producer = KafkaProducer(value_serializer=msgpack.dumps) producer.send('msgpack-topic', {'key': 'value'}) # produce json messages producer = KafkaProducer(value_serializer=lambda m: json.dumps(m).encode('ascii')) producer.send('json-topic', {'key': 'value'}) # produce asynchronously for _ in range(100): producer.send('my-topic', b'msg') def on_send_success(record_metadata): print(record_metadata.topic) print(record_metadata.partition) print(record_metadata.offset) def on_send_error(excp): log.error('I am an errback', exc_info=excp) # handle exception # produce asynchronously with callbacks producer.send('my-topic', b'raw_bytes').add_callback(on_send_success).add_errback(on_send_error) # block until all async messages are sent producer.flush() # configure multiple retries producer = KafkaProducer(retries=5) Microservice Architecture Distribute transactions (option 3)
  • 9. 9Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C Subscribe r Publisher RESTAPI Database (micro)Service(s) Service B Subscribe r Publisher RESTAPI Database (micro)Service(s) Service A Subscribe r Publisher RESTAPI KafkaPub/Sub Application (backend) UI Applications App. Backend Services API gateway Microservice Architecture Distribute transactions (option 3) Microservice Architecture Services can be a subscriber - Easily add new services by subscribing to topics - Kafka topic consumption: - REST API / Native Kafka client - PULL/PUSH - Subscriber defines the required actions on an event - Subscriber calls publisher server API to obtain data - Data should never be stored outside the context of the owning service - or with care and understanding{ "event": { "event_topic": "customerdata", "event_type": "create", "event_application": "CRMAPAC", "event_service": "customers", "event_data_object": "deliveryLocations", "event_data_location": "https://api.crmapac.acme.com/customers/1264/deliveryLocations/26/", "classification": { "classified_gdpr": true, "classified_internalviews": true, "classified_publicviews": false, "classified_privateviews": true } } }
  • 10. 10Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C Subscribe r Publisher RESTAPI Database (micro)Service(s) Service B Subscribe r Publisher RESTAPI Database (micro)Service(s) Service A Subscribe r Publisher RESTAPI KafkaPub/Sub Application (backend) UI Applications App. Backend Services API gateway from kafka import KafkaConsumer # To consume latest messages and auto-commit offsets consumer = KafkaConsumer('my-topic', group_id='my-group', bootstrap_servers=['localhost:9092']) for message in consumer: # message value and key are raw bytes -- decode if necessary! # e.g., for unicode: `message.value.decode('utf-8')` print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition, message.offset, message.key, message.value)) # consume earliest available messages, don't commit offsets KafkaConsumer(auto_offset_reset='earliest', enable_auto_commit=False) # consume json messages KafkaConsumer(value_deserializer=lambda m: json.loads(m.decode('ascii'))) # consume msgpack KafkaConsumer(value_deserializer=msgpack.unpackb) # StopIteration if no message after 1sec KafkaConsumer(consumer_timeout_ms=1000) # Subscribe to a regex topic pattern consumer = KafkaConsumer() consumer.subscribe(pattern='^awesome.*') # Use multiple consumers in parallel w/ 0.9 kafka brokers # typically you would run each on a different server / process / CPU consumer1 = KafkaConsumer('my-topic', group_id='my-group', bootstrap_servers='my.server.com') consumer2 = KafkaConsumer('my-topic', group_id='my-group', bootstrap_servers='my.server.com') Microservice Architecture Distribute transactions (option 3)
  • 11. 11Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C Subscribe r Publisher RESTAPI Database (micro)Service(s) Service B Subscribe r Publisher RESTAPI Database (micro)Service(s) Service A Subscribe r Publisher RESTAPI KafkaPub/Sub Application (backend) UI Applications App. Backend Services API gateway External API ServiceExt consumers Microservice Architecture Inform the world Microservice Architecture Enable the “world” to subscribe as much as possible - Allow all known services to subscribe to topics - Allow unknown parties to subscribe to topic via the external service API - Ensure both known (internal) and unknown (external) parties can only access the data in a secured manner (OAUTH2)
  • 12. 12Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Database (micro)Service(s) Service C Subscribe r Publisher RESTAPI Database (micro)Service(s) Service B Subscribe r Publisher RESTAPI Database (micro)Service(s) Service A Subscribe r Publisher RESTAPI KafkaPub/Sub Application (backend) UI Applications App. Backend Services External API ServiceExt consumers Outbound WebHook Ext/Int subscribers Microservice Architecture Inform the world Microservice Architecture Enable the “world” to subscribe as much as possible - Do provide the option to subscribe to a webhook - Push updates to HTTP(S) endpoints - Prevent aggressive polling - Allows for notification “spreading” - Prevent request storms API gateway
  • 13. 13Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Kafka Pub/Sub External API ServiceOutbound WebHook External Consumers Application 1 (backend) Application 3 (backend) Application 2 (backend) Microservice Architecture Inform everyone Microservice Architecture Simplify the picture - External and internal consumers - Provide APIs, native clients and webhooks - Strive for an event driven architecture
  • 14. 14Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Kafka Pub/Sub External API ServiceOutbound WebHook External Consumers Application 1 (backend) Application 3 (backend) Application 2 (backend) Remember – It is NOT a database More than pub/sub - KSQL Kafka, more than pub/sub Query kafka - Allow developers to query Kafka - Stream analytics - KSQL, a bit more than SQL - Kafka is NOT a database - Keep retention costs in mind
  • 15. 15Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. Kafka Pub/Sub External API ServiceOutbound WebHook External Consumers Application 1 (backend) Application 3 (backend) Application 2 (backend) CREATE STREAM pageviews (viewtime BIGINT, userid VARCHAR, gender VARCHAR, regionid VARCHAR, pageid VARCHAR) WITH (KAFKA_TOPIC='pageviews', VALUE_FORMAT='DELIMITED'); SELECT regionid, COUNT(*) FROM pageviews WINDOW HOPPING (SIZE 30 SECONDS, ADVANCE BY 10 SECONDS) WHERE UCASE(gender)='FEMALE' AND LCASE (regionid) LIKE '%_6' GROUP BY regionid; Remember – It is NOT a database More than pub/sub - KSQL
  • 16. 16Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. DC - A How to deploy Kafka Make it high available Make it High Available It is harder than you think - Single DC cluster - Issues with DC failure - Stretched DC cluster - Issues with split brain and CAP theorem - Cluster per DC - Issues with topic sync Kafka node A- 3 Kafka node A- 2 Kafka node A- 1 Kafka node A- 0 DC - B Kafka node A- 3 Kafka node A- 2 Kafka node A- 1 Kafka node B- 0 DC - A Kafka node AKafka node 0 DC - B Kafka node AKafka node 2 DC - A Kafka node A- 3 Kafka node A- 2 Kafka node A- 1 Kafka node A- 0 DC - B
  • 17. 17Apache Kafka| Johan Louwers | 2018 © 2018 Capgemini. All rights reserved. DC - A How to get Kafka Build versus buy versus consume Kafka provides a high value It comes with a lot of complexity - Build (& deploy) - Invest in a R&D and development - Invest in (virtual HW) - You build it you run it - You know and own everything - Buy - High support costs - Invest in (virtual HW) - Still requires deep knowledge - Could require a maintenance partner - Consume - Pay-per-use PaaS models - Most solutions are in the cloud - Some solutions are private cloud on converged infra Kafka node A- 3 Kafka node A- 2 Kafka node A- 1 Kafka node A- 0 DC - B Kafka node A- 3 Kafka node A- 2 Kafka node A- 1 Kafka node B- 0 DC - A Kafka node AKafka node 0 DC - B Kafka node AKafka node 2 DC - A Kafka node A- 3 Kafka node A- 2 Kafka node A- 1 Kafka node A- 0 DC - B