Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Saturn2017: No such thing as a microservice!

911 vues

Publié le

This is a keynote I gave at the SATURN 2017 in Denver:

The microservice architecture is becoming increasingly popular. However, frequent references to using “a microservice to solve a problem” suggest that the concept is not universally well understood.

In this talk we define the microservice architecture as an architectural style and explain what that actually means. You will learn why the architecture that you pick for your application matters. We describe how the primary goal of the microservice architecture is to enable continuous delivery/deployment and how it achieves that.

You will learn how to solve key challenges with decomposing an application into microservices. We describe why there is no such thing as a microservice!

Publié dans : Logiciels
  • Soyez le premier à commenter

Saturn2017: No such thing as a microservice!

  1. 1. @crichardson There is no such thing as a microservice! Chris Richardson Founder of Eventuate.io Founder of the original CloudFoundry.com Author of POJOs in Action @crichardson chris@chrisrichardson.net http://microservices.io http://eventuate.io http://plainoldobjects.com Copyright © 2017. Chris Richardson Consulting, Inc. All rights reserved
  2. 2. @crichardson Presentation goal Define the Microservice Architecture as an architectural style Explain what that means and why it matters
  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 https://www.manning.com/books/microservice-patterns
  7. 7. @crichardson For more information http://learnmicroservices.io
  8. 8. @crichardson Agenda A brief refresher on software architecture From monolith to microservices Microservices != silver bullet Managing distributed data
  9. 9. About software architecture “The software architecture of a computing system is the set of structures needed to reason about the system, which comprise software elements, relations among them, and properties of both.” Documenting Software Architectures, Bass et al
  10. 10. @crichardson Architecture = (elements, relations, properties)
  11. 11. @crichardson Architecture = Boxes and lines 😄
  12. 12. @crichardson Architecture is multi-dimensional e.g. Structural, electrical, plumbing, mechanical Described by multiple views View = (elements, relations, properties)
  13. 13. 4+1 view model Logical View Process View Deployment View Implementation View Scenarios
  14. 14. 4+1 Logical view Logical View Process View Deployment View Implementation View Scenarios Elements: classes and packages Relations: inheritance, associations, …
  15. 15. 4+1 Implementation view Logical View Process View Deployment View Implementation View Scenarios Elements: modules and components Relations: dependencies
  16. 16. 4+1 Process view Logical View Process View Deployment View Implementation View Scenarios Elements: processes Relations: IPC
  17. 17. 4+1 Deployment view Logical View Process View Deployment View Implementation View Scenarios Elements: “machines” Relations: networking
  18. 18. 4+1 Scenarios Logical View Process View Deployment View Implementation View Scenarios Derived from use cases/stories Animate the views
  19. 19. @crichardson ""… An architectural style determines the vocabulary of components and connectors that can be used in instances of that style, together with a set of constraints on how they can be combined….. ”” David Garlan and Mary Shaw, An Introduction to Software Architecture
  20. 20. @crichardson Layered architectural style Layer N Layer N - 1 Layer N - 2 Well defined responsibilities Constrained dependencies Uses Uses UsesUses
  21. 21. The role of architecture Requirements = Functional requirements + Non-functional requirements (-ilities) Domain knowledge Architecture
  22. 22. Important -ilities Maintainability Evolvability Testability Deployability Scalability Security Reliability … https://en.wikipedia.org/wiki/Non-functional_requirement Development velocity
  23. 23. @crichardson Businesses must innovate faster Build better software faster
  24. 24. @crichardson Reducing lead time Increasing deployment frequency
  25. 25. @crichardson Modern software development Architecture: Process: Small, autonomous teams ??? Continuous delivery/deployment Organization:
  26. 26. Agenda A brief refresher on software architecture From monolith to microservices Microservices != silver bullet Managing distributed data
  27. 27. @crichardson Tomcat/App. Server Traditional: Monolithic architecture Browser/ Client WAR/EAR MySQL Database Review Module Catalog Module Recommendation Module StoreFrontUI Order Module HTML REST/JSON Logical view
  28. 28. @crichardson The monolithic architecture is an architectural style that structures the application as a single executable component Implementation view
  29. 29. -ilities of small monoliths Maintainability Evolvability Testability Deployability Scalability … https://en.wikipedia.org/wiki/Non-functional_requirement 😄
  30. 30. @crichardson But successful applications keep growing…. Development Team Application
  31. 31. @crichardson … and growing Development Team A ApplicationDevelopment Team B Development Team C
  32. 32. @crichardson Eventually: agile development and deployment becomes impossible = monolithic hell
  33. 33. @crichardson Technology stack becomes increasingly obsolete BUT A rewrite is not feasible
  34. 34. -ilities of large monoliths Maintainability Evolvability Testability Deployability … https://en.wikipedia.org/wiki/Non-functional_requirement 😭
  35. 35. The microservice architecture is an architectural style that structures an application as a set of loosely coupled, services organized around business capabilities
  36. 36. @crichardson Two levels of architecture Application-level Services Inter-service glue: interfaces and communication mechanisms Slow changing Service-level Internal architecture of each service Each service could use a different technology stack Pick the best tool for the job Rapidly evolving
  37. 37. @crichardson Services vs. Service instances Implementation view: executable/deployable component Service = Process view: Process Service Instance =
  38. 38. @crichardson Application Service = business capability Acme, Inc Order Taking Inventory management Delivery management Business Capability = something a business does to deliver value … Order Service Inventory Management Service Delivery Management Service … Service
  39. 39. Service size is secondary microservice architecture
  40. 40. Service: Meaningful business functionality Developed by a small team Minimal lead time/high deployment frequency
  41. 41. Microservices = Microservice architecture = Application architecture No such thing as a microservice
  42. 42. @crichardson Example microservice architecture Browser Mobile Device Store Front Web App API Gateway Catalog Service Review Service Order Service … Service Catalog Database Review Database Order Database … Database HTML REST REST Supplier Inbound Gateway Catalog update messages Supplier System
  43. 43. -ilities of a microservice architecture Maintainability Evolvability Testability Deployability Scalability … https://en.wikipedia.org/wiki/Non-functional_requirement 😄
  44. 44. @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 improve testability and deployability Teams own services
  45. 45. @crichardson Evolve the technology stack Pick a new technology when Writing a new service Making major changes to an existing service Let’s you experiment and fail safely
  46. 46. @crichardson Agenda A brief refresher on software architecture From monolith to microservices Microservices != silver bullet Managing distributed data
  47. 47. @crichardson No silver bullets http://en.wikipedia.org/wiki/Fred_Brooks
  48. 48. @crichardson Drawbacks of microservices Complexity Development: IPC, partial failure, distributed data Testing: Integration, end to end, … Deployment …
  49. 49. @crichardson Are microservices a good fit for my application?
  50. 50. @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?
  51. 51. @crichardson It depends!
  52. 52. @crichardson What’s a pattern? Reusable solution to a problem occurring in a particular context
  53. 53. @crichardson The structure of a pattern Resulting context aka the situation Name Context Problem Related patterns (conflicting) issues etc to address Forces Solution
  54. 54. @crichardson Resulting context Benefits Drawbacks Issues to resolve
  55. 55. @crichardson Example resulting context Microservice Architecture Benefits Drawbacks Issues to resolve
  56. 56. @crichardson Related patterns Alternative solutions Solutions to problems introduced by this pattern
  57. 57. @crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  58. 58. @crichardson Agenda A brief refresher on software architecture From monolith to microservices Microservices != silver bullet Managing distributed data
  59. 59. @crichardson Loose coupling = encapsulated data Order Service Customer Service Order Database Customer Database Order table Customer table orderTotal creditLimit
  60. 60. @crichardson How to enforce credit limit? sum(order.total) <= customer.creditLimit
  61. 61. @crichardson Cannot use ACID transactions BEGIN TRANSACTION … SELECT ORDER_TOTAL FROM ORDERS WHERE CUSTOMER_ID = ? … SELECT CREDIT_LIMIT FROM CUSTOMERS WHERE CUSTOMER_ID = ? … INSERT INTO ORDERS … … COMMIT TRANSACTION Private to the Order Service Private to the Customer Service Distributed transactions
  62. 62. @crichardson 2PC is not an option
  63. 63. @crichardson Saga Instead: use event-driven sagas Distributed transaction Order Customer Local transaction Order Local transaction Customer Local transaction Order Event Event
  64. 64. @crichardson Order Service Saga-based, eventually consistent order processing Customer Service Order created Credit Reserved Credit Check Failed Create Order OR Customer creditLimit creditReservations ... Order state total … approve()/reject() Event Handler Event Handler reserveCredit()
  65. 65. @crichardson But how to reliably update the database and publish events without 2PC?
  66. 66. @crichardson Event sourcing: event-centric persistence Event table Entity type Event id Entity id Event data Order 902101 …OrderApproved Order 903101 …OrderShipped Event type Order 901101 …OrderCreated
  67. 67. @crichardson How to find recent, valuable customers? SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ? Customer Service Order Service What if event sourcing is used?…. is no longer easy
  68. 68. @crichardson Command Query Responsibility Segregation (CQRS) Command side Commands Aggregate Event Store Events Query side Queries (Materialized) View Events POST PUT DELETE GET
  69. 69. @crichardson Queries database (type) Command side POST PUT DELETE Aggregate Event Store Events Query side GET /customers/id MongoDB Query side GET /orders?text=xyz ElasticSearch Query side GET … Neo4j
  70. 70. @crichardson Summary The goal of architecture is to satisfy non-functional requirements Use the appropriate architectural style Small applications Monolithic architecture Complex applications Microservice architecture Use the pattern language to guide your decision making Use an event-driven architecture for transactions and queries
  71. 71. @crichardson @crichardson chris@chrisrichardson.net http://learnmicroservices.io Thank you!