Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

A Journey to Reactive Function Programming

5,115 views

Published on

A gentle introduction to functional reactive programming highlighting the reactive manifesto and ends with a demo in RxJS https://github.com/AhmedSoliman/rxjs-test-cat-scope

Published in: Technology

A Journey to Reactive Function Programming

  1. 1. A JOURNEY INTO REACTIVE FUNCTIONAL PROGRAMMING Ahmed Soliman ‫ان‬‫م‬‫ي‬‫سل‬‫د‬‫حم‬‫أ‬
  2. 2. • CAT Reloaded Co-founder • Life-long architect, software, and systems engineer. • Focusing on systems reliability, scalability, and clean code. Conictus
  3. 3. WHAT IS REACTIVE PROGRAMMING?
  4. 4. WHY REACTIVE PROGRAMMING?
  5. 5. THE INTERNET IN 2005
  6. 6. 2005
  7. 7. • 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
  8. 8. THE INTERNET IN 2015
  9. 9. • 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
  10. 10. JUSTTOO DAMN FAST!
  11. 11. WHAT REALLY IS REACTIVE PROGRAMMING?
  12. 12. • 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
  13. 13. REACTIVE SYSTEMS Message-driven ResilientElastic Responsive
  14. 14. • 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.
  15. 15. BOUNDED LATENCY Responsive
  16. 16. CIRCUIT BREAKER Circuit Breaker Backend ServiceClient X
  17. 17. BOUNDED QUEUES Queue Backend ServiceClient Average Latency = Queue Size x Duration Per Op
  18. 18. Failure is First Class Resilient
  19. 19. 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
  20. 20. Resilient Containment and Isolation
  21. 21. • Recovery of each component is delegated to another (external) component and high-availability is ensured by replication where necessary.
  22. 22. Response in the face of Changing load Elastic
  23. 23. PARTITIONING/SHARDING Consistent Hashing Router Bucket 1 Bucket 2 Bucket 100 Bucket 101 Machine 1 Machine (N) msg
  24. 24. SHARE NOTHING • Message-driven architectures are share-nothing by design. • No shared mutable state between components. • Avoid single-point-of-failures by partitioning+replication.
  25. 25. 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
  26. 26. 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
  27. 27. • Foundation of scalable, resilient, and ultimately responsive systems. • Immutable by design • Loose Coupling • LocationTransparency • Concurrency Control • Everything is a stream of messages Message-driven
  28. 28. WHAT REACTIVE PROGRAMMING ISN’T
  29. 29. • A programming language • A framework/library/tool • The only way to achieve concurrency and interactive applications
  30. 30. WHAT IS FUNCTIONAL AND WHY?
  31. 31. • 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.
  32. 32. function getEvens() { var x = 1; var result = []; while (x < 10) { if (x % 2 == 0) { result.push(x * 2); } } return result; }
  33. 33. 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)
  34. 34. LET’S ADDTIME The World is a set of Observable<T>
  35. 35. takeWhile filter map dropWhile map filter Observable Reduce
  36. 36. LET’S SEE SOME CODE
  37. 37. THINGSTO WATCH
  38. 38. http://reactivemanifesto.org/
  39. 39. LET’S REACH OUT AhmedSoliman
  40. 40. THANKYOU!

×