Adventures with
micro-Servicesby Anand Agrawal
@anand_agrawalanandagrawal84
What’s in it for you?
What?Why?How?When?
What are micro services?small independent composable
servicesthat do one thing well
What is the right size?
Unix philosophyWrite programs that do one thing well.
Write programs that work together.
cat | grep | sed | awk | ...
HTTP is the new pipe!
Single responsibility
Low coupling, high cohesion
Small, well defined interfaces
Object Oriented philosophy
“A 100k loc app is just 100 1k loc apps waiting to happen”
- Jeff Bay
used micro services?Why we
Once upon a time...
lots of legacy, no reuse
not flexible, high cost of change
concentrated complexity
no one knows how it works
90 year old business
independent small that do one thingcomposable
Adventure so far
25 VM’s in production
10 micro-services
one click deployment
60+ VM’s across environments
guess who does the deployments?
µService
DB
µService
DB
µService
DB
µService
DB
How did we start?
Solve small, valuable problems
Start with plain old services
When a service starts doing too much, extract a smaller one
Orders PaymentsCustomers
Legacy ResultsOrder Processing
Catalog (Games)
Looks like plain old services, what makes them ‘micro’?
single responsibility
1 service = 1 ‘resource’ (maybe 2!)
How do they communicate?
RESTful contracts
HTTP + JSON
Thumb Rules1 top level resource (2 at most)
bounded contexts
focus on contracts
extract cross cutting concerns
avoid coupling
sophisticated logging and monitoring
Orders PaymentsCustomers
Communications
Legacy ResultsOrder Processing
Scheduled Jobs
Error reporting
Catalog (Games)
Staying productive
client gems
ruby and rails
devops
automate, automate, automate
feature toggles over branches
How do I make a change and still stay sane?
Test It!
Unit Testsis my object doing what it should?
Contract Testsis my service doing what it should?
out of container
only test contracts, not implementation
Integration Testsare all my services playing nicely together?
testing distributed effects
testing async actions
Ship It!
“we’re effectively pushing the complexity from the application
into the infrastructure...”- James Lewis
Puppet Solo
Provisioning begins at home - Vagrant
Puppet scripts goes through CI just like app code
ImmutableServer
Provisioning
Continuous IntegrationUI# Services#Test# Puppet#Code#
Integra6on#
UAT#
Performance#
Produc6on#
10# 12# 20#
9#
8#
6#
3#
Configs#
15# 18#
4b3ee42#
with every checkin...run unit tests
run integration tests
run acceptance tests
build deployable package of the app
ship often!!
CI + CDenables
single-click deployment
so easy, our product owner does it!
it just works™
3 mins to production (~25 servers)
Cost of adding a service?
less than a day all the way to production
When to use micro-services?
Tradeoffs
benefit cost
small units of reuse/maintenance complex infrastructure
grow independently learning curve
scale independently network overhead
independent DB fragmented data
Questions?
Thanks!!