deconstructing a monolith
play

Deconstructing a Monolith 1 / 105 Introduction I am Peter - PowerPoint PPT Presentation

Deconstructing a Monolith 1 / 105 Introduction I am Peter (@pjausovec) Software Engineer at Oracle Working on "cloud-native" stu Books: Cloud Native: Using Containers, Functions, and Data to Build Next-Gen Apps SharePoint


  1. Deconstructing a Monolith 1 / 105

  2. Introduction I am Peter (@pjausovec) Software Engineer at Oracle Working on "cloud-native" stu� Books: Cloud Native: Using Containers, Functions, and Data to Build Next-Gen Apps SharePoint Development VSTO For Dummies Courses: Kubernetes Course (https://startkubernetes.com) Istio Service Mesh Course (https://learnistio.com) 2 / 105

  3. Agenda 1. What are Monoliths and Microservices? 2. Migration Patterns Strangler Pattern Branch by Abstraction Pattern Parallel Run Pattern 3. Decomposing Databases Database View Pattern Database Wrapping Service Pattern Database-as-a-Service Pattern Change Data Capture Aggregate Exposing Monolith Change Data Ownership Pattern 4. Data Synchronization 5. Transactions 3 / 105

  4. 4 / 105

  5. 5 / 105

  6. 6 / 105

  7. 7 / 105

  8. Monolith Challenges Developers getting in each others way changing same piece of code delaying deployments Ownership 8 / 105

  9. Monolith Advantages Simpler/single deployment Simpler inner loop/development also monitoring and E2E testing Code reuse 9 / 105

  10. Monolithic architecture is an option 10 / 105

  11. 11 / 105

  12. Microservices Characteristics Independently deployable Modeled around a business domain Own their own data 12 / 105

  13. What's the single biggest advantage of microservices? a) Scaling (like Net�ix!) b) Use any tech/language c) Flexibility d) Simpler deployment 13 / 105

  14. FLEXIBILITY 14 / 105

  15. Microservice Challenges Networking Distributed system, CAP theorem and all that It's not server-side only - What about the UIs? Urge to use the latest and greatest Culture change 15 / 105

  16. Recap Monolithic deployment Monoliths can be a good choice Avoid distributed monoliths Microservices o�er �exibility A lot of network 16 / 105

  17. Planning a migration 17 / 105

  18. Microservices are not the goal 18 / 105

  19. "Would you tell me, please, which way I ought to go from here?" "That depends a good deal on where you want to get to" "I don't much care where" "Then it doesn't matter which way you go" ... 19 / 105

  20. Questions to ask What are you hoping to achieve? Which alternatives did you consider? How do you know if migration worked? 20 / 105

  21. Reasons Improve team autonomy Amazon's two-pizza team Spotify's product squads Reduce time to market Scale and robustness Scale the developers Embrace new tech 21 / 105

  22. Migration Patterns 22 / 105

  23. Strangler Pattern 23 / 105

  24. 24 / 105

  25. Strangler Pattern Used when doing system rewrites Both systems coexist Allows for incremental changes and pausing/stopping the migration 25 / 105

  26. Strangler Pattern 1. Identify the functionality 2. Move the functionality 3. Redirect the calls 26 / 105

  27. 27 / 105

  28. 28 / 105

  29. 29 / 105

  30. 30 / 105

  31. 31 / 105

  32. Branch by Abstraction Pattern 1. Create the abstraction 2. Use the abstraction (with existing implementation) 3. Implement new service 4. Switch the implementation 5. Clean up 32 / 105

  33. 33 / 105

  34. 34 / 105

  35. 35 / 105

  36. 36 / 105

  37. 37 / 105

  38. DEMO - Branch by Abstraction 38 / 105

  39. BREAK 39 / 105

  40. 40 / 105

  41. 41 / 105

  42. 42 / 105

  43. 43 / 105

  44. DEMO Parallel Run/Mirroring with Service Mesh 44 / 105

  45. 45 / 105

  46. 46 / 105

  47. 47 / 105

  48. Decomposing Databases 48 / 105

  49. Sharing a Database You can't decide what's shared and what's hidden Goes against one of the microservices characteristics Data control - where is the logic? 49 / 105

  50. 50 / 105

  51. 1. Database holds read-only/static data 2. Database-as-a-Service Interface pattern 51 / 105

  52. 52 / 105

  53. 53 / 105

  54. 54 / 105

  55. 55 / 105

  56. 56 / 105

  57. Wrapper vs. View Not constrained to a view Ability to create more complex views API for writing requires changes to upstream services 57 / 105

  58. 58 / 105

  59. Updating the R/O database Change data capture Batch process Service events 59 / 105

  60. 60 / 105

  61. Change Data Capture Database triggers trigger behavior on data changes Transaction log pollers Batch delta copier 61 / 105

  62. Aggregate Exposing Monolith 62 / 105

  63. 63 / 105

  64. 64 / 105

  65. Change Data Ownership Pattern 65 / 105

  66. 66 / 105

  67. Data Sychronization 67 / 105

  68. 68 / 105

  69. What degree of consistency we need? 1. Keep data in one place 2. Batch copy all the data 3. Sync via code 69 / 105

  70. 70 / 105

  71. 71 / 105

  72. Sync via Code 1. Batch migrate the data to new database 2. Deploy the new service (sync on write, read from old) 3. Make the new database the source of truth 4. Verify and remove old DB/schema and switching logic 72 / 105

  73. 73 / 105

  74. 74 / 105

  75. 75 / 105

  76. 76 / 105

  77. Splitting Databases 77 / 105

  78. 78 / 105

  79. 79 / 105

  80. What to split �rst? Database �rst, code second Code �rst, database second Both at once 80 / 105

  81. DEMO 81 / 105

  82. 82 / 105

  83. 83 / 105

  84. 84 / 105

  85. BREAK 85 / 105

  86. Transactions 86 / 105

  87. ACID Transaction Atomicity Consistency Isolation Durability 87 / 105

  88. 88 / 105

  89. 89 / 105

  90. Two-Phase Commit (2PC) 90 / 105

  91. Two-Phase Commit Pros: Guarantees an atomic transaction Cons: Slow, depends on the transaction coordinator Database row locking can lead to deadlocks Doesn't scale 91 / 105

  92. Alternatives 1. Don't split the data 2. Sagas 92 / 105

  93. Sagas Coordinate multiple state changes How to handle long-lived transactions? Break-up the LLT into sub-transactions Short-lived sub-transactions 93 / 105

  94. Sagas - Example Online Purchase 1. Check if in stock and reserve -> Warehouse service 2. Charge the user for the product -> Payment service 3. Send the noti�cation -> Noti�cation service 4. Package and send the order -> Warehouse service 94 / 105

  95. Handling Failures Backward recovery Rollback Compensating actions Forward recovery Continue and retry https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf 95 / 105

  96. Compensating transaction Online Purchase 1. Check if in stock and reserve -> Warehouse service (OK) 2. Charge the user for the product -> Payment service (OK) 3. Send the noti�cation -> Noti�cation service (OK) 4. Package and send the order -> Warehouse service (ERROR) 96 / 105

  97. Compensating transaction - Rollback Online Purchase Rollback 1. Check if in stock and reserve -> Warehouse service (OK) (ROLLBACK) Remove the reservation 2. Charge the user for the product -> Payment service (OK) (ROLLBACK) Return the money back to the user 3. Send the noti�cation -> Noti�cation service (OK) (ROLLBACK) Notify use that the item is not available 4. Package and send the order -> Warehouse service (ERROR) 97 / 105

  98. Implementing Sagas Orchestrated Sagas rely on centralized coordination Choreographed Sagas no centralized coordination more complicated tracking 98 / 105

  99. 99 / 105

  100. Orchestrated Sagas Pros: Whole business process centralized orchestrator Easier to understand Cons Increased coupling (orchestrator knows about everything) Anemic services (logic in the orchestrator) 100 / 105

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend