JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

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

description

Building Java applications for the Cloud is easy, right? Perhaps, but if you want to build effective and reliable applications that not only work correctly within the Cloud, but also take advantage of running within this unique environment, then you might be in for a surprise. This talk will introduce lessons learnt over the past several years of designing and implementing successful Cloud-based Java applications which we have codified into our Cloud development ‘DHARMA' principles; Documented (just enough); Highly cohesive / lowly coupled (all the way down); Automated from commit to cloud; Resource aware; Monitored thoroughly; and Antifragile. We will look at these lessons from both a theoretic and practical perspective using several real-world case studies involving a move from JVM-based monolithic applications deployed into a data center on a 'big bang' schedule, to a platform of loosely-coupled components, all being continuously deployed into the Cloud. Topics discussed will include API contracts and documentation, microservices, build and deployment pipelines, Cloud fabric properties, monitoring in a distributed environment, and fault-tolerant design patterns.

Transcript of JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

Page 1: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

Building Java applications for the Cloud:The DHARMA

principles

Daniel BryantPrincipal Consultant, Open Credo

[email protected]@danielbryantuk

@OpenCredo

Page 2: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

What to expect

• Problems when developing for the Cloud– “Lift and shift”– Smashing the monolith– Greenfield (“Cloud native”)

• Some suggestions on where to focus efforts– Not specific platform/framework reviews

• Tools and techniques

• Lots of information… (slides will be available)

Page 3: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Who Am I?

• LJC Associate

• Adopt OpenJDK and JSR

• Principal Consultant at OpenCredo Agile transformations DevOps Microservices and Cloud

Page 4: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

The Current Industry Wish List…

• Service-Oriented Architecture

• Cloud-based deployments

• DevOps Culture

Page 5: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

The Current Industry Wish List…

• Service-Oriented Architecture– Twitter’s Story (bit.ly/1j1WbmI)

• Cloud-based deployments– Today!

• DevOps Culture– Devoxx UK talk (bit.ly/1BylnZb)– Previous LJC Event (bit.ly/1elVPJz)

Page 6: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Common Cloud Problems

TL;DR…

Page 7: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Not respecting the underlying environment

Page 8: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Lack of application/platform monitoring…

Page 9: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Bizarre failure modes…

Page 10: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Difficulty in understandingthe new architecture

Page 11: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Confusion over environment provisioning and config

Page 12: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Not testing in the Cloud…(hint: here be dragons!)

Page 13: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

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

Page 14: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @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)

Page 15: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Documented (just enough)

Highly cohesive/loosely coupled (all the way down)

Automated from commit to Cloud

Resource aware

Monitored thoroughly

Antifragile

Page 16: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Documented (just enough)

Highly cohesive/loosely coupled (all the way down)

Automated from commit to Cloud

Resource aware

Monitored thoroughly

Antifragile

Page 17: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Page 18: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Documentation (just enough)

• Provide a map for developers

• Component purpose (and contract)

• Initialisation instructions (mocks/stubs)

• Highlights areas of operational risk

Page 19: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Simon Brown’s C4 Model

www.codingthearchitecture.com

Page 20: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Page 21: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk09/04/2023 @danielbryantuk

Page 22: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

API Docs with Swagger

helloreverb.com/developers/swagger

Page 23: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Create a PACT

github.com/DiUS/pact-jvm

Page 24: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Documented (just enough)

Highly cohesive/loosely coupled (all the way down)

Automated from commit to Cloud

Resource aware

Monitored thoroughly

Antifragile

Page 25: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

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

• Code

• Architecture– Components– Services

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

Page 26: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Smashing the Monolith…

• Business functionality -“Cart Service”

• Technology chunk - “Email Service”

• Vertical Slice – “Registration” (Groupon: vimeo.com/105880150)

• Horizontal Slice– “User Repo” (Microservices: oreil.ly/1pp6qmx)

Page 27: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Microservices

• Probably won’t catch on… ;-)

Page 28: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Twelve Factor Apps

http://12factor.net/

Page 29: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Documented (just enough)

Highly cohesive/loosely coupled (all the way down)

Automated from commit to Cloud

Resource aware

Monitored thoroughly

Antifragile

Page 30: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Automated from Commit to Cloud

• Continuous Integration

• Continuous Deployment

• Continuous Delivery

Page 31: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

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

Page 32: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Our Build Pipeline

• Component Build– Compile– Unit Tests (surefire)– Integration Tests (failsafe)

• Deployment onto QA Cloud– Python Scripts + Chef to provision– Verify success using Python– Serverspec serverspec.org

Page 33: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Our Build Pipeline

• Acceptance Tests– Cucumber (and Selenium)

• Performance Tests– Jmeter + Jenkins performance plugin– Make sure environment is realistic!!

• Live Deployment?

Page 34: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Automating QA

• Intra-component integration testing– Utilise embedded datastore/middleware– “Scassandra” (github.com/scassandra)– Service virtualisation (www.mbtest.org)

• Inter-component integration testing– The hardest part of SOA…– Consider ‘synthetic txns’ (active monitoring)

Page 35: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @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– Netflix Aminator

Page 36: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Infrastructure: Say No To Snowflakes!

• Doing “Proper Development”– Gareth Rushgrove at Craft Conf (bit.ly/1njuc49)– Chef Conf (www.youtube.com/user/getchef)

• Local tooling/testing– Vagrant (www.vagrantup.com)– Docker (www.docker.io)

Page 37: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Configuring the Cloud

• Bundle config with app– Upload new config file– Re-deploy entire app (easier with Docker?)

• Store externally– Zookeeper & Curator curator.apache.org – Netflix Archaius github.com/Netflix/archaius – etcd github.com/coreos/etcd – Consul.io www.consul.io

Page 38: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Documented (just enough)

Highly cohesive/loosely coupled (all the way down)

Automated from commit to Cloud

Resource aware

Monitored thoroughly

Antifragile

Page 39: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Deployment Platform: What you’ve got…

Page 40: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

What you think you want…

Page 41: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

What you actually get…

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

Page 42: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Thou Shalt Know thy Cloud…

• AWS “Magnetic” 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 Sequential Write to SSD

Reference for Mac statistics: bit.ly/1ftJZH8

Page 43: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Thou Shalt Know they Cloud…

“Everything fails all the time [in the cloud]”Werner Vogels, CTO, Amazon.com

• Everything is ephemeral

• Volatility

• Noisy (virtual) neighbours – bit.ly/1w1HQy7

Page 44: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Thinking/Acting Operationally

• Cultivate “Mechanical Sympathy”

• Virtualisation – Tech Target (bit.ly/1kDVqyG)

• Networking– ‘Unix and Linux System Administration Handbook’– aws.amazon.com/documentation

Page 45: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Thinking/Acting Operationally

• Learn Linux fundamentals

• Diagnostic skills– top, netstat, vmstat, tcpdump– Java utils: jps, jstat, jmap, jhat– “DevOps Troubleshooting” by K. Rankin

Page 46: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Documented (just enough)

Highly cohesive/loosely coupled (all the way down)

Automated from commit to Cloud

Resource aware

Monitored thoroughly

Antifragile

Page 47: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Monitor All The Things!

• Infrastructure monitoring– Nagios / Zabbix– AppDynamics

• Distributed Tracing – twitter.github.io/zipkin

• Centralised Logging– logstash.net

Page 48: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Component Metrics

• Dropwizard’s Metrics– metrics.codahale.com– Spring Boot (bit.ly/1rGo76V)

• Netflix’s Servo– github.com/Netflix/servo

• Etsy’s StatsD– github.com/etsy/statsd/wiki

Page 49: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Health Checks

Page 50: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Gauges, Counters, Meters, Timers…

Page 51: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Graph It!

dashing.io

Page 52: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Phrase borrowed from Etsy!

Page 53: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Page 54: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Documented (just enough)

Highly cohesive/loosely coupled (all the way down)

Automated from commit to Cloud

Resource aware

Monitored thoroughly

Antifragile

Page 55: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Antifragile

• The opposite of fragile?– Robust…– Antifragile…

• Netflix are best-in-class– bit.ly/1gs5n3q

• System must be robust first!

Page 56: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Design for Failure

• Distributed Computing Principles– ‘For young bloods’ (bit.ly/1pKVepz)– Netflix (bit.ly/1h5GMid)

• Design patterns– Timeouts / retries– Bulkheads / circuit-breakers

Page 59: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Antifragile Patterns: Async FTW

Asynchronous Communication - queues, pub/subCommand Query Responsibility Segregation (CQRS)Event Sourcing (ES)

martinfowler.com/bliki/CQRS.html

Page 61: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Antifragile Patterns: Elastic Scaling

Stateless components

Distributed data stores / caches

Page 62: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Documented (just enough)

Highly cohesive/loosely coupled (all the way down)

Automated from commit to Cloud

Resource aware

Monitored thoroughly

Antifragile

So, Cloud Apps are ‘done’ when…

Page 63: JAX London 2014 "Building Java Applications for the Cloud: The DHARMA principles"

09/04/2023 @danielbryantuk

Thanks For Listening

• Massive thanks to all the OpenCredo team!

• Questions / comments?– [email protected]– @danielbryantuk