SlideShare a Scribd company logo
Reactive Android: RxJava & beyond
Fabio Tiriticco / @ticofab
AMSTERDAM 11-12 MAY 2016
A little info about myself
Android	Engineer	
Scala	Engineer
The Reactive Amsterdam meetup
Reactive Amsterdam
Because nobody knows what Reactive means
To explore the concept in all of its forms.
“Reactive” in the vocabulary
Reactive (adjective):
Tending to act in response to an agent or influence
Reactive Confusion
“I	was	thinking	of	using	Node.js,	but	
maybe	I	can	build	it	with	Reactive.”
“Thanks	for	running	a	meetup	about	React.js”
Reactive Confusion
• The	concept	of	“Reactive”	has	common	
basis	but	slightly	different	meanings	in	
each	domain
• Most	of	us	think	that	Reactive	==	React.js
Two	main	observations:
Reactive in (Android) frontend VS backend
ANDROID
Using	RxJava
WHAT	DO	PEOPLE	THINK	THAT	
“BEING	REACTIVE”	MEANS?
BACKEND
?
Hello, RxJava!
• Asynchronous	programming	
• Observable	streams
Open	source	libraries	for
Hello, RxJava!
Mobile	engineering	is	hard	and	there	are	high	expectations.
RxJava	is	cool	because
• it	makes	it	super	easy	to	switch	between	threads	
• lets	us	deal	with	data	as	a	stream	
• brings	us	some	degree	of	functional	programming.
RxJava goes hand in hand with Java8’s Lambdas
new Func1<String, Integer>() {
@Override
public Integer call(String s) {
return s.length();
}
}
(String s) -> {
return s.length();
}
s -> s.length();
Retrolamba	plugin	for	
Android	<	N
RxJava: dealing with a stream of items
class Cat {
...
public Collar getCollar() {…}
public Picture fetchPicture() {…}
...
}
RxJava: dealing with a stream of items
Observable.from(myCats);
(cat -> Log.d(TAG, “got cat”));
List<Cat> myCats;
Observable obs =
obs.subscribe
RxJava: dealing with a stream of items
Observable.from(myCats)
.subscribe(cat -> Log.d(TAG, “got cat”));
List<Cat> myCats;
RxJava: work on the stream
Observable.from(myCats)
.map(cat -> cat.getCollar())
.subscribe(collar -> Log.d(TAG, “got collar”));
map: T -> R
(this map: Cat -> Collar)
RxJava: operators to manipulate the stream
Observable.from(myCats)
.distinct()
.delay(2, TimeUnit.SECONDS)
.filter(cat -> cat.isWhite())
.subscribe(cat -> Log.d(TAG, “got white cat”));
Observable.from(myCats)
.subscribe(
cat -> Log.d(TAG, “cat”),
error -> error.printStackTrace(),
() -> Log.d(TAG, “done”)
);
RxJava: subscriber interface
Observable<T>.from(myCats)
.subscribe(
onNext<T>, // next item T
onError, // throwable
onComplete // void
);
Observable.from(myCats)
.subscribe(cat -> Log.d(TAG, “cat”));
RxJava: unsubscribe
Subscription subs =
subs.unsubscribe();
RxJava: threading
Observable.from(myCats)
.map(cat -> cat.fetchPicture())
.map(picture -> Filter.applyFilter(picture))
.subscribe(
filteredPicture -> display(filteredPicture)
);
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
RxJava: other ways of creating Observables
// emits on single item and completes
Observable.just
// emits one item after a certain delay
Observable.timer
.. plus many others, and you can create your own!
RxJava: demo with Retrofit & Meetup Streams
http://stream.meetup.com/2/rsvp
Meetup Streaming API
RxJava: demo with Meetup Streams
RxJava: demo with Retrofit & Meetup Streams
interface MeetupAPI {
@GET("http://stream.meetup.com/2/rsvp")
@Streaming
Observable<ResponseBody> meetupStream();
}
RxJava: demo with RSVP Meetup Streams
meetupAPI.meetupStream()
...
.flatMap(responseBody -> events(responseBody.source()))
.map(string -> gson.fromJson(string, RSVP.class))
...
.subscribe(rsvp -> ...);
map: T -> R
flatMap: T -> Observable<R>
RxJava: demo with Meetup Streams
RxJava: demo with Meetup Streams
https://github.com/ticofab/android-meetup-streams
Reactive in (Android) frontend VS backend
ANDROID
Using	RxJava
WHAT	DO	PEOPLE	THINK	THAT	
“BEING	REACTIVE”	MEANS?
BACKEND
?
Evolution of server applications & user expectations
2006 2016
Servers ~10 The	sky	is	the	limit.
Response	time seconds milliseconds
Offline	maintenance hours what?
Data	amount Gigabytes Petabytes
Machines Single	core,	little	distribution
Must	work	across	async	
boundaries	(location,	threads)
Kind	of	data Request	-	response Streams	(endless)
Evolution of internet usage
The Reactive traits
A	reactive	computer	system	must Trait
React	to	its	users Responsive
React	to	failure	and	stay	available Resilient
React	to	varying	load	conditions Elastic
Its	components	must	react	to	inputs Message-driven
The Reactive Manifesto
Responsive
ResilientElastic
Message	Driven
Reactive traits: Responsive
• A	human	who	visits	a	website	
• A	client	which	makes	a	request	to	a	server	
• A	consumer	which	contacts	a	provider	
• .	.	.	
A	Reactive	system	responds	to	inputs	and	usage	from	its	user.
Reactive traits: Elastic
• Scale	OUT	and	IN:	use	just	the	right	amount	
• Elasticity	relies	on	distribution	
• Ensure	replication	in	case	of	failure
Scale	on	demand	to	react	to	varying	load
Reactive traits: Resilient
It	doesn't	matter	how	great	your	application	is	if	it	doesn't	work.
FAULT	TOLERANCE RESILIENCEVS
Reactive traits: Message Driven
Reactive	systems	design	concentrates	on	Messages.
Asynchronous	messaging	enables:
• Separation	between	components	
• Error	containment	-	avoid	chain	failures	
• Domain	mapping	closer	to	reality
The Reactive Manifesto, take 2
Responsive
ResilientElastic
Message	Driven
Why Functional Programming?
More	supportive	of	reasoning	about	problems	in	concurrent	and	
parallelised	applications.
• encourages	use	of	pure	functions	-	minimise	side	effects	
• encourages	immutability	-	state	doesn’t	get	passed	around	
• higher-order	functions	-	reusability	and	composability
Reactive Patterns
Design	patterns	to	achieve	Reactive	principles.	
Toolkits	exist	to	implement	these	patterns.
Reactive Pattern: Simple Component Pattern
“One	component	should	do	only	one	thing	but	do	it	in	full.	The	aim	is	to	
maximise	cohesion	and	minimise	coupling	between	components.”
Reactive Pattern: Simple Component Pattern
Actor	1
	Actor	3
Actor	2
• contains	state	
• has	a	mailbox	to	receive	
and	send	messages	
• contains	behaviour	logic	
• has	a	supervisor
Actor	model Supervisor
Reactive Patterns: Let it crash!
"Prefer	a	full	component	restart	to	complex	internal	failure	handling".
• failure	conditions	WILL	occur	
• they	might	be	rare	and	hard	to	reproduce	
• it	is	much	better	to	start	clean	than	to	try	to	recover	
• …which	might	be	expensive	and	difficult!
Reactive Android: RxJava and beyond
Reactive Patterns: Let it crash!
• Components	should	be	isolated	-	state	is	not	shared	
• Components	should	have	a	supervisor	and	delegate	to	it	
some	or	all	error	handling	
• The	supervisor	can	transparently	restart	the	component	
• Message-passing	architectures	enforce	state	
confinement,	error	containment	and	transparency
In	practice…
Reactive Patterns: Let it crash!
Actor	supervision	example
Actor	1
	Actor	2
Supervisor
WhateverException!
X
Fix	or	
Restart
Reactive Patterns: Let it crash!
• the	machine	only	
accepts	exact	change
Reactive Patterns: Let it crash!
Scenario	1:	
The	user	inserts	wrong	
amount	of	coins
X
Error!
Reactive Patterns: Let it crash!
Scenario	2:	
The	machine	is	out	of	
coffee	beans
Failure!
(	!=	error)
Reactive Patterns: Let it crash!
Reactive Patterns: Let it crash!
Randomly	kills	instances	
of	their	AWS	system	to	
ensure	that	no	failure	is	
propagated.
BACKEND
?
BACKEND
Elasticity
Asyncrhonicity
Resilience
Supervision
Message	passing
State	encapsulation
Streams
Backpressure
…
Reactive in (Android) frontend VS backend
ANDROID
Using	RxJava
WHAT	DO	PEOPLE	THINK	THAT	
“BEING	REACTIVE”	MEANS?
Reactive traits in Android?
Can	we	apply	some	of	the	Reactive	Manifesto	
principles	to	our	Android	development?
Reactive traits in Android?
Reactive	trait In	Android?
Responsive Execute	as	much	as	possible	asynchronously
Elastic —
Resilient Delegate	risky	stuff	to	(Intent)Services	or	isolated	components
Message	passing
Communication	via	ResultReceiver	
Use	some	event	Bus
Reactive traits in Android?
…but	I	am	sure	that	we	can	take	this	further.
Resources
https://github.com/ReactiveX/RxJava/wiki RxJava	documentation	&	wiki
http://rxmarbles.com RxJava	operators	explained	visually
http://www.reactivemanifesto.org The	reactive	manifesto
https://www.youtube.com/watch?v=fNEZtx1VVAk	
https://www.youtube.com/watch?v=ryIAibBibQI	
https://www.youtube.com/watch?v=JvbUF33sKf8
The	Reactive	Revealed	series:	awesome	webinars	by	the	
creators	of	the	Reactive	Manifesto.
https://www.manning.com/books/reactive-design-patterns	
https://www.youtube.com/watch?v=nSfXcSWq0ug
Reactive	design	patterns,	book	and	webinar.
Thanks!
@ticofab
All pictures belong
to their respective authors
AMSTERDAM 11-12 MAY 2016

More Related Content

PDF
RxJava for Android - GDG DevFest Ukraine 2015
PDF
Practical RxJava for Android
PPTX
Reactive Programming on Android - RxAndroid - RxJava
PDF
The Mayans Lost Guide to RxJava on Android
PDF
RxJava@Android
PDF
RxJava on Android
PPTX
An Introduction to RxJava
PDF
Streams, Streams Everywhere! An Introduction to Rx
RxJava for Android - GDG DevFest Ukraine 2015
Practical RxJava for Android
Reactive Programming on Android - RxAndroid - RxJava
The Mayans Lost Guide to RxJava on Android
RxJava@Android
RxJava on Android
An Introduction to RxJava
Streams, Streams Everywhere! An Introduction to Rx

What's hot (20)

PDF
RxJava from the trenches
PDF
Reactive programming with RxJava
PDF
Introduction to Retrofit and RxJava
PDF
Practical RxJava for Android
PDF
Reactive programming on Android
PDF
Intro to RxJava/RxAndroid - GDG Munich Android
PDF
Rxjava 介紹與 Android 中的 RxJava
PDF
GKAC 2015 Apr. - RxAndroid
PDF
RxJava 2.0 介紹
PPTX
Reactive programming with RxAndroid
PPTX
Introduction to rx java for android
PPTX
Introduction to RxJava on Android
PDF
rx-java-presentation
PPTX
Reactive Java (33rd Degree)
PPTX
Rx java in action
PDF
RxJava in practice
PDF
Building Scalable Stateless Applications with RxJava
PPTX
RxJava Applied
PPTX
Reactive Java (GeeCON 2014)
PDF
Reactive programming using rx java & akka actors - pdx-scala - june 2014
RxJava from the trenches
Reactive programming with RxJava
Introduction to Retrofit and RxJava
Practical RxJava for Android
Reactive programming on Android
Intro to RxJava/RxAndroid - GDG Munich Android
Rxjava 介紹與 Android 中的 RxJava
GKAC 2015 Apr. - RxAndroid
RxJava 2.0 介紹
Reactive programming with RxAndroid
Introduction to rx java for android
Introduction to RxJava on Android
rx-java-presentation
Reactive Java (33rd Degree)
Rx java in action
RxJava in practice
Building Scalable Stateless Applications with RxJava
RxJava Applied
Reactive Java (GeeCON 2014)
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Ad

