Reactive stack paints a very rosy picture of the way to develop the scalable applications focusing on the 4 fundamental things that are responsive, elastic, resilient and asynchronous communication. The principles are pretty simple but there are a lot of pitfalls that nobody talks about.
The challenges are numerous to build the system in the right way and in this talk we will focus on what are these pitfalls and how can we avoid them. We will be exploring the myth that once you adapt to it the journey will be smooth and show how these distributed systems add to additional complexity but can be managed by making smart decisions. I will share our experience of building Reactive Applications and how we have overcome the difficulties that we encounter.
3. Base Concept
Reactive Architecture
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
If you cannot solve a problem without
programming, you cannot solve a problem with
programming.
Victor Klang
4. Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
5. Overview
Reactive Architecture
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
In this talk we will explore the domain of the Reactive
Applications.
● Domain Driven Design (DDD) to model the domain.
● How our domain can be partitioned into Reactive Microservices.
● Discuss concerns around scalability, consistency, and availability
● Analyze different messaging patterns.
● Command Query Responsibility Segregation and how it can be
combined with Event Sourcing.
7. The problem
Reactive Architecture
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
The software landscape has undergone remarkable change
● Earlier
○ Tens of nodes
○ GB’s of data (often at rest)
○ Long maintenance windows
● Now
○ Hundreds and thousands of nodes
○ PB’s of data (often streaming)
○ Almost 100% uptime
8.
9. User Expectations
Reactive Architecture
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
User expectations are huge from software today
● Modern users rely on software to do critical jobs - cannot
expect downtime.
● Software is expected to respond immediately
● Unresponsive software leads to dissatisfaction - users would
find a better software
10. Discussion
Unresponsive Software
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
Have you encountered an unresponsive software?
● What was your reaction?
● Did you reconsider the use of software?
● Did it change your impression about the company that built it?
● What did you do to overcome the challenge?
11. Goal
of Reactive Architecture
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
To build software
● Which scales from 10 to 10M users
● Consumes resources relevant for the current load only
● Gracefully handles failures
● Can we easily distributed across nodes, geographies
● Can give consistent level of quality irrespective of the load and
stress on the system
14. Responsive
Most Important Reactive Principle
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
A responsive system is quick to react to all users —
under blue skies and grey skies — in order to ensure a
consistently positive user experience.
16. Resilience
Reactive Principle
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
A resilient system applies proper design and
architecture principles in order to ensure
responsiveness under grey skies as well as blue.
18. Elastic
Reactive Principle
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
A scalable system is easily upgraded on demand in
order to ensure responsiveness under various load
conditions.
20. Message Driven
Reactive Principle
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
A message-driven architecture is the foundation of
Reactive applications. A message-driven application
may be event-driven, actor-based, or a combination of
the two.
22. Discussion
Responsive Software
Lorem Ipsum comes from section Contrary to
popular belief, Lorem Ipsum is not simply random
text.
Have you encountered a Responsive software?
● What was your reaction and impression?
● Do you think it was using reactive principles?
● Did it change your impression about the company that
built it?
● Have you built a reactive software?
○ What benefits did you achieve?
23. Reactive Programming and Systems
● Reactive systems apply reactive
principals to the architecture
● Reactive programming are
languages which support
building reactive systems like
Futures, Promises, Async
communication, streams etc
24. Summary
● Responsive and Unresponsive software
● Reactive Manifesto and Principles
○ Responsive
○ Resilient
○ Elastic
○ Message Driven
● Reactive programming and systems
26. Monoliths
Reactive Architecture
● The ball of mud represents the worst case
scenario for a Monolith.
● No clear isolation in the application.
● Complex dependencies.
● Hard to understand and harder to modify.
27. ● Deployed as a single unit.
● Single shared database.
● Communicate with synchronous method calls.
● Deep coupling between libraries and components (often
through the DB).
● "Big Bang" style releases.
● Long cycle times (weeks to months).
● Teams carefully synchronize features and releases.
Characteristics of a monolith
Reactive Architecture
28. Scaling a Monolith
Reactive Architecture
● Multiple copies of the monolith are deployed.
● Each copy is independent. They don't
communicate with each other.
● The database provides consistency between
deployed instances.
29. ● Easy Cross Module Refactoring.
● Easier to maintain consistency.
● Single deployment process.
● Single thing to monitor.
● Simple scalability model.
Advantages
Reactive Architecture
30. ● Limited by the maximum size of a single physical machine.
● Only scales as far as the database will allow.
● Components must be scaled as a group.
● Deep coupling leads to inflexibility.
● Development is typically slow (change is difficult, build times long).
● Serious failures in one component often bring down the whole
● monolith.
● Redistribution of load can cause cascading failures.
Disadvantages
Reactive Architecture
31. Next step - SOA
Reactive Architecture
● We can isolate our Monolith using Service
Oriented Architecture.
● Services don't share a database.
● All access must go through the API exposed by
the service.
● Services may live in the same process (monolith)
or separate (microservices).
32. Microservices
Reactive Architecture
● Microservices are a subset of SOA.
● Logical components are separated into isolated
microservices.
● Microservices can be physically separated and
independently deployed.
● Each component/microservice has its own
independent data store.
● Microservices are independent and self
governing.
46. A class should have only one reason to change.
Robert C. Martin
● The Single Responsibility Principle applies to object oriented classes,
but works for Microservices as well.
● A microservice should have a single responsibility (eg. managing
accounts).
● A change to the internals of one microservice should not necessitate
a change to another microservice.
SRP
Reactive Architecture
47. ● Bounded Contexts are a good place to start building microservices.
● They define a context in which a specific model applies.
● Further subdivision of the Bounded Context is possible.
Bounded Context
Reactive Architecture
48. ● Scalability: A system is scalable if it can meet increases in demand
while remaining responsive.
● Consistency: A system is consistent if all members of a system have
the same view or state.
● Availability: A system is available if it remains responsive despite
failures.
Definitions
49. ● Isolation provides reduced coupling and increased scalability.
● Reactive Microservices are isolated in:
○ State
○ Space
○ Time
○ Failure
Principles of Isolation
Reactive Architecture
50. Isolation of State
Reactive Architecture
● All access to a Microservice state
must go through its API.
● No backdoor access via the
database.
● Allows the microservice to evolve
internally without affecting the
outside.
51. Isolation of Space
Reactive Architecture
● Microservices should not care
where other microservices are
deployed.
● It should be possible to move a
microservice to another machine,
possibly in a different data center
without issue.
● Allows the microservice to be scaled
up/down to meet demand.
52. Isolation in Time
Reactive Architecture
● Microservices should not wait for each other.
Requests are asynchronous and non-blocking.
○ More efficient use of resources.
Resources can be freed immediately,
rather than waiting for a request to finish.
● Between microservices we expect eventual
consistency.
○ Provides increased scalability. Total
consistency requires central coordination
which limits scalability (more on this
later).
53. Isolation of Failure
Reactive Architecture
● Reactive Microservices also isolate
failure.
● A failure in one Microservice should
not cause another to fail.
● Allows the system to remain
operational in spite of failure.
54. Discussion
General rules
Two trees fall in the forest. Two people hear the sound. Both trees fall at the
same time.
Each person is closer to a different tree. Sound travels at 340 m/s.
● If we were to ask Martin and Grace what time each tree fell at, would they give
us the same answer?
● If we were to ask Martin and Grace which tree fell first, would they give us the
same answer?
55. ● Distributed Systems are systems that are separated by space.
● Physics puts an upper limit on information speed (The Speed of Light)
● When two systems are separated by space, there is always time
required to reach consensus.
● In the time it takes to transfer the information, the state of the
original sender may have changed.
Problem with distributed systems
56. ● Because it takes time to transfer information, the information being
received is always stale.
● This applies whether we are talking about Computer systems,
people, or even just the physical world.
● Reality is therefore Eventually Consistent
Reality is eventual
57. Eventual Consistency
Eventual consistency guarantees that, in the
absence of new updates, all accesses to a specific
piece of data will eventually return the most recent
value.
59. Strong Consistency
Reactive Architecture
● Traditional architectures were built for
Strong Consistency.
● Physics prevents Strong Consistency, so
instead we simulate it.
● Locks and Transactions allow us to simulate
Strong Consistency.
● The distributed problem is isolated it to a
non-distributed resource.
● These techniques introduce overhead in the
form of contention.
60. ● Any two things that contend for a single limited resource are in
competition.
● This competition can only have one winner.
● Others are forced to wait for the winner to complete.
● As the number of things competing increases, the time to free up the
● resource increases.
● As load increases we will eventually exceed acceptable time limits.
Contention
61. Discussion
General rules
Two people are collaborating on code. Strong Consistency will require that Martin
and Grace both have the exact same view of the code at all times.
A model based on locks will require Martin to lock the code when he wants to edit
it.
● How will the need for Strong Consistency affect Grace's workflow if she also
wants to edit the code?
● How do source control tools actually achieve consistency?
62. ● Reactive Systems put an emphasis on asynchronous, non-blocking
messages.
● Messages are sent without waiting for a response.
● The sender may be interested in a response, but it comes
asynchronously.
● Is there a place in a Reactive System for Synchronous Messaging?
Messaging in Reactive Systems
63. ● Async messages form the backbone of Reactive Systems, but
sometimes synchronous make more sense.
● Synchronous requirements can often be relaxed. In most scenarios
asynchronous messaging just works fine
● Can you acknowledge the receipt of a message synchronously, but
process it asynchronously?
Synchronous Messaging
64. ● The need for synchronous messages should be driven by domain
requirements rather than technical ones.
● Best Practice: Use asynchronous by default, fallback to synchronous
only when forced.
● Understand the consequences of the choice.
Synchronous Messaging
65. ● In a monolithic architecture, coordination and consensus building is
often done using transactions.
● Microservices, Distributed Systems, and Async Messages all make
transactions more difficult.
● Holding transactions open for long periods results in slow, brittle
systems.
● How can we manage long running transactions that span multiple
microservices?
Cost of Async Messaging
66. Sagas
Reactive Architecture
● The Saga Pattern is a way of representing a long running
transaction.
● Multiple requests are managed by a Saga.
● Individual requests are run in sequence or in parallel.
● When all requests complete, the Saga is complete.
● What happens when a request fails?
67. Failure In Sagas
Reactive Architecture
● Each request is paired with a compensating action.
● If any request fails, compensating actions are executed for all
completed steps.
● The Saga is then completed with a failure.
● If a compensating action fails, then it is retried. This requires
idempotence.
69. Timeout in Distributed System
Reactive Architecture
● In a Distributed System, timeouts present a difficult problem.
● A request timeout presents us with at least 3 possible scenarios.
○ The request failed.
○ The request succeeded, but the reply failed.
○ The request is still queued and may succeed (or fail)
eventually.
● Because the request may have succeeded, we need to run the
compensating action.
● The request may still be queued, therefore the compensating
action may complete first..
70. ● Compensating actions are different from rollbacks.
● Rollback:
○ Implies the transaction has not completed.
○ Removes evidence of the transaction.
● Compensation:
○ Applied on top of a previously completed action.
○ Evidence of the original action remains.
Compensating and Rollback are
different