in the eventual consistency of succeeding at …...in the eventual consistency of succeeding at...

63
In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017

Upload: others

Post on 21-May-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

In the Eventual Consistency of Succeeding at Microservices

Kenny Bastani Spring Developer Advocate

GOTO Chicago 2017

Page 2: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Kenny Bastani

@kennybastani

Spring Developer Advocate

Page 3: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Agenda

Agenda

1 Monolith to Microservices

2 Online store example

3 Spring Boot

4 Event-driven microservices

Page 4: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Microservices

How did we get there?

Page 5: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

We started with the monolith…

Page 6: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Slows our velocity getting into production.

Monolith problems…

Page 7: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Engineers take too long to ramp up.

Monolith problems…

Page 8: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

The code base becomes too large for any one person to reason about.

Monolith problems…

Page 9: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Development creates change.

DBAs resist change.

Monolith problems…

Page 10: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Coordinated releases batch many changes together from different teams.

Monolith problems…

Page 11: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Operations drives the runtime environment of applications.

Monolith problems…

Page 12: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Deploy everything at once, or nothing at all.

Monolith problems…

Page 13: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

We then moved towards SOA…

Page 14: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

We have now arrived at microservices…

Page 15: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Online Store Example

Cloud native application as microservices

Page 16: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

@kennybastani

Page 17: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani
Page 18: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Monolith to Microservice

Page 19: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Splitting the Monolith: User Service Migration

Page 20: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

No foreign key constraints between services.

Microservice problems…

Page 21: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

I’ve got legacy problems.

Microservice problems…

Page 22: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

What about my data warehouse?

Microservice problems…

Page 23: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Teams are creating redundant functionality.

Microservice problems…

Page 24: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Distributed transactions are brittle.

Microservice problems…

Page 25: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Every bug is a murder mystery.

Microservice problems…

Page 26: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Distributed systems are hard.

Microservice problems…

Page 27: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Without an event-driven architecture and a cloud platform…Microservices will drown you in hard problems you never knew existed.

Page 28: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Spring Boot

A JVM micro-framework for building microservices

Page 29: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

What is Spring Boot?

Page 30: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

@kennybastani

spring boot

Spring Initializr for bootstrapping your applications

supports rapid development of production-ready applications and services

Page 31: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Event-driven microservices

Implementing event-driven architectures in a distributed system

Page 32: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Events as a first-class citizen.

Event-driven microservices…

Page 33: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Domain events have a subject and contain immutable data.

Event-driven microservices…

Page 34: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Every domain event applies a state transition to an aggregate.

Event-driven microservices…

Page 35: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Domain events can only be applied if the aggregate is in a valid state.

Event-driven microservices…

Page 36: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani
Page 37: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Create meaningful exceptions if a domain event cannot be applied.

Event-driven microservices…

Page 38: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Event sourcing stores every state transition as an event in a log.

Event-driven microservices…

Page 39: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani
Page 40: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Build hypermedia APIs that attach event logs as a link on an aggregate.

Event-driven microservices…

Page 41: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Commands generate event(s).

Event-driven microservices…

Page 42: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Commands are attached to aggregates.

Event-driven microservices…

Page 43: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani
Page 44: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Event handlers subscribe to an event and apply state changes to an aggregate.

Event-driven microservices…

Page 45: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Event handlers use event sourcing to generate the current state of an aggregate.

Event-driven microservices…

Page 46: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani
Page 47: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Event handlers are nodes on a directed graph.

Event-driven microservices…

Page 48: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani
Page 49: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Events are edges on a directed graph.

Event-driven microservices…

Page 50: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani
Page 51: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

CQRS is used to create materialized views from streams of events.

Event-driven microservices…

Page 52: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Command Query model

Page 53: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

@kennybastani

Page 54: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

@kennybastani

Page 55: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

@kennybastani

Page 56: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

@kennybastani

Page 57: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Serverless event handlers

Microservices can be event sources

Page 58: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani
Page 59: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Do what makes sense

But don’t build microservices without events

Page 60: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

$200.002 Days, 10 sessions2 Spring team talks

Live Open Space discussions

Chicago: May 30, 31

Page 61: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Please provide feedback using the GOTO app

Page 62: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

Thank you!

Page 63: In the Eventual Consistency of Succeeding at …...In the Eventual Consistency of Succeeding at Microservices Kenny Bastani Spring Developer Advocate GOTO Chicago 2017 Kenny Bastani

© 2016 Pivotal Software, Inc. All rights reserved. @kennybastani

Thank you!

63