Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

63
Building Java applica.ons for the Cloud: The DHARMA principles Daniel Bryant Principal Consultant, Open Credo [email protected] @danielbryantuk

description

JAX London Presentation 2014

Transcript of Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Page 1: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Building  Java  applica.ons  for  the  Cloud:                The  DHARMA  principles  

Daniel  Bryant  Principal  Consultant,  Open  Credo  

 [email protected]  

@danielbryantuk  

Page 2: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 3: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Who  Am  I?  

•  LJC  Associate  

•  Adopt  OpenJDK  and  JSR  

14/10/2014   @danielbryantuk  

•  Principal  Consultant  at  OpenCredo  ü  Agile  transforma.ons  

ü  DevOps  ü  Microservices  and  Cloud  

 

Page 4: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

The  Current  Industry  Wish  List…  

•  Service-­‐Oriented  Architecture  

•  Cloud-­‐based  deployments  

•  DevOps  Culture  

@danielbryantuk  14/10/2014  

Page 5: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 6: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

 Common  Cloud  Problems  

 TL;DR…  

14/10/2014   @danielbryantuk  

Page 7: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Not  respec<ng  the  underlying  environment  

Page 8: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Lack  of  applica<on/plaDorm  monitoring…  

Page 9: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Bizarre  failure  modes…    

Page 10: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Difficulty  in  understanding  the  new  architecture  

Page 11: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Confusion  over  environment  provisioning  and  config  

Page 12: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Not  tes<ng  in  the  Cloud…  (hint:  here  be  dragons!)  

Page 13: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

   We’ve  created  the  “Cloud  DHARMA  Principles”  to  act  as  a  checklist  when  building  Cloud  apps  

14/10/2014   @danielbryantuk  

Page 14: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 15: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 16: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 17: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Page 18: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 19: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Simon  Brown’s  C4  Model  

14/10/2014   @danielbryantuk  

www.codingthearchitecture.com    

Page 20: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Page 21: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  14/10/2014   @danielbryantuk  

Page 22: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

API  Docs  with  Swagger  

14/10/2014   @danielbryantuk  

helloreverb.com/developers/swagger    

Page 23: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Create  a  PACT  

14/10/2014   @danielbryantuk  

github.com/DiUS/pact-­‐jvm    

Page 24: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 25: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

High  Cohesion  /  Loose  Coupling    (all  the  way  down…)  

•  Code  

•  Architecture  –  Components  –  Services  

•  Public  API  –  PayPal  (bit.ly/1hnZNly)  

14/10/2014   @danielbryantuk  

Page 26: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 27: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Microservices    

•  Probably  won’t  catch  on…  ;-­‐)  

14/10/2014   @danielbryantuk  

Page 28: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Twelve  Factor  Apps  

14/10/2014   @danielbryantuk  

h`p://12factor.net/  

Page 29: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 30: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Automated  from  Commit  to  Cloud  

14/10/2014   @danielbryantuk  

•  Con.nuous  Integra.on  

•  Con.nuous  Deployment  

•  Con.nuous  Delivery  

Page 31: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 32: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 33: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 34: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 35: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 36: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 37: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 38: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 39: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Deployment  PlaPorm:  What  you’ve  got…  

14/10/2014   @danielbryantuk  

Page 40: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

What  you  think  you  want…  

14/10/2014   @danielbryantuk  

Page 41: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

What  you  actually  get…  

14/10/2014   @danielbryantuk  

Fact:  9  out  of  10  cheetahs  prefer  the    taste  of  an  Ops  team  over  <nned  food  

Page 42: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 43: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 44: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 45: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 46: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 47: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Monitor  All  The  Things!  

•  Infrastructure  monitoring  – Nagios  /  Zabbix  – AppDynamics  

 •  Distributed  Tracing    –  twi`er.github.io/zipkin  

•  Centralised  Logging  –  logstash.net    

14/10/2014   @danielbryantuk  

Page 48: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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    

Page 49: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Health  Checks  

14/10/2014   @danielbryantuk  

Page 50: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Gauges,  Counters,  Meters,  Timers…  

14/10/2014   @danielbryantuk  

Page 51: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Graph  It!  

14/10/2014   @danielbryantuk  

dashing.io    

Page 52: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Phrase  borrowed  from  Etsy!  

Page 53: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

14/10/2014   @danielbryantuk  

Page 54: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 55: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 56: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 57: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Retries  

14/10/2014   @danielbryantuk  

github.com/rholder/guava-­‐retrying    

Page 58: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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/    

 

Page 59: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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  

Page 60: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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/    

Page 61: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

An.fragile  Pa`erns:  Elas.c  Scaling  

Stateless  components                

Distributed  data  stores  /  caches    14/10/2014   @danielbryantuk  

Page 62: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

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…  

Page 63: Building effective Java applications for the Cloud: The DHARMA principles - Daniel Bryant

Thanks  For  Listening  

•  Massive  thanks  to  all  the  OpenCredo  team!  

•  Ques.ons  /  comments?  – [email protected]  – @danielbryantuk  

14/10/2014   @danielbryantuk