KEMBAR78
Going MicroServices with Net | PPTX
GOING MICROSERVICES
WITH .NETDavid Revoledo
@deirevoledo
Contamos con el apoyo de:
About me !
David Revoledo | @deirevoledo
• Working with Microsoft technologies pretty much all my career.
• Speaker
• .Net, AzureTrainer and Consultant.
• Open Source active contributor (Azure event hub, service bus SDK’s
and a Few Plugins).
• Focused onAsp. NET Core / Azure
• Software Architect at DGENIX
19/12/2018
19/12/2018
Agenda
1. Microservices Introduction
2. Starting Microservices with .NET
3. Conclusion
4. Q&A
19/12/2018
19/12/2018
Microservices?
Let’s start saying is a very bad name.
• Serverless ?
• NoSQL ?
• Data Lake ?
19/12/2018
What is a Microservices Architecture?
“a microservices architecture as a service-oriented architecture
composed of loosely coupled elements that have bounded
contexts. “
?
19/12/2018
But what is the difference with a Layer/Tier (Coding)
Architecture
19/12/2018
What microservices are not
• When a solutions need to be deployed complete to provide a “new
version” of a product.
• When a component failing is causing a complete system failure.
19/12/2018
Microservices is “Multi Process Applications”
19/12/2018
Common characteristics
• Componentization via Services by Domain “bounded context”.
• Organized around business capabilities.
• Decentralized Data Management.
• Infrastructure Automation.
• Design for Failure.
• Aggressive monitoring.
19/12/2018
Benefits
• Allows to create pieces of software in loosely coupled services kind.
• Allow to release features/fixes continuously (better Time To Market)
• Allows to evolve the company technology stack.
• Allows to migrate a services changing nothing if the contract does not change.
• Because MS is built with failures in mind, we are building resilience.
• Because MS is built with automation in mind, we are saving time/money in the future.
• Because MS is built with monitoring in mind, we have a better control how what is happening.
• We don’t have to marry with a technology/framework (devs engagement)
• Let us built software with business first with a service scope instead of a technical layers.
19/12/2018
There ain't no such thing as a free lunch
• Inter Process Communication.
• Async Calling by Messaging.
• Eventual Consistency.
• Duplicated data.
• Process failures.
19/12/2018
CAP Theorem
19/12/2018
19/12/2018
Microservices Architecture Is Not a Silver Bullet
• As is not just a technical decision, it require a mindset change of the
complete team including the client.
• Business boundaries need to be identified.
• Is the solution being too simply, probably MS will bring more complexity
than flexibility.
• You need to be mature with Devops. Practices.
19/12/2018
Let’s start MS with NET
19/12/2018
Structure
• DDD / CRQS Microservices
• Messaging communication between services
• Api Gateway
• Retries.
• Containers.
19/12/2018
Api Gateway
• How do the clients of a Microservices-based application access the
individual services?
19/12/2018
19/12/2018
Api Gateway
• Coupling: Without the API Gateway pattern the client apps are coupled to the
internal microservices.
• Too many round-trips: A single page/screen in the client app might require
several calls to multiple services.
• Security issues: Without a gateway, all the microservices must be exposed to
the "external world“. The smaller is the attack surface, the more secure your
application can be.
• Cross-cutting concerns: Each publicly published microservice must handle
concerns such as authorization, SSL, etc. In many situations those concerns
could be handled in a single tier so the internal microservices are simplified.
19/12/2018
Use an API Gateway
REST
Product info service
REST
Recommendation service
AMQP
Review service
API
gateway
View Controller
Model
Traditional server-side
web application
View Controller
Model
Browser/native app
Single entry
point
Client
specific API Protocol
translation
19/12/2018
Variation: Backends for frontends
Web application
Mobile app
3rd party applications
Web app
API
gateway
Mobile API
gateway
Public API
gateway
REST
Catalog service
REST
Recommendation service
gRPC
Review service
19/12/2018
Ocelot Api Gateway
• Routing
• Request Aggregation
• Service Discovery with Consul &
Eureka
• Service Fabric
• WebSockets
• Authentication
• Authorization
• Rate Limiting
• Caching
• Retry policies / QoS
• Load Balancing
• Logging / Tracing / Correlation
• Headers / Query String / Claims
Transformation
• Custom Middleware / Delegating Handlers
• Configuration / Administration REST API
• Platform / Cloud Agnostic
• Etc.
19/12/2018
Ocelot ASP.NET Core configuration.
dotnet add package Ocelot
19/12/2018
Ocelot ASP.NET Core configuration.
19/12/2018
Ocelot Load balancing.
19/12/2018
Ocelot Auth.
19/12/2018
Ocelot Rate Limits.
19/12/2018
Ocelot
• Is a code level gateway useful also to run multiple services in a single
docker container image.
19/12/2018
Options.
For others features not supported by Ocelot or a better infrastructure
throughput consider infrastructure solutions like.
• Azure Application Gateway.
• Azure Api Management.
• Others
19/12/2018
Messaging between Microservices “Breaking RPC”
• Async communication between microservices
• Event driven design
• Easy to add a sub-action for an event/command without change the
communication in the producer
19/12/2018
Messaging in Microservices
The more nodes there are, more work load Messaging will improve
performance, resilience and resources usages.
• If there is a network outage / issue with the code with an RCP call the
operations will break down and client need to execute it again.
• With RPC, threads are allocated with load, the more nodes there are
more accumulated memory you have. (Gen2 Garbage collector problem).
• Instead of using threads and memory the work going through durable
disk saved messages.
19/12/2018
19/12/2018
Using RabbitMQ
19/12/2018
Using RabbitMQ
19/12/2018
Using Messaging
Using messages we are doing workload by an async call that is not waiting for the
response of an external process (RPC).
Using other Messaging providers like Azure Service Bus we have others features
Like:
• Automatic duplicated detection.
• Transactions.
• Pub/Sub scenarios.
• Sessions / Ordered messages.
19/12/2018
CQRS + DDD
• Not all microservices need same level of complexity but for those who are
not trivial, and the business is complex enough, CQRS + DDD is the perfect
combination
• DDD let us focus on bounded context, perfect to structure our
microservices
• CQRS let us divide Command and Event models, perfect to use messaging,
rcp calls.
19/12/2018
Drive Domain Design
• Being Aligned with the business’ model, strategies, and processes.
• Being isolated from other domains and layers in the business.
• A Common Set of Terms and Definitions Used by the Entire Team
• Keeping Track Is Made Easier
• Better Code
• Agility Is a Standard
• Get a Good Software Architecture
• Stay Focused on the Solution
• Purely Flexible
19/12/2018
MediatR
Is the most popular framework to implement domain events
implementations under CQRS fashion.
19/12/2018
MediatR
MediatR acting as an internal process message broker has two kinds of
messages it dispatches:
• Request/response messages, dispatched to a single handler
• Notification messages, dispatched to multiple handlers
19/12/2018
MediatR
• Request/response messages, dispatched to a single handler
19/12/2018
MediatR
• Notification messages, dispatched to multiple handlers
19/12/2018
MediatR Installing in ASP.NET Core
dotnet add package MediatR
dotnet add package MediatR.Extensions.Microsoft.DependencyInjection
19/12/2018
That’s it start using MediatR and IRequests Handler
19/12/2018
MediatR + Messaging
Combining MediatR + Async Messaging is an excellent choise
For an Event Driven solution that works with high throughput
for high Work Load without data lost in a microservices architecture.
19/12/2018
Retry Strategy
19/12/2018
Retry Strategy
As we can deal with multiple distributed nodes things can fail and WILL fail.
Retry is an important deal to consider in a Microservices architecture.
• Retry Pattern
• Circuit Breaker
• Exponential Retry.
19/12/2018
Polly
19/12/2018
Containers
Contrary to how VMs work, with Docker we don’t need to constantly set up
clean environments in the hopes of avoiding conflicts.
With Docker, we know that there will be no conflicts. Docker guarantees that
application microservices will run in their own environments that are
completely separate from the operating system.
Docker becomes the facto technology for applications containerization.
19/12/2018
Containers
Docker allow us to configure the environment of an app an include all the OS
dependencies and configuration insolated of the OS it runs.
With docker we can run containers dependencies for our nodes (Microservices)
create the whole environment where they run.
Also configure the required software like Databases, Rabbit, otc.
There are tons of images in Docker Hub
- Rabbit
- Redis
- SQL Server
19/12/2018
Docker ASP.NET Core Configuration.
Just a file
19/12/2018
Docker Visual Studio integration.
19/12/2018
19/12/2018
Docker Benefit
• Faster start time. A Docker container starts in a matter of seconds
because a container is just an operating system process. A VM with a
complete OS can take minutes to load.
• Faster deployment. There’s no need to set up a new environment; with
Docker, web development team members only need to download a Docker
image to run it on a different server.
• Easier management and scaling of containers, as you can destroy and run
containers faster than you can destroy and run virtual machines.
• Better usage of computing resources as you can run more containers than
virtual machines on a single server.
• Support for various operating systems: you can get Docker for Windows,
Mac, Debian, and other OSs.
19/12/2018
Conclusion.
Microservices is an evolution of SOA, actually is not something new.
It’s a more aggressive solution that require the complete team ready to
implement it. Implementing MS is not just a technical decision.
19/12/2018
Conclusion.
19/12/2018
Conclusion.
You Build it, Test it, Deploy it.
19/12/2018
More Information.
https://dotnet.microsoft.com/download/thank-you/microservices-architecture-ebook
¡MUCHAS GRACIAS!
Follow me:
@deirevoledo
davidrevoledo@d-genix.com

