SlideShare uma empresa Scribd logo
1 de 42
Baixar para ler offline
Event Driven Architecture
Introduction to Event driven systems and Apache Kafka
Agenda
● Introduction to Event Driven Systems
● Introduction to different problems that arise when using Event Driven Systems
● Different patterns
● Apache Kafka
● Org-wide implementations
Lets Build Scamazon
Disclaimer: The session will have stupid poor jokes scattered all over. Forgive the incompetent joker in me.
Developer report
My code provisions the order
quickly. While investigating, I
observed that sending the order
successful mail takes a lot of
time.
Customer report
Placing an order on
Scamazon is such a pain.
It takes too long.
Latency: Amount of time it takes to complete one request
Throughput: Amount of requests that can be completed in a unit of time
Asynchronous Messaging
1. Postponing an action
2. Perform time consuming
operations
3. Faster API responses/page load
times
Command
Scamazon Customer report
I placed an order on the last
samsong smart watch before
my friend yesterday. But he got
the watch and I didnt.
Annoying Business manager
What? How can that happen?
Devs, fix it.
Transaction Ordering
1. Have a Distributed Locking
mechanism
2. Ensure Message queues
inherently supports ordering
Customer report
On your Great Scamazon
sale, I purchased a shoe. I
never got it.
Apparently Microservices
are in trend now!
Business Manager
Each customer we lose, is
one gained for FlopKart! Jeff
Bozo is going to kill us. Devs,
Do Something !!
Developer
Delivery Service was down
because some SysAd
upgraded something.
Blame them! My code is gold.
Resiliency
1. Guarantee that the action is
processed
2. Handle traffic spikes
Scale Independently
Message queues
1. Message queueing allows applications to communicate
asynchronously by sending messages to each other.
2. Messages may or may not be sent in FIFO
Message queues v/s APIs
APIs are 2-way communication.
Message Queues are 1-way communication.
Some theory
● Messages: Messages can be commands or events. Each message can have a type
and payload data to be sent across.
● Channels/Queues: Channels/Queues are delivery points the messages are sent to.
● Event Dispatcher/Producers: The duty of the dispatcher is to register channels and
produce events/messages.
● Event Handlers/Consumers: Event handlers act as destination points for receiving
events as channels do.
● Dynamic Routers: The harmony of messaging systems occurs through its routers.
Routers are responsible for selecting the proper path for a given message.
Review Message Queue Advantages
1. Decoupled Architecture: The sender’s job is to send messages to the queue
and the receiver’s job is to receive messages from the queue. This separation
allows for components to operate independently, while still communicating
with each other.
1. Fault tolerant: If the consumer server is down, the messages would still be
stored in queue until the server goes back up and retrieves it
2. Scalability: We can push all the messages in the queue and configure the rate
at which the consumer server pulls from it. This way, the receiver won’t get
overloaded with network requests and can instead maintain a steady stream
of data to process.
3. Transaction Ordering: Have patterns to Ensure messages are delivered in
order of they getting published if the use-case needs it
Publish/Subscribe
Event Notification
Advantages
1. Decoupled
2. Simple to use
3. Reduced team dependency
Disadvantages
1. Behavior of the system is
harder to determine.
Event-carried state transfer
Event Sourcing
Events may or may not be stored in
an EventStore(ex: broker).
4
Designed for Fast & low latency
applications(ex: stock trading)
1
Capture all changes to an application
state as a sequence of events.
2
Events define the state of the
system.
3
Like git, it doesn't store the latest
version of code, but maintains the
changes from the base version.
5
If server goes down, we can replay
the events and get the state back.
6
Event sourcing Advantages/ Disadvantages
Advantages
1. Entire applications can be in
memory
2. Parallel model
Disadvantages
1. Event schemas
2. Non event sourcing service
interaction
Apache Kafka
● Developed by LinkedIn.
● Building real-time streaming data pipelines that reliably
get data between systems or applications
● Building real-time streaming applications that transform
or react to the streams of data
1. Channels a.k.a Topics
2. Brokers a.k.a Routers
Distributed Streaming Platform
Records in Kafka
Each Record(Message) in kafka has:
1. Key
2. Value
3. Timestamp
Key
Value
Timestamp
null
{“orderid”:1,
“cid”: 5}
1322468906767
8461
Abhishek
1592468905404
resellerhosting
{“cid”: 5,
“addons”: []}
1492468905404
Examples:
Topic
1. Partition: Ordered, immutable
sequence of records that is
continually appended to
2. Offset: Uniquely identifies each
record within the partition
How is kafka resilient ?
1. Cluster of kafka servers
2. Partitions are replicated in all
3. Each Server function as leader for a fair share
of partitions
4. Followers passively replicate leader.
5. Each kafka server will have leaders and
followers.
P1
Broker 1
P1 P2 P3
P2 P3
Broker 2
Can you Explain?
Scenario 1:
Brokers: 3
Partitions: 3
Replication Factor: 2
Scenario 2:
Brokers: 3
Partitions: 2
Replication Factor: 3
Broker 1
P
1
P
3
Broker 2
P
2
P
1
Broker 3
P
3
P
2
Broker 1
P
1
P
2
Broker 2
P
2
P
1
P
1
Broker 3
P
2
APIs provided by Kafka
1. Producer: publish messages to one or more topics
2. Consumer: subscribe to a topic and process these messages
3. Connect API: Bind existing systems like databases to kafka topics
4. Streams API: Consume a stream of data and produce one or more output streams.
5. Admin API: manage topics, broker and other kafka objects
How Kafka handles
multiple partitions and consumers ?
Kafka Producers
● Producers publish records to the kafka topics with help of kafka provided kafka APIs
● Any number of producer can public records to the same topic
● Producers can decide the partition of the topic into which record to publish
○ For normal use case and better load balancing they follow round-robin allocation
● Batch processing on producer side. Why and at What cost?
● How records are routed from producer to the leader of target partition?
Why Zookeeper?
● Zookeeper can provide primitives to support:
○ Distributed Configuration Service
○ Synchronization
○ Cluster Management
○ Service Discovery
● Highly optimized for reads than writes.
● How kafka utilizes Zookeeper?
○ Controller Election
○ Configuration of Topics
○ Membership of the cluster
Coordination Service for Distributed Applications
Difference Between
Queue and Pub-Sub
Model?
Why is Kafka not a simple queue ?
1. durably persists all published
records—whether or not they have
been consumed—using a
configurable retention period
2. This offset is controlled by the
consumer
3. Consumer can consume however it
wants.
4. Consumer can reset to an older
offset to reprocess data or skip
ahead.
5. Kafka provides feature of both
Queuing and Pub-Sub model with its
partitioned topic based design.
Ordering of Records in Kafka
● Total ordering over records within partition
● How to achieve total ordering over all data?
● Why kafka decided to provide ordering over
only partition?
Kafka Provides better ordering than Queues!!?
Sample use cases of Kafka
1. Messaging
2. Website Activity Tracking
3. Metrics
4. Log aggregation
5. Stream processing
6. Event sourcing
Example of Enterprise Messaging in Endurance
BLL implemented event driven architecture using Kafka.
1
RP uses ActiveMQ’s Queues and Topics for messaging,
notifications etc.
2
CA uses it for CQRS via ActiveMQ.
4
OrderBox uses Kafka for Streaming changes from databases.
3
Example of
Event Driven Architecture
In Email Hosting BLL
CQRS of CA
Cassandra does replication
across nodes asynchronously
and hence is said to be
eventually consistent.
Real Time Data Streaming in OrderBox
Why Kafka for Data Streaming(why not ActiveMQ) ?
● Plethora of connectors to connect to multiple data sources.
● Inherent architecture promotes its use as a Log store.
● Kafka Streams provides an amazing set of API’s to provide aggregation features.
● This format of streaming is abbreviated as Change Data Capture
○ More details can be found here
RP use cases
1. Message from Core Web layer to
Executor Layer(Queue)
2. Cache Eviction across containers of
same service(Topic)
3. Cache eviction across different
services(Topic)
4. Can use Event Carried State
Transfer for cache updation(Topic)
Questions?
Homework!! 😬
Domain Driven Design
1
CQRS
2
Event Sourcing
3
Distributed Transactions
4
Change Data Capture
5
Log Compacted Topics
6
Thank You

