"Offline mode for a mobile application, redux on server and a little bit about event sourcing." talk at React Native Camp by Viktor Turskyi
Offline mode for a mobile application
Redux on server and a little bit about event sourcing
Viktor Turskyi
React Native CAMP Conference 2018
About me
● CTO at WebbyLab
● Open Source developer
(Perl, JavaScript)
● 13 years in Software
development
● Successfully delivered more
than 60 projects
Classical 3-tier architecture
Stateless
Source: https://www.mrc-productivity.com/blog/2011/01/mobile-applications-why-architecture-matters/
Classical database
REST API (CRUD)
What if your data is
Large append-only log
Just huge list of immutable facts
Everything else is a cache
Source: https://www.mrc-productivity.com/blog/2011/01/mobile-applications-why-architecture-matters/
Classical approach (mutate state)
Initial DB state:
BALANCE 100USD
User spends 30 USD
New DB state:
BALANCE 70 USD
Event sourcing (append fact)
Initial DB state:
FUNDS_ADDED 25 USD
FUNDS_ADDED 61 USD
FUNDS_SPENT 10 USD
FUNDS_ADDED 24 USD
User spends 30 USD
New DB state:
FUNDS_ADDED 25 USD
FUNDS_ADDED 61 USD
FUND_SPENT 10 USD
FUNDS_ADDED 24 USD
FUNDS_SPENT 30 USD
Event sourcing
Source:https://docs.microsoft.com/en-us/azure/architecture/patterns/event-sourcing
Why to use event sourcing?
● Build specific materialized views for different business domains
● Capture intent of the data, track user behaviour (not only results)
● Audit trail
● Possibility to rollback to any previous state
● Minimize data conflicts
● High processing performance (gracefully degrade on load, no locks)
● Flexibility to change format of materialized view (replay events)
Business task - create LMS for compliance
● Create training app (training == quiz): iOS, Android, Web
● Offline mode for mobile (read and write)
● Audit trail support
● Detailed analytics in mobile, web, nodejs
● Constantly evolving requirements to analytics
Mobile
Web
Session (user) metrics
● Training adoption burndown chart
● Adoption level
● Predict time to finish
● Spent time in training
● Monthly activity charts
● Spent time on each question
Training (group) metrics
● Training adoption burndown chart
● Aggregated students activity
● Adoption level for group
● etc
Technologies
Mobile: React Native + Redux
Web: React + Redux
Backend: NodeJs + Mongo + Redux?
Event sourcing
Source: https://www.confluent.io/blog/event-sourcing-cqrs-stream-processing-apache-kafka-whats-connection/
Redux
Source: https://itnext.io/integrating-semantic-ui-modal-with-redux-4df36abb755c?gi=5cd4056739b8
"Offline mode for a mobile application, redux on server and a little bit about event sourcing." talk at React Native Camp by Viktor Turskyi
Merge Redux with event sourcing
● Client: create temporary queue
● Client: Add timestamp to every event
● Server: split event handlers into two parts:
○ Pure functions with business logic (reducer)
○ Side effects containing utils (db utils etc)
● Server: Use immutable structures for metrics.
● Client and Server share the same reducers
"Offline mode for a mobile application, redux on server and a little bit about event sourcing." talk at React Native Camp by Viktor Turskyi
Now we do have offline mode for free
Event creation (mobile)
"Offline mode for a mobile application, redux on server and a little bit about event sourcing." talk at React Native Camp by Viktor Turskyi
Send events (mobile)
What do we use for events persistence in RN?
RN AsyncStorage for redux store
react-native-fs for large blobs (images, audio etc)
Events structure (mongoose schema)
Event handler initialization in app.js
EventHandler - main
Never mutate events
Instead store reference to last applied event in metrics
Track processed events
Code structure
Main issues to solve
Mobile: Store larger number of events in offline mode
Backend: Store events in a more suitable place (Kafka)
Backend: Split the event queue into “realtime” and “delayed”
Links
Event Sourcing pattern by Microsoft
https://docs.microsoft.com/en-us/azure/architecture/patterns/event-sourcing
Event Sourcing pattern by Martin Fowler
https://martinfowler.com/eaaDev/EventSourcing.html
"Turning the database inside out with Apache Samza" by Martin Kleppmann
https://www.youtube.com/watch?v=fU9hR3kiOK0
Viktor Turskyi (koorchik)
viktor@webbylab.com
https://twitter.com/koorchik https://twitter.com/webbylab
https://github.com/koorchik https://github.com/webbylab
http://webbylab.com

More Related Content

