building microservice architectures(neal ford)

80
B UILDING M ICROSERVICE A RCHITECTURES @neal4d nealford.com

Upload: sefdeni

Post on 10-Nov-2015

30 views

Category:

Documents


4 download

DESCRIPTION

f

TRANSCRIPT

  • BUILDING MICROSERVICE ARCHITECTURES

    @neal4d nealford.com

  • AGENDA

    denitions

    engineeringcharacteristics

    what problem

  • Conways Laworganizations which design systems ... are constrained to produce designs which are

    copies of the communication structures of these organizations

    Melvin Conway

  • The Inverse Conway Maneuver Domain/Architecture Isomorphism

    Organized Around Business Capabilities

  • Coupling Metrics

    code artifact

    afferent efferentx i t

  • X-Rayxray.inf.usi.ch/xray.php

  • Class Dependency

  • Package Dependency

  • Azureus Packages

  • FilteredAzureus Packages

  • From a Real Monolith

    Name withheld by request

    Package level coupling from a real monolith

    Attempting to generate class

    diagram crashed x-ray.

  • Software architecture represents the

    tension between coupling & cohesion.

  • versusACID BASE

  • ACID

    Atomic Consistent Isolated Durable

    BASE

    Basic Availability Soft-state Eventual Consistency

    # of users

    because CAP Theoremwww.julianbrowne.com/article/viewer/brewers-cap-theorem

    Formal proof: http://lpd.ep.ch/sgilbert/pubs/BrewersConjecture-SigAct.pdf

    As your system becomes more distributed, prefer BASE to ACID

  • http://www.eaipatterns.com/docs/IEEE_Software_Design_2PC.pdf

    http://highscalability.com/blog/2013/5/1/myth-eric-brewer-on-why-banks-are-base-not-acid-

    availability.html

  • AGENDA

    denitions

    engineeringcharacteristics

    what problem

  • What Traditional SOA Got RightBreaking monoliths into services

    Focus on integration over internal coupling

    Prefer BASE to ACID

    What Traditional SOA Missed

    Architecture is abstract until operationalized.

    Impact of Conways Law

    The folly of trying to build Uber services (Customer) Didnt support easy change (ESB pattern)

  • support Microservice is the rst

    architectural style developed post-Continuous Delivery.

  • AGENDA

    denitions

    engineeringcharacteristics

    what problem

  • Monoliths vs. Microservices

  • user interface

    server-side

    DBA

  • Orders

    Shipping

    Catalog

  • Products, not Projects

    projects:

    products:

    s You build it, you run it

  • Smart Endpoints, Dumb Pipes

    as decoupled & cohesive as possible inspired by Unix lters/pipes transport: HTTP messaging over lightweight bus

  • Prefer Choreography to Orchestration

    traditional SOA / ESB pattern

    Because Conways Law!Consumer Driven Contracts

    pack of enterprise architects

  • http://martinfowler.com/articles/consumerDrivenContracts.htmlConsumer Driven Contracts

  • Prefer REST over SOAP

    REST is less brittle at integration points

    SOAP = RPC

  • Standardize on integration, not platform

    embrace polyglot solutions where sensible

    too few languages/platforms

    too many languages/platforms

    Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Standardize in the gaps between services - be exible about what

    happens inside the boxes

  • Standardize on integration, not platform

    but dont go crazy

    Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Have one, two or maybe three ways of integrating, not 20.

    Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Pick some sensible conventions, and stick with them.

  • Microservice architectures promote coupling from application to integration architecture.

    explicit about coupling

    forces coarser- grained coupling

    engineering safety nets

    undisciplined coupling = messcoupling dynamics become integration issues

  • Decentralized Data Management

    ACID versus BASE

    Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Avoid distributed transactions if at all possible

  • Decentralized Governance

  • Decentralized Governance

  • Decentralized Governance

    Enterprise architects suer from less pressure to make the correct choice(s)

    in microservice architectures.

  • Small, Single Responsibility

    small enough to t in your head

    rewrite over maintain

    (101000 LOC)-ish / service

    single responsibility

  • How Big?

    Standardize on integration, not platform

    partition along natural boundaries

    nd a balance between standardization and freeforall

    transactional

    domain

    organizational

  • Partitioning by Existing Coupling

    God Object: an object that knows too much or does too much

  • Asynchronicity

    Prefer timely partial over slow complete

    return optimized for ranking/aggregation,

    not display

  • Traditional Monolith

    Model

    User Interface

  • CQRS

    http://codebetter.com/gregyoung/2010/02/16/cqrs-task-based-uis-event-sourcing-agh/

    Query Model

    Command Model

    User Interface

  • ReportingQuery Model

    Command Model

    User Interface

    . . .

  • AGENDA

    denitions

    engineeringcharacteristics

    what problem

  • Design For Failure

    clients must respond gracefully to provider failure

    aggressive monitoring: - business relevant - architectural - semantic

  • Monitoring

    Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    You have to get much better at monitoring.

  • Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    You are not a badass if you use an SSH Multiplexer!

  • Aggregating Monitors

    Response TimeResponse Time

    Response Time

  • Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Capture metrics, and logs, for each node, and aggregate them

    to get a rolled up picture.

    Aggregating Monitors

  • Synthetic Transactions

    Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Use synthetic transactions to test production systems.

  • Correlation IDs ID: 123

    ID: 123

    ID: 123

    Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Use correlation IDs to track down nasty bugs

  • Engineering Consistency

    service behavior

    integration

    downstream

    metrics

    Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Consider Service Templates to make it easy to do the right

    thing!

  • SCM RepositoriesPrefer repository per service to monolithic

    repository

    Integrate via continuous integration

  • Testing Microservices

    http://martinfowler.com/articles/microservice-testing/

  • Inside the Box

  • Unit Testing

    Sociable

    Solitary

  • Integration Testing

  • Integration Testing

  • Component Testing

  • Component Testing

    shims:

    inproctester github.com/aharin/inproctester

    Plasma github.com/jennifersmith/plasma

  • Component Testing

  • Contract TestingPact

    github.com/realestate-com-au/pact

    Pacto github.com/thoughtworks/pacto

    Janus github.com/gga/janus

  • End-to-End Testing

  • Test Pyramid for Microservices

  • engineering

    Deployment

  • Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS Abstract out underlying

    platform dierences to provide a uniform deployment

    mechanism.

  • Dont Let Changes Build Upstaging production

  • Dont Let Changes Build Upstaging production

    Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Dont let changes build up - release as soon as you can, and

    preferably one at a time!

  • Integration & Disintegration

  • Reducing Risk of Release

    production

    Components are deployed.

    Features are released.

    Applications consist of routing.

  • Blue/Green Deployments

    Message Router

    Web serverApplication

    serverDatabase

    server

    Message Router

    Web serverApplication

    serverDatabase

    server

    1.1 1.1 1.1

    Message Router

    Web serverApplication

    serverDatabase

    server

    1.1 1.1 1.1

    Web serverApplication

    serverDatabase

    server

    1.2 1.2 1.2

    Message Router

    1.1 1.1 1.1

  • Blue/Green for Services

    Deploy

    Release

    Route

    Re-route upon failure

    production

  • How Big?

    rele

    ase

    risk

    # services

  • production

    Dis-integrate services that

    monitoring shows are no longer used

  • Sam Newman

    Building MicroservicesDESIGNING FINE-GRAINED SYSTEMS

    Use timeouts, circuit breakers and bulk-heads to avoid

    cascading failure.

  • SUMMARY

    denitions

    engineeringcharacteristics

    what problem

  • (Micro)service architectures provide unique benets at the cost of increased (essential)

    complexity.

    You must be this tall to use microservices

  • Inverse Conway Maneuver

    Build teams that look like the architecture you want

    (and it will follow).

  • Efferent Coupling

    efferent

    Strive for low efferent coupling for your team.

  • Continuous DeliveryTeams with low eerent coupling deliver relatively independently

    into a common integration pipeline (without fearing breaking

    each others builds).

  • ?SPresentation Patterns Neal Ford, Matthew McCullough, Nathaniel Schutta http://presentationpatterns.com

    Clojure (inside out) Stuart Halloway, Neal Ford bit.ly/clojureinsideout

    Functional Thinking bit.ly/nf_ftvideo

    Functional Thinking http://shop.oreilly.com/product/0636920029687.do

    Understanding the Basics Neal Ford, Mark Richards http://oreil.ly/1kM7IuV

    Taking a Deeper Dive Neal Ford, Mark Richards

    http://oreil.ly/RfKUqh

    nealford.com@neal4d