SlideShare a Scribd company logo
1 of 14
Architecture of Falcon,
a new chat messaging
backend system
build on Scala
Yusuke Yasuda
ChatWork
2017/02/26
Architecture of Falcon, a new backend chat messaging system build on Scala
2017/02/27 © ChatWork All rights reserved. 2
Goal of Architecture
• Scalability:
• linear increase of throughput by adding nodes
• keep stable and low latency
• High Performance:
• achieve 100 times higher throughput than the current load without further
architectural changes
• Resiliency:
• avoid chain reaction of failures
• fast recovery from partial failure
• Low cost:
• keep cluster size as small as possible
• resist temporal load without additional resources
• high performance/resource ratio
• Legacy system integration
• keep consistency without transactions
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved. 3
Architecture Overview
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved. 4
Architecture Overview
• “Write API” exposes asynchronous API. Persists event and immediately returns
`202 Accepted`. No queries and mutations. Storage is Kafka.
• “Read API” can only query read model. No mutation. Both query by key and
query by key range are supported. Storage is HBase.
• ReadModelUpdater is a Kafka consumer creates read model queried by Read
API from events generated by Write API.
• PostProcessorForwarder is a Kafka consumer notifies legacy PHP system to
execute remaining transactions, e.g. push notification.
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved. 5
CQRS: Command Query Responsibility Segregation
• Command and Query responsibility is segregated at system level.
• Specialized responsibility make a system simple
• Each system uses different models
• “Write API” uses immutable events to represent history of user actions.
• “Read API” uses read models optimized for query.
• Dedicated storages are used for command and query system each.
2017/02/27 © ChatWork All rights reserved.
Convergent Evolution of technology
“Convergent evolution is the independent evolution of similar features in species of
different lineages. ”
6
https://en.wikipedia.org/wiki/Convergent_evolution
DDD
Fighting against complexity
of domain model with Event
Sourcing
Big Data
Fighting against complexity
of big data with Log
Processing
https://www.infoq.com/news/2016/05/event-sourcing-stream-processing
Two communities invented similar features independently.
Falcon is influenced by knowledge of two communities.
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved. 7
Inter-system Synchronization
• Falcon subsystems and PHP system are so called
“microservices”.
• Microservices do not share persistent storage.
• Event Sourcing to synchronize systems with properties:
• No events are lost (within retention period).
• The order of message events are preserved within a chat
room.
• Events are processed in at-least-once manner.
• Processing the same event twice has no effects
(idempotent).
Architecture of Falcon, a new backend system build on Scala
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved. 8
Kafka features helpful for Event Sourcing
• auto-sharding
• Events are partitioned to be processed in parallel.
• strong consistency:
• One partition can be processed by single consumer.
• Consumer can have internal states.
• Resilient:
• Partition assigned to crashed consumer is rebalanced to
another consumer automatically.
• Easy to connect services
• Forward events to next topic
topic 1
topic 3
topic 2
topic 4
2017/02/27 © ChatWork All rights reserved. 9
• subsystem may show temporarily poor performance:
• load spikes
• Compaction of HBase
• Legacy PHP system failure caused by process saturation
• AWS component failure
•Using Kafka as command-side storage help defend subsystem:
•Kafka can easily handle events produced with higher throughput as 40
times as normal load without scaling out.
•Kafka consumer can consume events with stable throughput. This
ensures subsystem to deal with predictable throughput.
•Throttling of Kafka ensures upper limit of throughput.
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved. 10
1. SQL query latency increased at Amazon
Aurora of PHP system
2. PostProcessorForwarder caused
timeout to call PHP system
4. Throughput of processing events decreased.
Once subsystem recovered from failure, the
throughput increased to consume stacked events
but never exceeded upper limit due to throttling.
3. Events stacked on queue in Kafka
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved.
ACID semantics of Falcon
• Atomicity: No atomicity among posting message and associated
operations, e.g. unread count calculation. Intermediate state can be
observed.
• Consistency: Eventual consistency. Read “Consistency Model”.
• Isolation: No concurrent mutation of the same record. Events are
processed sequentially. No need to isolate.
• Durability: Yes. No messages are lost.
• Visibility: No guarantee. There is short term posted message cannot be
observed. We try making the term as short a.p.
11
ACID does not provide high availability and scalability.
Falcon does not have ACID properties.
http://people.eecs.berkeley.edu/~brewer/cs262b/TACC.pdf
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved.
Consistency Model
14
Choose C or A based on CAP theorem.
CA CA CA
CA
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved.
Consistency Model
15
CA CA CA
CA
•Availability for user-facing subsystems, Write API and Read API
• Ensure always writable and readable. Loosing availability means service down.
•Consistency for background subsystems, ReadModelUpdater and PostProcessorForwarder.
• Ensure internal state consistency. Loosing availability is not obvious for users.
Architecture of Falcon, a new backend system build on Scala
2017/02/27 © ChatWork All rights reserved.
Recovery from human errors
• Falcon can recover from data corruption without service stop.
• The system might damage data was ReadModelUpdater if
malfunctioning.
• “Write API”, “Read API”, “PostProcessorForwarder” cannot
mutate data.
• Since input events are preserved in Kafka, output can be
recalculated by resetting offsets of Kafka consumer.
• Stopping ReadModelUpdater does not affect availability of
service.
18
Architecture of Falcon, a new backend system build on Scala

