101
@mgrzejszczak Microservices at 4financeIT 08/06/2015, Prague

4finance microservices 2015.06 Prague JUG

Embed Size (px)

Citation preview

Page 1: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Microservices at 4financeIT

08/06/2015, Prague

Page 2: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

About meSoftware Architect atAuthor of "Mockito Instant", "Mockito Cookbook" booksCo-author of the Groovy core’s @Builder AST Co-founder of the Warsaw Groovy User GroupCo-author of "micro-infra-spring" libCo-author of “spring-cloud-zookeeper” and “spring-cloud-sleuth”

Twitter: @MGrzejszczakBlog: http://toomuchcoding.blogspot.comHomepage: http://marcin.grzejszczak.pl

Page 3: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Agendashort intro to microserviceshow we did it in 4financeITmicroservice challenges

Page 4: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Agendashort intro to microserviceshow we did it in 4financeITmicroservice challenges

Page 5: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Conway’s Law

Conway, Melvin E. (April 1968), How do Committees Invent?, Datamation 14 (5): 28–31, retrieved 2009-04-05

Organizations which design systems ... are constrained to produce designs which are copies of the communication structures of these organizations

— M. Conway

Page 6: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

A single codebase

Conway’s Law in practice

Page 7: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

A single codebase

Conway’s Law in practice

Page 8: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Conway’s Law in practiceConcept:

one team

two countries

one codebase

Page 9: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Conway’s Law in practiceReality:

two teams

two countries

one codebase

Page 10: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Conway’s Law in practiceEffect:

two different solutions

solving same stuff

one codebase

Page 11: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Conway’s Law - siloed teams

extract from http://martinfowler.com/articles/microservices.html

Page 12: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Conway’s Law - cross functional teams

extract from http://martinfowler.com/articles/microservices.html

Page 13: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Business flow

AccountingBack officeFront office

Page 14: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Common problematic code flow

Dto Service

Impl Entity

Accounting Accounting

Accounting Accounting

Front office Front office

Front office Front office

Back office Back office

Back office Back office

monolith

many programmers

big organization

Page 15: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Common problematic code flow

Looks familiar?

http://www.foodnetwork.com/topics/spaghetti-recipes.html

Page 16: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Code flow

REST REST

Autonomous

Business oriented

PolyglotLeightweight

Front officebounded context

JARS

Back officebounded context

JARS

Accountingbounded context

JARS

Page 17: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Small and lightweight

single application as a suite of small applications

each running in its own process

communicating with lightweight mechanisms

extract from http://martinfowler.com/articles/microservices.html

Page 18: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Business oriented

http://www.ops.fhwa.dot.gov/publications/ics_guide/

Page 19: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Business orientedbuilt around business capabilities

products not projects

cross business not technical boundaries

extract from http://martinfowler.com/articles/microservices.html

Page 20: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Polyglot

Page 21: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Autonomous

Page 22: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Autonomous

independently deployable / upgradeable

deployed via fully automated deployment machinery

extract from http://martinfowler.com/articles/microservices.html

Page 23: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Autonomous

bare minimum of centralized management (do not share your data, minimum set of standards)

embrace failure (resilience - recover fast)

extract from http://martinfowler.com/articles/microservices.html

Page 24: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Deployment - provisoning (Ansible)

http://labs.qandidate.com/blog/2013/11/21/installing-a-lamp-server-with-ansible-playbooks-and-roles/

Page 25: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Deployment - pipeline (Jenkins)

Page 26: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Deployment - job scheduling (Rundeck)

http://rundeck.org/

Page 27: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Fail fast

Page 28: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Agendashort intro to microserviceshow we did it in 4financeITmicroservice challenges

Page 29: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Explain one simple truth

Page 30: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Microservices are complex!who can I talk towhere are my collaboratorshow can I contact othershow can others contact mewhere do I take my properties fromwhat’s my APIhow to be part of a bigger system: logshow do I expose and view my metrics

Page 31: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Page 32: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

So we wrote a framework...

Page 33: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

… having management on our side

Page 34: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Microservices are complex!who can I talk towhere are my collaboratorshow can I contact othershow can others contact mewhere do I take my properties fromwhat’s my APIhow to be part of a bigger system: logshow do I expose and view my metrics

Page 35: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

The big picture

Page 36: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

The big picture

HEY GUYS LET’S TELL ZOOKEEPER WHERE WE ARE

Page 37: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

The big picture

MY IP: …MY PORT: ….

Page 38: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

The big pictureI WOULD LOVE TO TALK TO SERVICE X

Page 39: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

The big pictureWHERE IS SERVICE X ? GIVE ME ANY INSTANCE

Page 40: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

The big pictureTHERE YOU GO!IP: ….PORT: ….

Page 41: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