Mais conteúdo relacionado

Mais procurados

How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
Laura Lorenz
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Thomas Lockney
 

Mais procurados (20)

Building distributed processing system from scratch - Part 2
Building distributed processing system from scratch - Part 2Building distributed processing system from scratch - Part 2
Building distributed processing system from scratch - Part 2
 
Log ingestion kafka -- impala using apex
Log ingestion   kafka -- impala using apexLog ingestion   kafka -- impala using apex
Log ingestion kafka -- impala using apex
 
Apache Airflow in Production
Apache Airflow in ProductionApache Airflow in Production
Apache Airflow in Production
 
Introduction to Structured Streaming
Introduction to Structured StreamingIntroduction to Structured Streaming
Introduction to Structured Streaming
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 
Core Services behind Spark Job Execution
Core Services behind Spark Job ExecutionCore Services behind Spark Job Execution
Core Services behind Spark Job Execution
 
Flink Forward Berlin 2017: Boris Lublinsky, Stavros Kontopoulos - Introducing...
Flink Forward Berlin 2017: Boris Lublinsky, Stavros Kontopoulos - Introducing...Flink Forward Berlin 2017: Boris Lublinsky, Stavros Kontopoulos - Introducing...
Flink Forward Berlin 2017: Boris Lublinsky, Stavros Kontopoulos - Introducing...
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
 
Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsIntroduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actors
 
Structured Streaming with Kafka
Structured Streaming with KafkaStructured Streaming with Kafka
Structured Streaming with Kafka
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
 
Structured streaming in Spark
Structured streaming in SparkStructured streaming in Spark
Structured streaming in Spark
 
Data Engineer’s Lunch #41: PygramETL
Data Engineer’s Lunch #41: PygramETLData Engineer’s Lunch #41: PygramETL
Data Engineer’s Lunch #41: PygramETL
 
Introduction to reactive programming
Introduction to reactive programmingIntroduction to reactive programming
Introduction to reactive programming
 
Introduction to Apache Airflow - Data Day Seattle 2016
Introduction to Apache Airflow - Data Day Seattle 2016Introduction to Apache Airflow - Data Day Seattle 2016
Introduction to Apache Airflow - Data Day Seattle 2016
 
State management in Structured Streaming
State management in Structured StreamingState management in Structured Streaming
State management in Structured Streaming
 
Introduction to Flink Streaming
Introduction to Flink StreamingIntroduction to Flink Streaming
Introduction to Flink Streaming
 
Pluggable Pipelines
Pluggable PipelinesPluggable Pipelines
Pluggable Pipelines
 
Exploratory Data Analysis in Spark
Exploratory Data Analysis in SparkExploratory Data Analysis in Spark
Exploratory Data Analysis in Spark
 
Computing recommendations at extreme scale with Apache Flink @Buzzwords 2015
Computing recommendations at extreme scale with Apache Flink @Buzzwords 2015Computing recommendations at extreme scale with Apache Flink @Buzzwords 2015
Computing recommendations at extreme scale with Apache Flink @Buzzwords 2015
 

Semelhante a Event driven-arch

Copy of Kafka-Camus
Copy of Kafka-CamusCopy of Kafka-Camus
Copy of Kafka-Camus
Deep Shah
 
Cluster_Performance_Apache_Kafak_vs_RabbitMQ
Cluster_Performance_Apache_Kafak_vs_RabbitMQCluster_Performance_Apache_Kafak_vs_RabbitMQ
Cluster_Performance_Apache_Kafak_vs_RabbitMQ
Shameera Rathnayaka
 
Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...
Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...
Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...
confluent
 

Semelhante a Event driven-arch (20)

Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Copy of Kafka-Camus
Copy of Kafka-CamusCopy of Kafka-Camus
Copy of Kafka-Camus
 
Fundamentals and Architecture of Apache Kafka
Fundamentals and Architecture of Apache KafkaFundamentals and Architecture of Apache Kafka
Fundamentals and Architecture of Apache Kafka
 
Apache Kafka Introduction
Apache Kafka IntroductionApache Kafka Introduction
Apache Kafka Introduction
 
Cluster_Performance_Apache_Kafak_vs_RabbitMQ
Cluster_Performance_Apache_Kafak_vs_RabbitMQCluster_Performance_Apache_Kafak_vs_RabbitMQ
Cluster_Performance_Apache_Kafak_vs_RabbitMQ
 
Unleashing Real-time Power with Kafka.pptx
Unleashing Real-time Power with Kafka.pptxUnleashing Real-time Power with Kafka.pptx
Unleashing Real-time Power with Kafka.pptx
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQ
 
Introduction to Kafka Streams Presentation
Introduction to Kafka Streams PresentationIntroduction to Kafka Streams Presentation
Introduction to Kafka Streams Presentation
 
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-Driven
 
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-Driven
 
Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With Kafka
 
Netflix Data Pipeline With Kafka
Netflix Data Pipeline With KafkaNetflix Data Pipeline With Kafka
Netflix Data Pipeline With Kafka
 
Kafka aws
Kafka awsKafka aws
Kafka aws
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...
Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...
Ten reasons to choose Apache Pulsar over Apache Kafka for Event Sourcing_Robe...
 
Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...
Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...
Kafka Cluster Federation at Uber (Yupeng Fui & Xiaoman Dong, Uber) Kafka Summ...
 
