there is no such thing as a microservice! (oracle code nyc)

68
@crichardson There is no such thing as a microservice! Chris Richardson Founder of Eventuate.io Founder of the original CloudFoundry.com Author of POJOs in Action @crichardson [email protected] http://microservices.io http://eventuate.io http://plainoldobjects.com Copyright © 2017. Chris Richardson Consulting, Inc. All rights reserved

Upload: chris-richardson

Post on 07-Apr-2017

1.081 views

Category:

Software


0 download

TRANSCRIPT

Page 1: There is no such thing as a microservice! (oracle code nyc)

@crichardson

There is no such thing as a microservice!

Chris Richardson

Founder of Eventuate.io Founder of the original CloudFoundry.com Author of POJOs in Action

@crichardson [email protected] http://microservices.io http://eventuate.io http://plainoldobjects.com

Copyright © 2017. Chris Richardson Consulting, Inc. All rights reserved

Page 2: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Presentation goal

Define the Microservice Architecture as an architectural style

Explain what that means and why it matters

Page 3: There is no such thing as a microservice! (oracle code nyc)

@crichardson

About Chris

Page 4: There is no such thing as a microservice! (oracle code nyc)

@crichardson

About Chris

Consultant and trainer focusing on modern

application architectures including microservices

(http://www.chrisrichardson.net/)

Page 5: There is no such thing as a microservice! (oracle code nyc)

@crichardson

About Chris

Founder of a startup that is creating an open-source/SaaS platform

that simplifies the development of transactional microservices

(http://eventuate.io)

Page 6: There is no such thing as a microservice! (oracle code nyc)

@crichardson

About Chris

https://www.manning.com/books/microservice-patterns

Page 7: There is no such thing as a microservice! (oracle code nyc)

@crichardson

For more information

http://learnmicroservices.io

Page 8: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Agenda

A brief refresher on software architecture

From monolith to microservices

Microservices != silver bullet

Managing distributed data

Page 9: There is no such thing as a microservice! (oracle code nyc)

About software architecture

“The software architecture of a computing system is the set of structures needed to reason about the system, which comprise software elements, relations among

them, and properties of both.”

Documenting Software Architectures, Bass et al

Page 10: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Architecture =

(elements, relations, properties)

Page 11: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Architecture =

Boxes and lines 😄

Page 12: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Architecture is multi-dimensional e.g. Structural, electrical, plumbing,

mechanical⇒

Described by multiple views

View = (elements, relations, properties)

Page 13: There is no such thing as a microservice! (oracle code nyc)

4+1 view model

Logical View

Process View

Deployment View

Implementation View

Scenarios

Page 14: There is no such thing as a microservice! (oracle code nyc)

4+1 Logical view

Logical View

Process View

Deployment View

Implementation View

Scenarios

Elements: classes and packages Relations: inheritance, associations, …

Page 15: There is no such thing as a microservice! (oracle code nyc)

4+1 Implementation view

Logical View

Process View

Deployment View

Implementation View

Scenarios

Elements: modules and components Relations: dependencies

Page 16: There is no such thing as a microservice! (oracle code nyc)

4+1 Process view

Logical View

Process View

Deployment View

Implementation View

ScenariosElements: processes Relations: IPC

Page 17: There is no such thing as a microservice! (oracle code nyc)

4+1 Deployment view

Logical View

Process View

Deployment View

Implementation View

ScenariosElements: “machines” Relations: networking

Page 18: There is no such thing as a microservice! (oracle code nyc)

4+1 Scenarios

Logical View

Process View

Deployment View

Implementation View

ScenariosDerived from use cases/stories

Animate the views

Page 19: There is no such thing as a microservice! (oracle code nyc)

@crichardson

""… An architectural style determines the vocabulary of components and

connectors that can be used in instances of that style, together with a set of constraints on how they can be

combined….. ”” David Garlan and Mary Shaw, An Introduction to Software Architecture

Page 20: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Layered architectural styleLayer N

Layer N - 1

Layer N - 2

Well defined responsibilities

Page 21: There is no such thing as a microservice! (oracle code nyc)

The role of architecture

Requirements =

Functional requirements +

Non-functional requirements (-ilities)

Domain knowledge

Architecture

Page 22: There is no such thing as a microservice! (oracle code nyc)

Important -ilitiesMaintainability

Evolvability

Testability

Deployability

Scalability

Security

Reliability

https://en.wikipedia.org/wiki/Non-functional_requirement

Development velocity

Page 23: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Businesses must innovate faster ⇒

Build better software faster

Page 24: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Reducing lead time

Increasing deployment frequency

Page 25: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Modern software development

Architecture:

Process:

Small, autonomous teams

???

Continuous delivery/deployment

Organization:

Page 26: There is no such thing as a microservice! (oracle code nyc)

Agenda

A brief refresher on software architecture

From monolith to microservices

Microservices != silver bullet

Managing distributed data

Page 27: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Tomcat/App. Server

Traditional: Monolithic architecture

Browser/Client

WAR/EAR

MySQL Database

Review Module

Catalog Module

Recommendation Module

StoreFrontUI

Order Module

HTMLREST/JSON

Logical view

Page 28: There is no such thing as a microservice! (oracle code nyc)

@crichardson

The monolithic architecture is an architectural style

that structures the application as a single executable

component

Implementation view

Page 29: There is no such thing as a microservice! (oracle code nyc)

-ilities of small monolithsMaintainability

Evolvability

Testability

Deployability

Scalability

https://en.wikipedia.org/wiki/Non-functional_requirement

😄

Page 30: There is no such thing as a microservice! (oracle code nyc)

@crichardson

But successful applications keep growing….

Development Team Application

Page 31: There is no such thing as a microservice! (oracle code nyc)

@crichardson

… and growing

Development Team A

ApplicationDevelopment Team B

Development Team C

Page 32: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Eventually:

agile development

and deployment becomes

impossible

=

monolithic hell

Page 33: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Technology stack becomes increasingly obsolete

BUT A rewrite is not feasible

Page 34: There is no such thing as a microservice! (oracle code nyc)

-ilities of large monoliths

Maintainability

Evolvability

Testability

Deployability

https://en.wikipedia.org/wiki/Non-functional_requirement

😭

Page 35: There is no such thing as a microservice! (oracle code nyc)

The microservice architecture is an architectural style

that structures an application as a

set of loosely coupled, services organized around

business capabilities

Implementation view

Page 36: There is no such thing as a microservice! (oracle code nyc)

@crichardson

A business has a business capabilities

Acme, Inc

Order Taking Inventory

management

Delivery management

A Business Capability

is something a business

does in order to deliver value

Page 37: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Service = business capability

Order Taking Service

Inventory management Service

Delivery management Service

… Service

Page 38: There is no such thing as a microservice! (oracle code nyc)

Service size is secondary

microservice architecture

Page 39: There is no such thing as a microservice! (oracle code nyc)

Service:

Meaningful business functionality

Developed by a small team

Minimal lead time/high deployment frequency

Page 40: There is no such thing as a microservice! (oracle code nyc)

Microservices =

Microservice architecture =

Application architecture ⇒

No such thing as a microservice

Page 41: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Example microservice architecture

Browser

Mobile Device

Store Front

Web App

API Gateway

Catalog Service

Review Service

Order Service

… Service

Catalog Database

Review Database

Order Database

… Database

HTML

REST

REST

Supplier Inbound Gateway

Catalog update messages

Supplier System

Page 42: There is no such thing as a microservice! (oracle code nyc)

-ilities of a microservice architecture

Maintainability

Evolvability

Testability

Deployability

Scalability

https://en.wikipedia.org/wiki/Non-functional_requirement

😄

Page 43: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Microservices enable continuous delivery/deployment

Process: Continuous delivery/deployment

Organization:Small, agile, autonomous,

cross functional teams

Architecture: Microservice architecture

Enables

Enables Enables

SuccessfulSoftware

Development

Services improve testability

and deployability

Teams own services

Page 44: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Evolve the technology stack

Pick a new technology when

Writing a new service

Making major changes to an existing service

Let’s you experiment and fail safely

Page 45: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Agenda

A brief refresher on software architecture

From monolith to microservices

Microservices != silver bullet

Managing distributed data

Page 46: There is no such thing as a microservice! (oracle code nyc)

@crichardson

No silver bullets

http://en.wikipedia.org/wiki/Fred_Brooks

Page 47: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Drawbacks of microservices

Complexity

Development: partial failure, distributed data Testing: Integration, end to end, …Deployment …

Page 48: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Are microservices a good fit for my application?

Page 49: There is no such thing as a microservice! (oracle code nyc)

@crichardson

When using microservices:How to decompose an application into services?

How to deploy an application’s services?How to handle cross cutting concerns?

Which communication mechanisms to use?

How do external clients communicate with the services?

How does a client discover the network location of a service instance?

How to prevent a network or service failure from cascading to other services?

How to maintain data consistency and implement queries?

How to make testing easier?

How to understand the behavior of an application and troubleshoot problems?

How to implement a UI screen or page that displays data from multiple services?

Page 50: There is no such thing as a microservice! (oracle code nyc)

@crichardson

It depends!

Page 51: There is no such thing as a microservice! (oracle code nyc)

@crichardson

What’s a pattern?

Reusable solution to a problem

occurring in a particular context

Page 52: There is no such thing as a microservice! (oracle code nyc)

@crichardson

The structure of a pattern

Resulting context

aka the situation

Name

Context

Problem

Related patterns

(conflicting) issues etc to address Forces

Solution

Page 53: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Example resulting context

Microservice

Architecture

Benefits

Drawbacks

Issues to resolve

Page 54: There is no such thing as a microservice! (oracle code nyc)

@crichardsonMicroservice patterns

Communication patterns

Core

Cross-cutting concerns Security

Deployment

Maintaining data consistency

Database architecture

External API

Reliability

Discovery

Communication style

Testing

Observability

UI

Decomposition

API gateway

Client-side discovery

Server-side discovery

Service registry

Self registration

3rd party registration

Multiple Services per host

Single Service per Host

Service-per-Container

Service-per-VM

Messaging Remote ProcedureInvocation

Database per Service

Event-driven architectureShared

database

Microservice Chassis

Backend for front end

Event sourcing

Transaction log tailing

Database triggers

Application events

Monolithic architecture

Microservice architecture

CQRS

MotivatingPattern

SolutionPattern

Solution A Solution B

General Specific

Serverless deployment

Circuit BreakerAccess Token

Domain-specific

Externalized configuration

Service Integration Contract Test

Service Component Test

Exception tracking

Distributed tracing

Audit logging Application metrics

Log aggregation

Health check API

Service deployment platform

Server-side page fragment

composition

Client-side UI composition

Decompose bybusiness capability

Decompose bysubdomain

Application patterns

Infrastructure patterns

Application Infrastructure patterns

Microservices pattern language: http://microservices.io

Page 55: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Agenda

A brief refresher on software architecture

From monolith to microservices

Microservices != silver bullet

Managing distributed data

Page 56: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Loose coupling = encapsulated data

Order Service Customer Service

Order Database Customer Database

Order table Customer table

orderTotal creditLimit

Page 57: There is no such thing as a microservice! (oracle code nyc)

@crichardson

How to enforce credit limit?

sum(order.total) <= customer.creditLimit

Page 58: There is no such thing as a microservice! (oracle code nyc)

@crichardson

How to enforce credit limit?

BEGIN TRANSACTION … SELECT ORDER_TOTAL FROM ORDERS WHERE CUSTOMER_ID = ? … SELECT CREDIT_LIMIT FROM CUSTOMERS WHERE CUSTOMER_ID = ? … INSERT INTO ORDERS … … COMMIT TRANSACTION

Private to the Order Service

Private to the Customer Service

Distributed transactions

Page 59: There is no such thing as a microservice! (oracle code nyc)

@crichardson

2PC is not an option

Page 60: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Saga

Instead: use event-driven sagasDistributed transaction

Order Customer

Local transaction

Order

Local transaction

Customer

Local transaction

Order

Event Event

Page 61: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Order Service

Saga-based, eventually consistent order processing

Customer Service

Order created

Credit Reserved

Credit Check Failed

Create Order

OR Customer

creditLimit creditReservations ...

Order

state total …

approve()/reject()

Event Handler

Event Handler

reserveCredit()

Page 62: There is no such thing as a microservice! (oracle code nyc)

@crichardson

But how to reliably update the database

and publish events?

Page 63: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Event sourcing: event-centric persistence

Event table

Entity type Event id

Entity id

Event data

Order 902101 …OrderApproved

Order 903101 …OrderShipped

Event type

Order 901101 …OrderCreated

Page 64: There is no such thing as a microservice! (oracle code nyc)

@crichardson

How to find recent, valuable customers?

SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ?

Customer Service

Order Service

What if event sourcing is

used?…. is no longer easy

Page 65: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Command Query Responsibility Segregation (CQRS)

Command side

Commands

Aggregate

Event Store

Events

Query side

Queries

(Materialized) View

Events

POST PUT DELETE

GET

Page 66: There is no such thing as a microservice! (oracle code nyc)

@crichardson

Queries ⇒ database (type)

Command side

POST PUT DELETE

Aggregate

Event Store

Events

Query side

GET /customers/id

MongoDB

Query side

GET /orders?text=xyz

ElasticSearch

Query side

GET …

Neo4j

Page 67: There is no such thing as a microservice! (oracle code nyc)

@crichardson

SummaryThe goal of architecture is to satisfy non-functional requirements

Use the appropriate architectural style

Small applications ⇒ Monolithic architecture

Complex applications ⇒ Microservice architecture

Use the pattern language to guide your decision making

Use an event-driven architecture for transactions and queries

Page 68: There is no such thing as a microservice! (oracle code nyc)

@crichardson

@crichardson [email protected]

http://learnmicroservices.io

Thank you!