43
Adventures with micro-Services by Anand Agrawal @anand_agrawal anandagrawal84

Adventures with Microservices

Embed Size (px)

DESCRIPTION

I have spent some time working on a project, and built 8 micro services and 2 applications, and planned to carve out a few more. Deployment was carried out in a farm of 25 servers in production with a single click in less than 3 minutes. This presentation is about the experiences with building a micro service based architecture - the good, the bad and the ugly. - What are micro services? - When/Why/How micro services? - Why NOT micro services? - Managing Continuous Integration and Continuous Delivery with micro services - A few design principles that we followed and that worked for us

Citation preview

Page 1: Adventures with Microservices

Adventures with

micro-Servicesby Anand Agrawal

@anand_agrawalanandagrawal84

Page 2: Adventures with Microservices

What’s in it for you?

Page 3: Adventures with Microservices

What?Why?How?When?

Page 4: Adventures with Microservices

What are micro services?small independent composable

servicesthat do one thing well

Page 5: Adventures with Microservices

What is the right size?

Page 6: Adventures with Microservices

Unix philosophyWrite programs that do one thing well.

Write programs that work together.

cat | grep | sed | awk | ...

HTTP is the new pipe!

Page 7: Adventures with Microservices

Single responsibility

Low coupling, high cohesion

Small, well defined interfaces

Object Oriented philosophy

Page 8: Adventures with Microservices

“A 100k loc app is just 100 1k loc apps waiting to happen”

- Jeff Bay

Page 9: Adventures with Microservices

used micro services?Why we

Page 10: Adventures with Microservices

Once upon a time...

Page 11: Adventures with Microservices

lots of legacy, no reuse

not flexible, high cost of change

concentrated complexity

no one knows how it works

90 year old business

Page 12: Adventures with Microservices

independent small that do one thingcomposable

Page 13: Adventures with Microservices

Adventure so far

25 VM’s in production

10 micro-services

one click deployment

60+ VM’s across environments

guess who does the deployments?

Page 14: Adventures with Microservices

µService

DB

µService

DB

µService

DB

µService

DB

Page 15: Adventures with Microservices

How did we start?

Page 16: Adventures with Microservices

Solve small, valuable problems

Page 17: Adventures with Microservices

Start with plain old services

Page 18: Adventures with Microservices

When a service starts doing too much, extract a smaller one

Page 19: Adventures with Microservices

Orders PaymentsCustomers

Legacy ResultsOrder Processing

Catalog (Games)

Page 20: Adventures with Microservices

Looks like plain old services, what makes them ‘micro’?

Page 21: Adventures with Microservices

single responsibility

1 service = 1 ‘resource’ (maybe 2!)

Page 22: Adventures with Microservices

How do they communicate?

RESTful contracts

HTTP + JSON

Page 23: Adventures with Microservices

Thumb Rules1 top level resource (2 at most)

bounded contexts

focus on contracts

extract cross cutting concerns

avoid coupling

sophisticated logging and monitoring

Page 24: Adventures with Microservices

Orders PaymentsCustomers

Communications

Legacy ResultsOrder Processing

Scheduled Jobs

Error reporting

Catalog (Games)

Page 25: Adventures with Microservices

Staying productive

client gems

ruby and rails

devops

automate, automate, automate

feature toggles over branches

Page 26: Adventures with Microservices

How do I make a change and still stay sane?

Page 27: Adventures with Microservices

Test It!

Page 28: Adventures with Microservices
Page 29: Adventures with Microservices
Page 30: Adventures with Microservices

Unit Testsis my object doing what it should?

Page 31: Adventures with Microservices

Contract Testsis my service doing what it should?

out of container

only test contracts, not implementation

Page 32: Adventures with Microservices

Integration Testsare all my services playing nicely together?

testing distributed effects

testing async actions

Page 33: Adventures with Microservices

Ship It!

Page 34: Adventures with Microservices

“we’re effectively pushing the complexity from the application

into the infrastructure...”- James Lewis

Page 35: Adventures with Microservices

Puppet Solo

Provisioning begins at home - Vagrant

Puppet scripts goes through CI just like app code

ImmutableServer

Provisioning

Page 36: Adventures with Microservices

Continuous IntegrationUI# Services#Test# Puppet#Code#

Integra6on#

UAT#

Performance#

Produc6on#

10# 12# 20#

9#

8#

6#

3#

Configs#

15# 18#

4b3ee42#

Page 37: Adventures with Microservices

with every checkin...run unit tests

run integration tests

run acceptance tests

build deployable package of the app

ship often!!

Page 38: Adventures with Microservices

CI + CDenables

single-click deployment

so easy, our product owner does it!

it just works™

3 mins to production (~25 servers)

Page 39: Adventures with Microservices

Cost of adding a service?

less than a day all the way to production

Page 40: Adventures with Microservices

When to use micro-services?

Page 41: Adventures with Microservices

Tradeoffs

benefit cost

small units of reuse/maintenance complex infrastructure

grow independently learning curve

scale independently network overhead

independent DB fragmented data

Page 42: Adventures with Microservices

Questions?

Page 43: Adventures with Microservices

Thanks!!