SlideShare a Scribd company logo
A Core Banking System:
A Kafka Proposal
By: Diego Irismar da Costa
Brazil, São Paulo Apache Kafka® Meetup
August 22th, 2019
About Me
@diegoicosta
Current Manager of Infrastructure, sometimes also Chief Software Architect.
Worked mostly with java financial related backends since the early 2000s.
Always interested on Event Streaming, Event Oriented Systems, Distributed
Architectures, Cloud Computing, Observability, Data Bases
At Wirecard BR since 2010
• Previously Buscapé (2008-2010)
• Previously UOL (2000-2010)
Agenda
• Scope
• Kafka General Approach
• Kafka Applied to “A Core Bank System”
• Kafka Streams Topology and Strong Requirements
• Combining AKKA, Kafka and Kafka Streams
• Solution Scalability
• References
A Core Banking System ?
Let’s restrict the Scope
Apply Credit
KBank Account
Apply Debit
Balance
Credit/Debit/Read commands
KBank
An Old School Approach
The 60/70’s have gone
Get over it !
The Greater RDBMS
of the Universe
User Layer
Business Layer
Kafka in General: Basic Approach
Message Broker
Producers
Consumers
Kafka Approach: Beyond Basics
Message Broker
Producers
Consumers
Kafka Streams
Kafka Streams Possibilities
Stream Process Topologies
- Read Streams
- One Topic
- Join Topic Streams
- Process
- Map
- Sum, Count, Group, Merge
- Produce
- Branches
- Another Stream
- Change Log Stream (Ktable)
- Materialize Views
- Local State Store
?
Applying Kafka to a Core Bank System: How ?
?Apply Credit
KBank Account
Apply Debit
Balance
Credit/Debit/Read commands
The Core Topology
1. A account command stream is the topology input
2. The account have to accept the command. Does it have balance ?
3. The input stream is splitted: OK / NOK stream.
Both goes to different topics
?
4. A group by Account is applied to the OK stream
5. An aggregation summarizing the command value by account
6. The aggregation is materialized and persisted into a
changelog topic
The “Core” Requirements What is Needed to Build this ?
No Parallelism, No Multithread
ACID Transactions
Apply Credit
KBank Account
Apply Debit
Balance
Credit/Debit/Read commands
No Parallelism, No Multithread Partitions and Msg Keys
Topic
key:A1 | val:10 key:A2 | val:33 key:A3 | val:77
key:A1 | val:21
Conclusions
If AccountID is the key, each message from
that account will be processed by one
unique thread
ACID Transactions exactly-once “magic”
Kafka Streams Perspective
StreamsConfig.PROCESSING_GUARANTEE_CONFIG, "exactly_once";
It offers end-to-end exactly once guarantees for a stream processing
application that extends from the data read from Kafka, any state
materialized to Kafka by the Streams app, to the final output
written back to Kafka.
The Core Topology Implementation
1. A account command stream is the topology input
builder.stream("kbank.account”,
Consumed.with(Serdes.String(), new JsonSerde()))
consume
The Core Topology Implementation
2. The account have to accept the command. Does it have balance ?
3. The input stream is splitted: OK / NOK stream.
Both goes to different topics
?
accountStreams[] = builder.stream(
“kbank.account”,
Consumed.with(Serdes.String(), new JsonSerde()))
.branch(
(account, command) -> hasBalance(account, command.getValue()),
(account, command) -> noBalance(account, command.getValue())
);
Split based on some defined predicates
accountStreams[0] // OK can be applied
accountStreams[1].through(“kbank.account.refused”) // NOK must be refused
The Core Topology Implementation
accountStreams[0].through(“kbank.account.accepted”)
.mapValues((accountCommand) -> {
return accountCommand.value;
}).groupByKey();
4. A group by Account is applied to the OK stream
The Core Topology Implementation
5. An aggregation summarizing the command value by account
6. The aggregation is materialized and persisted into a
changelog topic
.aggregate(
() -> 0L,
(accountId, balance, oldBalance) -> oldBalance + balance,
Materialized.<String, Long, KeyValueStore<Bytes, byte[]>>
as("kbank.account.store")
.withKeySerde(Serdes.String())
.withValueSerde(Serdes.Long())
);
accountStore = streams.store("kbank.account.store".keyValueStore());
Combining AKKA, Kafka and Kafka Streams
http
COMMAND HANDLER “Sync” COMMAND STREAM PROCESSING “Async”
AKKA
Actors
Kafka
Streams
The Kafka Streams role
http
Id:12er3-34b
Id:12er3-34b
JsonResponse
Response
Streams
COMMAND HANDLER “Sync” COMMAND STREAM PROCESSING - Async
Command
Account
Stream
The AKKA role
http
Id:12er3-34b
Id:12er3-34b
JsonResponse
Command
Account
Stream
Response
Streams
COMMAND HANDLER “Sync” STREAM PROCESSING - Async
Command
Handler
actorRef
actorRef
Response
Router
Id:12er3-34b actorRef
Command
Account
Stream
HTTP
Kafka-Streams
Akka-HTTP
Kafka as …
-Stream Platform
-Event-Store
Changelog
KTable
State store
Materialized
view
Non-Blocking
Exactly-Once
ACID guarantees
Response
Streams
OK / NOK Streams
Actor
per
request
Solution Scalability: Kafka
Kafka, by design …
- A cluster is able to handle trillions of events per day
- Absurd throughput rate
- Battle-proven
Solution Scalability: Kafka Streams
Highly coupled with Kafka
- Also, must count on distribution to handle high volumes
- A Kafka Stream app must also be “partitioned”
- The Materialized views could be by partition
Solution Scalability: Kafka Streams
Command
Account
Stream
Server #3
Command
Account
Stream
Server #1
Command
Account
Stream
Server #2
HTTP
HTTP
Final Thoughts
A Bunch of Concepts Together
Where these ideas came from ?
Pat Helland
Ben Stopford
Martin Kleppmann
Jim Gray
Mato
Some References
https://www.confluent.io/blog/
https://www.confluent.io/blog/exactly-once-semantics-are-possible-heres-how-apache-kafka-does-it/
https://www.confluent.io/blog/transactions-apache-kafka/
https://www.confluent.io/blog/transactional-systems-with-apache-kafka
https://www.confluent.io/blog/data-dichotomy-rethinking-the-way-we-treat-data-and-services/ (part 1 to 7)
https://www.confluent.io/designing-event-driven-systems
https://docs.confluent.io/current/streams/developer-guide/index.html
https://doc.akka.io/docs/akka/current/actors.htm
http://adrianmarriott.net/logosroot/papers/LifeBeyondTxns.pdf
https://learning.oreilly.com/library/view/designing-data-intensive-applications/9781491903063/
The Code
github.com/diegoicosta/kbank
The end

