Top Banner
48

Eduards Sizovs - Micro Service Architecture

May 13, 2015

Download

Software

DevConFu

Eduards will talk about micro service architecture - approach to designing software when complex app is broken into tiny, cohesive services which are apps themselves. Anatomy of micro services will be covered with practical implementation advices in Java.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Eduards Sizovs - Micro Service Architecture
Page 2: Eduards Sizovs - Micro Service Architecture

Service Architectureµwww.craftsmans.lv

Page 3: Eduards Sizovs - Micro Service Architecture

Eduards [email protected]

www.linkedin.com/in/eduardsi

@eduardsi on Twitter

Who is broadcasting?

Page 4: Eduards Sizovs - Micro Service Architecture

Agenda

• Anatomy of a micro service• Micro service architecture by

example• The Good Parts of the solution• Tooling• Q&A

Page 5: Eduards Sizovs - Micro Service Architecture

Anatomy of a micro service

Page 6: Eduards Sizovs - Micro Service Architecture

Micro services are tiny apps talking via uniform interface

installed as well-behaved OS services.

Page 7: Eduards Sizovs - Micro Service Architecture

java –jar micro-service.jar config.yml

Page 8: Eduards Sizovs - Micro Service Architecture
Page 9: Eduards Sizovs - Micro Service Architecture

Traditional application vs. µ service based

Page 10: Eduards Sizovs - Micro Service Architecture

Micro service architecture by example

Page 11: Eduards Sizovs - Micro Service Architecture

Dropwizard

• Jetty

• Jersey

• Jackson

• Metrics

• Guava

• Joda Time

• Hibernate Validator

• LiquiBase

• YAML configuration

• Graceful shutdown

• Command-line API

Foundation for production ready micro services developed by

Dropwizard on InfoQ goo.gl/2RYALb

Page 12: Eduards Sizovs - Micro Service Architecture

Command-line API?

unrecognized argument '--tpye'Did you mean: --type

Page 13: Eduards Sizovs - Micro Service Architecture

Internal Loan Underwriting System

Requirement №1

Perform underwriting according to rules

specified in DSL and store decisions in

relational DB.

Page 14: Eduards Sizovs - Micro Service Architecture

“…according to rules specified in DSL

DSL hero is…

Page 15: Eduards Sizovs - Micro Service Architecture

RDB hero is…

“…and store decisions in Relational DB

Page 16: Eduards Sizovs - Micro Service Architecture

Underwriter

Relational DB

RESTful API / JSON

Page 17: Eduards Sizovs - Micro Service Architecture

Internal Loan Underwriting System

Requirement №2

Fancy back-office application that allows users to

perform underwriting and look over decisions.

Why separate micro service?

• Back-office is a regular client. Many still to come.

• Back-office is stateful

• Back-office is server-centric, no JavaScript

experience

• Independent coding, testing & deployment

Page 18: Eduards Sizovs - Micro Service Architecture

“…fancy back-office application

Fancy UI hero

is…

…because we’re close to

Finland

Page 19: Eduards Sizovs - Micro Service Architecture

Underwriter

Relational DB

Back-Office

Page 20: Eduards Sizovs - Micro Service Architecture

Internal Loan Underwriting System

Requirement №3

Collect credit history from various 3rd party

providers in parallel.

Why separate micro service?

• SRP!

• We have a team of Scala enthusiasts

• ... which never Bootstrapped apps from scratch

• Operations must self-heal in case of failure –

Akka

Page 21: Eduards Sizovs - Micro Service Architecture

Underwriter

Relational DB

Back-Office

Credit History Collector

Page 22: Eduards Sizovs - Micro Service Architecture

Internal Loan Underwriting System

Requirement №4

Project codename «CHNAPI» - API for our brand new

partner «Chuck Norris».

Why separate micro service?

• Public service must run in DMZ

• Huge number of requests – queuing is a must

• Underwriter is not ready to scale – other dev

priorities

• We don’t know what kind of architecture to apply

yet

Page 23: Eduards Sizovs - Micro Service Architecture

Underwriter & CHNAPI Gateway integration

• Push can cause overload• What if Underwriter is down?

Underwriter CHNAPIGateway?

HTTPUnderwriter CHNAPI

Gateway

• More elements in chain• How well does it scale?

JMSUnderwriter CHNAPIGateway

• CHNAPI exposes Feed• Underwriter polls CHNAPI

for updates

Underwriter CHNAPIGateway

HTTP Polling

WebSockets Web Hooks

Page 24: Eduards Sizovs - Micro Service Architecture

Underwriter CHNAPIGateway

HTTP Polling

CHNAPIGateway

CHNAPIGateway

Load Balance

r

Load Balancer

DMZ

CHNAPI Gateway

JSON feed, OData or custom-crafted

Any JSON storage, e.g. MongoDB

Page 25: Eduards Sizovs - Micro Service Architecture

CHNAPI Gateway

Underwriter

Relational DB

Back-Office

Credit History Collector

MongoDB

Page 26: Eduards Sizovs - Micro Service Architecture

Internal Loan Underwriting System

Requirement №5

Chuck Norris is interested in all underwriting

decisions. Project codename «CHNORR».

Why separate micro service?

• Daily reporting, during active working hours

• External API Client with a tail of transitive

dependencies

• Neightbor dev team would like to use CHNORR!

Page 27: Eduards Sizovs - Micro Service Architecture

Underwriter CHNORR

CHNORR

CHNORR

DMZ

CHNORR

Load Balancer

Events

Spring Batch

Any storage for keeping data in reporting-friendly format

HTTP

Page 28: Eduards Sizovs - Micro Service Architecture

