SlideShare a Scribd company logo
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

PDF
Non-blocking IO to tame distributed systems ー How and why ChatWork uses async...
PDF
Akka at Enterprise Scale: Performance Tuning Distributed Applications
PDF
Deploying Kafka on DC/OS
PPTX
Data Pipelines with Kafka Connect
PPTX
Putting Kafka In Jail – Best Practices To Run Kafka On Kubernetes & DC/OS
ODP
Kafka aws
PDF
Developing Secure Scala Applications With Fortify For Scala
PDF
Making Scala Faster: 3 Expert Tips For Busy Development Teams
Non-blocking IO to tame distributed systems ー How and why ChatWork uses async...
Akka at Enterprise Scale: Performance Tuning Distributed Applications
Deploying Kafka on DC/OS
Data Pipelines with Kafka Connect
Putting Kafka In Jail – Best Practices To Run Kafka On Kubernetes & DC/OS
Kafka aws
Developing Secure Scala Applications With Fortify For Scala
Making Scala Faster: 3 Expert Tips For Busy Development Teams

What's hot (20)

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

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

PDF
Introduction to Apache Mesos and DC/OS
PDF
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
PPTX
Building streaming data applications using Kafka*[Connect + Core + Streams] b...
PDF
New Features in Confluent Platform 6.0 / Apache Kafka 2.6
PDF
Building Streaming Data Applications Using Apache Kafka
PDF
Streaming Movies brings you Streamlined Applications -- How Adopting Netflix ...
PPTX
HPC and cloud distributed computing, as a journey
PPTX
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with A...
PPTX
Unleashing Real-time Power with Kafka.pptx
PPT
LinuxONE cavemen mmit 20160505 v1.0
PDF
Streaming to a New Jakarta EE
PDF
Streaming to a new Jakarta EE
PPT
Kafka Explainaton
PDF
OpenStack Silicon Valley - Enterprise Storage Trends Driving OpenStack Features
PDF
Docker vs. Kubernetes vs. Serverless
PPT
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
PPT
Flying to clouds - can it be easy? Cloud Native Applications
PPTX
OS for AI: Elastic Microservices & the Next Gen of ML
PDF
MySQL Operator for Kubernetes
PDF
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Introduction to Apache Mesos and DC/OS
Confluent REST Proxy and Schema Registry (Concepts, Architecture, Features)
Building streaming data applications using Kafka*[Connect + Core + Streams] b...
New Features in Confluent Platform 6.0 / Apache Kafka 2.6
Building Streaming Data Applications Using Apache Kafka
Streaming Movies brings you Streamlined Applications -- How Adopting Netflix ...
HPC and cloud distributed computing, as a journey
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with A...
Unleashing Real-time Power with Kafka.pptx
LinuxONE cavemen mmit 20160505 v1.0
Streaming to a New Jakarta EE
Streaming to a new Jakarta EE
Kafka Explainaton
OpenStack Silicon Valley - Enterprise Storage Trends Driving OpenStack Features
Docker vs. Kubernetes vs. Serverless
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
Flying to clouds - can it be easy? Cloud Native Applications
OS for AI: Elastic Microservices & the Next Gen of ML
MySQL Operator for Kubernetes
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Ad

More from TanUkkii (15)

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

Recently uploaded (20)

PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
web development for engineering and engineering
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
DOCX
573137875-Attendance-Management-System-original
PPTX
Sustainable Sites - Green Building Construction
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Lecture Notes Electrical Wiring System Components
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
web development for engineering and engineering
Model Code of Practice - Construction Work - 21102022 .pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
573137875-Attendance-Management-System-original
Sustainable Sites - Green Building Construction
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
additive manufacturing of ss316l using mig welding
Lecture Notes Electrical Wiring System Components
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Foundation to blockchain - A guide to Blockchain Tech
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
CYBER-CRIMES AND SECURITY A guide to understanding
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.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