Guest User

Untitled

a guest
Jan 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.77 KB | None | 0 0
  1. ## Monolith
  2. ### The Monolithic Ball of Mud
  3. - The *Ball Of Mud* represents the worst case scenario for a Monolith. Also called as Spaghetti Code.
  4. - No clear isolation in the application.
  5. - Complex dependencies where everything depends on every other thing.
  6. - Hard to understand and harder to modify.
  7.  
  8. ### Cleaning Up The Ball Of Mud
  9. - To clean up the ball of mud we introduce isolation into the application by dividing the application along clear domain boundaries.
  10. - We introduce packages and libraries that help isolate related pieces of code. They provide a clean and consistent interface.
  11.  
  12. ### Characteristics Of A Monolith
  13. - Deployed as a single unit.
  14. - Single shared database.
  15. - Communicate with synchronous method calls.
  16. - "Big Bang" style releases i.e., "All or Nothing" leading to longer release cycle times usually from weeks to months.
  17. - Requires teams to carefully synchronize features and releases.
  18.  
  19. ### Scaling A Monolith
  20. - Multiple copies of the monolith are deployed.
  21. - Each copy is independent. They don't communicate with each other.
  22. - The database provides consistency between deployed instances. In other words, communication between instances of a monolith typically happens through the database.
  23.  
  24. ### Advantages Of Monolith
  25. - Easy cross module refactoring
  26. - Easier to maintain consistency
  27. - Single deployment process
  28. - Single thing to monitor
  29. - Simple scalability model
  30.  
  31. ### Disadvantages Of Monolith
  32. - Limited by the maximum size of a single physical machine.
  33. - Only scales as far as the database will allow.
  34. - Components must be scaled as group even if their is no such scalability requirement for a particular component.
  35. - Deep coupling leads to inflexibility in terms of necessary refactorings.
  36. - Development is typically slow (change is difficult, built times long).
  37. - Serious failure in one component often brings down the whole monolith.
  38. - Redistribution of load can cause cascading failure.
  39.  
  40. ## Microservices
  41. ### Service Oriented Architecture
  42. - Besides using packages or libraries, we can introduce additional isolation into our Monolith using Service Oriented Architecture.
  43. - Services don't share database.
  44. - All access must go through the API exposed by the service.
  45. - SOA doesn't dictate any requirements around deployment. Service may live in the same process (monolith) or may be hosted as different applications (microservices).
  46.  
  47. ### Microservices
  48. - Microservices are a subset of Service Oriented Architecture.
  49. - Logical components are separated into isolated microservices.
  50. - Microservices can be physically separated and independently deployed.
  51. - Each component/microservice has its own independent data store.
  52. - Microservices are independent and self governing.
  53.  
  54. ### Microservice Characteristics
  55. - Each service is deployed independently.
  56. - Multiple independent databases.
  57. - Communication is synchronous or asynchronous (Reactive Microservice).
  58. - Loose coupling between components.
  59. - Rapid deployments (possibly continuous).
  60. - Team release features when they are ready.
  61. - Team often organized around a DevOps approach.
  62.  
  63. ### Scaling A Microservice Application
  64. - Each microservice is scaled independently.
  65. - Could be one or more copies of a service per machine.
  66. - Each machine hosts a subset of the entire system.
  67.  
  68. ### Advantages To The Microservice System
  69. - Individual services can be deployed/scaled as needed.
  70. - Increased availability. Serious failures are isolated to a single service though cascading failures due load redistribution is still possible.
  71. - Isolation/decoupling provides more flexibility to evolve within a module.
  72. - Supports multiple platform and languages.
  73.  
  74. ### Microservice Team Organization
  75. - Microservices often come with organizational change.
  76. - Teams operate more independently.
  77. - Release cycles are shorter.
  78. - Cross team coordination becomes less necessary.
  79. - These changes can facilitate an increase in productivity.
  80.  
  81. ### Disadvantages To The Microservice System
  82. - May require multiple complex deployment and monitoring approaches.
  83. - Cross service refactoring is more challenging.
  84. - Requires supporting old API versions.
  85. - Organizational change to microservices may be challenging.
  86.  
  87. ### The Responsibilities Of Microservices
  88. - The Single Responsibility Principle (SRP) applies to object oriented classes, but works for Microservices as well.
  89. - A microservice should have a single responsibility (eg. managing accounts).
  90. - A change to the internals of one microservice should not necessitate a change to another microservice.
  91. - Bounded Contexts are a good place to start building microservices. They define a context in which a specific model applies. Although further subdivision of the Bounded Context is possible.
  92.  
  93. ## Principles Of Isolation
  94. - As we move from Monoliths to Microservices we are introducing more isolation.
  95. - Isolation provides reduced coupling and increased scalability.
  96. - Reactive Microservices are isolated in:
  97. State, Space, Time, Failure
  98.  
  99. ### Isolation Of State
  100. - All access to a Microservice's state must go through its API.
  101. - No backdoor access via the database.
  102. - Allows the microservices to evolve internally without effecting the outside.
  103.  
  104. ### Isolation Of Space
  105. - Microservices should not care where other microservices are deployed.
  106. - It should be possible to move a microservice to another machine, possibly in a different data center without issue.
  107. - Allows the microservices to be scaled up/down to meet demand.
  108.  
  109. ### Isolation In Time
  110. - Microservices should not wait for each other. Requests are asynchronous and non-blocking. This results in more efficient use of resources. Resources can be freed immediately, rather than waiting for a request to finish.
  111. - Between microservices we expect *Eventual Consistency*. Provides increased scalability. *Total Consistency* requires central coordination which limits scalability.
  112.  
  113. ### Isolation Of Failure
  114. - Reactive Microservices also isolate failure.
  115. - A failure in one Microservice should not cause another to fail.
  116. - Allows system to remain operational in spite of failure.
  117.  
  118. ## Isolation Techniques
  119. ### Bulkheading
  120. - Bulkheading is a tool used to isolate failure.
  121. - Failures are isolated in failure zones.
  122. - Failures in one service will not propagate to other services.
  123. - Overall system can remain operational (possibly in a degraded state).
  124. - Introducing microservices has given us a form of bulkheading since each microservice can act as a potential failure zone.
  125.  
  126. ### Circuit Breakers
  127. **What happens when a service depends on another that is overloaded?**
  128. - Calls to the overloaded service may fail.
  129. - The caller may not realize the service is under stress and may retry.
  130. - The retry makes the load worse.
  131. - Callers need to be careful to avoid this.
  132.  
  133. - Circuit Breakers are a way to avoid overloading a service.
  134. - They quarantine a failing service so it can fail fast.
  135. - Allows the failing service time to recover without overloading it.
  136. - Akka and Lagom both feature circuit breakers.
  137. - A circuit breaker between the service and the database would allow us to prevent the database from becoming overloaded. It also allows us to fail fast when the database is slow to respond.
  138.  
  139. ### Asynchronous Messaging
  140. - Async, non-blocking messaging allows us to decouple both Time and Failure.
  141. - Services are not dependant on the response from each other.
  142. - If a request to a service fails, the failure won't propagate.
  143. - The client service isn't waiting for a response. It can continue to operate normally.
  144.  
  145. ### Autonomy
  146. - We build systems using principles of isolation to achieve what we call as Autonomy.
  147. - Autonomy is basically the idea that each of our services that we build can operate independant of one another.
  148.  
  149. #### Autonomous Services
  150. - Microservices can only guarantee their own behaviour (via their APIs) and not that of their peer services.
  151. - Isolation allows a service to operate independent of other services.
  152. - Each service can be Autonomous.
  153. - Autonomous services have enough information to resolve conflicts and repair failures.
  154. - They don't require other services to be operational all the time.
  155.  
  156. #### Benefits Of Autonomous Services
  157. - Autonomy allows for stronger scalability and availability.
  158. - Fully autonomous services i.e, services that have no external dependencies whatsoever can be scaled indefinitely. Fully autonomous services however isn't something very practical but the closer we can get a system to being fully autonomous, the better it would be.
  159. - Operating independently means that they can tolerate any amount of failure.
  160.  
  161. #### Achieving Autonomy
  162. - Communicate only through asynchronous messages.
  163. - Maintain enough internal state for the microservice to function in isolation. This may require *Eventual Consistency* to be in place. Having an eventually consistent cache of the delivery data in the driver's app would be unnacceptable because most changes would not be allowed after the order has left the restaurant.
  164. - Avoid direct, synchronous dependencies on external services.
  165.  
  166. ### Gateway Services
  167. #### Managing API Complexity
  168. - Microservices can lead to complexities in the API.
  169. - A single request may require information from multiple microservices.
  170. - Client in such an architecuture are required to handle the complexity of sending out many requests to multiple microservices and aggregating the results.
  171. - Mostly updating client code is in control of user who may choose not to update the client as frenquently as the services are getting updated. This leads to slowed development and improvements.
  172.  
  173. #### API Gateway Services
  174. - Requests can be sent through a Gateway Service.
  175. - A Gateway Service sends the requests to individual microservices and aggregates the response.
  176. - Logic for aggregation is moved out of the client and into the Gateway Service.
  177. - Gateway handles failures from each service. Client only needs to deal with possible failure from the gateway.
  178. - Gateway services creates an additional layer of isolation between our client and the individual microservices. More isolation, generally is a good thing.
Add Comment
Please, Sign In to add comment