CHNAPI Gateway

Underwriter

Relational DB

Back-Office

Credit History Collector

MongoDB

CHNORR

MongoDB

Page 29: Eduards Sizovs - Micro Service Architecture

The Good Parts of the solution

Page 30: Eduards Sizovs - Micro Service Architecture

Toolset unchained

• Architectural approaches

• Polyglot• Storages

• Frameworks

Page 31: Eduards Sizovs - Micro Service Architecture

Scalability

• HTTP stack• Independent

provisioning• Fine tuning

• Elasticity

Page 32: Eduards Sizovs - Micro Service Architecture

Independence

• Development• Testing

• Deployment

Page 33: Eduards Sizovs - Micro Service Architecture

How to deploy in a proper order?

Supply Dependency Descriptor

with each micro service. For example:

depend.yaml for foo-service

dependencies:group: com.microservicesartifact: bar-serviceversion: 2.x.x

-

Page 34: Eduards Sizovs - Micro Service Architecture

How to deploy in a proper order?

We can forbid deployment in the wrong

order by validating dependencies on

Pipeline2.0.0

Test Prodbar-service

1.0.0

foo-service

Test Prod

1.9.0

bar-service

1.0.0

foo-service

Page 35: Eduards Sizovs - Micro Service Architecture

How to develop?

Together with Dependency Descriptor

(DD), put Vagrant file with DD-fed

provisioner in a root source directory.

- depend.yaml

- Vagrantfileup

Launch app with test doubles in place of real dependencies

Page 36: Eduards Sizovs - Micro Service Architecture

How to test?

For every dependency create a test

double

App

Foo

Bar Qux

Production

HTTP App

Foo-TD

Bar-TD

Testing

HTTP

Never mock internals. Mock externals

instead.

Page 37: Eduards Sizovs - Micro Service Architecture
Page 38: Eduards Sizovs - Micro Service Architecture

Tooling

Page 39: Eduards Sizovs - Micro Service Architecture

Testing & Live Doc

• MOCO for test double creation

• REST-assured for testing REST APIs

• Cucumber for describing API usage with examples

• Relish for publishing Cucumbers online

Page 40: Eduards Sizovs - Micro Service Architecture
Page 41: Eduards Sizovs - Micro Service Architecture
Page 42: Eduards Sizovs - Micro Service Architecture
Page 43: Eduards Sizovs - Micro Service Architecture

A shipping container system for your apps

VM without an overhead of VM

Docker on InfoQ http://goo.gl/ALnjYt

Why Docker? Why Not Chef? goo.gl/iJ8Idl

Page 44: Eduards Sizovs - Micro Service Architecture

Learn more • Micro Services by James Lewis goo.gl/PS7BYK

• Micro Services by Fred George goo.gl/dgd8Ya

Page 45: Eduards Sizovs - Micro Service Architecture

http://goo.gl/khddl

Page 46: Eduards Sizovs - Micro Service Architecture

Conclusion

Page 47: Eduards Sizovs - Micro Service Architecture

The next morning, "we had this orgy of `one liners.' Everybody had a one liner. Look at this, look at that. ...Everybody started putting forth the UNIX philosophy. Write programs that do one thing and do it well. Write programs to work together. Write programs that handle text streams, because that is a universal interface." Those ideas which add up to the tool approach, were there in some unformed way before pipes, but they really came together afterwards. Pipes became the catalyst for this UNIX philosophy. "The tool thing has turned out to be actually successful. With pipes, many programs could work together, and they could work together at a distance."

The Unix Philosophy http://www.faqs.org/docs/artu/ch01s06.html

The next morning, "we had this orgy of `one liners.' Everybody had a one liner. Look at this, look at that. ...Everybody started putting forth the UNIX philosophy. Write programs that do one thing and do it well. Write programs to work together. Write programs that handle text streams, because that is a universal interface." Those ideas which add up to the tool approach, were there in some unformed way before pipes, but they really came together afterwards. Pipes became the catalyst for this UNIX philosophy. "The tool thing has turned out to be actually successful. With pipes, many programs could work together, and they could work together at a distance."

The next morning, "we had this orgy of `one liners.' Everybody had a one liner. Look at this, look at that. ...Everybody started putting forth the UNIX philosophy. Write programs that do one thing and do it well. Write programs to work together. Write programs that handle text streams, because that is a universal interface." Those ideas which add up to the tool approach, were there in some unformed way before pipes, but they really came together afterwards. Pipes became the catalyst for this UNIX philosophy. "The tool thing has turned out to be actually successful. With pipes, many programs could work together, and they could work together at a distance."

The next morning, "we had this orgy of `one liners.' Everybody had a one liner. Look at this, look at that. ...Everybody started putting forth the UNIX philosophy. Write programs that do one thing and do it well. Write programs to work together. Write programs that handle text streams, because that is a universal interface." Those ideas which add up to the tool approach, were there in some unformed way before pipes, but they really came together afterwards. Pipes became the catalyst for this UNIX philosophy. "The tool thing has turned out to be actually successful. With pipes, many programs could work together, and they could work together at a distance."

The next morning, "we had this orgy of `one liners.' Everybody had a one liner. Look at this, look at that. ...Everybody started putting forth the UNIX philosophy. Write programs that do one thing and do it well. Write programs to work together. Write programs that handle text streams, because that is a universal interface." Those ideas which add up to the tool approach, were there in some unformed way before pipes, but they really came together afterwards. Pipes became the catalyst for this UNIX philosophy. "The tool thing has turned out to be actually successful. With pipes, many programs could work together, and they could work together at a distance."

Page 48: Eduards Sizovs - Micro Service Architecture

THANK YOU!