Top Banner
A JOURNEY INTO REACTIVE FUNCTIONAL PROGRAMMING Ahmed Soliman ان م ي سل د حم أ
42

A Journey to Reactive Function Programming

Jul 16, 2015

Download

Technology

Ahmed Soliman
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A Journey to Reactive Function Programming

A JOURNEY INTO REACTIVE FUNCTIONAL PROGRAMMING

Ahmed Solimanأحمد سليمان

Page 2: A Journey to Reactive Function Programming

• CAT Reloaded Co-founder

• Life-long architect, software, and systems engineer.

• Focusing on systems reliability, scalability, and clean code.

Conictus

Page 3: A Journey to Reactive Function Programming

WHAT IS REACTIVE PROGRAMMING?

Page 4: A Journey to Reactive Function Programming
Page 5: A Journey to Reactive Function Programming
Page 6: A Journey to Reactive Function Programming

WHY REACTIVE PROGRAMMING?

Page 7: A Journey to Reactive Function Programming

THE INTERNET IN 2005

Page 8: A Journey to Reactive Function Programming

2005

Page 9: A Journey to Reactive Function Programming

• 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

Page 10: A Journey to Reactive Function Programming

THE INTERNET IN 2015

Page 11: A Journey to Reactive Function Programming

• 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

Page 12: A Journey to Reactive Function Programming

JUST TOO DAMN FAST!

Page 13: A Journey to Reactive Function Programming

WHAT REALLY IS REACTIVE PROGRAMMING?

Page 14: A Journey to Reactive Function 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

Page 15: A Journey to Reactive Function Programming

REACTIVE SYSTEMS

Message-driven

ResilientElastic

Responsive

Page 16: A Journey to Reactive Function Programming

• 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.

Page 17: A Journey to Reactive Function Programming

BOUNDED LATENCYResponsive

Page 18: A Journey to Reactive Function Programming

CIRCUIT BREAKER

Circuit Breaker Backend ServiceClient X

Page 19: A Journey to Reactive Function Programming

BOUNDED QUEUES

Queue Backend ServiceClient

Average Latency = Queue Size x Duration Per Op

Page 20: A Journey to Reactive Function Programming

Failure is First Class

Resilient

Page 21: A Journey to Reactive Function Programming

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

Page 22: A Journey to Reactive Function Programming

Resilient

Containment and Isolation

Page 23: A Journey to Reactive Function Programming

• Recovery of each component is delegated to another (external) component and high-availability is ensured by replication where necessary.

Page 24: A Journey to Reactive Function Programming

Response in the face of Changing load

Elastic

Page 25: A Journey to Reactive Function Programming

PARTITIONING/SHARDING

Consistent HashingRouter

Bucket 1

Bucket 2

Bucket 100

Bucket 101

Machine 1

Machine (N)

msg

Page 26: A Journey to Reactive Function Programming

SHARE NOTHING

• Message-driven architectures are share-nothing by design.

• No shared mutable state between components.

• Avoid single-point-of-failures by partitioning+replication.

Page 27: A Journey to Reactive Function Programming

SCALE UP/DOWN AND OUT/INProcess 1

Process 2

MachineProcess 3

Process 4

Process 1

Process 2Server 1

Process 1

Process 2Server 1

Process 1

Process 2Server 1

Page 28: A Journey to Reactive Function Programming

LOCATION TRANSPARENCY

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

Page 29: A Journey to Reactive Function Programming

• Foundation of scalable, resilient, and ultimately responsive systems.

• Immutable by design

• Loose Coupling

• Location Transparency

• Concurrency Control

• Everything is a stream of messages

Message-driven

Page 30: A Journey to Reactive Function Programming

WHAT REACTIVE PROGRAMMING ISN’T

Page 31: A Journey to Reactive Function Programming

• A programming language

• A framework/library/tool

• The only way to achieve concurrency and interactive applications

Page 32: A Journey to Reactive Function Programming

WHAT IS FUNCTIONAL AND WHY?

Page 33: A Journey to Reactive Function Programming

• 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.

Page 34: A Journey to Reactive Function Programming

function getEvens() { var x = 1; var result = []; while (x < 10) { if (x % 2 == 0) { result.push(x * 2); } } return result;}

Page 35: A Journey to Reactive Function Programming

scala> Stream.from(1) .takeWhile(x => x < 10) .filter(x => x % 2 == 0) .map(x => x * 2) .toListres2: List[Int] = List(4, 8, 12, 16)

Page 36: A Journey to Reactive Function Programming

LET’S ADD TIMEThe World is a set of Observable<T>

Page 37: A Journey to Reactive Function Programming

takeWhile filter map

dropWhile map

filter

Observable Reduce

Page 38: A Journey to Reactive Function Programming

LET’S SEE SOME CODE

Page 39: A Journey to Reactive Function Programming

THINGS TO WATCH

Page 40: A Journey to Reactive Function Programming

http://reactivemanifesto.org/

Page 41: A Journey to Reactive Function Programming

LET’S REACH OUT

AhmedSoliman!"

Page 42: A Journey to Reactive Function Programming

THANK YOU!