Reactive Microservices
Matt Clement - @mallize
LifeWay IT
tech.lifeway.com @lifewaytech
Reactive Microservices
Matt Clement - @mallize
LifeWay IT - tech.lifeway.com - @lifewaytech
LifeWay
LifeWay
Evolutionary Architecture
https://www.thoughtworks.com/insights/blog/microservices-evolutionary-architecture
Evolutionary Architecture
Microservices
&
Reactive Programming
Microservices
Microservices vs Monolithic
Microservices vs Service Oriented (SOA)
Microservices
Breaking down an application into a suite of small, well-defined services that are built around business capabilities, independently deployable and do not share their data model.
Built around business capabilities
Domain Driven Design
Independently Deployable
Share Nothing
SOA is built on the concept of a share-as-much- as-possible architecture style, whereas microservices architecture is built on the concept of a share-as-little-as-possible architecture style.
~Mark Richards
Microservices Suggestions
API Gateways for client applications
Microservices Suggestions
Create facades in front of capabilities.
Allows for evolutionary architecture.
Microservices Suggestions
Create 12 factor apps (https://12factor.net/)
Microservices Prerequisites
Microservices Prerequisites - Build Pipeline
Each microservice should have it's own build pipeline in GoCD. An example build pipeline is shown in the diagram below. Variations of this pipeline will exist for different services but the required pipeline steps are:
Microservices
Breaking down an application into a suite of small, well-defined services that are built around business capabilities, independently deployable and do not share their data model.
Reactive Programming
http://www.reactivemanifesto.org
Responsive
Resilient
Elastic
Message Driven
Reactive Microservices
Jonas Bonér lists the following as characteristics of Reactive Microservices
Isolation
Isolation has a huge impact on design and should be considered at the start of designing a system.
Conway’s Law
"Any organization that designs a system (defined more broadly here than just information systems) will inevitably produce a design whose structure is a copy of the organization's communication structure." ~ Melvin Conway
Good or bad is a matter of perspective. Create teams around suites of services or capabilities.
Isolation
Isolation allows us to reduce the blast radius of errors. We don’t want cascading failures to take down our system.
Isolation
If service E goes down...
Isolation
We don’t want all other services to be affected
Isolation
Similar to ship bulkheading
Isolation
Similar to ship bulkheading
Isolation - How?
Circuit Breaker Pattern
Isolation - Circuit Breaker Pattern
A degraded experience is better than no experience.
Isolation
In a highly distributed system, synchronous API calls are dangerous.
Isolation
Temporally decouple components through message driven communication.
Message Driven at LifeWay
Message Driven - CQRS
“CQRS is simply the creation of two objects where there was previously only one. The separation occurs based upon whether the methods are a command or a query (the same definition that is used by Meyer in Command and Query Separation: a command is any method that mutates state and a query is any method that returns a value). —Greg Young
Message Driven - CQRS
Reason for segregation
Message Driven - CQRS
Message Driven - CQRS - Event Sourcing
Event Sourcing - Storing changes as a set of event logs rather than just the current state. The current state is derived from replaying the events.
Message Driven - CQRS - Event Sourcing
Benefits of using event sourcing for the write side
CQRS
CQRS
{ event : “ItemAddedToCart”, sku : “sku123”, quantity : 2 } | { items : [ {sku : “sku123”, quantity : 2}, {sku : “sku456”, quantity : 1} ] } |
{ event : “ItemRemovedFromCart”, sku : “sku123”, quantity : 1 } | { items : [ {sku : “sku456”, quantity : 1} ] } |
{ event : “ItemAddedToCart”, sku : “sku456”, quantity : 1 } | { items : [ {sku : “sku123”, quantity : 1}, {sku : “sku456”, quantity : 1} ] } |
{ event : “ItemAddedToCart”, sku : “sku123”, quantity : 1 } | { items : [ {sku : “123”, quantity : 1} ] } |
Event Log Current State
CQRS end to end demo
https://www.smallgroup.com
Procedural REST Calls
Async Message Passing (Events)
What about transactions?
Saga - A finite state machine that’s state transitions are based on the events pertaining to a certain business process. Errors captured include invalid state transitions, timeouts and errors in messaging when orchestrating API calls.
Compensating events can be used to undo portions of a saga (similar to rolling back).
Message Driven
Physical Architecture
Scaling under 3x avg load
Latency under 3x load
Summary
Microservices provide the means for creating autonomous, single responsibility services that can provide quick turn around for a company's feature sets. Because of their limited scope of responsibility they are easy to implement, change and maintain.
Complexity is contextual. The complexity in microservices moves out of the services themselves and into their deployment strategy, communication patterns and HA strategy.
Reactive Programming provides guidelines for creating systems that are designed to handle failure, load and asynchronous communication.
Questions?
Twitter:
@mallize
@lifewaytech
GitHub: github.com/LifeWay
More Info: http://tech.lifeway.com/more-info/