A Pattern Language for Microservices

383 views

Published on

This is a talk I gave at PLoP 2017 - http://www.hillside.net/plop/2017/index.php?nav=program

The microservice architecture is growing in popularity. It is an architectural style that structures an application as a set of loosely coupled services that are organized around business capabilities. Its goal is to enable the continuous delivery of large, complex applications. However, the microservice architecture is not a silver bullet and it has some significant drawbacks.
The goal of the microservices pattern language is to enable software developers to apply the microservice architecture effectively. It is a collection of patterns that solve architecture, design, development and operational problems. In this talk, I’ll provide an overview of the microservice architecture and describe the motivations for the pattern language. You will learn about the key patterns in the pattern language.

Published in: Software

A Pattern Language for Microservices

  1. 1. @crichardson A pattern language for microservices Chris Richardson Founder of Eventuate.io Founder of the original CloudFoundry.com Author of POJOs in Action @crichardson chris@chrisrichardson.net http://learnmicroservices.io Copyright © 2017. Chris Richardson Consulting, Inc. All rights reserved
  2. 2. @crichardson Presentation goal Overview of the microservice architecture pattern language and how to use it to architect an application
  3. 3. @crichardson About Chris
  4. 4. @crichardson About Chris Consultant and trainer focusing on modern application architectures including microservices (http://www.chrisrichardson.net/)
  5. 5. @crichardson About Chris Founder of a startup that is creating an open-source/SaaS platform that simplifies the development of transactional microservices (http://eventuate.io)
  6. 6. @crichardson About Chris http://learnmicroservices.io
  7. 7. @crichardson The paper that never made it to PLoP 2001
  8. 8. @crichardson Agenda Why microservices? Benefits of the microservice architecture Microservices != silver bullet The microservice pattern language Applying the microservice pattern language
  9. 9. @crichardson Modern software development: moving fast and not breaking things! 46x 440x 24x 5x lower Amazon: ~0.001% Netflix: 16 minutes
  10. 10. @crichardson How to move fast and not break things? Architecture: Process: Small, autonomous teams ???? DevOps/Continuous delivery/deployment Organization:
  11. 11. @crichardson The monolithic architecture Tomcat Browser WAR SQL database HTML REST/JSON Client App Simple to …. Develop Test Deploy Scale Catalog Module Reviews Module Orders Module StoreFront UI Module
  12. 12. @crichardson But successful applications keep growing ….
  13. 13. @crichardson … and modularity breaks down… http://www.laputan.org/mud/ “Shantytowns are squalid, sprawling slums.”
  14. 14. @crichardson Monolithic hell Agile development and deployment becomes impossible By John Martin, Public Domain, https://commons.wikimedia.org/w/index.php?curid=3353638
  15. 15. @crichardson Monolithic hell: Technology stack becomes increasingly obsolete BUT a rewrite is not feasible
  16. 16. The microservice architecture is an architectural style that structures an application as a set of loosely coupled, services organized around business capabilities
  17. 17. @crichardson The Microservice architecture tackles complexity through modularization Improved scalability is secondary *
  18. 18. @crichardson Microservice architecture Browser Mobile Device Content Router API Gateway Catalog Service Review Service Order Service … Service Catalog Database Review Database Order Database … Database HTTP /HTML REST REST Browse & Search WebApp Product Detail WebApp ….
  19. 19. @crichardson Agenda Why microservices? Benefits of the microservice architecture Microservices != silver bullet The microservice pattern language Applying the microservice pattern language
  20. 20. @crichardson Microservices enable continuous delivery/deployment Process: Continuous delivery/deployment Organization: Small, agile, autonomous, cross functional teams Architecture: Microservice architecture Enables Enables Enables Successful Software Development Services = testability and deployability Teams own services
  21. 21. @crichardson Smaller, simpler applications Easier to understand, develop and test Less jar/classpath hell - who needs OSGI? Faster to build, test and deploy Reduced startup time - improves MTTR
  22. 22. Scales development: develop, deploy and scale each service independently Small, autonomous teams Clearly defined responsibilities Catalog Service Review Service Order Service … Service Catalog Team Review Team Order Team … Team Responsible for
  23. 23. @crichardson Easier to scale
  24. 24. @crichardson Improves fault isolation
  25. 25. @crichardson Easily evolve your technology stack ... and fail safely
  26. 26. @crichardson Agenda Why microservices? Benefits of the microservice architecture Microservices != silver bullet The microservice pattern language Applying the microservice pattern language
  27. 27. @crichardson No silver bullets http://en.wikipedia.org/wiki/Fred_Brooks
  28. 28. @crichardson Complexity http://highscalability.com/blog/2014/4/8/microservices-not-a-free-lunch.html
  29. 29. @crichardson Complexity of developing a distributed system
  30. 30. @crichardson Multiple databases & Transaction management Must use event-driven eventual consistency
  31. 31. @crichardson Complexity of testing a distributed system
  32. 32. @crichardson Complexity of deploying and operating a distributed system You need a lot of automation: VM/container orchestration or PaaS
  33. 33. @crichardson Developing and deploying features that span multiple services requires careful coordination
  34. 34. @crichardson Agenda Why microservices? Benefits of the microservice architecture Microservices != silver bullet The microservice pattern language Applying the microservice pattern language
  35. 35. @crichardson Are microservices a good fit for my application?
  36. 36. @crichardson When using microservices: How to decompose an application into services? How to deploy an application’s services? How to handle cross cutting concerns? Which communication mechanisms to use? How do external clients communicate with the services? How does a client discover the network location of a service instance? How to prevent a network or service failure from cascading to other services? How to maintain data consistency and implement queries? How to make testing easier? How to understand the behavior of an application and troubleshoot problems? How to implement a UI screen or page that displays data from multiple services?
  37. 37. @crichardson Microservice pattern language = collection of patterns that solve these architecture, design, development and operational problems
  38. 38. @crichardson What’s a pattern? Reusable solution to a problem occurring in a particular context
  39. 39. @crichardson The structure of a pattern encourages objectivity Resulting context aka the situation Name Context Problem Related patterns (conflicting) issues etc to address Forces Solution Benefits Drawbacks Issues to resolve Alternatives Solutions to issues
  40. 40. @crichardson Microservice architecture pattern Context Developing large, complex architecture Problem What’s the runtime architecture? Benefits Faster development Easy adopt new technologies Drawbacks Complexity of a distributed system Issues Decomposition Distributed system issues: IPC, discovery, … Alternative patterns Monolithic architecture Successor patterns Service Registry, API Gateway, …
  41. 41. @crichardson Microservices pattern language: http://microservices.io
  42. 42. @crichardson Microservices pattern language: layers
  43. 43. @crichardson Agenda Why microservices? Benefits of the microservice architecture Microservices != silver bullet The microservice pattern language Applying the microservice pattern language
  44. 44. @crichardson The pattern language guides you when developing an architecture What architectural decisions you must make For each decision: Available options Trade-offs of each option
  45. 45. @crichardson Predecessor - Successor Sequence?
  46. 46. @crichardson Key patterns
  47. 47. Problem: What’s the architecture? Forces Maintainability Deployability Testability Extensibility … Monolithic architecture Microservice architecture Single deployable/ executable OR Tightly coupled services Multiple loosely coupled services
  48. 48. Problem: How to decompose an application into services? Forces Stability Cohesive Loosely coupled Not too large Decompose by business capability Decompose by subdomain Organize around business capabilities Organize around DDD subdomains
  49. 49. Problem: how to ensure services are loosely coupled? Forces: Services must be loosely coupled Evolving schema of shared database = coordination … Ensures loose coupling
  50. 50. @crichardson Problem: how to maintain data consistency? Context • Each service has its own database • Data is private to a service Forces Transactional data consistency must be maintained across multiple services 2PC is not an option
  51. 51. @crichardson Problem: how to perform queries? CQRS Context Each service has its own database Forces Queries must join data from multiple services Data is private to a service Maintain query views by subscribing to events API Composition
  52. 52. @crichardson Problem: How do services communicate? Messaging Remote Procedure Invocation Domain-specific Forces Services must communicate Usually processes on different machines …
  53. 53. @crichardson The rest are generic technical architecture patterns = Undifferentiated heavy lifting!
  54. 54. @crichardson Problem: How to handle cross cutting concerns? Microservice Chassis Forces Every service must implement logging; externalize configuration; health check endpoint; metrics; …
  55. 55. Problem: How to deploy an application’s services? Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Serverless deployment Service deployment platform Forces Multiple languages Isolated Constrained Monitor-able Reliable Efficient
  56. 56. @crichardson Problem: How to discover a service instance’s network location? Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Forces Client needs IP address of service instance Dynamic IP addresses Dynamically provisioned instances
  57. 57. @crichardson Problem: How do external clients communicate with the services? API gateway Backend for front end
  58. 58. @crichardson Problem: How to prevent a network or service failure from cascading? Circuit Breaker
  59. 59. @crichardson Problem: how to monitor the behavior of your application? Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API
  60. 60. @crichardson Summary The monolithic architecture is a good choice for small/simple applications Use the microservice architecture for large/complex applications Microservice architecture != silver bullet Use the microservice architecture pattern language to guide your decision making
  61. 61. @crichardson @crichardson chris@chrisrichardson.net http://learnmicroservices.io Thank you!

×