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
(Reactive Systems rather than Reactive Programming, though)
- Message-driven
- Scalable
- Resilient / fault tolerant
- Responsive
- responsive from any device
- responsive anytime even under heavy user traffic
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
(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
(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
Picture from The Reactive Manifesto
Picture from RezaSamee's The Reactive Manifesto slide
┌- ┌--------------┐
Goal | ┌----> |Responsiveness| <--┐
└- | └--------------┘ |
| ^ |
┌- ┌-----┴----┐ | ┌----┴-----┐
| |Elasticity| <------------> |Resilience|
| └----------┘ | └----------┘
| ^ | ^
Principles | ┌---------------------> | | | <----------------------------------┐
| | | | | |
| | ┌-----┴-----┐ | ┌-------┴-------┐ |
| | |Scalability| | |Fault tolerance| |
| | └-----------┘ | └---------------┘ |
└- | ^ | | |
| | | | |
┌- | ┌---------------------┴--------------┴-----------┴----------------------------------┐ |
| | | ┌-------------------------------------------------------------------------------┐ | |
| | | | ┌-----------┐ ┌---------------------┐ ┌----------┐ ┌-----------┐ ┌----------┐ | | |
Method | └-┤ | |Supervision| |Isolation(Decoupling)| |Delegation| |Replication| |Clustering| | ├-┘
| | | └-----------┘ └---------------------┘ └----------┘ └-----------┘ └----------┘ | |
| | └-------------------------------------------------------------------------------┘ |
| | (Akka) Message−Driven architecture |
└- └-----------------------------------------------------------------------------------┘
- 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.
- Single-threaded synchronous process / Multi-threaded synchronous process
- Concurrency, which uses multiple threads / Parallelism, which uses multicore processors
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.
(page 13) Currently, the reactive streams standard targets only JVM.
- 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
- REpresentational State Transfer: an architectural style for networked hypermedia appliactions
- Representations
- Messages
- URIs
- Statelessness
- Caching
(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
(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
- Colossus - I/O and Microservice library for Scala
- Finagle - A fault tolerant, protocol-agnostic RPC system
- Apache Kafka - A high-throughput distributed messaging system
TBD
- Scala
- Akka: Actor-based toolkit and runtime part of the typesafe reactive platform
- SBT
- ScalaTest
- IDE