More Related Content

What's hot

A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
Legacy Typesafe (now Lightbend)
 
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
confluent
 

What's hot (20)

Akka and Kubernetes: Reactive From Code To Cloud
Akka and Kubernetes: Reactive From Code To CloudAkka and Kubernetes: Reactive From Code To Cloud
Akka and Kubernetes: Reactive From Code To Cloud
 
Revitalizing Enterprise Integration with Reactive Streams
Revitalizing Enterprise Integration with Reactive StreamsRevitalizing Enterprise Integration with Reactive Streams
Revitalizing Enterprise Integration with Reactive Streams
 
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and moreTypesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
 
KSQL Intro
KSQL IntroKSQL Intro
KSQL Intro
 
Error Resilient Design: Building Scalable & Fault-Tolerant Microservices with...
Error Resilient Design: Building Scalable & Fault-Tolerant Microservices with...Error Resilient Design: Building Scalable & Fault-Tolerant Microservices with...
Error Resilient Design: Building Scalable & Fault-Tolerant Microservices with...
 
Scala Security: Eliminate 200+ Code-Level Threats With Fortify SCA For Scala
Scala Security: Eliminate 200+ Code-Level Threats With Fortify SCA For ScalaScala Security: Eliminate 200+ Code-Level Threats With Fortify SCA For Scala
Scala Security: Eliminate 200+ Code-Level Threats With Fortify SCA For Scala
 
Real time Messages at Scale with Apache Kafka and Couchbase
Real time Messages at Scale with Apache Kafka and CouchbaseReal time Messages at Scale with Apache Kafka and Couchbase
Real time Messages at Scale with Apache Kafka and Couchbase
 
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
 
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
 
How Apache Kafka® Works
How Apache Kafka® WorksHow Apache Kafka® Works
How Apache Kafka® Works
 
What's new in Confluent 3.2 and Apache Kafka 0.10.2
What's new in Confluent 3.2 and Apache Kafka 0.10.2 What's new in Confluent 3.2 and Apache Kafka 0.10.2
What's new in Confluent 3.2 and Apache Kafka 0.10.2
 
Kafka internals
Kafka internalsKafka internals
Kafka internals
 
Introduction to Kafka
Introduction to KafkaIntroduction to Kafka
Introduction to Kafka
 
Stream Collections - Scala Days
Stream Collections - Scala DaysStream Collections - Scala Days
Stream Collections - Scala Days
 
A Journey to Reactive Function Programming
A Journey to Reactive Function ProgrammingA Journey to Reactive Function Programming
A Journey to Reactive Function Programming
 
Introduction to Apache Kafka and why it matters - Madrid
Introduction to Apache Kafka and why it matters - MadridIntroduction to Apache Kafka and why it matters - Madrid
Introduction to Apache Kafka and why it matters - Madrid
 
Apache Kafka® Security Overview
Apache Kafka® Security OverviewApache Kafka® Security Overview
Apache Kafka® Security Overview
 
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
 
Scala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud PlatformScala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud Platform
 
Multi-threading in the modern era: Vertx Akka and Quasar
Multi-threading in the modern era: Vertx Akka and QuasarMulti-threading in the modern era: Vertx Akka and Quasar
Multi-threading in the modern era: Vertx Akka and Quasar
 

Similar to Architecture of Falcon, a new chat messaging backend system build on Scala

Similar to Architecture of Falcon, a new chat messaging backend system build on Scala (20)

Introduction to Apache Mesos and DC/OS
Introduction to Apache Mesos and DC/OSIntroduction to Apache Mesos and DC/OS
Introduction to Apache Mesos and DC/OS
 
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
 
Building streaming data applications using Kafka*[Connect + Core + Streams] b...
Building streaming data applications using Kafka*[Connect + Core + Streams] b...Building streaming data applications using Kafka*[Connect + Core + Streams] b...
Building streaming data applications using Kafka*[Connect + Core + Streams] b...
 
New Features in Confluent Platform 6.0 / Apache Kafka 2.6
New Features in Confluent Platform 6.0 / Apache Kafka 2.6New Features in Confluent Platform 6.0 / Apache Kafka 2.6
New Features in Confluent Platform 6.0 / Apache Kafka 2.6
 
Building Streaming Data Applications Using Apache Kafka
Building Streaming Data Applications Using Apache KafkaBuilding Streaming Data Applications Using Apache Kafka
Building Streaming Data Applications Using Apache Kafka
 
Streaming Movies brings you Streamlined Applications -- How Adopting Netflix ...
Streaming Movies brings you Streamlined Applications -- How Adopting Netflix ...Streaming Movies brings you Streamlined Applications -- How Adopting Netflix ...
Streaming Movies brings you Streamlined Applications -- How Adopting Netflix ...
 
HPC and cloud distributed computing, as a journey
HPC and cloud distributed computing, as a journeyHPC and cloud distributed computing, as a journey
HPC and cloud distributed computing, as a journey
 
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with A...
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with A...Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with A...
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with A...
 
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
 
LinuxONE cavemen mmit 20160505 v1.0
LinuxONE cavemen mmit 20160505 v1.0LinuxONE cavemen mmit 20160505 v1.0
LinuxONE cavemen mmit 20160505 v1.0
 
Streaming to a New Jakarta EE
Streaming to a New Jakarta EEStreaming to a New Jakarta EE
Streaming to a New Jakarta EE
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EE
 
Kafka Explainaton
Kafka ExplainatonKafka Explainaton
Kafka Explainaton
 
OpenStack Silicon Valley - Enterprise Storage Trends Driving OpenStack Features
OpenStack Silicon Valley - Enterprise Storage Trends Driving OpenStack FeaturesOpenStack Silicon Valley - Enterprise Storage Trends Driving OpenStack Features
OpenStack Silicon Valley - Enterprise Storage Trends Driving OpenStack Features
 
Docker vs. Kubernetes vs. Serverless
Docker vs. Kubernetes vs. ServerlessDocker vs. Kubernetes vs. Serverless
Docker vs. Kubernetes vs. Serverless
 
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
 
Flying to clouds - can it be easy? Cloud Native Applications
Flying to clouds - can it be easy? Cloud Native ApplicationsFlying to clouds - can it be easy? Cloud Native Applications
Flying to clouds - can it be easy? Cloud Native Applications
 
OS for AI: Elastic Microservices & the Next Gen of ML
OS for AI: Elastic Microservices & the Next Gen of MLOS for AI: Elastic Microservices & the Next Gen of ML
OS for AI: Elastic Microservices & the Next Gen of ML
 
MySQL Operator for Kubernetes
MySQL Operator for KubernetesMySQL Operator for Kubernetes
MySQL Operator for Kubernetes
 
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...
 

More from TanUkkii

スケールするシステムにおけるエンティティの扱いと 分散ID生成
スケールするシステムにおけるエンティティの扱いと 分散ID生成スケールするシステムにおけるエンティティの扱いと 分散ID生成
スケールするシステムにおけるエンティティの扱いと 分散ID生成
TanUkkii
 
すべてのアクター プログラマーが知るべき 単一責務原則とは何か
すべてのアクター プログラマーが知るべき 単一責務原則とは何かすべてのアクター プログラマーが知るべき 単一責務原則とは何か
すべてのアクター プログラマーが知るべき 単一責務原則とは何か
TanUkkii
 

More from TanUkkii (15)

Distributed ID generator in ChatWork
Distributed ID generator in ChatWorkDistributed ID generator in ChatWork
Distributed ID generator in ChatWork
 
JSON CRDT
JSON CRDTJSON CRDT
JSON CRDT
 
Akka Clusterの耐障害設計
Akka Clusterの耐障害設計Akka Clusterの耐障害設計
Akka Clusterの耐障害設計
 
WaveNet
WaveNetWaveNet
WaveNet
 
スケールするシステムにおけるエンティティの扱いと 分散ID生成
スケールするシステムにおけるエンティティの扱いと 分散ID生成スケールするシステムにおけるエンティティの扱いと 分散ID生成
スケールするシステムにおけるエンティティの扱いと 分散ID生成
 
Akka HTTP
Akka HTTPAkka HTTP
Akka HTTP
 
すべてのアクター プログラマーが知るべき 単一責務原則とは何か
すべてのアクター プログラマーが知るべき 単一責務原則とは何かすべてのアクター プログラマーが知るべき 単一責務原則とは何か
すべてのアクター プログラマーが知るべき 単一責務原則とは何か
 
ディープニューラルネット入門
ディープニューラルネット入門ディープニューラルネット入門
ディープニューラルネット入門
 
プログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けー
プログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けープログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けー
プログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けー
 
プログラミング言語のパラダイムシフトーScalaから見る関数型と並列性時代の幕開けー
プログラミング言語のパラダイムシフトーScalaから見る関数型と並列性時代の幕開けープログラミング言語のパラダイムシフトーScalaから見る関数型と並列性時代の幕開けー
プログラミング言語のパラダイムシフトーScalaから見る関数型と並列性時代の幕開けー
 
Isomorphic web development with scala and scala.js
Isomorphic web development  with scala and scala.jsIsomorphic web development  with scala and scala.js
Isomorphic web development with scala and scala.js
 
Scalaによる型安全なエラーハンドリング
Scalaによる型安全なエラーハンドリングScalaによる型安全なエラーハンドリング
Scalaによる型安全なエラーハンドリング
 
ECMAScript6による関数型プログラミング
ECMAScript6による関数型プログラミングECMAScript6による関数型プログラミング
ECMAScript6による関数型プログラミング
 
プログラミング言語Scala
プログラミング言語Scalaプログラミング言語Scala
プログラミング言語Scala
 
これからのJavaScriptー関数型プログラミングとECMAScript6
これからのJavaScriptー関数型プログラミングとECMAScript6これからのJavaScriptー関数型プログラミングとECMAScript6
これからのJavaScriptー関数型プログラミングとECMAScript6
 

Recently uploaded

Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
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
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Recently uploaded (20)

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
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
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 

