KEMBAR78
A Journey to Reactive Function Programming | PDF
A JOURNEY INTO REACTIVE FUNCTIONAL
PROGRAMMING
Ahmed Soliman
‫ان‬‫م‬‫ي‬‫سل‬‫د‬‫حم‬‫أ‬
• CAT Reloaded Co-founder
• Life-long architect, software, and
systems engineer.
• Focusing on systems reliability,
scalability, and clean code.
Conictus
WHAT IS REACTIVE PROGRAMMING?
WHY REACTIVE PROGRAMMING?
THE INTERNET IN 2005
2005
• The Internet had 1 billion users.
• Facebook had 5.5 million users.
• YouTube was a new born.
• Netflix had yet to introduce video streaming (2007)
https://medium.com/reactive-programming/what-is-reactive-programming-bc9fa7f4a7fc
THE INTERNET IN 2015
• The internet has 2.95 billion users.
• Facebook has 1.393 billion monthly active users.
• YouTube has 1 billion users with 6 billions of hours of video/
month.
• Twitter has 270 million users.
• Netflix has 57.4 million digital subscriber with 1 billion
hours of video/month
JUSTTOO DAMN FAST!
WHAT REALLY IS REACTIVE
PROGRAMMING?
• A set of ideas and principles to manage complexity in the world
of highly responsive, asynchronous, scalable applications.
• The goal of reactive programming is to build responsive, flexible,
and highly scalable applications without managing the complexity
REACTIVE SYSTEMS
Message-driven
ResilientElastic
Responsive
• The system responds in a timely manner if at all possible.
• Responsive systems focus on providing rapid and consistent
response times, establishing reliable upper bounds so they
deliver a consistent quality of service.
Responsive
Responsiveness is the cornerstone of usability and utility, but more
than that, responsiveness means that problems may be detected
quickly and dealt with effectively.
BOUNDED LATENCY
Responsive
CIRCUIT BREAKER
Circuit Breaker Backend ServiceClient X
BOUNDED QUEUES
Queue Backend ServiceClient
Average Latency = Queue Size x Duration Per Op
Failure is First Class
Resilient
Responsive in the face of failure!
This applies not only to highly-available, mission critical
systems — any system that is not resilient will be
unresponsive after a failure.
Resilient
Resilient
Containment and Isolation
• Recovery of each component is delegated to another (external)
component and high-availability is ensured by replication where
necessary.
Response in the face of Changing load
Elastic
PARTITIONING/SHARDING
Consistent
Hashing
Router
Bucket 1
Bucket 2
Bucket 100
Bucket 101
Machine 1
Machine (N)
msg
SHARE NOTHING
• Message-driven architectures are share-nothing by design.
• No shared mutable state between components.
• Avoid single-point-of-failures by partitioning+replication.
SCALE UP/DOWN AND OUT/IN
Process 1
Process 2
Machine
Process 3
Process 4
…
Process 1
Process 2
Server 1
Process 1
Process 2
Server 1
Process 1
Server 1
LOCATIONTRANSPARENCY
AuthService x = getAuthService(/* local or remote*/)
x.sendMessage(new Login("asoliman", "password"))
• Abstraction over location of components enables you to scale out
and up in the same way.
• The underlying message-passing system should handle all the
plumbing and the optimization for the message delivery
• Foundation of scalable, resilient, and ultimately responsive systems.
• Immutable by design
• Loose Coupling
• LocationTransparency
• Concurrency Control
• Everything is a stream of messages
Message-driven
WHAT REACTIVE PROGRAMMING ISN’T
• A programming language
• A framework/library/tool
• The only way to achieve concurrency and interactive
applications
WHAT IS FUNCTIONAL AND WHY?
• Programming with functions where functions and data are
treated the same way.
• A program is an evaluation of mathematical functions.
• Avoids mutable-data and changing-state.
function getEvens() {
var x = 1;
var result = [];
while (x < 10) {
if (x % 2 == 0) {
result.push(x * 2);
}
}
return result;
}
scala> Stream.from(1)
.takeWhile(x => x < 10)
.filter(x => x % 2 == 0)
.map(x => x * 2)
.toList
res2: List[Int] = List(4, 8, 12, 16)
LET’S ADDTIME
The World is a set of Observable<T>
takeWhile filter map
dropWhile map
filter
Observable Reduce
LET’S SEE SOME CODE
THINGSTO WATCH
http://reactivemanifesto.org/
LET’S REACH OUT
AhmedSoliman
THANKYOU!

A Journey to Reactive Function Programming