building effective java applications for the cloud: the dharma principles - daniel bryant
DESCRIPTION
JAX London Presentation 2014TRANSCRIPT
Building Java applica.ons for the Cloud: The DHARMA principles
Daniel Bryant Principal Consultant, Open Credo
@danielbryantuk
What to expect • Problems when developing for the Cloud – “LiG and shiG” – Smashing the monolith – Greenfield (“Cloud na.ve”)
• Some sugges.ons on where to focus efforts – Not specific plaPorm/framework reviews
• Tools and techniques
• Lots of informa.on… (slides will be available)
14/10/2014 @danielbryantuk
Who Am I?
• LJC Associate
• Adopt OpenJDK and JSR
14/10/2014 @danielbryantuk
• Principal Consultant at OpenCredo ü Agile transforma.ons
ü DevOps ü Microservices and Cloud
The Current Industry Wish List…
• Service-‐Oriented Architecture
• Cloud-‐based deployments
• DevOps Culture
@danielbryantuk 14/10/2014
The Current Industry Wish List…
• Service-‐Oriented Architecture – Twi`er’s Story (bit.ly/1j1WbmI)
• Cloud-‐based deployments – Today!
• DevOps Culture – Devoxx UK talk (bit.ly/1BylnZb) – Previous LJC Event (bit.ly/1elVPJz)
@danielbryantuk 14/10/2014
Common Cloud Problems
TL;DR…
14/10/2014 @danielbryantuk
14/10/2014 @danielbryantuk
Not respec<ng the underlying environment
14/10/2014 @danielbryantuk
Lack of applica<on/plaDorm monitoring…
14/10/2014 @danielbryantuk
Bizarre failure modes…
14/10/2014 @danielbryantuk
Difficulty in understanding the new architecture
14/10/2014 @danielbryantuk
Confusion over environment provisioning and config
14/10/2014 @danielbryantuk
Not tes<ng in the Cloud… (hint: here be dragons!)
We’ve created the “Cloud DHARMA Principles” to act as a checklist when building Cloud apps
14/10/2014 @danielbryantuk
dharma /ˈdɑːmə,ˈdəːmə/ noun 1. Signifies behaviors that are considered to be in
accord with order that makes life and universe possible (Hinduism)
2. "cosmic law and order”, but is also applied to the teachings of the Buddha (Buddhism)
14/10/2014 @danielbryantuk
Documented (just enough)
Highly cohesive/loosely coupled (all the way down)
Automated from commit to Cloud
Resource aware Monitored thoroughly
An.fragile
14/10/2014 @danielbryantuk
Documented (just enough)
Highly cohesive/loosely coupled (all the way down)
Automated from commit to Cloud
Resource aware Monitored thoroughly
An.fragile
14/10/2014 @danielbryantuk
14/10/2014 @danielbryantuk
Documenta.on (just enough)
• Provide a map for developers
• Component purpose (and contract)
• Ini.alisa.on instruc.ons (mocks/stubs)
• Highlights areas of opera.onal risk
14/10/2014 @danielbryantuk
Simon Brown’s C4 Model
14/10/2014 @danielbryantuk
www.codingthearchitecture.com
14/10/2014 @danielbryantuk
14/10/2014 @danielbryantuk 14/10/2014 @danielbryantuk
API Docs with Swagger
14/10/2014 @danielbryantuk
helloreverb.com/developers/swagger
Create a PACT
14/10/2014 @danielbryantuk
github.com/DiUS/pact-‐jvm
Documented (just enough)
Highly cohesive/loosely coupled (all the way down)
Automated from commit to Cloud
Resource aware Monitored thoroughly
An.fragile
14/10/2014 @danielbryantuk
High Cohesion / Loose Coupling (all the way down…)
• Code
• Architecture – Components – Services
• Public API – PayPal (bit.ly/1hnZNly)
14/10/2014 @danielbryantuk
Smashing the Monolith…
• Business func.onality -‐“Cart Service”
• Technology chunk -‐ “Email Service”
• Ver.cal Slice – “Registra.on” (Groupon: vimeo.com/105880150)
• Horizontal Slice – “User Repo” (Microservices: oreil.ly/1pp6qmx)
14/10/2014 @danielbryantuk
Microservices
• Probably won’t catch on… ;-‐)
14/10/2014 @danielbryantuk
Twelve Factor Apps
14/10/2014 @danielbryantuk
h`p://12factor.net/
Documented (just enough)
Highly cohesive/loosely coupled (all the way down)
Automated from commit to Cloud
Resource aware Monitored thoroughly
An.fragile
14/10/2014 @danielbryantuk
Automated from Commit to Cloud
14/10/2014 @danielbryantuk
• Con.nuous Integra.on
• Con.nuous Deployment
• Con.nuous Delivery
Our Build Pipeline
Jenkins, with plugins…
• Build Pipeline – wiki.jenkins-‐ci.org/display/JENKINS/Build+Pipeline+Plugin
• Parameterized build – wiki.jenkins-‐ci.org/display/JENKINS/Parameterized+Build
• Promoted Builds Plugin – wiki.jenkins-‐ci.org/display/JENKINS/Promoted+Builds+Plugin
14/10/2014 @danielbryantuk
Our Build Pipeline
• Component Build – Compile – Unit Tests (surefire) – Integra.on Tests (failsafe)
• Deployment onto QA Cloud – Python Scripts + Chef to provision – Verify success using Python – Serverspec serverspec.org
14/10/2014 @danielbryantuk
Our Build Pipeline
• Acceptance Tests – Cucumber (and Selenium)
• Performance Tests – Jmeter + Jenkins performance plugin – Make sure environment is realis.c!!
• Live Deployment?
14/10/2014 @danielbryantuk
Automa.ng QA
• Intra-‐component integra.on tes.ng – U.lise embedded datastore/middleware – “Scassandra” (github.com/scassandra) – Service virtualisa.on (www.mbtest.org)
• Inter-‐component integra.on tes.ng – The hardest part of SOA… – Consider ‘synthe.c txns’ (ac.ve monitoring)
14/10/2014 @danielbryantuk
Infrastructure: Say No To Snowflakes!
• Automate all provisioning (store in SCM)
• Fry... – Chef, Puppet, SaltStack, Ansible – Bash, Python (Fabric) – Vendor APIs
• …or bake? – Packer.io – NePlix Aminator
14/10/2014 @danielbryantuk
Infrastructure: Say No To Snowflakes!
• Doing “Proper Development” – Gareth Rushgrove at CraG Conf (bit.ly/1njuc49) – Chef Conf (www.youtube.com/user/getchef)
• Local tooling/tes.ng – Vagrant (www.vagrantup.com) – Docker (www.docker.io)
14/10/2014 @danielbryantuk
Configuring the Cloud
• Bundle config with app – Upload new config file – Re-‐deploy en.re app (easier with Docker?)
• Store externally – Zookeeper & Curator curator.apache.org – NePlix Archaius github.com/NePlix/archaius – etcd github.com/coreos/etcd – Consul.io www.consul.io
14/10/2014 @danielbryantuk
Documented (just enough)
Highly cohesive/loosely coupled (all the way down)
Automated from commit to Cloud
Resource aware Monitored thoroughly
An.fragile
14/10/2014 @danielbryantuk
Deployment PlaPorm: What you’ve got…
14/10/2014 @danielbryantuk
What you think you want…
14/10/2014 @danielbryantuk
What you actually get…
14/10/2014 @danielbryantuk
Fact: 9 out of 10 cheetahs prefer the taste of an Ops team over <nned food
Thou Shalt Know thy Cloud…
• AWS “Magne.c” EBS 100 IOPS – New SSD EBS 3K IOPS (burst, PIOPS available) – My Mac SSD does 49K IOPS
• 1000Mbps network max transfer ~125MB/s – My Mac does 400+ MB/s Sequen.al Write to SSD
Reference for Mac sta.s.cs: bit.ly/1GJZH8
14/10/2014 @danielbryantuk
Thou Shalt Know they Cloud…
“Everything fails all the <me [in the cloud]” Werner Vogels, CTO, Amazon.com
• Everything is ephemeral
• Vola.lity • Noisy (virtual) neighbours – bit.ly/1w1HQy7
14/10/2014 @danielbryantuk
Thinking/Ac.ng Opera.onally
• Cul.vate “Mechanical Sympathy”
• Virtualisa.on – Tech Target (bit.ly/1kDVqyG)
• Networking – ‘Unix and Linux System Administra.on Handbook’ – aws.amazon.com/documenta.on
14/10/2014 @danielbryantuk
Thinking/Ac.ng Opera.onally
• Learn Linux fundamentals
• Diagnos.c skills – top, netstat, vmstat, tcpdump – Java u.ls: jps, jstat, jmap, jhat – “DevOps Troubleshoo.ng” by K. Rankin
14/10/2014 @danielbryantuk
Documented (just enough)
Highly cohesive/loosely coupled (all the way down)
Automated from commit to Cloud
Resource aware Monitored thoroughly
An.fragile
14/10/2014 @danielbryantuk
Monitor All The Things!
• Infrastructure monitoring – Nagios / Zabbix – AppDynamics
• Distributed Tracing – twi`er.github.io/zipkin
• Centralised Logging – logstash.net
14/10/2014 @danielbryantuk
Component Metrics
14/10/2014 @danielbryantuk
• Dropwizard’s Metrics – metrics.codahale.com – Spring Boot (bit.ly/1rGo76V)
• NePlix’s Servo – github.com/NePlix/servo
• Etsy’s StatsD – github.com/etsy/statsd/wiki
Health Checks
14/10/2014 @danielbryantuk
Gauges, Counters, Meters, Timers…
14/10/2014 @danielbryantuk
Graph It!
14/10/2014 @danielbryantuk
dashing.io
14/10/2014 @danielbryantuk
Phrase borrowed from Etsy!
14/10/2014 @danielbryantuk
Documented (just enough)
Highly cohesive/loosely coupled (all the way down)
Automated from commit to Cloud
Resource aware Monitored thoroughly
An.fragile
14/10/2014 @danielbryantuk
An.fragile
• The opposite of fragile? – Robust… – An.fragile…
• NePlix are best-‐in-‐class – bit.ly/1gs5n3q
• System must be robust first!
14/10/2014 @danielbryantuk
Design for Failure
• Distributed Compu.ng Principles – ‘For young bloods’ (bit.ly/1pKVepz) – NePlix (bit.ly/1h5GMid)
• Design pa`erns – Timeouts / retries – Bulkheads / circuit-‐breakers
14/10/2014 @danielbryantuk
Retries
14/10/2014 @danielbryantuk
github.com/rholder/guava-‐retrying
Circuit-‐breaker
14/10/2014 @danielbryantuk
github.com/NePlix/Hystrix github.com/NePlix/Hystrix/tree/master/hystrix-‐contrib/hystrix-‐javanica
java.dzone.com/ar.cles/hystrix-‐and-‐spring-‐boot projects.spring.io/spring-‐cloud/
An.fragile Pa`erns: Async FTW Asynchronous Communica.on -‐ queues, pub/sub Command Query Responsibility Segrega.on (CQRS) Event Sourcing (ES)
mar.nfowler.com/bliki/CQRS.html
14/10/2014 @danielbryantuk
An.fragile Pa`erns: Respect the CAP
Eventual consistency (ACID vs BASE)
Clever caching (soG-‐state)
14/10/2014 @danielbryantuk
en.wikipedia.org/wiki/CAP_theorem cloudshankar.blogspot.co.uk/2013/05/eventual-‐consistency.html www.dataversity.net/acid-‐vs-‐base-‐the-‐shiGing-‐ph-‐of-‐database-‐transac.on-‐processing/
An.fragile Pa`erns: Elas.c Scaling
Stateless components
Distributed data stores / caches 14/10/2014 @danielbryantuk
Documented (just enough)
Highly cohesive/loosely coupled (all the way down)
Automated from commit to Cloud
Resource aware Monitored thoroughly
An.fragile 14/10/2014 @danielbryantuk
So, Cloud Apps are ‘done’ when…
Thanks For Listening
• Massive thanks to all the OpenCredo team!
• Ques.ons / comments? – [email protected] – @danielbryantuk
14/10/2014 @danielbryantuk