Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Data Architecturen Not Just for Microservices

920 views

Published on

Microservices change the way data is handled and stored. This presentation shows how Bounded Context, Events, Event Sourcing and CQRS provide new approaches to handle data.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Data Architecturen Not Just for Microservices

  1. 1. Data Architecture – Not Just for Microservices Eberhard Wolff @ewolff Fellow
  2. 2. http://continuous-delivery-buch.de/
  3. 3. http://microservices-buch.de/ http://microservices-book.com/
  4. 4. http://microservices-book.com/primer.html FREE!!!!
  5. 5. Classic Data Architecture > Centralized databases > …or services that provide data > Ensures consistency across systems > …for data model > ...and updates to data > Reuse
  6. 6. Classic Data Architecture Billing Order Process CRM Order
  7. 7. Who is using a centralized database?
  8. 8. Who likes the centralized database?
  9. 9. Microservices: Definition > No consistent definition > Microservices are modules > Independent deployment units > E.g. processes, Docker container > Microservice owned by one team
  10. 10. Microservices: Definition Server / Container Server / Container Micro Service Micro Service
  11. 11. Why Microservices? > Develop a feature > …bring it into production > ...with no coordination > Independent scaling > Free choice of technology > Robustness > Security
  12. 12. Microservices aim for decoupling
  13. 13. Microservices & Data Server / Container Server / Container Micro Service Micro Service Order Schema
  14. 14. Microservices & Data Server / Container Server / Container Micro Service Micro Service Order Schema
  15. 15. Microservices & Data > Decoupling for data, too > Separate data storage
  16. 16. Data Microservices Server / Container Server / Container Micro Service Micro Service Order Data Microservice
  17. 17. Data Microservices Server / Container Micro Service Order Data Microservice Customer Data Microservice Remote calls influence performance availability No transaction across customer and order
  18. 18. Data Microservice > Change two microservices if new feature requires change to data schema > But: data in one place > No consistency issues
  19. 19. Data microservice limits decoupling.
  20. 20. Encapsulation > Information hiding > Hide the internal data structure > Provide access only through a well defined interface > Data and databases should not be exported
  21. 21. Violates Encapsulation Billing Order Process CRM Order Shared data model Logic
  22. 22. Violates Encapsulation Server / Container Server / Container Micro Service Micro Service Order Data Microservice Shared data model Logic
  23. 23. Separate Databases Server / Container Server / Container Micro Service Micro Service Order Order
  24. 24. Different Databases Server / Container Server / Container Micro Service Micro Service neo4j Oracle
  25. 25. Different Databases > “Polyglot persistence” > Use the best tool for the job > Technology freedom – advantage of microservices > …but extra effort > Backup, disaster recovery etc. > Not as easy as e.g. different frameworks
  26. 26. Separate Schema Server / Container Server / Container Micro Service Micro Service Oracle Schema Schema
  27. 27. Separate Schemas > Less effort > Decoupled data models > ...but limited independent scaling and robustness
  28. 28. Billing Order Process CRM OrderOrder Order
  29. 29. Redundancy!!!
  30. 30. Domain-driven Design
  31. 31. Domain-driven Design > 2004 > Still very relevant > By Eric Evans > Focus on part IV > Free reference: http://domainlanguage.com/ ddd/reference/
  32. 32. Order Shipping address Tracking # Items Item Categories Priority shipping Customs # Account # ... Credit card # Order #
  33. 33. My Domain Model is a mess!
  34. 34. Bounded Context > Domain model is only valid for one context > There is no universal data model! > See all failed SOA attempts
  35. 35. Order Shipping address Tracking # Items Item Categories Priority shipping Customs # Account # ... Credit card # Order # Customs Order Recommen- dations Order Tracking Order Shipping address Tracking # Item Categories Priority shipping Customs # Payment Order Account # Credit card #
  36. 36. Billing Order Process CRM OrderOrder Order
  37. 37. Bounded Context > Microservice = BOUNDED CONTEXTS > Changes for new features are local > …even if data models need to be changed
  38. 38. Billing Order Process CRM OrderOrder Order
  39. 39. Redundancy?
  40. 40. Redundancy? Not really
  41. 41. Bounded Context
  42. 42. What about basic data of an order?
  43. 43. Strategic Design > How do BOUNDED CONTEXTS relate to each other? > Context can have relationships > DDD defines several relationship patterns
  44. 44. Shared Kernel > Subset of a model > …that two teams share > Eric Evans: Including code and database > Microservices: Just sharing a model
  45. 45. Anti-corruption Layer > Don’t let e.g. a legacy model influence a new model > Isolate model by additional layer > No need to modify the old system
  46. 46. Context Relationships > Team = Deployment Unit = BOUNDED CONTEXT > Context Relationships define how BOUNDED CONTEXT are used… > ...and how much teams need to collaborate
  47. 47. Coordination Effort Shared BOUNDED CONTEXT SHARED KERNEL CUSTOMER / SUPPLIER ANTICORRUPTION LAYER CONFORMIST SEPARATE WAYS
  48. 48. Context Map
  49. 49. Context Map > Show the different BOUNDED CONTEXT > …and the relation to each other > BOUNDED CONTEXT might be microservices > ...or communication links
  50. 50. Order ProcessRegistration Basic Customer Data Basic Customer Data Customer Order Data Delivery Customer Order Data Billing Anticorruption Layer Mainframe Customer Data Customer Order Data Customer Order Data Basic Customer Data + Customer Order Data = Shared Kernel
  51. 51. Billing Order Process CRM Shared Kernel Order Additional data Additional data Additional data Order Data
  52. 52. Centralized Shared Kernel > Ensures consistency > ...but needs to be called for a lot of operations > Resilience / performance / transactions > Have one master as the source of truth
  53. 53. Billing Order Process CRM Shared Kernel Order Shared Kernel Order Shared Kernel Order Additional data Additional data Additional data
  54. 54. Decentralized Shared Kernel > Might be inconsistent > ...but all data for all requests is available in the local database > Better resilience… > ...and performance
  55. 55. How to Replicate Data?
  56. 56. Database Replication > Built into the database > Replicate schema across database instances > But: Microservices have separated schemas > Every Microservice might have different data > …so database replication is not a good fit
  57. 57. Replication with Events
  58. 58. Events > Later addition to Domain-driven Design > Events with a business meaning > Decouple time: Asynchronous > Decouple logic: System can handle event as it pleases
  59. 59. Billing Order Process CRM Shared Kernel Order Shared Kernel Order Shared Kernel Order Additional data Additional data Additional data New Order Event
  60. 60. Events & Data Replication > Events lead to data replication > i.e. each system stores information it received in an event > Data stored in separate schema > Very decoupled > Hard to repair inconsistencies
  61. 61. More Fun With Events
  62. 62. Event Sourcing > Internal Structure for Microservice with events > Current state result of all events > Calculate state on the fly?
  63. 63. Event Queue Event Event Event Event Handler Event Handler Event Store Snapshot
  64. 64. Event Sourcing > Event store and snapshot help to repair inconsistencies > Event-based architecture in microservices
  65. 65. CQRS > Command – Query Responsibility Segregation > Commands change data > Query provide data > Implement in separate modules > …or even microservices > ...with potentially different BOUNDED CONTEXTS
  66. 66. Commands vs Events > Command: Change that data! > Event: Something has happened > Component decides if data should be changed
  67. 67. Command Queue Command Command Command Command Handler Query Handler Command Store Database
  68. 68. Batch Replication
  69. 69. Batch > Get all data > Provide API > …to decouple schema > Copy interesting data into local database
  70. 70. Billing Order Process CRM Shared Kernel Order Shared Kernel Order Shared Kernel Order Additional data Additional data Additional data BatchBatch API API
  71. 71. Batch & Data Replication > Easy to repair inconsistencies > Batch run at specific points > i.e. updates take time > Data not consistent across microservices
  72. 72. CAP: Challenge for Replication
  73. 73. CAP Theorem > Consistency > All nodes see the same data > Availability > Node failures do not prevent survivors from operating > Partition Tolerance > System continues to operate despite arbitrary message loss C P A
  74. 74. CAP Theorem: P > Network partitions do occur > Even with highly available network hardware > Also: very slow response = partition > Need to deal with P
  75. 75. CAP Theorem: C or A? > Node cannot access other nodes > Might have missed updates > A, not C: Answer with a potentially wrong answer > C, not A: Don’t answer – the answer might be wrong
  76. 76. Billing Order Process CRM Shared Kernel Order Shared Kernel Order Shared Kernel Order Additional data Additional data Additional data New Order Event inconsistent or unavailable
  77. 77. Conclusion
  78. 78. Classic: Centralized Database Microservices: private database decoupling Data Microservices: Consistent but resilience / performance / transactions / decoupling? Database per Microservice: Polyglot Persistence Schema per Microservice: Simple infrastructure
  79. 79. Redundant Data or Bounded Context? Batch Database Replication Events Redundancy? Context Map and Context Relations Replication CAP Event Sourcing CQRS e.g. Shared Kernel
  80. 80. Decentralize data!

×