Strimzi - Where Apache Kafka meets OpenShift - OpenShift Spain MeetUp
Strimzi - Where Apache Kafka meets OpenShift - OpenShift Spain MeetUpStrimzi - Where Apache Kafka meets OpenShift - OpenShift Spain MeetUp
Strimzi - Where Apache Kafka meets OpenShift - OpenShift Spain MeetUp
 
Kafka internals
Kafka internalsKafka internals
Kafka internals
 
Kafka Deep Dive
Kafka Deep DiveKafka Deep Dive
Kafka Deep Dive
 

Último

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 

Último (20)

HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 

Event driven-arch

  • 1. Event Driven Architecture Introduction to Event driven systems and Apache Kafka
  • 2. Agenda ● Introduction to Event Driven Systems ● Introduction to different problems that arise when using Event Driven Systems ● Different patterns ● Apache Kafka ● Org-wide implementations
  • 3. Lets Build Scamazon Disclaimer: The session will have stupid poor jokes scattered all over. Forgive the incompetent joker in me.
  • 4. Developer report My code provisions the order quickly. While investigating, I observed that sending the order successful mail takes a lot of time. Customer report Placing an order on Scamazon is such a pain. It takes too long. Latency: Amount of time it takes to complete one request Throughput: Amount of requests that can be completed in a unit of time
  • 5. Asynchronous Messaging 1. Postponing an action 2. Perform time consuming operations 3. Faster API responses/page load times Command
  • 6. Scamazon Customer report I placed an order on the last samsong smart watch before my friend yesterday. But he got the watch and I didnt. Annoying Business manager What? How can that happen? Devs, fix it.
  • 7. Transaction Ordering 1. Have a Distributed Locking mechanism 2. Ensure Message queues inherently supports ordering
  • 8. Customer report On your Great Scamazon sale, I purchased a shoe. I never got it. Apparently Microservices are in trend now! Business Manager Each customer we lose, is one gained for FlopKart! Jeff Bozo is going to kill us. Devs, Do Something !! Developer Delivery Service was down because some SysAd upgraded something. Blame them! My code is gold.
  • 9. Resiliency 1. Guarantee that the action is processed 2. Handle traffic spikes
  • 11. Message queues 1. Message queueing allows applications to communicate asynchronously by sending messages to each other. 2. Messages may or may not be sent in FIFO
  • 12. Message queues v/s APIs APIs are 2-way communication. Message Queues are 1-way communication.
  • 13. Some theory ● Messages: Messages can be commands or events. Each message can have a type and payload data to be sent across. ● Channels/Queues: Channels/Queues are delivery points the messages are sent to. ● Event Dispatcher/Producers: The duty of the dispatcher is to register channels and produce events/messages. ● Event Handlers/Consumers: Event handlers act as destination points for receiving events as channels do. ● Dynamic Routers: The harmony of messaging systems occurs through its routers. Routers are responsible for selecting the proper path for a given message.
  • 14. Review Message Queue Advantages 1. Decoupled Architecture: The sender’s job is to send messages to the queue and the receiver’s job is to receive messages from the queue. This separation allows for components to operate independently, while still communicating with each other. 1. Fault tolerant: If the consumer server is down, the messages would still be stored in queue until the server goes back up and retrieves it 2. Scalability: We can push all the messages in the queue and configure the rate at which the consumer server pulls from it. This way, the receiver won’t get overloaded with network requests and can instead maintain a steady stream of data to process. 3. Transaction Ordering: Have patterns to Ensure messages are delivered in order of they getting published if the use-case needs it
  • 16. Event Notification Advantages 1. Decoupled 2. Simple to use 3. Reduced team dependency Disadvantages 1. Behavior of the system is harder to determine.
  • 18. Event Sourcing Events may or may not be stored in an EventStore(ex: broker). 4 Designed for Fast & low latency applications(ex: stock trading) 1 Capture all changes to an application state as a sequence of events. 2 Events define the state of the system. 3 Like git, it doesn't store the latest version of code, but maintains the changes from the base version. 5 If server goes down, we can replay the events and get the state back. 6
  • 19. Event sourcing Advantages/ Disadvantages Advantages 1. Entire applications can be in memory 2. Parallel model Disadvantages 1. Event schemas 2. Non event sourcing service interaction
  • 20.
  • 21. Apache Kafka ● Developed by LinkedIn. ● Building real-time streaming data pipelines that reliably get data between systems or applications ● Building real-time streaming applications that transform or react to the streams of data 1. Channels a.k.a Topics 2. Brokers a.k.a Routers Distributed Streaming Platform
  • 22. Records in Kafka Each Record(Message) in kafka has: 1. Key 2. Value 3. Timestamp Key Value Timestamp null {“orderid”:1, “cid”: 5} 1322468906767 8461 Abhishek 1592468905404 resellerhosting {“cid”: 5, “addons”: []} 1492468905404 Examples:
  • 23. Topic 1. Partition: Ordered, immutable sequence of records that is continually appended to 2. Offset: Uniquely identifies each record within the partition
  • 24. How is kafka resilient ? 1. Cluster of kafka servers 2. Partitions are replicated in all 3. Each Server function as leader for a fair share of partitions 4. Followers passively replicate leader. 5. Each kafka server will have leaders and followers. P1 Broker 1 P1 P2 P3 P2 P3 Broker 2
  • 25. Can you Explain? Scenario 1: Brokers: 3 Partitions: 3 Replication Factor: 2 Scenario 2: Brokers: 3 Partitions: 2 Replication Factor: 3 Broker 1 P 1 P 3 Broker 2 P 2 P 1 Broker 3 P 3 P 2 Broker 1 P 1 P 2 Broker 2 P 2 P 1 P 1 Broker 3 P 2
  • 26. APIs provided by Kafka 1. Producer: publish messages to one or more topics 2. Consumer: subscribe to a topic and process these messages 3. Connect API: Bind existing systems like databases to kafka topics 4. Streams API: Consume a stream of data and produce one or more output streams. 5. Admin API: manage topics, broker and other kafka objects
  • 27. How Kafka handles multiple partitions and consumers ?
  • 28. Kafka Producers ● Producers publish records to the kafka topics with help of kafka provided kafka APIs ● Any number of producer can public records to the same topic ● Producers can decide the partition of the topic into which record to publish ○ For normal use case and better load balancing they follow round-robin allocation ● Batch processing on producer side. Why and at What cost? ● How records are routed from producer to the leader of target partition?
  • 29. Why Zookeeper? ● Zookeeper can provide primitives to support: ○ Distributed Configuration Service ○ Synchronization ○ Cluster Management ○ Service Discovery ● Highly optimized for reads than writes. ● How kafka utilizes Zookeeper? ○ Controller Election ○ Configuration of Topics ○ Membership of the cluster Coordination Service for Distributed Applications
  • 31. Why is Kafka not a simple queue ? 1. durably persists all published records—whether or not they have been consumed—using a configurable retention period 2. This offset is controlled by the consumer 3. Consumer can consume however it wants. 4. Consumer can reset to an older offset to reprocess data or skip ahead. 5. Kafka provides feature of both Queuing and Pub-Sub model with its partitioned topic based design.
  • 32. Ordering of Records in Kafka ● Total ordering over records within partition ● How to achieve total ordering over all data? ● Why kafka decided to provide ordering over only partition? Kafka Provides better ordering than Queues!!?
  • 33. Sample use cases of Kafka 1. Messaging 2. Website Activity Tracking 3. Metrics 4. Log aggregation 5. Stream processing 6. Event sourcing
  • 34. Example of Enterprise Messaging in Endurance BLL implemented event driven architecture using Kafka. 1 RP uses ActiveMQ’s Queues and Topics for messaging, notifications etc. 2 CA uses it for CQRS via ActiveMQ. 4 OrderBox uses Kafka for Streaming changes from databases. 3
  • 35. Example of Event Driven Architecture In Email Hosting BLL
  • 36. CQRS of CA Cassandra does replication across nodes asynchronously and hence is said to be eventually consistent.
  • 37. Real Time Data Streaming in OrderBox
  • 38. Why Kafka for Data Streaming(why not ActiveMQ) ? ● Plethora of connectors to connect to multiple data sources. ● Inherent architecture promotes its use as a Log store. ● Kafka Streams provides an amazing set of API’s to provide aggregation features. ● This format of streaming is abbreviated as Change Data Capture ○ More details can be found here
  • 39. RP use cases 1. Message from Core Web layer to Executor Layer(Queue) 2. Cache Eviction across containers of same service(Topic) 3. Cache eviction across different services(Topic) 4. Can use Event Carried State Transfer for cache updation(Topic)
  • 41. Homework!! 😬 Domain Driven Design 1 CQRS 2 Event Sourcing 3 Distributed Transactions 4 Change Data Capture 5 Log Compacted Topics 6