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.

Decomposing the Monolith using Microservices that don't give you pain

1 263 vues

Publié le

If I have to name a single hype in software architecture land then I would have to mention the micro-service architecture. Microservices are supposed to be small, have a very focused purpose, can be deployed independently, are completely self-supporting and loosely coupled. Ideally, microservices are technology agnostic, but hey, we're in the .NET space, aren't we? And they are not a goal, but a means to an end. In fact, a microservice architecture has many benefits and are a great strategy for decomposing a monolith. So how do you build a microservice? What technologies does the .NET realm offer for us? And what if you don't want to deploy them independently? In this talk, I'll show you some of the pros and cons of microservices and how you can leverage OWIN and .NET to move your monolith into a bright new future.

Publié dans : Technologie

Decomposing the Monolith using Microservices that don't give you pain

  1. 1. Dennis Doomen | @ddoomen | Aviva Solutions | The Continuous Improver
  2. 2. Also known as the Microservices Premium
  3. 3. Hybrid of Front-end Technologies Multiple patterns for the same problems Long compile time Large source control repositories Long-running unit tests Too much coupling Limited team scalability Devs need to know everything NoIsolationProductivity drops over time.
  4. 4. • The network is reliable • Latency is zero • Bandwidth is infinite • The network is secure • Topology doesn't change • There is one administrator • Transport cost is zero • The network is homogeneous. https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing
  5. 5. The First Law of Distributed Computing
  6. 6. Very scalable, very reliable Very difficult to debug distributed problems Unreliable network requires complicated techniques Requires message bus/broker End-to-end testing very unpractical Very mature DevOps culture is a prerequisite Advanced monitoring and visualization is a must Security can not be an afterthought High operational maintenance. Can be deployed/upgraded independently.
  7. 7. Monolith Microservice Microservice Microservice HTTP API HTTP API HTTP API OWIN component released through MyGet/Nuget No network I/O at all Can have its own database instance, shared with monolith, or shared storage service Microservice owns the schema Separate repos with distinct owners. Runs in-process, thus easier debugging New version requires redeployment of the monolith. Loose coupling through HTTP Less scalability options HTTP is not the fastest serialization format Relies on libraries, not frameworks.
  8. 8. Client IIS Console WinSvc Unit Test HTTP request HTTP response Middleware environment handler next Middleware IDictionary<string, object> Func<IDictionary<string, object>, Task> Task Func< Func<IDictionary<string, object>, Task>, Func<IDictionary<string, object>, Task> >
  9. 9. Monolith Microservice HTTP API Service Registry Contract documented through Swagger Webhooks Microservice Microservice Provides OWIN- aware HttpClient to connect to service Event payload exposed as Swagger (e.g. SwaggerHub) Subscribers register URLs or in-process OWIN message handler API/payload consumers use liberal JSON interpretation Circuit Breaking to handle unreliable consumers At-least-once payload delivery Subcribers can request replays. Payload includes ID to help idempotency Each request requires correlation ID that flows through all APIs, webhooks and services
  10. 10. Aggregates Command Handlers Queries Commands Events Upconverters Value Objects Query Handlers Schema Migrations Projectors Data Importers Query API Jobs Projections HTML CSS JS API Controllers Projectors Projections Registrations Webhook API Command API Event Storage Payload Definitions Outer layers depend on inner layers Domain is persistency ignorant Can be tested independently For eventual consistent business rules Master data To support domain queries For microservices that provide a (partial) UI or management screen Based on Domain Driven Design Supported by LibLog, TinyIoc Designed according to the 12 Factor principles
  11. 11. UI / HTTP API Command Service ChangeUser EmailHandler User Unit of Work User Projector DAL Read DB Write DB ChangeUserEmailCommand Execute query Get<User>(identity) Invoke method Event Store Load(events) Apply Get changes Dispatcher Events Handle(UserEmailChangedEvent) Submit changes History Dennis Doomen | @ddoomen | The Continuous Improver
  12. 12. Monolith Microservice HTTP API Event Store Events Payload Projector Subscription Request Payload ‘event store’ Projectors use LiquidProjections Have their own checkpoints Projects fine-grained events into payload projections Projector Payload schema is documented using Swagger Projector Projector Webhook Projectors Separate instance per subscription Subscriber HTTP API ‘Project’ payload ‘event store’ into HTTP calls Projected Data Uses the incoming payloads as an ‘event store’ Payload Use Circuit Breakers to handle slow/unavailable subscribers SQL DB Schema changes using FluentMigrator or using NoSQL DB
  13. 13. Domain Event Store Events App RDBMS Events Projection EventsProjection Projection Projector Optimized for specific queries Separate projections database NoSQL Projector Projection-specific storage Projector HTML Raw SQL or Dapper Run asynchronously Great for sharding Dennis Doomen | @ddoomen | The Continuous Improver
  14. 14. Events Transaction 6 Transaction 5 Transaction 4 Transaction 3 Transaction 2 Transaction 1 Temporal Projector Read Store Time Projected until this point Immutable, thus auditable and SOX compliance Dennis Doomen | @ddoomen | The Continuous Improver
  15. 15. Domain Event Store Events App Events Projection EventsProjection Projection Projector Application projections RDBMS Reporting Projector Traditional reporting model Asynchronous OLAP Dennis Doomen | @ddoomen | The Continuous Improver
  16. 16. StreamId: User-Dedo, Rev: 5 Persisted State Changes StreamId: User-Dedo, Rev: 4 Grant Role “Editor” Change Password 2nd StreamId: User-Dedo, Rev: 4 StreamId: User-Dedo, Rev: 3 Create User Grant Role “Owner” Add Phone Number Change Password 1st StreamId: User-Dedo, Rev: 5 Revoke Role “Owner” StreamId: User-Dedo, Rev: 6 Grant Role “Editor” Time StreamId: User-Dedo, Rev: 7 Changed Password 2nd Dennis Doomen | @ddoomen | The Continuous Improver
  17. 17. Events 1 2 3 6297 6298 6298 Projections Documents Groups Users Objects Folders Microservice V2 Changes Queries Events 1 2 3 6299 6300 6301 Projections Documents Groups Users Objects Folders Microservice V1 ChangesQueries Migration Process Dennis Doomen | @ddoomen | The Continuous Improver
  18. 18. Events Aggregate Root Entity Entity Value Object Aggregate Root Aggregate Root Aggregate Root Entity Value Object Value Object Dennis Doomen | @ddoomen | The Continuous Improver
  19. 19. • Asynchronous projections • Idempotency of projections • Self-tracking • Projection autonomy -> more duplication • Projection tracking and prediction.
  20. 20. • Functional archiving • Clear separation between critical and auxiliary data -> prioritization • Partitioning • Dynamic rebuilding (after bugs, schema changes, etc).
  21. 21. • Projections that crash – Column constraints – Changes in data invariants – Unexpected projection dependencies – Lookups vs stream dependencies. • (Unexpected) projection dependencies – Synchronous -> asynchronous and existing bugs – Aggregrate dependencies. • Bugs – Causing large event streams.
  22. 22. Prerequisites - Microservice owns ‘schema’ - Supports upgrading and downgrading - NoSQL preferred, but RDBMS can work too.
  23. 23. Rebuild schema in-place – Rebuilding using event store – Requires tracking API – Involves down-time.
  24. 24. Disallow breaking changes – Only new ‘columns’ and ‘tables’ – Partial rebuilding using event store – Requires forwards compatibility.
  25. 25. Rebuild side-by-side – Rebuilding using event store – Requires tracking API – Requires compatibility with previous ‘schema’ – Previous ‘schema’ is removed in the next release.
  26. 26. Microservice Bunch of classes that should be used directly X No inheritance Uses composition over inheritance internally Convenience classes that don’t hide the magic Library Abstract Package Interfaces Delegates DTOs Only depend on abstract packages… Stable Package …or depend on more stable packages Auxiliary Package Classes that are not used together do not belong togetherOptional Dependency Dependency Package Consumers should not be faced with optional dependencies
  27. 27. • Delegates • Source-only Packages • Merge dependencies
  28. 28. Monolith Microservice Microservice Microservice HTTP API HTTP API HTTP API Apply routing conventions Versioning using Accept Headers, Response Headers or Routes Optimize body using AVRO or Protobuf Cross-service tracing using OpenTracing Replace OWIN with (upcoming) in- process gRPC Common contracts for diagnostics, monitoring Add KPI dashboards, e.g. Sumologic
  29. 29. 1 Build a (container-based) cloud capability. 2 Deploy monolith to the cloud. 3 Automate your delivery pipeline. 4 Full end-to-end responsibility 5 Break-up delivery teams and code 6 Evaluate status-quo on micro-services (products, platforms, etc) 7 Slide-and-dice microservices one-by- one.
  30. 30. • Liquid Projections – The Example https://github.com/liquidprojections • Bliki: MonolithFirst https://dzone.com/articles/martin-fowler%E2%80%94bliki • In-process gRPC https://github.com/grpc/grpc-go/issues/906 • Protobuf in WebAPI http://www.infoworld.com/article/2982579/application- architecture/working-with-protocol-buffers-in-web-api.html • Ingredients for well-design OWIN components http://www.continuousimprover.com/search/label/OWIN%20Recip es • The good, the bad and the ugly of Event Sourcing http://www.continuousimprover.com/search/label/event%20sourci ng