Similar to Reactive Android: RxJava and beyond (20)

PDF
Reactive in Android and Beyond Rx
PPTX
Reactive for the Impatient - Mary Grygleski
PPT
Reactive java programming for the impatient
PDF
An introduction to Reactive applications, Reactive Streams, and options for t...
PDF
Modern app programming with RxJava and Eclipse Vert.x
PDF
Moving towards Reactive Programming
PDF
Reactive Streams and the Wide World of Groovy
PDF
A Quick Intro to ReactiveX
PDF
RxJava pour Android : présentation lors du GDG Android Montréal
PDF
Reactive Thinking in Java with RxJava2
PDF
What is rxjava?
PDF
An Introduction to Reactive Application, Reactive Streams, and options for JVM
PDF
RxJava - introduction & design
PPTX
Reactive programming
PDF
Reactive Functional Programming with Java 8 on Android N
PDF
Reactive Applications
PDF
Go reactive - Manuel Vicente Vivo
PPTX
Reactive programming with rx java
PPTX
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
PPTX
The Reactive Landscape
Reactive in Android and Beyond Rx
Reactive for the Impatient - Mary Grygleski
Reactive java programming for the impatient
An introduction to Reactive applications, Reactive Streams, and options for t...
Modern app programming with RxJava and Eclipse Vert.x
Moving towards Reactive Programming
Reactive Streams and the Wide World of Groovy
A Quick Intro to ReactiveX
RxJava pour Android : présentation lors du GDG Android Montréal
Reactive Thinking in Java with RxJava2
What is rxjava?
An Introduction to Reactive Application, Reactive Streams, and options for JVM
RxJava - introduction & design
Reactive programming
Reactive Functional Programming with Java 8 on Android N
Reactive Applications
Go reactive - Manuel Vicente Vivo
Reactive programming with rx java
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
The Reactive Landscape
Ad

More from Fabio Tiriticco (12)

PDF
Intro slides - Global Reactive Meetup - Move over JDBC!
PDF
Planespotting - From Zero To Deep Learning
PDF
From Zero To Deep Learning With Scala
PDF
Reactive Amsterdam - Maxim Burgerhout - Quarkus Intro
PDF
Ten Frustrations From The Community Trenches (And How To Deal With Them)
PDF
We all need friends and Akka just found Kubernetes
PDF
Cloud native akka and kubernetes holy grail to elasticity
PDF
Reactive Summit 2017 Highlights!
PDF
Reactive Programming or Reactive Systems? (spoiler: both)
PDF
Beyond Fault Tolerance with Actor Programming
PDF
Akka Streams at Weeronline
PDF
WebSockets wiith Scala and Play! Framework
Intro slides - Global Reactive Meetup - Move over JDBC!
Planespotting - From Zero To Deep Learning
From Zero To Deep Learning With Scala
Reactive Amsterdam - Maxim Burgerhout - Quarkus Intro
Ten Frustrations From The Community Trenches (And How To Deal With Them)
We all need friends and Akka just found Kubernetes
Cloud native akka and kubernetes holy grail to elasticity
Reactive Summit 2017 Highlights!
Reactive Programming or Reactive Systems? (spoiler: both)
Beyond Fault Tolerance with Actor Programming
Akka Streams at Weeronline
WebSockets wiith Scala and Play! Framework

Recently uploaded (20)

PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Cloud computing and distributed systems.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Cloud computing and distributed systems.
Chapter 3 Spatial Domain Image Processing.pdf
Unlocking AI with Model Context Protocol (MCP)
Understanding_Digital_Forensics_Presentation.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation

Reactive Android: RxJava and beyond