PDF
Apache Airflow at Dailymotion
PDF
From business requirements to working pipelines with apache airflow
PPTX
Quick prototyping with VulcanJS
PPTX
Apache Airflow overview
PDF
Airflow introduction
PDF
Airflow presentation
PDF
Building an analytics workflow using Apache Airflow
PPTX
Stream Processing Live Traffic Data with Kafka Streams
Apache Airflow at Dailymotion
From business requirements to working pipelines with apache airflow
Quick prototyping with VulcanJS
Apache Airflow overview
Airflow introduction
Airflow presentation
Building an analytics workflow using Apache Airflow
Stream Processing Live Traffic Data with Kafka Streams

What's hot (20)

PDF
Industrializing Machine learning pipelines
PDF
How I learned to time travel, or, data pipelining and scheduling with Airflow
PDF
Apache Airflow
PDF
Web App Prototypes with Google App Engine
PDF
Orchestrating workflows Apache Airflow on GCP & AWS
PDF
Apache Airflow
PDF
Lambda architecture
PDF
Sprint 74
PDF
Sprint 73
PDF
Productionize spark structured streaming
PDF
Apache airflow
PDF
Stream Processing Live Traffic Data with Kafka Streams
PDF
Building a Data Pipeline using Apache Airflow (on AWS / GCP)
PDF
Intro to Airflow: Goodbye Cron, Welcome scheduled workflow management
PDF
Introducing MagnetoDB, a key-value storage sevice for OpenStack
PDF
Vocanic Map Reduce Lite
PPTX
Serverless GraphQL. AppSync 101
PDF
Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...
PDF
Sprint 75
PPTX
【EDD Workshop@140718】eztable architecture hao kang den
Industrializing Machine learning pipelines
How I learned to time travel, or, data pipelining and scheduling with Airflow
Apache Airflow
Web App Prototypes with Google App Engine
Orchestrating workflows Apache Airflow on GCP & AWS
Apache Airflow
Lambda architecture
Sprint 74
Sprint 73
Productionize spark structured streaming
Apache airflow
Stream Processing Live Traffic Data with Kafka Streams
Building a Data Pipeline using Apache Airflow (on AWS / GCP)
Intro to Airflow: Goodbye Cron, Welcome scheduled workflow management
Introducing MagnetoDB, a key-value storage sevice for OpenStack
Vocanic Map Reduce Lite
Serverless GraphQL. AppSync 101
Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...
Sprint 75
【EDD Workshop@140718】eztable architecture hao kang den
Ad

Similar to "Offline mode for a mobile application, redux on server and a little bit about event sourcing." talk at React Native Camp by Viktor Turskyi (20)

DOC
ChandanResume
PDF
Google Cloud Dataflow
PDF
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
PDF
Angular (v2 and up) - Morning to understand - Linagora
PDF
Cloud-Native Patterns for Data-Intensive Applications
PDF
Cloud APIs Overview Tucker
PDF
Big rewrites without big risks
PDF
Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference
PDF
exploring-spring-boot-clients.pdf Spring Boot
PDF
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
PDF
Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...
PDF
Apache Flink Adoption at Shopify
PDF
Thinking DevOps in the era of the Cloud - Demi Ben-Ari
PPTX
StrongLoop Overview
PDF
A presentationon SPRING-BOOT and CRUD operation
PDF
Accelerating Digital Transformation: It's About Digital Enablement
PPTX
Raising ux bar with offline first design
DOC
B.Karthik
PDF
Google Cloud Dataflow Two Worlds Become a Much Better One
PDF
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
ChandanResume
Google Cloud Dataflow
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
Angular (v2 and up) - Morning to understand - Linagora
Cloud-Native Patterns for Data-Intensive Applications
Cloud APIs Overview Tucker
Big rewrites without big risks
Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference
exploring-spring-boot-clients.pdf Spring Boot
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...
Apache Flink Adoption at Shopify
Thinking DevOps in the era of the Cloud - Demi Ben-Ari
StrongLoop Overview
A presentationon SPRING-BOOT and CRUD operation
Accelerating Digital Transformation: It's About Digital Enablement
Raising ux bar with offline first design
B.Karthik
Google Cloud Dataflow Two Worlds Become a Much Better One
Monitoring Big Data Systems Done "The Simple Way" - Codemotion Milan 2017 - D...
Ad

More from Viktor Turskyi (19)