The big pictureGREAT NOW I CAN SEND HIM A REQUEST

Page 42: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Microservice descriptor{

"pl": {

"this": "some/path/my-name",

"dependencies": {

"an-alias": {

"path": "some/path/his-name"

}

}

}

Page 43: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Microservice descriptor{

"pl": {

"this": "some/path/my-name",

"dependencies": {

"an-alias": {

"path": "some/path/his-name"

}

}

}

REALM

Page 44: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Microservice descriptor{

"pl": {

"this": "some/path/my-name",

"dependencies": {

"an-alias": {

"path": "some/path/his-name"

}

}

}

MY NAME IN ZOOKEEPER

Page 45: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Microservice descriptor{

"pl": {

"this": "some/path/my-name",

"dependencies": {

"an-alias": {

"path": "some/path/his-name"

}

}

}

HIS NAME IN ZOOKEEPER

Page 46: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Problems of a microservicewho can I talk towhere are my collaboratorshow can I contact othershow can others contact mewhere do I take my properties fromwhat’s my APIhow to be part of a bigger system: logshow do I expose my metricshow do I view my metrics

Page 47: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How can I communicate easily?serviceRestClient.forService('an-alias')

.post()

.onUrl('/api/whatever/123')

.body('''{"some":"json"}''')

.withHeaders()

.contentTypeJson()

.andExecuteFor()

.anObject()

.ofType(String)

Page 48: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Problems of a microservicewho can I talk towhere are my collaboratorshow can I contact othershow can others contact mewhere do I take my properties fromwhat’s my APIhow to be part of a bigger system: logshow do I expose and view my metrics

Page 49: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Where do I take my props from?

Page 50: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Where do I take my props from?

Page 51: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Where do I take my props from?

Page 52: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Where do I take my props from?

Page 53: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Problems of a microservicewho can I talk towhere are my collaboratorshow can I contact othershow can others contact mewhere do I take my properties fromwhat’s my APIhow to be part of a bigger system: logshow do I expose and view my metrics

Page 54: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

your microservice publishes its API by itself!

What’s my API?

Page 55: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

What’s my API?

Page 56: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

What’s my API?

RESTCONTROLLERS

Page 57: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

What’s my API?

METHOD TYPES

Page 58: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

What’s my API?

METHOD URLS METHOD NAMES

Page 59: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

What’s my API? - Try me out!

Page 60: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

What’s my API? - Try me out!

ENTER PARAMETERS

SEND A REQUEST

Page 61: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Problems of a microservicewho can I talk towhere are my collaboratorshow can I contact othershow can others contact mewhere do I take my properties fromwhat’s my APIhow to be part of a bigger system: logshow do I expose and view my metrics

Page 62: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?You’re not going to grep your logs from 10 servers, right?

Page 63: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Correlation ID

a header value in a request

in each microservice this header is the same for the same business action

you can see a flow of messages between microservices in a chronological order

Page 64: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?

FIRST SERVICE

REQUEST

No correlationId

CorrelationId set to X

CorrelationId set to X

RESPONSE

SECOND SERVICE

REQUEST

CorrelationId set to X

CorrelationId set to X

RESPONSE

ANOTHER SERVICE

REQUEST

CorrelationId set to XCorrelationId

set to X

RESPONSECorrelationId set to X

YET ANOTHER SERVICE

REQUEST

CorrelationId set to XCorrelationId

set to X

RESPONSE

Page 65: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?Log example:

2014-09-10 14:34:40.448+0200 |

INFO |

538898f2-543f-48a3-ad9e-3d2961b2b73d |

qtp326276239-140 |

c.o.c.v.w.a.AbstractBackofficeApplication |

Initializing new backoffice application

Page 66: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?Log example:

2014-09-10 14:34:40.448+0200 |

INFO |

538898f2-543f-48a3-ad9e-3d2961b2b73d |

qtp326276239-140 |

c.o.c.v.w.a.AbstractBackofficeApplication |

Initializing new backoffice application

TIMESTAMP IN ISO8601 FORMAT

Page 67: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?Log example:

2014-09-10 14:34:40.448+0200 |

INFO |

538898f2-543f-48a3-ad9e-3d2961b2b73d |

qtp326276239-140 |

c.o.c.v.w.a.AbstractBackofficeApplication |

Initializing new backoffice application

LOGGING LEVEL

Page 68: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?Log example:

2014-09-10 14:34:40.448+0200 |

INFO |

538898f2-543f-48a3-ad9e-3d2961b2b73d |

qtp326276239-140 |

c.o.c.v.w.a.AbstractBackofficeApplication |

Initializing new backoffice application

CORRELATION ID

Page 69: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?Log example:

2014-09-10 14:34:40.448+0200 |

INFO |

538898f2-543f-48a3-ad9e-3d2961b2b73d |

qtp326276239-140 |

c.o.c.v.w.a.AbstractBackofficeApplication |

Initializing new backoffice application

THREAD NAME

Page 70: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?Log example:

2014-09-10 14:34:40.448+0200 |

INFO |

538898f2-543f-48a3-ad9e-3d2961b2b73d |

qtp326276239-140 |

c.o.c.v.w.a.AbstractBackofficeApplication |

Initializing new backoffice application

CLASS FULLY QUALIFIED NAME (SHORTENED)

Page 71: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?Log example:

2014-09-10 14:34:40.448+0200 |

INFO |

538898f2-543f-48a3-ad9e-3d2961b2b73d |

qtp326276239-140 |

c.o.c.v.w.a.AbstractBackofficeApplication |

Initializing new backoffice applicationLOG MESSAGE

Page 72: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?

Page 73: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?

SAME CORRELATION ID

Page 74: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How to be part of a bigger system: logs?

DIFFERENT MICROSERVICES

Page 75: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

View the logs in Kibana

Page 76: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Problems of a microservicewho can I talk towhere are my collaboratorshow can I contact othershow can others contact mewhere do I take my properties fromwhat’s my APIhow to be part of a bigger system: logshow do I expose and view my metrics

Page 77: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How do I expose my metrics?just have to update your metrics:

// treat this code more of a pseudocode ;)Counter transferBalanceRequests = metricRegistry.counter(‘transfer.requests.balance’)

void doSomethingUponTransferBalanceRequest() {

// do sth with the request for transfer balance…

// and update the counter metrictransferBalanceRequests.inc()

}

Page 78: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How do I view my metrics?

Page 79: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

How do I view my metrics?

Page 80: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Ok, so how do I start?But, but, but… it sounds so complicated!

Page 81: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Perform 3 steps...You just have to:

add ONE dependency - 4finance micro-infra-spring to your project

add ONE annotation - @EnableMicroservice

create ONE file - microservice.json

Page 82: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

One dependency with Spring Boot

And for Spring-Boot….

Page 83: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

It’s even easier with Spring Boot!You just have to:

add ONE dependency - 4finance micro-infra-spring-boot to your project

create ONE file - microservice.json

Page 84: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Ok, so how do I start?

Question:what should I do to start working on a new microservice?

Page 85: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Ok, so how do I start?

Answer:

Clone a repo

Page 86: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Ok, so how do I start?

Without UI:https://github.com/4finance/boot-microservice

With UI:https://github.com/4finance/boot-microservice (branch boot-microservice-gui)

Page 87: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Ok, so how do I start?those repos:

contain completely set up microservice

are written in Groovy and built with Gradle

are JDK8 compliant

contain an example of a business scenario

Page 88: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Where are we?

Majority of microservice related features are there…

We are moving our stuff to Spring-Cloud

We have automated / standardized plenty of things already

NOW

Move more stuff to Spring-Cloud

Leave 4financeIT related stuff in micro-infra-spring

Automate more

Standardize more stuff

NEXT

New templates for other JVM languages

Scale dynamically our production servers (Mesos, Marathon etc.)

Sky is the limit...

FUTURE

Page 89: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Working closely with Pivotal

Page 90: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Working closely with Pivotal

Page 91: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

3 steps to eternal fame1. Get account at Github

2. Pick an issue, fix it and create a pull request

3. Once merged profit from eternal fame

Page 92: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

The setup - overview

Page 93: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Agendashort intro to microserviceshow we did it in 4financeITmicroservice challenges

Page 94: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Code reusedo not abstract everything

sometimes copy paste gives you code decoupling

no - copy paste is not a solution to all problems ;)

Page 95: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Too many technology stackspick a right tool for the job but don’t exaggerate

do you really want to support a microservice written in Brainfuck or Whitespace?

Page 96: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Managing dozens of servicesmonitoring, monitoring, monitoring!

Zabbix, Nagios, Kibana, Graphite etc.

do not write nanoservices - who will support it?

Page 97: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Microservice envythose guys wrote a microservice and I’m diving in the abyss of a monolith

I will write a microservice per feature!

one bounded context - 100 microservices with duplicated data - WRONG!

Page 98: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Global changes (big features)you’ll have to work piece by piece and communicate

you can use feature toggling and API versioning

easier A/B testing - load balancing via Service Discovery

Page 99: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Testingcontract changes - how to test that?

how do I know what’s the API of other services?

Consumer Driven Contracts to the rescue!Accurest - https://github.com/Codearte/accurestPact - https://github.com/DiUS/pact-jvm

Page 100: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Management issueshave to invest time and effort to build foundations

have to invest in infrastructure and devops

feature delivery pace will decrease for some time

Page 101: 4finance microservices 2015.06 Prague JUG

@mgrzejszczak

Questions?