SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Building an Event Bus at Scale
Senior Software Developer
@jimriecken
Jim Riecken
• Senior developer on the Platform Team at Hootsuite
• Building backend services + infrastructure
• I <3 Scala
About me
A bit of history
• PHP monolith, horizontally
scaled
• Single Database
• Any part of the system can
easily interact with any other
part of the system
• Local method calls
• Shared cache
• Shared database
The early days
Load balancers
Memcache + DB
• Smaller PHP monolith
• Lots of Scala microservices
• Multiple databases
• Distributed Systems
• Not local anymore
• Latency
• Failures, partial failures
Now
Dealing with Complexity
• As the number of services
increases, the coupling of them
tends to as well
• More network calls end up in
the critical path of the request
• Slows user experience
• More prone to failure
• Do all of them need to be?
Coupling
sendMessage()
1
2 3
4 5
Event Bus
• Decouple asynchronous
consumption of data/events
from the producer of that data.
• New consumers easily added
• No longer in the critical path of
the request, and fewer
potential points for failure
• Faster requests + happier
users!
Event Bus
sendMessage()
Event Bus
1
2 3
4
• High throughput
• High availability
• Durability
• Handle fast producers + slow consumers
• Multi-region/data center support
• Must have Scala and PHP clients
Requirements
Which technology to choose?
• RabbitMQ (or some other flavour of AMQP)
• ØMQ
• Apache Kafka
Candidates
• ØMQ
• Too low level, would have to build a lot on top of it
• RabbitMQ
• Based on previous experience
• Doesn’t recover well from crashes
• Doesn’t perform well when messages are persisted to disk
• Slow consumers can affect performance of the system
Why not ØMQ or RabbitMQ?
• Simple - conceptually it’s just a log
• High performance - in use at large organizations (e.g. LinkedIn, Etsy,
Netflix)
• Can scale up to millions of messages per second / terabytes of data per day
• Highly available - designed to be fault tolerant
• High durability - messages are replicated across cluster
• Handles slow consumers
• Pull model, not push
• Configurable message retention
• Can work with multiple regions/data centers
• Written in Scala!
Why Kafka?
What is
• Distributed, partitioned,
replicated commit log service
• Producers publish messages
to Topics
• Consumers pull + process the
feed of published messages
• Runs as a cluster of Brokers
• Requires ZooKeeper for
coordination/leader election
Kafka
P P P
C C C
ZK
Brokers
w/ Topics
| | | | | | | | | | |
| | | | | | | | | | |
| | | | | | | | | | |
• Split into Partitions (which are stored in log files)
• Each partition is an ordered, immutable sequence of messages
that is only appended to
• Partitions are distributed and replicated across the cluster of
Brokers
• Data is kept for a configurable retention period after which it is
either discarded or compacted
• Consumers keep track of their offset in the logs
Topics
• Push messages to partitions of topics
• Can send to
• A random/round-robined partition
• A specific partition
• A partition based on a hash constructed from a key
• Maintain per-key order
• Messages and Keys are just Array[Byte]
• Responsible for your own serialization
Producers
• Pull messages from partitions of topics
• Can either
• Manually manage offsets (“simple consumer”)
• Have offsets/partition assignment automatically managed (“high level
consumer”)
• Consumer Groups
• Offsets stored in ZooKeeper (or Kafka itself)
• Partitions are distributed among consumers
• # Consumers > # Partitions => Some consume nothing
• # Partitions > # Consumers => Some consume several partitions
Consumers
How we set up Kafka
• Each cluster consists of a set of
Kafka brokers and a ZooKeeper
quorum
• At least 3 brokers
• At least 3 ZK nodes (preferably
more)
• Brokers have large disks
• Standard topic retention -
overridden per topic as necessary
• Topics are managed via Jenkins jobs
Clusters
ZK ZK
ZK
B B
B
• MirrorMaker
• Tool for consuming topics
from one cluster + producing
to another
• Aggregate + Local clusters
• Producers produce to local
cluster
• Consumers consume from
local + aggregate
• MirrorMaker consumes from
local + produces to aggregate
Multi-Region
ZK
Local
Aggregate
MirrorMaker
ZK
Local
Aggregate
MirrorMaker
Region 1 Region 2
PP
C C
Producing + Consuming
• Wrote a thin Scala wrapper around the Kafka “New” Producer Java
API
• Effectively send(topic, message, [key])
• Use minimum “in-sync replicas” setting for Topics
• We set it to ceil(N/2 + 1) where N is the size of the cluster
• Wait for acks from partition replicas before committing to leader
Producing
• To produce from our PHP
components, we use a Scala
proxy service with a REST API
• We also produce directly from
MySQL by using Tungsten
Replicator and a filter that
converts binlog changes to
event bus messages and
produces them
Producing
Kafka
TR
• Wrote a thin Scala wrapper on top of the High-Level Kafka
Consumer Java API
• Abstracts consuming from Local + Aggregate clusters
• Register consumer function for a topic
• Offsets auto-committed to ZooKeeper
• Consumer group for each logical consumer
• Sometimes have more consumers than partitions (fault tolerance)
• Also have consumption mechanism for PHP/Python
Consuming
Message Format
• Need to be able to serialize/deserialize messages in an efficient,
language agnostic way that tolerates evolution in message data
• Options
• JSON
• Plain text, everything understands it, easy to add/change fields
• Expensive to parse, large size, still have convert parsed JSON into domain
objects
• Protocol Buffers (protobuf)
• Binary, language-specific impls generated from an IDL
• Fast to parse, small size, generated code, easy to make
backwards/forwards compatible changes
Data -> Array[Byte] -> Data
• All of the messages we publish/consume from Kafka are serialized
protobufs
• We use ScalaPB (https://github.com/trueaccord/ScalaPB)
• Built on top of Google’s Java protobuf library
• Generates scala case class definitions from .proto
• Use only “optional” fields
• Helps forwards/backwards compatibility of messages
• Can add/remove fields without breaking
Protobuf
• You have to know the type of the serialized protobuf data before
you can deserialize it
• Potential solutions
• Only publish one type of message per topic
• Prepend a non-protobuf type tag in the payload
• The previous, but with protobufs inside protobufs
Small problem
• Protobuf that contains a list
• UUID string
• Payload bytes (serialized protobuf)
• Benefits
• Multiple objects per logical event
• Evolution of data in a topic
• Automatic serialization and
deserialization (maintain a
mapping of UUID-to-Type in each
language)
Message wrapper
UUID
Serialized protobuf payload bytes
• We use Kafka as a high-performance, highly-available
asynchronous event bus to decouple our services and reduce
complexity.
• Kafka is awesome - it just works!
• We use Protocol Buffers for an efficient message format that is
easy to use and evolve.
• Scala support for Kafka + Protobuf is great!
Wrapping up
Thank you!
Questions?
Senior Software Developer
@jimriecken
Jim Riecken

Weitere ähnliche Inhalte

Was ist angesagt?

A visual introduction to Apache Kafka
A visual introduction to Apache KafkaA visual introduction to Apache Kafka
A visual introduction to Apache KafkaPaul Brebner
 
Apache Kafka - Martin Podval
Apache Kafka - Martin PodvalApache Kafka - Martin Podval
Apache Kafka - Martin PodvalMartin Podval
 
Stream processing using Kafka
Stream processing using KafkaStream processing using Kafka
Stream processing using KafkaKnoldus Inc.
 
RabbitMQ & Kafka
RabbitMQ & KafkaRabbitMQ & Kafka
RabbitMQ & KafkaVMware Tanzu
 
An Introduction to Apache Kafka
An Introduction to Apache KafkaAn Introduction to Apache Kafka
An Introduction to Apache KafkaAmir Sedighi
 
Architecture Patterns for Event Streaming (Nick Dearden, Confluent) London 20...
Architecture Patterns for Event Streaming (Nick Dearden, Confluent) London 20...Architecture Patterns for Event Streaming (Nick Dearden, Confluent) London 20...
Architecture Patterns for Event Streaming (Nick Dearden, Confluent) London 20...confluent
 
Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Timothy Spann
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?confluent
 
Fundamentals of Apache Kafka
Fundamentals of Apache KafkaFundamentals of Apache Kafka
Fundamentals of Apache KafkaChhavi Parasher
 
Getting Started with Confluent Schema Registry
Getting Started with Confluent Schema RegistryGetting Started with Confluent Schema Registry
Getting Started with Confluent Schema Registryconfluent
 
Streaming all over the world Real life use cases with Kafka Streams
Streaming all over the world  Real life use cases with Kafka StreamsStreaming all over the world  Real life use cases with Kafka Streams
Streaming all over the world Real life use cases with Kafka Streamsconfluent
 
Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Flink Forward
 
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022HostedbyConfluent
 
Kafka at Peak Performance
Kafka at Peak PerformanceKafka at Peak Performance
Kafka at Peak PerformanceTodd Palino
 
Flink powered stream processing platform at Pinterest
Flink powered stream processing platform at PinterestFlink powered stream processing platform at Pinterest
Flink powered stream processing platform at PinterestFlink Forward
 
Kafka 101 and Developer Best Practices
Kafka 101 and Developer Best PracticesKafka 101 and Developer Best Practices
Kafka 101 and Developer Best Practicesconfluent
 
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity PlanningFrom Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planningconfluent
 

Was ist angesagt? (20)

A visual introduction to Apache Kafka
A visual introduction to Apache KafkaA visual introduction to Apache Kafka
A visual introduction to Apache Kafka
 
Apache Kafka - Martin Podval
Apache Kafka - Martin PodvalApache Kafka - Martin Podval
Apache Kafka - Martin Podval
 
Kafka basics
Kafka basicsKafka basics
Kafka basics
 
Stream processing using Kafka
Stream processing using KafkaStream processing using Kafka
Stream processing using Kafka
 
RabbitMQ & Kafka
RabbitMQ & KafkaRabbitMQ & Kafka
RabbitMQ & Kafka
 
An Introduction to Apache Kafka
An Introduction to Apache KafkaAn Introduction to Apache Kafka
An Introduction to Apache Kafka
 
Architecture Patterns for Event Streaming (Nick Dearden, Confluent) London 20...
Architecture Patterns for Event Streaming (Nick Dearden, Confluent) London 20...Architecture Patterns for Event Streaming (Nick Dearden, Confluent) London 20...
Architecture Patterns for Event Streaming (Nick Dearden, Confluent) London 20...
 
Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?
 
Fundamentals of Apache Kafka
Fundamentals of Apache KafkaFundamentals of Apache Kafka
Fundamentals of Apache Kafka
 
Getting Started with Confluent Schema Registry
Getting Started with Confluent Schema RegistryGetting Started with Confluent Schema Registry
Getting Started with Confluent Schema Registry
 
Kafka presentation
Kafka presentationKafka presentation
Kafka presentation
 
Apache Kafka Best Practices
Apache Kafka Best PracticesApache Kafka Best Practices
Apache Kafka Best Practices
 
Streaming all over the world Real life use cases with Kafka Streams
Streaming all over the world  Real life use cases with Kafka StreamsStreaming all over the world  Real life use cases with Kafka Streams
Streaming all over the world Real life use cases with Kafka Streams
 
Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...
 
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
 
Kafka at Peak Performance
Kafka at Peak PerformanceKafka at Peak Performance
Kafka at Peak Performance
 
Flink powered stream processing platform at Pinterest
Flink powered stream processing platform at PinterestFlink powered stream processing platform at Pinterest
Flink powered stream processing platform at Pinterest
 
Kafka 101 and Developer Best Practices
Kafka 101 and Developer Best PracticesKafka 101 and Developer Best Practices
Kafka 101 and Developer Best Practices
 
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity PlanningFrom Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
 

Ähnlich wie Building an Event Bus at Scale

Fundamentals and Architecture of Apache Kafka
Fundamentals and Architecture of Apache KafkaFundamentals and Architecture of Apache Kafka
Fundamentals and Architecture of Apache KafkaAngelo Cesaro
 
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.pptxKnoldus Inc.
 
Modern Distributed Messaging and RPC
Modern Distributed Messaging and RPCModern Distributed Messaging and RPC
Modern Distributed Messaging and RPCMax Alexejev
 
Apache kafka
Apache kafkaApache kafka
Apache kafkaSrikrishna k
 
apachekafka-160907180205.pdf
apachekafka-160907180205.pdfapachekafka-160907180205.pdf
apachekafka-160907180205.pdfTarekHamdi8
 
Kafka tutorial
Kafka tutorialKafka tutorial
Kafka tutorialSrikrishna k
 
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...Lucas Jellema
 
Building High-Throughput, Low-Latency Pipelines in Kafka
Building High-Throughput, Low-Latency Pipelines in KafkaBuilding High-Throughput, Low-Latency Pipelines in Kafka
Building High-Throughput, Low-Latency Pipelines in Kafkaconfluent
 
kafka simplicity and complexity
kafka simplicity and complexitykafka simplicity and complexity
kafka simplicity and complexityPaolo Platter
 
Distributed messaging with Apache Kafka
Distributed messaging with Apache KafkaDistributed messaging with Apache Kafka
Distributed messaging with Apache KafkaSaumitra Srivastav
 
Apache kafka- Onkar Kadam
Apache kafka- Onkar KadamApache kafka- Onkar Kadam
Apache kafka- Onkar KadamOnkar Kadam
 
Apache Kafka Introduction
Apache Kafka IntroductionApache Kafka Introduction
Apache Kafka IntroductionAmita Mirajkar
 
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...Erik Onnen
 
Messaging, storage, or both? The real time story of Pulsar and Apache Distri...
Messaging, storage, or both?  The real time story of Pulsar and Apache Distri...Messaging, storage, or both?  The real time story of Pulsar and Apache Distri...
Messaging, storage, or both? The real time story of Pulsar and Apache Distri...Streamlio
 
Hands-on Workshop: Apache Pulsar
Hands-on Workshop: Apache PulsarHands-on Workshop: Apache Pulsar
Hands-on Workshop: Apache PulsarSijie Guo
 
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...Bob Pusateri
 
Kafka Summit SF 2017 - Best Practices for Running Kafka on Docker Containers
Kafka Summit SF 2017 - Best Practices for Running Kafka on Docker ContainersKafka Summit SF 2017 - Best Practices for Running Kafka on Docker Containers
Kafka Summit SF 2017 - Best Practices for Running Kafka on Docker Containersconfluent
 
Reducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive StreamsReducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive Streamsjimriecken
 
Apache kafka
Apache kafkaApache kafka
Apache kafkaKumar Shivam
 

Ähnlich wie Building an Event Bus at Scale (20)

Fundamentals and Architecture of Apache Kafka
Fundamentals and Architecture of Apache KafkaFundamentals and Architecture of Apache Kafka
Fundamentals and Architecture of Apache Kafka
 
Kafka overview v0.1
Kafka overview v0.1Kafka overview v0.1
Kafka overview v0.1
 
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
 
Modern Distributed Messaging and RPC
Modern Distributed Messaging and RPCModern Distributed Messaging and RPC
Modern Distributed Messaging and RPC
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
apachekafka-160907180205.pdf
apachekafka-160907180205.pdfapachekafka-160907180205.pdf
apachekafka-160907180205.pdf
 
Kafka tutorial
Kafka tutorialKafka tutorial
Kafka tutorial
 
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
 
Building High-Throughput, Low-Latency Pipelines in Kafka
Building High-Throughput, Low-Latency Pipelines in KafkaBuilding High-Throughput, Low-Latency Pipelines in Kafka
Building High-Throughput, Low-Latency Pipelines in Kafka
 
kafka simplicity and complexity
kafka simplicity and complexitykafka simplicity and complexity
kafka simplicity and complexity
 
Distributed messaging with Apache Kafka
Distributed messaging with Apache KafkaDistributed messaging with Apache Kafka
Distributed messaging with Apache Kafka
 
Apache kafka- Onkar Kadam
Apache kafka- Onkar KadamApache kafka- Onkar Kadam
Apache kafka- Onkar Kadam
 
Apache Kafka Introduction
Apache Kafka IntroductionApache Kafka Introduction
Apache Kafka Introduction
 
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
 
Messaging, storage, or both? The real time story of Pulsar and Apache Distri...
Messaging, storage, or both?  The real time story of Pulsar and Apache Distri...Messaging, storage, or both?  The real time story of Pulsar and Apache Distri...
Messaging, storage, or both? The real time story of Pulsar and Apache Distri...
 
Hands-on Workshop: Apache Pulsar
Hands-on Workshop: Apache PulsarHands-on Workshop: Apache Pulsar
Hands-on Workshop: Apache Pulsar
 
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
 
Kafka Summit SF 2017 - Best Practices for Running Kafka on Docker Containers
Kafka Summit SF 2017 - Best Practices for Running Kafka on Docker ContainersKafka Summit SF 2017 - Best Practices for Running Kafka on Docker Containers
Kafka Summit SF 2017 - Best Practices for Running Kafka on Docker Containers
 
Reducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive StreamsReducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive Streams
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 

KĂźrzlich hochgeladen

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto GonzĂĄlez Trastoy
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 

KĂźrzlich hochgeladen (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 

Building an Event Bus at Scale

  • 1. Building an Event Bus at Scale Senior Software Developer @jimriecken Jim Riecken
  • 2. • Senior developer on the Platform Team at Hootsuite • Building backend services + infrastructure • I <3 Scala About me
  • 3. A bit of history
  • 4. • PHP monolith, horizontally scaled • Single Database • Any part of the system can easily interact with any other part of the system • Local method calls • Shared cache • Shared database The early days Load balancers Memcache + DB
  • 5. • Smaller PHP monolith • Lots of Scala microservices • Multiple databases • Distributed Systems • Not local anymore • Latency • Failures, partial failures Now
  • 7. • As the number of services increases, the coupling of them tends to as well • More network calls end up in the critical path of the request • Slows user experience • More prone to failure • Do all of them need to be? Coupling sendMessage() 1 2 3 4 5
  • 9. • Decouple asynchronous consumption of data/events from the producer of that data. • New consumers easily added • No longer in the critical path of the request, and fewer potential points for failure • Faster requests + happier users! Event Bus sendMessage() Event Bus 1 2 3 4
  • 10. • High throughput • High availability • Durability • Handle fast producers + slow consumers • Multi-region/data center support • Must have Scala and PHP clients Requirements
  • 12. • RabbitMQ (or some other flavour of AMQP) • ØMQ • Apache Kafka Candidates
  • 13. • ØMQ • Too low level, would have to build a lot on top of it • RabbitMQ • Based on previous experience • Doesn’t recover well from crashes • Doesn’t perform well when messages are persisted to disk • Slow consumers can affect performance of the system Why not ØMQ or RabbitMQ?
  • 14. • Simple - conceptually it’s just a log • High performance - in use at large organizations (e.g. LinkedIn, Etsy, Netflix) • Can scale up to millions of messages per second / terabytes of data per day • Highly available - designed to be fault tolerant • High durability - messages are replicated across cluster • Handles slow consumers • Pull model, not push • Configurable message retention • Can work with multiple regions/data centers • Written in Scala! Why Kafka?
  • 16. • Distributed, partitioned, replicated commit log service • Producers publish messages to Topics • Consumers pull + process the feed of published messages • Runs as a cluster of Brokers • Requires ZooKeeper for coordination/leader election Kafka P P P C C C ZK Brokers w/ Topics | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  • 17. • Split into Partitions (which are stored in log files) • Each partition is an ordered, immutable sequence of messages that is only appended to • Partitions are distributed and replicated across the cluster of Brokers • Data is kept for a configurable retention period after which it is either discarded or compacted • Consumers keep track of their offset in the logs Topics
  • 18. • Push messages to partitions of topics • Can send to • A random/round-robined partition • A specific partition • A partition based on a hash constructed from a key • Maintain per-key order • Messages and Keys are just Array[Byte] • Responsible for your own serialization Producers
  • 19. • Pull messages from partitions of topics • Can either • Manually manage offsets (“simple consumer”) • Have offsets/partition assignment automatically managed (“high level consumer”) • Consumer Groups • Offsets stored in ZooKeeper (or Kafka itself) • Partitions are distributed among consumers • # Consumers > # Partitions => Some consume nothing • # Partitions > # Consumers => Some consume several partitions Consumers
  • 20. How we set up Kafka
  • 21. • Each cluster consists of a set of Kafka brokers and a ZooKeeper quorum • At least 3 brokers • At least 3 ZK nodes (preferably more) • Brokers have large disks • Standard topic retention - overridden per topic as necessary • Topics are managed via Jenkins jobs Clusters ZK ZK ZK B B B
  • 22. • MirrorMaker • Tool for consuming topics from one cluster + producing to another • Aggregate + Local clusters • Producers produce to local cluster • Consumers consume from local + aggregate • MirrorMaker consumes from local + produces to aggregate Multi-Region ZK Local Aggregate MirrorMaker ZK Local Aggregate MirrorMaker Region 1 Region 2 PP C C
  • 24. • Wrote a thin Scala wrapper around the Kafka “New” Producer Java API • Effectively send(topic, message, [key]) • Use minimum “in-sync replicas” setting for Topics • We set it to ceil(N/2 + 1) where N is the size of the cluster • Wait for acks from partition replicas before committing to leader Producing
  • 25. • To produce from our PHP components, we use a Scala proxy service with a REST API • We also produce directly from MySQL by using Tungsten Replicator and a filter that converts binlog changes to event bus messages and produces them Producing Kafka TR
  • 26. • Wrote a thin Scala wrapper on top of the High-Level Kafka Consumer Java API • Abstracts consuming from Local + Aggregate clusters • Register consumer function for a topic • Offsets auto-committed to ZooKeeper • Consumer group for each logical consumer • Sometimes have more consumers than partitions (fault tolerance) • Also have consumption mechanism for PHP/Python Consuming
  • 28. • Need to be able to serialize/deserialize messages in an efficient, language agnostic way that tolerates evolution in message data • Options • JSON • Plain text, everything understands it, easy to add/change fields • Expensive to parse, large size, still have convert parsed JSON into domain objects • Protocol Buffers (protobuf) • Binary, language-specific impls generated from an IDL • Fast to parse, small size, generated code, easy to make backwards/forwards compatible changes Data -> Array[Byte] -> Data
  • 29. • All of the messages we publish/consume from Kafka are serialized protobufs • We use ScalaPB (https://github.com/trueaccord/ScalaPB) • Built on top of Google’s Java protobuf library • Generates scala case class definitions from .proto • Use only “optional” fields • Helps forwards/backwards compatibility of messages • Can add/remove fields without breaking Protobuf
  • 30. • You have to know the type of the serialized protobuf data before you can deserialize it • Potential solutions • Only publish one type of message per topic • Prepend a non-protobuf type tag in the payload • The previous, but with protobufs inside protobufs Small problem
  • 31. • Protobuf that contains a list • UUID string • Payload bytes (serialized protobuf) • Benefits • Multiple objects per logical event • Evolution of data in a topic • Automatic serialization and deserialization (maintain a mapping of UUID-to-Type in each language) Message wrapper UUID Serialized protobuf payload bytes
  • 32. • We use Kafka as a high-performance, highly-available asynchronous event bus to decouple our services and reduce complexity. • Kafka is awesome - it just works! • We use Protocol Buffers for an efficient message format that is easy to use and evolve. • Scala support for Kafka + Protobuf is great! Wrapping up
  • 33. Thank you! Questions? Senior Software Developer @jimriecken Jim Riecken