Going MicroServices with Net

  • 1.
  • 2.
    Contamos con elapoyo de:
  • 3.
    About me ! DavidRevoledo | @deirevoledo • Working with Microsoft technologies pretty much all my career. • Speaker • .Net, AzureTrainer and Consultant. • Open Source active contributor (Azure event hub, service bus SDK’s and a Few Plugins). • Focused onAsp. NET Core / Azure • Software Architect at DGENIX 19/12/2018
  • 4.
    19/12/2018 Agenda 1. Microservices Introduction 2.Starting Microservices with .NET 3. Conclusion 4. Q&A
  • 5.
  • 6.
    19/12/2018 Microservices? Let’s start sayingis a very bad name. • Serverless ? • NoSQL ? • Data Lake ?
  • 7.
    19/12/2018 What is aMicroservices Architecture? “a microservices architecture as a service-oriented architecture composed of loosely coupled elements that have bounded contexts. “ ?
  • 8.
    19/12/2018 But what isthe difference with a Layer/Tier (Coding) Architecture
  • 9.
    19/12/2018 What microservices arenot • When a solutions need to be deployed complete to provide a “new version” of a product. • When a component failing is causing a complete system failure.
  • 10.
    19/12/2018 Microservices is “MultiProcess Applications”
  • 11.
    19/12/2018 Common characteristics • Componentizationvia Services by Domain “bounded context”. • Organized around business capabilities. • Decentralized Data Management. • Infrastructure Automation. • Design for Failure. • Aggressive monitoring.
  • 12.
    19/12/2018 Benefits • Allows tocreate pieces of software in loosely coupled services kind. • Allow to release features/fixes continuously (better Time To Market) • Allows to evolve the company technology stack. • Allows to migrate a services changing nothing if the contract does not change. • Because MS is built with failures in mind, we are building resilience. • Because MS is built with automation in mind, we are saving time/money in the future. • Because MS is built with monitoring in mind, we have a better control how what is happening. • We don’t have to marry with a technology/framework (devs engagement) • Let us built software with business first with a service scope instead of a technical layers.
  • 13.
    19/12/2018 There ain't nosuch thing as a free lunch • Inter Process Communication. • Async Calling by Messaging. • Eventual Consistency. • Duplicated data. • Process failures.
  • 14.
  • 15.
  • 16.
    19/12/2018 Microservices Architecture IsNot a Silver Bullet • As is not just a technical decision, it require a mindset change of the complete team including the client. • Business boundaries need to be identified. • Is the solution being too simply, probably MS will bring more complexity than flexibility. • You need to be mature with Devops. Practices.
  • 17.
  • 18.
    19/12/2018 Structure • DDD /CRQS Microservices • Messaging communication between services • Api Gateway • Retries. • Containers.
  • 19.
    19/12/2018 Api Gateway • Howdo the clients of a Microservices-based application access the individual services?
  • 20.
  • 21.
    19/12/2018 Api Gateway • Coupling:Without the API Gateway pattern the client apps are coupled to the internal microservices. • Too many round-trips: A single page/screen in the client app might require several calls to multiple services. • Security issues: Without a gateway, all the microservices must be exposed to the "external world“. The smaller is the attack surface, the more secure your application can be. • Cross-cutting concerns: Each publicly published microservice must handle concerns such as authorization, SSL, etc. In many situations those concerns could be handled in a single tier so the internal microservices are simplified.
  • 22.
    19/12/2018 Use an APIGateway REST Product info service REST Recommendation service AMQP Review service API gateway View Controller Model Traditional server-side web application View Controller Model Browser/native app Single entry point Client specific API Protocol translation
  • 23.
    19/12/2018 Variation: Backends forfrontends Web application Mobile app 3rd party applications Web app API gateway Mobile API gateway Public API gateway REST Catalog service REST Recommendation service gRPC Review service
  • 24.
    19/12/2018 Ocelot Api Gateway •Routing • Request Aggregation • Service Discovery with Consul & Eureka • Service Fabric • WebSockets • Authentication • Authorization • Rate Limiting • Caching • Retry policies / QoS • Load Balancing • Logging / Tracing / Correlation • Headers / Query String / Claims Transformation • Custom Middleware / Delegating Handlers • Configuration / Administration REST API • Platform / Cloud Agnostic • Etc.
  • 25.
    19/12/2018 Ocelot ASP.NET Coreconfiguration. dotnet add package Ocelot
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
    19/12/2018 Ocelot • Is acode level gateway useful also to run multiple services in a single docker container image.
  • 31.
    19/12/2018 Options. For others featuresnot supported by Ocelot or a better infrastructure throughput consider infrastructure solutions like. • Azure Application Gateway. • Azure Api Management. • Others
  • 32.
    19/12/2018 Messaging between Microservices“Breaking RPC” • Async communication between microservices • Event driven design • Easy to add a sub-action for an event/command without change the communication in the producer
  • 33.
    19/12/2018 Messaging in Microservices Themore nodes there are, more work load Messaging will improve performance, resilience and resources usages. • If there is a network outage / issue with the code with an RCP call the operations will break down and client need to execute it again. • With RPC, threads are allocated with load, the more nodes there are more accumulated memory you have. (Gen2 Garbage collector problem). • Instead of using threads and memory the work going through durable disk saved messages.
  • 34.
  • 35.
  • 36.
  • 37.
    19/12/2018 Using Messaging Using messageswe are doing workload by an async call that is not waiting for the response of an external process (RPC). Using other Messaging providers like Azure Service Bus we have others features Like: • Automatic duplicated detection. • Transactions. • Pub/Sub scenarios. • Sessions / Ordered messages.
  • 38.
    19/12/2018 CQRS + DDD •Not all microservices need same level of complexity but for those who are not trivial, and the business is complex enough, CQRS + DDD is the perfect combination • DDD let us focus on bounded context, perfect to structure our microservices • CQRS let us divide Command and Event models, perfect to use messaging, rcp calls.
  • 39.
    19/12/2018 Drive Domain Design •Being Aligned with the business’ model, strategies, and processes. • Being isolated from other domains and layers in the business. • A Common Set of Terms and Definitions Used by the Entire Team • Keeping Track Is Made Easier • Better Code • Agility Is a Standard • Get a Good Software Architecture • Stay Focused on the Solution • Purely Flexible
  • 40.
    19/12/2018 MediatR Is the mostpopular framework to implement domain events implementations under CQRS fashion.
  • 41.
    19/12/2018 MediatR MediatR acting asan internal process message broker has two kinds of messages it dispatches: • Request/response messages, dispatched to a single handler • Notification messages, dispatched to multiple handlers
  • 42.
  • 43.
    19/12/2018 MediatR • Notification messages,dispatched to multiple handlers
  • 44.
    19/12/2018 MediatR Installing inASP.NET Core dotnet add package MediatR dotnet add package MediatR.Extensions.Microsoft.DependencyInjection
  • 45.
    19/12/2018 That’s it startusing MediatR and IRequests Handler
  • 46.
    19/12/2018 MediatR + Messaging CombiningMediatR + Async Messaging is an excellent choise For an Event Driven solution that works with high throughput for high Work Load without data lost in a microservices architecture.
  • 47.
  • 48.
    19/12/2018 Retry Strategy As wecan deal with multiple distributed nodes things can fail and WILL fail. Retry is an important deal to consider in a Microservices architecture. • Retry Pattern • Circuit Breaker • Exponential Retry.
  • 49.
  • 50.
    19/12/2018 Containers Contrary to howVMs work, with Docker we don’t need to constantly set up clean environments in the hopes of avoiding conflicts. With Docker, we know that there will be no conflicts. Docker guarantees that application microservices will run in their own environments that are completely separate from the operating system. Docker becomes the facto technology for applications containerization.
  • 51.
    19/12/2018 Containers Docker allow usto configure the environment of an app an include all the OS dependencies and configuration insolated of the OS it runs. With docker we can run containers dependencies for our nodes (Microservices) create the whole environment where they run. Also configure the required software like Databases, Rabbit, otc. There are tons of images in Docker Hub - Rabbit - Redis - SQL Server
  • 52.
    19/12/2018 Docker ASP.NET CoreConfiguration. Just a file
  • 53.
  • 54.
  • 55.
    19/12/2018 Docker Benefit • Fasterstart time. A Docker container starts in a matter of seconds because a container is just an operating system process. A VM with a complete OS can take minutes to load. • Faster deployment. There’s no need to set up a new environment; with Docker, web development team members only need to download a Docker image to run it on a different server. • Easier management and scaling of containers, as you can destroy and run containers faster than you can destroy and run virtual machines. • Better usage of computing resources as you can run more containers than virtual machines on a single server. • Support for various operating systems: you can get Docker for Windows, Mac, Debian, and other OSs.
  • 56.
    19/12/2018 Conclusion. Microservices is anevolution of SOA, actually is not something new. It’s a more aggressive solution that require the complete team ready to implement it. Implementing MS is not just a technical decision.
  • 57.
  • 58.
  • 59.
  • 60.