More Related Content

What's hot

Mainframe Integration, Offloading and Replacement with Apache Kafka
Mainframe Integration, Offloading and Replacement with Apache KafkaMainframe Integration, Offloading and Replacement with Apache Kafka
Mainframe Integration, Offloading and Replacement with Apache Kafka
Kai Wähner
 
Change Data Streaming Patterns For Microservices With Debezium (Gunnar Morlin...
Change Data Streaming Patterns For Microservices With Debezium (Gunnar Morlin...Change Data Streaming Patterns For Microservices With Debezium (Gunnar Morlin...
Change Data Streaming Patterns For Microservices With Debezium (Gunnar Morlin...
confluent
 

What's hot (20)

Mainframe Integration, Offloading and Replacement with Apache Kafka
Mainframe Integration, Offloading and Replacement with Apache KafkaMainframe Integration, Offloading and Replacement with Apache Kafka
Mainframe Integration, Offloading and Replacement with Apache Kafka
 
Microservices in the Apache Kafka Ecosystem
Microservices in the Apache Kafka EcosystemMicroservices in the Apache Kafka Ecosystem
Microservices in the Apache Kafka Ecosystem
 
Securing Kafka
Securing Kafka Securing Kafka
Securing Kafka
 
CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®CDC patterns in Apache Kafka®
CDC patterns in Apache Kafka®
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
 
Multi tier, multi-tenant, multi-problem kafka
Multi tier, multi-tenant, multi-problem kafkaMulti tier, multi-tenant, multi-problem kafka
Multi tier, multi-tenant, multi-problem kafka
 
Kafka 101 and Developer Best Practices
Kafka 101 and Developer Best PracticesKafka 101 and Developer Best Practices
Kafka 101 and Developer Best Practices
 
Kafka to the Maxka - (Kafka Performance Tuning)
Kafka to the Maxka - (Kafka Performance Tuning)Kafka to the Maxka - (Kafka Performance Tuning)
Kafka to the Maxka - (Kafka Performance Tuning)
 
Containers Docker Kind Kubernetes Istio
Containers Docker Kind Kubernetes IstioContainers Docker Kind Kubernetes Istio
Containers Docker Kind Kubernetes Istio
 
Service-mesh options with Linkerd, Consul, Istio and AWS AppMesh
Service-mesh options with Linkerd, Consul, Istio and AWS AppMeshService-mesh options with Linkerd, Consul, Istio and AWS AppMesh
Service-mesh options with Linkerd, Consul, Istio and AWS AppMesh
 
Big Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb ShardingBig Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb Sharding
 
IBM Cloud Pak for Integration with Confluent Platform powered by Apache Kafka
IBM Cloud Pak for Integration with Confluent Platform powered by Apache KafkaIBM Cloud Pak for Integration with Confluent Platform powered by Apache Kafka
IBM Cloud Pak for Integration with Confluent Platform powered by Apache Kafka
 
Change Data Streaming Patterns for Microservices With Debezium
Change Data Streaming Patterns for Microservices With Debezium Change Data Streaming Patterns for Microservices With Debezium
Change Data Streaming Patterns for Microservices With Debezium
 
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
 
Espresso: LinkedIn's Distributed Data Serving Platform (Paper)
Espresso: LinkedIn's Distributed Data Serving Platform (Paper)Espresso: LinkedIn's Distributed Data Serving Platform (Paper)
Espresso: LinkedIn's Distributed Data Serving Platform (Paper)
 
Introduction to Kafka connect
Introduction to Kafka connectIntroduction to Kafka connect
Introduction to Kafka connect
 
Everything you ever needed to know about Kafka on Kubernetes but were afraid ...
Everything you ever needed to know about Kafka on Kubernetes but were afraid ...Everything you ever needed to know about Kafka on Kubernetes but were afraid ...
Everything you ever needed to know about Kafka on Kubernetes but were afraid ...
 
Walking through the Spring Stack for Apache Kafka with Soby Chacko | Kafka S...
 Walking through the Spring Stack for Apache Kafka with Soby Chacko | Kafka S... Walking through the Spring Stack for Apache Kafka with Soby Chacko | Kafka S...
Walking through the Spring Stack for Apache Kafka with Soby Chacko | Kafka S...
 
Stream processing using Kafka
Stream processing using KafkaStream processing using Kafka
Stream processing using Kafka
 
Change Data Streaming Patterns For Microservices With Debezium (Gunnar Morlin...
Change Data Streaming Patterns For Microservices With Debezium (Gunnar Morlin...Change Data Streaming Patterns For Microservices With Debezium (Gunnar Morlin...
Change Data Streaming Patterns For Microservices With Debezium (Gunnar Morlin...
 

Similar to Core Banking System on Apache Kafka

Resume_Ashok-updated (1) (1)
Resume_Ashok-updated (1) (1)Resume_Ashok-updated (1) (1)
Resume_Ashok-updated (1) (1)
chimmili ashok
 

Similar to Core Banking System on Apache Kafka (20)

Flexible Authentication Strategies with SASL/OAUTHBEARER (Michael Kaminski, T...
Flexible Authentication Strategies with SASL/OAUTHBEARER (Michael Kaminski, T...Flexible Authentication Strategies with SASL/OAUTHBEARER (Michael Kaminski, T...
Flexible Authentication Strategies with SASL/OAUTHBEARER (Michael Kaminski, T...
 
Event Streaming Architectures with Confluent and ScyllaDB
Event Streaming Architectures with Confluent and ScyllaDBEvent Streaming Architectures with Confluent and ScyllaDB
Event Streaming Architectures with Confluent and ScyllaDB
 
Kafka streams decoupling with stores
Kafka streams decoupling with storesKafka streams decoupling with stores
Kafka streams decoupling with stores
 
Knock Knock, Who’s There? With Justin Chen and Dhruv Jauhar | Current 2022
Knock Knock, Who’s There? With Justin Chen and Dhruv Jauhar | Current 2022Knock Knock, Who’s There? With Justin Chen and Dhruv Jauhar | Current 2022
Knock Knock, Who’s There? With Justin Chen and Dhruv Jauhar | Current 2022
 
Use ksqlDB to migrate core-banking processing from batch to streaming | Mark ...
Use ksqlDB to migrate core-banking processing from batch to streaming | Mark ...Use ksqlDB to migrate core-banking processing from batch to streaming | Mark ...
Use ksqlDB to migrate core-banking processing from batch to streaming | Mark ...
 
Harness the Power of Infrastructure as Code
Harness the Power of Infrastructure as CodeHarness the Power of Infrastructure as Code
Harness the Power of Infrastructure as Code
 
Streaming with Spring Cloud Stream and Apache Kafka - Soby Chacko
Streaming with Spring Cloud Stream and Apache Kafka - Soby ChackoStreaming with Spring Cloud Stream and Apache Kafka - Soby Chacko
Streaming with Spring Cloud Stream and Apache Kafka - Soby Chacko
 
BBL KAPPA Lesfurets.com
BBL KAPPA Lesfurets.comBBL KAPPA Lesfurets.com
BBL KAPPA Lesfurets.com
 
APAC ksqlDB Workshop
APAC ksqlDB WorkshopAPAC ksqlDB Workshop
APAC ksqlDB Workshop
 
Event Driven Architectures with Apache Kafka
Event Driven Architectures with Apache KafkaEvent Driven Architectures with Apache Kafka
Event Driven Architectures with Apache Kafka
 
Resume_Ashok-updated (1) (1)
Resume_Ashok-updated (1) (1)Resume_Ashok-updated (1) (1)
Resume_Ashok-updated (1) (1)
 
Real time data pipline with kafka streams
Real time data pipline with kafka streamsReal time data pipline with kafka streams
Real time data pipline with kafka streams
 
The Very Very Latest in Database Development - Oracle Open World 2012
The Very Very Latest in Database Development - Oracle Open World 2012The Very Very Latest in Database Development - Oracle Open World 2012
The Very Very Latest in Database Development - Oracle Open World 2012
 
The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...
The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...
The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...
 
AWS re:Invent 2016: How to Launch a 100K-User Corporate Back Office with Micr...
AWS re:Invent 2016: How to Launch a 100K-User Corporate Back Office with Micr...AWS re:Invent 2016: How to Launch a 100K-User Corporate Back Office with Micr...
AWS re:Invent 2016: How to Launch a 100K-User Corporate Back Office with Micr...
 
Chicago Kafka Meetup
Chicago Kafka MeetupChicago Kafka Meetup
Chicago Kafka Meetup
 
Elastically Scaling Kafka Using Confluent
Elastically Scaling Kafka Using ConfluentElastically Scaling Kafka Using Confluent
Elastically Scaling Kafka Using Confluent
 
Data-Streaming at DKV
Data-Streaming at DKVData-Streaming at DKV
Data-Streaming at DKV
 
Apache Kafka and Blockchain - Comparison and a Kafka-native Implementation
Apache Kafka and Blockchain - Comparison and a Kafka-native ImplementationApache Kafka and Blockchain - Comparison and a Kafka-native Implementation
Apache Kafka and Blockchain - Comparison and a Kafka-native Implementation
 
Real time dashboards with Kafka and Druid
Real time dashboards with Kafka and DruidReal time dashboards with Kafka and Druid
Real time dashboards with Kafka and Druid
 

Recently uploaded

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 

Core Banking System on Apache Kafka

  • 1. A Core Banking System: A Kafka Proposal By: Diego Irismar da Costa Brazil, São Paulo Apache Kafka® Meetup August 22th, 2019
  • 2. About Me @diegoicosta Current Manager of Infrastructure, sometimes also Chief Software Architect. Worked mostly with java financial related backends since the early 2000s. Always interested on Event Streaming, Event Oriented Systems, Distributed Architectures, Cloud Computing, Observability, Data Bases At Wirecard BR since 2010 • Previously Buscapé (2008-2010) • Previously UOL (2000-2010)
  • 3. Agenda • Scope • Kafka General Approach • Kafka Applied to “A Core Bank System” • Kafka Streams Topology and Strong Requirements • Combining AKKA, Kafka and Kafka Streams • Solution Scalability • References
  • 4. A Core Banking System ? Let’s restrict the Scope Apply Credit KBank Account Apply Debit Balance Credit/Debit/Read commands KBank
  • 5. An Old School Approach The 60/70’s have gone Get over it ! The Greater RDBMS of the Universe User Layer Business Layer
  • 6. Kafka in General: Basic Approach Message Broker Producers Consumers
  • 7. Kafka Approach: Beyond Basics Message Broker Producers Consumers Kafka Streams
  • 8. Kafka Streams Possibilities Stream Process Topologies - Read Streams - One Topic - Join Topic Streams - Process - Map - Sum, Count, Group, Merge - Produce - Branches - Another Stream - Change Log Stream (Ktable) - Materialize Views - Local State Store ?
  • 9. Applying Kafka to a Core Bank System: How ? ?Apply Credit KBank Account Apply Debit Balance Credit/Debit/Read commands
  • 10. The Core Topology 1. A account command stream is the topology input 2. The account have to accept the command. Does it have balance ? 3. The input stream is splitted: OK / NOK stream. Both goes to different topics ? 4. A group by Account is applied to the OK stream 5. An aggregation summarizing the command value by account 6. The aggregation is materialized and persisted into a changelog topic
  • 11. The “Core” Requirements What is Needed to Build this ? No Parallelism, No Multithread ACID Transactions Apply Credit KBank Account Apply Debit Balance Credit/Debit/Read commands
  • 12. No Parallelism, No Multithread Partitions and Msg Keys Topic key:A1 | val:10 key:A2 | val:33 key:A3 | val:77 key:A1 | val:21 Conclusions If AccountID is the key, each message from that account will be processed by one unique thread
  • 13. ACID Transactions exactly-once “magic” Kafka Streams Perspective StreamsConfig.PROCESSING_GUARANTEE_CONFIG, "exactly_once"; It offers end-to-end exactly once guarantees for a stream processing application that extends from the data read from Kafka, any state materialized to Kafka by the Streams app, to the final output written back to Kafka.
  • 14. The Core Topology Implementation 1. A account command stream is the topology input builder.stream("kbank.account”, Consumed.with(Serdes.String(), new JsonSerde())) consume
  • 15. The Core Topology Implementation 2. The account have to accept the command. Does it have balance ? 3. The input stream is splitted: OK / NOK stream. Both goes to different topics ? accountStreams[] = builder.stream( “kbank.account”, Consumed.with(Serdes.String(), new JsonSerde())) .branch( (account, command) -> hasBalance(account, command.getValue()), (account, command) -> noBalance(account, command.getValue()) ); Split based on some defined predicates accountStreams[0] // OK can be applied accountStreams[1].through(“kbank.account.refused”) // NOK must be refused
  • 16. The Core Topology Implementation accountStreams[0].through(“kbank.account.accepted”) .mapValues((accountCommand) -> { return accountCommand.value; }).groupByKey(); 4. A group by Account is applied to the OK stream
  • 17. The Core Topology Implementation 5. An aggregation summarizing the command value by account 6. The aggregation is materialized and persisted into a changelog topic .aggregate( () -> 0L, (accountId, balance, oldBalance) -> oldBalance + balance, Materialized.<String, Long, KeyValueStore<Bytes, byte[]>> as("kbank.account.store") .withKeySerde(Serdes.String()) .withValueSerde(Serdes.Long()) ); accountStore = streams.store("kbank.account.store".keyValueStore());
  • 18. Combining AKKA, Kafka and Kafka Streams http COMMAND HANDLER “Sync” COMMAND STREAM PROCESSING “Async” AKKA Actors Kafka Streams
  • 19. The Kafka Streams role http Id:12er3-34b Id:12er3-34b JsonResponse Response Streams COMMAND HANDLER “Sync” COMMAND STREAM PROCESSING - Async Command Account Stream
  • 20. The AKKA role http Id:12er3-34b Id:12er3-34b JsonResponse Command Account Stream Response Streams COMMAND HANDLER “Sync” STREAM PROCESSING - Async Command Handler actorRef actorRef Response Router Id:12er3-34b actorRef
  • 21. Command Account Stream HTTP Kafka-Streams Akka-HTTP Kafka as … -Stream Platform -Event-Store Changelog KTable State store Materialized view Non-Blocking Exactly-Once ACID guarantees Response Streams OK / NOK Streams Actor per request
  • 22. Solution Scalability: Kafka Kafka, by design … - A cluster is able to handle trillions of events per day - Absurd throughput rate - Battle-proven
  • 23. Solution Scalability: Kafka Streams Highly coupled with Kafka - Also, must count on distribution to handle high volumes - A Kafka Stream app must also be “partitioned” - The Materialized views could be by partition
  • 24. Solution Scalability: Kafka Streams Command Account Stream Server #3 Command Account Stream Server #1 Command Account Stream Server #2 HTTP HTTP
  • 25. Final Thoughts A Bunch of Concepts Together
  • 26. Where these ideas came from ? Pat Helland Ben Stopford Martin Kleppmann Jim Gray Mato
  • 27. Some References https://www.confluent.io/blog/ https://www.confluent.io/blog/exactly-once-semantics-are-possible-heres-how-apache-kafka-does-it/ https://www.confluent.io/blog/transactions-apache-kafka/ https://www.confluent.io/blog/transactional-systems-with-apache-kafka https://www.confluent.io/blog/data-dichotomy-rethinking-the-way-we-treat-data-and-services/ (part 1 to 7) https://www.confluent.io/designing-event-driven-systems https://docs.confluent.io/current/streams/developer-guide/index.html https://doc.akka.io/docs/akka/current/actors.htm http://adrianmarriott.net/logosroot/papers/LifeBeyondTxns.pdf https://learning.oreilly.com/library/view/designing-data-intensive-applications/9781491903063/