The Basics of Reactive System Design for Traditional Java Enterprises

39
WEBINAR The Basics Of Reactive System Design For Traditional Java Enterprises By Sean Walsh (@SeanWalshEsq) and Duncan DeVore (@ironfish)

Transcript of The Basics of Reactive System Design for Traditional Java Enterprises

Page 1: The Basics of Reactive System Design for Traditional Java Enterprises

WEBINAR

The Basics Of Reactive System Design For Traditional Java Enterprises

By Sean Walsh (@SeanWalshEsq) and Duncan DeVore (@ironfish)

Page 2: The Basics of Reactive System Design for Traditional Java Enterprises

What is Reactive?

Page 3: The Basics of Reactive System Design for Traditional Java Enterprises

• Responsive, even in the face of failure

• Elastic, responsive under load

• Resilient, expect failure, programmatic and systemic

• Message Driven, the only way to communicate asynchronously in a distributed environment

Page 4: The Basics of Reactive System Design for Traditional Java Enterprises

Why Reactive?

Page 5: The Basics of Reactive System Design for Traditional Java Enterprises

Exploding User Bases and Cheaper

Page 6: The Basics of Reactive System Design for Traditional Java Enterprises

The CAP Theorem

You can’t have your cake and eat it too.

Page 7: The Basics of Reactive System Design for Traditional Java Enterprises

The Monolith• Traditional way of building applications

• Monoliths do not distribute

• Typically blocking code is used everywhere

• Tight coupling all over the place

• Many times leading to…

Page 8: The Basics of Reactive System Design for Traditional Java Enterprises

Big Ball of Mud

Page 9: The Basics of Reactive System Design for Traditional Java Enterprises

• Cumulative damage due to rushed fixes and enhancements…sweeping it under the rug

• Don’t touch it, you’ll break it

• Piecemeal growth

• Too many hands in the pudding

• Can actually stop you from doing business…

A Big Ball of Mud You Say?

Page 10: The Basics of Reactive System Design for Traditional Java Enterprises

Story Timeof many millions of users running on

a ball of mud.

Page 11: The Basics of Reactive System Design for Traditional Java Enterprises

How do we avoid the monolith and distribute our systems?

Page 12: The Basics of Reactive System Design for Traditional Java Enterprises

Microservices

Page 13: The Basics of Reactive System Design for Traditional Java Enterprises

• Are not necessarily “micro” and of no strictly defined size

• Do one thing and do it well

• Are of little value individually but have great value as part of an overall system of micro services

• Distribute!

Microservices…

Page 14: The Basics of Reactive System Design for Traditional Java Enterprises

Ok microservices but where to start?

Page 15: The Basics of Reactive System Design for Traditional Java Enterprises

Help has been out there all along

Domain Driven Design (DDD), Command Query Responsibility Segregation (CQRS) and Event Sourcing (ES)

Page 16: The Basics of Reactive System Design for Traditional Java Enterprises

Domain Driven Design• Mapping behavior as closely as possible to the real world

• Lots of us have been doing it all along as simply “good architecture”

• Gives us a structure of practices and vocabulary via the ubiquitous language

• It also introduces the bounded context…

Page 17: The Basics of Reactive System Design for Traditional Java Enterprises

Bounded Contexts

Page 18: The Basics of Reactive System Design for Traditional Java Enterprises

• A bounded context contains its own knowledge and view of the world

• An aircraft in the flight control context may have a different meaning from the aircraft used by ground control

• When data is interchanged between contexts it is done via an anti-corruption layer…

Page 19: The Basics of Reactive System Design for Traditional Java Enterprises

Anti-corruption Layers

Data and events from the outside world

A bounded context as a micro service

Page 20: The Basics of Reactive System Design for Traditional Java Enterprises

Each bounded context is really a first pass at defining a microservice!

Page 21: The Basics of Reactive System Design for Traditional Java Enterprises

A bounded context becomes the basis of a microservice but there are a couple

more mechanisms that will help us not only further break it down but also help us

share data between them!

Page 22: The Basics of Reactive System Design for Traditional Java Enterprises

CQRS (command query responsibility segregation)

Page 23: The Basics of Reactive System Design for Traditional Java Enterprises

• The domain command side only accepts imperative commands such as AddFlight, which usually become events or facts such as FlightAdded

• The command side is optimized for writes only

• The command side is fully independent and runs by its lonesome

Cqrs - The Command Side

Page 24: The Basics of Reactive System Design for Traditional Java Enterprises

cQrs - The Query Side• The query side is purpose built for the clients

query needs and is optimized for reads and is a first class customer, not an afterthought!

• The separation of read concerns avoids the common problem of impedance mismatch

• A query side is also a fully independent microservice

Page 25: The Basics of Reactive System Design for Traditional Java Enterprises

All this talk of separate microservices being either read or

write…

How do the services communicate with each other? Do they even do that?

Page 26: The Basics of Reactive System Design for Traditional Java Enterprises

Event Sourcing FTW!• The state of any domain is the accumulation of the events that have

occurred on it over time

• Events are facts and can be published without the need to know who is subscribing

• Events are immutable and are the only storage mechanism of the domain

• Proper event sourcing will help save you from…

Page 27: The Basics of Reactive System Design for Traditional Java Enterprises

THIS

Page 28: The Basics of Reactive System Design for Traditional Java Enterprises

Events are an easy to reason about thing to publish

Page 29: The Basics of Reactive System Design for Traditional Java Enterprises

• Event producers (command sides) need not be aware of all their event consumers

• Services may be up or down without message loss

• New services may be brought into existence with the benefit of catching up with previous domain activities from the beginning of time!

Durable Event Pub/Sub

Page 30: The Basics of Reactive System Design for Traditional Java Enterprises

i s o l a t i o n

Page 31: The Basics of Reactive System Design for Traditional Java Enterprises

The Akka Actor Modelisolation through supervision

Page 32: The Basics of Reactive System Design for Traditional Java Enterprises

Why Akka?• Concurrency is hard

• Blocking is bad

• Divide and conquer through the actor model

• Reactive first, not as an afterthought

Page 33: The Basics of Reactive System Design for Traditional Java Enterprises

What about my current stack?• Lots of blocking code

• Distributed microservices require a bigger leap than in the past

• Reactive last, if at all; asynchronous <> reactive!

• But I’m so comfortable, maybe my tooling with catch up!

Page 34: The Basics of Reactive System Design for Traditional Java Enterprises

–Oren Harari

“Edison’s electric light did not come about from the continuous

improvement of the candle”

Page 35: The Basics of Reactive System Design for Traditional Java Enterprises

–Henry Ford

“If I had asked people what they wanted, they’d have told me ‘a faster

horse”

Page 36: The Basics of Reactive System Design for Traditional Java Enterprises

A final word about resilience• Resilience is like an onion and must appear in every layer

• Though the actor model and supervision hierarchies allowing isolation within each microservice

• Through the specific application cluster with unique intelligence on its own behavior

• At the datacenter OS level, across all deployed services, databases, messaging and nodes

Page 37: The Basics of Reactive System Design for Traditional Java Enterprises

Upgrade your grey matterGet free sample chapters and a 40% off Sean & Duncan’s book

https://www.lightbend.com/resources/e-books

Page 38: The Basics of Reactive System Design for Traditional Java Enterprises

MICROSERVICES.FASTDATAPIPELINES.DISTRIBUTEDSYSTEMS.

Austin(TX)-October18-20,2017

reactivesummit.org

Page 39: The Basics of Reactive System Design for Traditional Java Enterprises

Build modern systems for the modern world www.lightbend.com