Architecture of Falcon, a new chat messaging backend system build on Scala

  • 1. Architecture of Falcon, a new chat messaging backend system build on Scala Yusuke Yasuda ChatWork 2017/02/26
  • 2. Architecture of Falcon, a new backend chat messaging system build on Scala 2017/02/27 © ChatWork All rights reserved. 2 Goal of Architecture • Scalability: • linear increase of throughput by adding nodes • keep stable and low latency • High Performance: • achieve 100 times higher throughput than the current load without further architectural changes • Resiliency: • avoid chain reaction of failures • fast recovery from partial failure • Low cost: • keep cluster size as small as possible • resist temporal load without additional resources • high performance/resource ratio • Legacy system integration • keep consistency without transactions
  • 3. Architecture of Falcon, a new backend system build on Scala 2017/02/27 © ChatWork All rights reserved. 3 Architecture Overview
  • 4. Architecture of Falcon, a new backend system build on Scala 2017/02/27 © ChatWork All rights reserved. 4 Architecture Overview • “Write API” exposes asynchronous API. Persists event and immediately returns `202 Accepted`. No queries and mutations. Storage is Kafka. • “Read API” can only query read model. No mutation. Both query by key and query by key range are supported. Storage is HBase. • ReadModelUpdater is a Kafka consumer creates read model queried by Read API from events generated by Write API. • PostProcessorForwarder is a Kafka consumer notifies legacy PHP system to execute remaining transactions, e.g. push notification.
  • 5. Architecture of Falcon, a new backend system build on Scala 2017/02/27 © ChatWork All rights reserved. 5 CQRS: Command Query Responsibility Segregation • Command and Query responsibility is segregated at system level. • Specialized responsibility make a system simple • Each system uses different models • “Write API” uses immutable events to represent history of user actions. • “Read API” uses read models optimized for query. • Dedicated storages are used for command and query system each.
  • 6. 2017/02/27 © ChatWork All rights reserved. Convergent Evolution of technology “Convergent evolution is the independent evolution of similar features in species of different lineages. ” 6 https://en.wikipedia.org/wiki/Convergent_evolution DDD Fighting against complexity of domain model with Event Sourcing Big Data Fighting against complexity of big data with Log Processing https://www.infoq.com/news/2016/05/event-sourcing-stream-processing Two communities invented similar features independently. Falcon is influenced by knowledge of two communities. Architecture of Falcon, a new backend system build on Scala
  • 7. 2017/02/27 © ChatWork All rights reserved. 7 Inter-system Synchronization • Falcon subsystems and PHP system are so called “microservices”. • Microservices do not share persistent storage. • Event Sourcing to synchronize systems with properties: • No events are lost (within retention period). • The order of message events are preserved within a chat room. • Events are processed in at-least-once manner. • Processing the same event twice has no effects (idempotent). Architecture of Falcon, a new backend system build on Scala
  • 8. Architecture of Falcon, a new backend system build on Scala 2017/02/27 © ChatWork All rights reserved. 8 Kafka features helpful for Event Sourcing • auto-sharding • Events are partitioned to be processed in parallel. • strong consistency: • One partition can be processed by single consumer. • Consumer can have internal states. • Resilient: • Partition assigned to crashed consumer is rebalanced to another consumer automatically. • Easy to connect services • Forward events to next topic topic 1 topic 3 topic 2 topic 4
  • 9. 2017/02/27 © ChatWork All rights reserved. 9 • subsystem may show temporarily poor performance: • load spikes • Compaction of HBase • Legacy PHP system failure caused by process saturation • AWS component failure •Using Kafka as command-side storage help defend subsystem: •Kafka can easily handle events produced with higher throughput as 40 times as normal load without scaling out. •Kafka consumer can consume events with stable throughput. This ensures subsystem to deal with predictable throughput. •Throttling of Kafka ensures upper limit of throughput. Architecture of Falcon, a new backend system build on Scala
  • 10. 2017/02/27 © ChatWork All rights reserved. 10 1. SQL query latency increased at Amazon Aurora of PHP system 2. PostProcessorForwarder caused timeout to call PHP system 4. Throughput of processing events decreased. Once subsystem recovered from failure, the throughput increased to consume stacked events but never exceeded upper limit due to throttling. 3. Events stacked on queue in Kafka Architecture of Falcon, a new backend system build on Scala
  • 11. 2017/02/27 © ChatWork All rights reserved. ACID semantics of Falcon • Atomicity: No atomicity among posting message and associated operations, e.g. unread count calculation. Intermediate state can be observed. • Consistency: Eventual consistency. Read “Consistency Model”. • Isolation: No concurrent mutation of the same record. Events are processed sequentially. No need to isolate. • Durability: Yes. No messages are lost. • Visibility: No guarantee. There is short term posted message cannot be observed. We try making the term as short a.p. 11 ACID does not provide high availability and scalability. Falcon does not have ACID properties. http://people.eecs.berkeley.edu/~brewer/cs262b/TACC.pdf Architecture of Falcon, a new backend system build on Scala
  • 12. 2017/02/27 © ChatWork All rights reserved. Consistency Model 14 Choose C or A based on CAP theorem. CA CA CA CA Architecture of Falcon, a new backend system build on Scala
  • 13. 2017/02/27 © ChatWork All rights reserved. Consistency Model 15 CA CA CA CA •Availability for user-facing subsystems, Write API and Read API • Ensure always writable and readable. Loosing availability means service down. •Consistency for background subsystems, ReadModelUpdater and PostProcessorForwarder. • Ensure internal state consistency. Loosing availability is not obvious for users. Architecture of Falcon, a new backend system build on Scala
  • 14. 2017/02/27 © ChatWork All rights reserved. Recovery from human errors • Falcon can recover from data corruption without service stop. • The system might damage data was ReadModelUpdater if malfunctioning. • “Write API”, “Read API”, “PostProcessorForwarder” cannot mutate data. • Since input events are preserved in Kafka, output can be recalculated by resetting offsets of Kafka consumer. • Stopping ReadModelUpdater does not affect availability of service. 18 Architecture of Falcon, a new backend system build on Scala