PDF
How to create a high performance excel engine in java script
PDF
Livr 2.0 in JS - Vinnytsia.JS 2019
PDF
The working architecture of node js applications open tech week javascript ...
PDF
Yet another json rpc library (mole rpc)
PDF
KharkivJS 2018 Information Security Practice
PDF
The working architecture of NodeJs applications
PDF
Language Independent Validation Rules 2.0, Viktor Turskyi, talk at OSDN 2017
PDF
How to extract information from text with Semgrex
PDF
How to translate your Single Page Application - Webcamp 2016 (en)
PDF
JS Lab 2016 - Frontend trends 2015 - 2016
PDF
It's Quiz - Cloud testing platform
PDF
Kharkiv JS 2015 - Creating isomorphic applications in React (en)
PDF
Kharkiv JS 2015: Боль и радость создания изоморфных приложений на ReactJS (RU)
PDF
Language Independent Validation Rules (LIVR)
PDF
Hadoop webcamp 2015
PDF
Mapreduce in JavaScript
PDF
Excel in Javascript
PDF
Testing orm based code
ODP
Maybe you do not know that ...
How to create a high performance excel engine in java script
Livr 2.0 in JS - Vinnytsia.JS 2019
The working architecture of node js applications open tech week javascript ...
Yet another json rpc library (mole rpc)
KharkivJS 2018 Information Security Practice
The working architecture of NodeJs applications
Language Independent Validation Rules 2.0, Viktor Turskyi, talk at OSDN 2017
How to extract information from text with Semgrex
How to translate your Single Page Application - Webcamp 2016 (en)
JS Lab 2016 - Frontend trends 2015 - 2016
It's Quiz - Cloud testing platform
Kharkiv JS 2015 - Creating isomorphic applications in React (en)
Kharkiv JS 2015: Боль и радость создания изоморфных приложений на ReactJS (RU)
Language Independent Validation Rules (LIVR)
Hadoop webcamp 2015
Mapreduce in JavaScript
Excel in Javascript
Testing orm based code
Maybe you do not know that ...

Recently uploaded (20)

PPTX
DATA STRCUTURE LABORATORY -BCSL305(PRG1)
PPTX
AI-Reporting for Emerging Technologies(BS Computer Engineering)
PDF
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
PPT
Programmable Logic Controller PLC and Industrial Automation
PDF
Software defined netwoks is useful to learn NFV and virtual Lans
PPTX
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
PDF
Project_Mgmt_Institute_-Marc Marc Marc .pdf
PDF
Cryptography and Network Security-Module-I.pdf
PPT
UNIT-I Machine Learning Essentials for 2nd years
PDF
V2500 Owner and Operatore Guide for Airbus
PDF
IAE-V2500 Engine Airbus Family A319/320
PPTX
BBOC407 BIOLOGY FOR ENGINEERS (CS) - MODULE 1 PART 1.pptx
DOCX
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
PPTX
WN UNIT-II CH4_MKaruna_BapatlaEngineeringCollege.pptx
PDF
Using Technology to Foster Innovative Teaching Practices (www.kiu.ac.ug)
PDF
ECT443_instrumentation_Engg_mod-1.pdf indroduction to instrumentation
PDF
CELDAS DE COMBUSTIBLE TIPO MEMBRANA DE INTERCAMBIO PROTÓNICO.pdf
PDF
Lesson 3 .pdf
PPTX
Real Estate Management PART 1.pptxFFFFFFFFFFFFF
PDF
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
DATA STRCUTURE LABORATORY -BCSL305(PRG1)
AI-Reporting for Emerging Technologies(BS Computer Engineering)
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
Programmable Logic Controller PLC and Industrial Automation
Software defined netwoks is useful to learn NFV and virtual Lans
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
Project_Mgmt_Institute_-Marc Marc Marc .pdf
Cryptography and Network Security-Module-I.pdf
UNIT-I Machine Learning Essentials for 2nd years
V2500 Owner and Operatore Guide for Airbus
IAE-V2500 Engine Airbus Family A319/320
BBOC407 BIOLOGY FOR ENGINEERS (CS) - MODULE 1 PART 1.pptx
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
WN UNIT-II CH4_MKaruna_BapatlaEngineeringCollege.pptx
Using Technology to Foster Innovative Teaching Practices (www.kiu.ac.ug)
ECT443_instrumentation_Engg_mod-1.pdf indroduction to instrumentation
CELDAS DE COMBUSTIBLE TIPO MEMBRANA DE INTERCAMBIO PROTÓNICO.pdf
Lesson 3 .pdf
Real Estate Management PART 1.pptxFFFFFFFFFFFFF
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL

"Offline mode for a mobile application, redux on server and a little bit about event sourcing." talk at React Native Camp by Viktor Turskyi