Share
Embed
Rethinking Reactive Architectures
NDC Oslo 2021
Video: https://youtu.be/L1Zgfr6bFvA
SQUER Solutions
December 02, 2021
Transcript
160 slides
-
Reactivity @duffleit and many more. “ Programming with, or designing
upon, asynchronous data streams. -
“ streams are just another data structure. @duffleit Time Space
Value Getter Setter Collections Iterators Generators Promise Deferred Resolver Stream Subscriber Emitter -
@duffleit What has this to do with reactivity? 🤔 “
Programming with, or designing upon, asynchronous data streams. -
@duffleit var counter = 2; var doubled = counter *
2; assert(doubled, 4); 1 2 3 4 ✅ -
@duffleit var counter = 2; var doubled = counter *
2; // updating the counter counter = 3; 1 2 3 4 5 -
@duffleit var counter = 2; var doubled = counter *
2; // updating the counter counter = 3; assert(doubled, 6) 1 2 3 4 5 6 7 💔 -
@duffleit var counter = 2; var doubled = counter *
2; // updating the counter counter = 3; doubled = counter * 2; 1 2 3 4 5 6 -
@duffleit var counter = 2; var doubled = counter *
2; // updating the counter counter = 3; doubled = counter * 2; assert(doubled, 6) 1 2 3 4 5 6 7 8 -
@duffleit var counter = 2; var doubled = counter *
2; // updating the counter counter = 3; doubled = counter * 2; assert(doubled, 6) 1 2 3 4 5 6 7 8 ✅ doubled 🔗 counter paulstovell.com/reactive-programming/ -
@duffleit var counter = 2; var doubled <= counter *
2; 1 2 doubled 🔗 counter 👆 -
@duffleit var counter = 2; var doubled <= counter *
2; // updating the counter counter = 3; 1 2 3 4 5 doubled 🔗 counter -
@duffleit var counter = 2; var doubled <= counter *
2; // updating the counter counter = 3; assert(doubled, 6) 1 2 3 4 5 6 7 doubled 🔗 counter ✅ -
@duffleit var counter = stream(2); 1 🔗 = streams 👈
counter: [2] -
@duffleit var counter = stream(2); var doubled = counter.map(x ->
x * 2) 1 2 👈 counter: [2] -
@duffleit var counter = stream(2); var doubled = counter.map(x ->
x * 2) 1 2 🔗 = streams 👆 counter: [2] -
@duffleit var counter = stream(2); var doubled = counter.map(x ->
x * 2) 1 2 👆 counter: [2] doubled: [4] -
@duffleit var counter = stream(2); var doubled = counter.map(x ->
x * 2) 1 2 “ we project the data from our counter stream into our doubled stream. 👆 counter: [2] doubled: [4] -
@duffleit var counter = stream(2); var doubled = counter.map(x ->
x * 2) // updating the counter 1 2 3 4 👈 counter: [2] doubled: [4] -
@duffleit var counter = stream(2); var doubled = counter.map(x ->
x * 2) // updating the counter counter.emit(3); 1 2 3 4 5 👈 counter: [2] doubled: [4] -
@duffleit var counter = stream(2); var doubled = counter.map(x ->
x * 2) // updating the counter counter.emit(3); 1 2 3 4 5 counter: [2, 3] doubled: [4] 👈 -
@duffleit var counter = stream(2); var doubled = counter.map(x ->
x * 2) // updating the counter counter.emit(3); 1 2 3 4 5 counter: [2, 3] doubled: [4, 6] 👈 -
@duffleit var counter = stream(2); var doubled = counter.map(x ->
x * 2) // updating the counter counter.emit(3); assert(doubled.value, 6) 1 2 3 4 5 6 7 👈 counter: [2, 3] doubled: [4, 6] ✅ -
@duffleit var counter = new BehaviorSubject<number>(2); var doubled = counter.pipe(map(x
-> x * 2)); // updating the counter counter.emit(3); 1 2 3 4 5 👈 -
@duffleit var counter = new BehaviorSubject<number>(2); var doubled = counter.pipe(map(x
-> x * 2)); // updating the counter counter.emit(3); assert(doubled.value, 6); 1 2 3 4 5 6 7 👈 ✅ -
@duffleit var counter = 2; $: doubled = counter *
2; // updating the counter counter = 3; 1 2 3 4 5 👈 -
@duffleit var counter = 2; $: doubled = counter *
2; // updating the counter counter = 3; assert(doubled, 6); 1 2 3 4 5 6 7 👈 ✅ -
@duffleit We can apply those Concepts of Reactive Programming on
Architecture as well. * and hope they still make sense. -
@duffleit User <μService> Account <μService> Legder <μService> WebBanking New Payment
💸 Perform Payment € 20, 00 👧 Lisa to David from transferMoney triggerPayment createTransactions -
@duffleit User <μService> Account <μService> Legder <μService> WebBanking Your payment
was successfully executed. transferMoney triggerPayment createTransactions ✅ -
@duffleit User <μService> Account <μService> Legder <μService> WebBanking New Payment
💸 Perform Payment € 20, 00 👧 Lisa to David from transferMoney triggerPayment createTransactions <μService> Legder Legder <μService> -
@duffleit User <μService> Account <μService> Legder <μService> WebBanking Your payment
was successfully executed. transferMoney triggerPayment createTransactions ✅ Retries Timeouts Circuit Breakers Synchronise -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment New Payment
💸 € 20, 00 👧 Lisa to David from Perform Payment <μService> Legder -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment New Payment
💸 € 20, 00 👧 Lisa to David from Perform Payment <μService> Legder -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions New
Payment 💸 € 20, 00 👧 Lisa to David from Perform Payment Queue <μService> Legder -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions New
Payment 💸 € 20, 00 👧 Lisa to David from Perform Payment Queue <μService> Legder -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions New
Payment 💸 € 20, 00 👧 Lisa to David from Perform Payment Queue <μService> Legder -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions New
Payment 💸 € 20, 00 👧 Lisa to David from Perform Payment Queue <μService> Legder -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions New
Payment 💸 € 20, 00 👧 Lisa to David from Perform Payment Queue <μService> Legder -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions Queue
<μService> Legder Your payment was accepted. ✅ -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions Queue
<μService> Legder Your payment was accepted. ✅ Legder <μService> -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions Queue
<μService> Legder Your payment was accepted. ✅ Legder <μService> -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions Queue
<μService> Legder Your payment was accepted. ✅ Legder <μService> Queue -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions Queue
<μService> Legder Your payment was accepted. ✅ Legder <μService> Queue Queue -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions New
Payment 💸 € 20, 00 👧 Lisa to David from Perform Payment Legder <μService> Queue Queue Queue -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions New
Payment 💸 € 20, 00 👧 Lisa to David from Perform Payment Legder <μService> Queue Queue Queue As a Customer, I want my transaction to be booked by the ledger. -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions New
Payment 💸 € 20, 00 👧 Lisa to David from Perform Payment Legder <μService> Queue Queue Queue As a Customer, I want the account service to update my balance. -
@duffleit User <μService> Account <μService> WebBanking transferMoney triggerPayment createTransactions New
Payment 💸 € 20, 00 👧 Lisa to David from Perform Payment Legder <μService> Queue Queue Queue As a Customer, I want to transfer money to someone else. -
@duffleit “ On the Criteria To Be Used in Decomposing
Systems into Modules — Parnas, 1972 -
@duffleit User <μService> Account <μService> WebBanking New Payment 💸 €
20, 00 👧 Lisa to David from Perform Payment Legder <μService> Payments <μService> Domain Services Journey Services As a Customer, I want to transfer money to someone else. -
@duffleit User <μService> Account <μService> WebBanking New Payment 💸 €
20, 00 👧 Lisa to David from Perform Payment Legder <μService> Web-BFF <μService> Domain Services Backend For Frontends As a Customer, I want to transfer money to someone else. Mobile-BFF <μService> Mobile Banking € 20, 00 Pay Payment Flow Payment Flow -
@duffleit No Domain Logic in Backend For Frontends. It's about
Ui-Specific Aggregation, to get rid of over-fetching and over-requesting. -
@duffleit User <μService> Account <μService> WebBanking New Payment 💸 €
20, 00 👧 Lisa to David from Perform Payment Legder <μService> Payments <μService> Domain Services Journey Services -
@duffleit User <μService> Account <μService> WebBanking New Payment 💸 €
20, 00 👧 Lisa to David from Perform Payment Legder <μService> Payments <μService> Domain Services Journey Services Balance <μService> -
@duffleit User Account WebBanking New Payment 💸 € 20, 00
👧 Lisa to David from Perform Payment Transactions Payments Domain Services Journey Services Onboarding Fraud Detection User Account Account Transactions -
@duffleit User Account WebBanking New Payment 💸 € 20, 00
👧 Lisa to David from Perform Payment Transactions Payments Domain Services Journey Services Onboarding Fraud Detection User Account Account Transactions ⚡ ⚡ ⚡ -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Service Autnomy -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Data Duplication ⚡ -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Data Syncronisation 🤯 ⚡ -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Synchronous Calls 😔 -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Synchronous Calls 😔 -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Cache Account Transactions Synchronous Calls 😔 -
@duffleit “ we project data from our counter variable into
our doubled variable. There must be a better solution 🤔 -
@duffleit “ we project the data from our onboarding service
into our payments service. There must be a better solution 🤔 Payments User Onboarding User project -
@duffleit Payments Onboarding User Aggregate User Readmodel UserChangedEvent UserChange Command
That's CQRS in a nutshell 🥜 updates -
@duffleit Payments Onboarding User Aggregate User Readmodel UserChange Command Stream
UserChangedEvent transform apply -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream Projections -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream Projections -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream Projections -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream Projections -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream Projections -
@duffleit Eventual Consistency Eventual Divergence Dashboard User (age: 22) UserChanged
(age: 21) UserChanged (age: 22) Profile User (age: 21) ⚡ timestamp timestamp -
@duffleit Eventual Consistency Eventual Divergence Eventual Variance Ledger Dashboard Stream
🔥 Transaction (+10€) Transaction (+10€) Balance: 20€ -
@duffleit Eventual Consistency Eventual Divergence Eventual Variance Eventual Latency Service
B Stream UserChanged (age: 21) UserChanged (age: 22) Profile User (age: 21) Dashboard User (age: 21) User (age: 22) -
Single User Context @duffleit Eventual Consistency Eventual Divergence Eventual Variance
Eventual Latency Service B Stream UserChanged (age: 21) UserChanged (age: 22) Profile User (age: 21) Dashboard User (age: 21) User (age: 22) 🕰 -
@duffleit Eventual Consistency Eventual Divergence Eventual Variance Eventual Latency same
events, different results. same events, different quantity. same events, different realisation. Ordering Guarantees Optimistic UIs At-Least-Once Delivery Deduplication Mechanisms -
@duffleit tl/dr: Eventual Consistency is often used as a knock-out
argument but isn't, in most cases. -
@duffleit WebBanking New Payment 💸 € 20, 00 👧 Lisa
to David from Perform Payment Payments Journey Services Onboarding Fraud Detection User Account Account Transactions User Account Transactions Stream Projections -
@duffleit Mobile Banking Usage 93% — Show balance & last
transactions 3% — Initiate new payment 4% — Any other functionality -
@duffleit Payments Journey Services Onboarding Overview User Account Account Transactions
User Account Transactions Stream -
@duffleit Payments Journey Services Onboarding Overview User Account Account Transactions
User Account Transactions Stream -
@duffleit Payments Journey Services Onboarding Overview User Account Account Transactions
User Account Transactions Stream -
@duffleit Payments Journey Services Onboarding Overview User Account Account Transactions
User Account Transactions Stream -
@duffleit Payments Journey Services Onboarding Overview User Account Account Transactions
User Account Transactions Stream -
@duffleit Payments Journey Services Onboarding Overview User Account Account Transactions
User Account Transactions Stream 93% of what our users need can still be performed. WebBanking Current Balance: 200€ 👧 You sent Lisa 100€ Christoph sent you 300€ -
@duffleit WebBanking Current Balance: 200€ 👧 You sent Lisa 100€
Christoph sent you 300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream Overview Transactions We can easily scale horizontally. -
@duffleit WebBanking Current Balance: 200€ 👧 You sent Lisa 100€
Christoph sent you 300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream Overview Transactions We can easily scale horizontally. -
@duffleit WebBanking of David Current Balance: 300€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment -
@duffleit WebBanking of David Current Balance: 300€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment -
@duffleit WebBanking of David Current Balance: 300€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment -
@duffleit WebBanking of David Current Balance: 300€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment -
@duffleit WebBanking of David Current Balance: 300€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment -
@duffleit WebBanking of David Current Balance: 300€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment -
@duffleit WebBanking of David Current Balance: 300€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment -
@duffleit WebBanking of David Current Balance: 300€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment 👧 Lisa sent you 20€ -
@duffleit WebBanking of David Current Balance: 320€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment 👧 Lisa sent you 20€ -
@duffleit WebBanking of David Current Balance: 320€ Christoph sent you
300€ Payments Journey Services Onboarding Overview User Account Transactions User Account Transactions Stream WebBanking of Lisa 👧 New Payment 💸 € 20, 00 David to 👧 Lisa from Perform Payment 👧 Lisa sent you 20€ GraphQL subscriptions mutations Out-of-the-box real-time capabilities. -
@duffleit WebBanking of David Current Balance: 320€ Christoph sent you
300€ Payments Journey Services Legacy System Accounts Stream 👧 Lisa sent you 20€ User 😮 💨😮 💨 😮 💨 Change Data Capture (CDC) User User -
Third Generation of MicroServices Fully Reactive @duffleit High Resilience 🔥
Horizontal Scaling ↔ Real Time Integration ⏱ Good Integration with Legacy Systems 🏚 -
Dimensions of Scaling Vertical Horizontal Service Service Service Sharding Users
A-H Users I-P Users Q-Z -
Dimensions of Scaling Vertical Horizontal Service Service Service User from
User from Users from Service Service Service Sharding -
@duffleit Stream UserTriggeredPayment Partition 0 Partition 1 Partition 2 UserTriggeredPayment
Payments Payments Payments -
@duffleit Stream UserTriggeredPayment Partition 0 Partition 1 Partition 2 UserTriggeredPayment
Payments Payments Payments ValidPaymentReceived -
@duffleit Stream UserTriggeredPayment Partition 0 Partition 1 Partition 2 UserTriggeredPayment
Payments Payments Payments Stream ValidPaymentReceived Partition 0 Partition 1 Partition 2 -
Fraud Detection Fraud Detection @duffleit Stream UserTriggeredPayment Partition 0 Partition
1 Partition 2 UserTriggeredPayment Payments Payments Payments Stream ValidPaymentReceived Partition 0 Partition 1 Partition 2 Fraud Detection PaymentCheckedAgainstFraud -
Fraud Detection Fraud Detection @duffleit Stream UserTriggeredPayment Partition 0 Partition
1 Partition 2 UserTriggeredPayment Payments Payments Payments Stream ValidPaymentReceived Partition 0 Partition 1 Partition 2 Fraud Detection Stream PaymentChecked Partition 0 Partition 1 Partition 2 -
Fraud Detection Fraud Detection @duffleit Stream UserTriggeredPayment Partition 0 Partition
1 Partition 2 UserTriggeredPayment Payments Payments Payments Stream ValidPaymentReceived Partition 0 Partition 1 Partition 2 Fraud Detection Stream PaymentChecked Partition 0 Partition 1 Partition 2 Ledger Ledger Ledger TransactionBooked -
Fraud Detection Fraud Detection @duffleit Stream UserTriggeredPayment Partition 0 Partition
1 Partition 2 UserTriggeredPayment Payments Payments Payments Stream ValidPaymentReceived Partition 0 Partition 1 Partition 2 Fraud Detection Stream PaymentChecked Partition 0 Partition 1 Partition 2 Ledger Ledger Ledger Partition 0 Partition 1 Partition 2 Stream TransactionBooked Project Transactions Streams Flink -
Fraud Detection Fraud Detection @duffleit Stream UserTriggeredPayment Partition 0 Partition
1 Partition 2 UserTriggeredPayment Payments Payments Payments Stream ValidPaymentReceived Partition 0 Partition 1 Partition 2 Fraud Detection Stream PaymentChecked Partition 0 Partition 1 Partition 2 Ledger Ledger Ledger Partition 0 Partition 1 Partition 2 Stream TransactionBooked Project Transactions Shard 0 Shard 1 Shard 2 DataSink WebBanking Current Balance: 200€ 👧 You sent Lisa 100€ Christoph sent you 300€ Streams Flink -
Fraud Detection Fraud Detection @duffleit Stream UserTriggeredPayment Partition 0 Partition
1 Partition 2 UserTriggeredPayment Payments Payments Payments Stream ValidPaymentReceived Partition 0 Partition 1 Partition 2 Fraud Detection Stream PaymentChecked Partition 0 Partition 1 Partition 2 Ledger Ledger Ledger Partition 0 Partition 1 Partition 2 Stream TransactionBooked Project Transactions WebBanking Current Balance: 200€ 👧 You sent Lisa 100€ Christoph sent you 300€ Shard 0 Shard 1 Shard 2 DataSink Streams Flink -
Fraud Detection Fraud Detection @duffleit Stream UserTriggeredPayment Partition 0 Partition
1 Partition 2 UserTriggeredPayment Payments Payments Payments Stream ValidPaymentReceived Partition 0 Partition 1 Partition 2 Fraud Detection Stream PaymentChecked Partition 0 Partition 1 Partition 2 Ledger Ledger Ledger Partition 0 Partition 1 Partition 2 Stream TransactionBooked Project Transactions WebBanking Current Balance: 200€ 👧 You sent Lisa 100€ Christoph sent you 300€ Shard 0 Shard 1 Shard 2 DataSink 🚀 We can scale nearly unlimited. -
Forth Generation of MicroServices Stream Based @duffleit Massive Throughput 🚀
Extremely Scalable ↔ -
Monolith Reactive Push-Based Async Pull-Based Streamed Availability 🟢 , Resilience
🦺 , Scalability ↔ , Throughput 🚀 Complexity 💰 @duffleit -
Monolith Reactive Push-Based Async Pull-Based Streamed @duffleit The Rise of
Reactive Microservices. And the future of fully Stream Based Architectures.