Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tkqubo/fbb43d5b0f8d93b59d081a8643ac7f1c to your computer and use it in GitHub Desktop.
Save tkqubo/fbb43d5b0f8d93b59d081a8643ac7f1c to your computer and use it in GitHub Desktop.
Reactive Programming with Scala and Akka - Chapter 1

1 Background (page 2)

Today's system requirement

  • large number of request
  • huge amount of data
  • quick response time
  • (almost) 100% uptime

(page 3) If we compare the number of Internet users in the past decades with the number of users of the two afore mentioned websites, we can see that they now handle as much traffic as the entire Internet used to.

  • 2000-2005: Internet 1 billion users
  • 2006~: Facebook 1.3 billion, Twitter 240 million

2 What is Reactive Programming ? (page 3~)

(Reactive Systems rather than Reactive Programming, though)

2.1 Tenets of reactive programming

  • Message-driven
  • Scalable
  • Resilient / fault tolerant
  • Responsive

Responsive

  • responsive from any device
  • responsive anytime even under heavy user traffic

Resilient / fault tolerant

On some nodes failing:

  • handle them gracefully
  • resume after they are back

(page 6) Reactive applications should always treat a failure as a first-class event, which means that we expect failures to occur

Scalable

(page 6) A scalable system is another important trait needed to ensure responsiveness under various load conditions

e.g. Storage scaling

(page 6) NoSQL ... scales better than a traditional RDBMS

Message-driven

(page 9) Actor-based concurrency is an extension of the message-passing architecture, where messages are directed to a recipient. This recipient happens to be an actor.
...
The main difference between messages and events is that messages are directed while events happen

Actor's characteristics:

  • isolated state rather than a shared state
  • scaling out computation across network boundaries (location transparency)
  • the loose coupling of components

Another view of Reactive Systems

           ┌-                                 ┌--------------┐
      Goal |                           ┌----> |Responsiveness| <--┐
           └-                          |      └--------------┘    |
                                       |              ^           |
           ┌-                    ┌-----┴----┐         |      ┌----┴-----┐
           |                     |Elasticity| <------------> |Resilience|
           |                     └----------┘         |      └----------┘
           |                           ^              |           ^
Principles |   ┌---------------------> |              |           | <----------------------------------┐
           |   |                       |              |           |                                    |
           |   |                 ┌-----┴-----┐        |   ┌-------┴-------┐                            |
           |   |                 |Scalability|        |   |Fault tolerance|                            | 
           |   |                 └-----------┘        |   └---------------┘                            |
           └-  |                       ^              |           |                                    |
               |                       |              |           |                                    |
           ┌-  | ┌---------------------┴--------------┴-----------┴----------------------------------┐ |
           |   | | ┌-------------------------------------------------------------------------------┐ | |
           |   | | | ┌-----------┐ ┌---------------------┐ ┌----------┐ ┌-----------┐ ┌----------┐ | | |
    Method |   └-┤ | |Supervision| |Isolation(Decoupling)| |Delegation| |Replication| |Clustering| | ├-┘
           |     | | └-----------┘ └---------------------┘ └----------┘ └-----------┘ └----------┘ | |
           |     | └-------------------------------------------------------------------------------┘ |
           |     |                     (Akka) Message−Driven architecture                            |
           └-    └-----------------------------------------------------------------------------------┘

3 Around Reactive Programming (page 10~)

3.1 Functional Programming

  • Characteristics of pure function
    • no side effects (e.g. writing to a screen, reading from a file, mutating the value of a variable, etc.)
    • immutable
    • no shared state

They enable lockless algorithm, which give rise to concurrency.

3.2 Asynchronous Programming

  • Single-threaded synchronous process / Multi-threaded synchronous process
  • Concurrency, which uses multiple threads / Parallelism, which uses multicore processors

http://joearms.github.io/images/con_and_par.jpg

3.3 Data Streams

Source and Sink

(page 13) Reactive streams are an upcoming standard for asynchronous stream processing with back pressure

  • Back-pressure: a feedback mechanism for the component to upstream components to reduce their load
    The back-pressure may cascade all the way up to the user.

Akka Stream

(page 13) Currently, the reactive streams standard targets only JVM.

3.4 Micro-services

  • Modular service
  • Can be run on lightweight container

(page 13) Mcro-services is a modern architectural approach that allows components to be modularized and exposed as services.
...
(page 14) components can be debugged in isolation and fixed

3.5 RESTful services

  • REpresentational State Transfer: an architectural style for networked hypermedia appliactions

Features of a RESTful service

  • Representations
  • Messages
  • URIs
  • Statelessness
  • Caching

4 Use cases (page 16~)

4.1 Internet of Things

(page 16) Reactive streams play a major role in collecting data from the devices

  • Reactive electricity measure
    • meters send messages to mini computer (e.g. Raspberry Pi or Arduhino), then forward them to cloud as byte stream

4.2 Tumblr's architecture

(page 18) Tumblr gets more than 50 million posts per day
... Tumblr has 500 million page views per day
... they get more than 40,000 concurrent requests per second
... Tumblr uses hardware that comprises 500 web servers, 200 database servers, 30 memcached servers, 22 Redis servers

Frameworks

Pros and Cons about Finagle

TBD

4 Tools (page 18~)

  • Scala
  • Akka: Actor-based toolkit and runtime part of the typesafe reactive platform
  • SBT
  • ScalaTest
  • IDE

LINKS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment