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

Post on 28-Nov-2014

591 views 1 download

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"

Building Java applications for the Cloud:The DHARMA

principles

Daniel BryantPrincipal Consultant, Open Credo

daniel.bryant@opencredo.com@danielbryantuk

@OpenCredo

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)

09/04/2023 @danielbryantuk

Who Am I?

• LJC Associate

• Adopt OpenJDK and JSR

• Principal Consultant at OpenCredo Agile transformations DevOps Microservices and Cloud

09/04/2023 @danielbryantuk

The Current Industry Wish List…

• Service-Oriented Architecture

• Cloud-based deployments

• DevOps Culture

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)

09/04/2023 @danielbryantuk

Common Cloud Problems

TL;DR…

09/04/2023 @danielbryantuk

Not respecting the underlying environment

09/04/2023 @danielbryantuk

Lack of application/platform monitoring…

09/04/2023 @danielbryantuk

Bizarre failure modes…

09/04/2023 @danielbryantuk

Difficulty in understandingthe new architecture

09/04/2023 @danielbryantuk

Confusion over environment provisioning and config

09/04/2023 @danielbryantuk

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

09/04/2023 @danielbryantuk

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

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)

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

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

09/04/2023 @danielbryantuk

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

09/04/2023 @danielbryantuk

Simon Brown’s C4 Model

www.codingthearchitecture.com

09/04/2023 @danielbryantuk

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

09/04/2023 @danielbryantuk

API Docs with Swagger

helloreverb.com/developers/swagger

09/04/2023 @danielbryantuk

Create a PACT

github.com/DiUS/pact-jvm

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

09/04/2023 @danielbryantuk

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

• Code

• Architecture– Components– Services

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

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)

09/04/2023 @danielbryantuk

Microservices

• Probably won’t catch on… ;-)

09/04/2023 @danielbryantuk

Twelve Factor Apps

http://12factor.net/

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

09/04/2023 @danielbryantuk

Automated from Commit to Cloud

• Continuous Integration

• Continuous Deployment

• Continuous Delivery

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

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

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?

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)

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

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)

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

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

09/04/2023 @danielbryantuk

Deployment Platform: What you’ve got…

09/04/2023 @danielbryantuk

What you think you want…

09/04/2023 @danielbryantuk

What you actually get…

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

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

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

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

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

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

09/04/2023 @danielbryantuk

Monitor All The Things!

• Infrastructure monitoring– Nagios / Zabbix– AppDynamics

• Distributed Tracing – twitter.github.io/zipkin

• Centralised Logging– logstash.net

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

09/04/2023 @danielbryantuk

Health Checks

09/04/2023 @danielbryantuk

Gauges, Counters, Meters, Timers…

09/04/2023 @danielbryantuk

Graph It!

dashing.io

09/04/2023 @danielbryantuk

Phrase borrowed from Etsy!

09/04/2023 @danielbryantuk

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

09/04/2023 @danielbryantuk

Antifragile

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

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

• System must be robust first!

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

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

09/04/2023 @danielbryantuk

Antifragile Patterns: Elastic Scaling

Stateless components

Distributed data stores / caches

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…

09/04/2023 @danielbryantuk

Thanks For Listening

• Massive thanks to all the OpenCredo team!

• Questions / comments?– daniel.bryant@opencredo.com– @danielbryantuk