37
Microservice Architecture Beginning Microservices with .NET & RabbitMQ Paul Mooney @daishisystems | www.insidethecpu.com

Beginning Microservices with .NET & RabbitMQ

Embed Size (px)

Citation preview

Page 1: Beginning Microservices with .NET & RabbitMQ

Microservice Architecture

Beginning Microservices with .NET & RabbitMQ

Paul Mooney@daishisystems | www.insidethecpu.com

Page 2: Beginning Microservices with .NET & RabbitMQ

Overview

Microservice design based on real-world examples

Focus on, but not restricted to .NET and RabbitMQ

Design Patterns

Decoupled Middleware

Circuit Breaker

Flyball Governor

Implementation Problems

Consistent Message Delivery

Load balancing a RabbitMQ Cluster

Selling to the Business

Page 3: Beginning Microservices with .NET & RabbitMQ

Decoupled MiddlewareD

isp

atch

erR

ece

iver

ASP.NET

Receiver

Disp

atch

er

SimpleMathMicroservice

Input Queue

Output Queue

Message Bus

Page 4: Beginning Microservices with .NET & RabbitMQ

Decoupled Middleware

Microservice Daemon

Message Dispatcher

Event Listener

Microservice Daemon

Event Listener

Message Dispatcher

Service Bus

Queue #1

Queue #2

Message Message

Message Message

Page 5: Beginning Microservices with .NET & RabbitMQ

Circuit Breaker

Filter

Cir

cuit

Bre

aker

Service

Fea

ture

1Featu

re 2Fe

atu

re 3

Client

Request

Page 6: Beginning Microservices with .NET & RabbitMQ

Circuit Breaker

Filter

Cir

cuit

Bre

aker

Service

Fea

ture

1Featu

re 2Fe

atu

re 3

Client

requestCount < threshHold

Page 7: Beginning Microservices with .NET & RabbitMQ

Circuit Breaker

Filter

Cir

cuit

Bre

aker

Service

Fea

ture

1Featu

re 2Fe

atu

re 3

Client

RequestrequestCount >= threshHold

Page 8: Beginning Microservices with .NET & RabbitMQ

Flyball Governor

Page 9: Beginning Microservices with .NET & RabbitMQ

Flyball Governor

Load never drops to 0% capacity

Load never rises to 100% capacity

Balance is achieved through polling

Requires detailed tuning to establish optimal setting

End result is Autoscaling through natural equilibrium

Page 10: Beginning Microservices with .NET & RabbitMQ

Flyball Governor

QueueWatch

Inbound Queue

Outbound Queue

Diagnostics Queue

Inbound Queue

Outbound Queue

Diagnostics Queue

Inbound Queue

Outbound Queue

Diagnostics Queue

1

2 2 2

Direct Exchange

3 3 3

Page 11: Beginning Microservices with .NET & RabbitMQ

Flyball GovernorD

isp

atch

erR

ece

iver

ASP.NET

Receiver

Disp

atch

er

SimpleMathMicroservice

Input Queue

Output Queue

Message Bus

Page 12: Beginning Microservices with .NET & RabbitMQ

Flyball GovernorD

isp

atc

he

rR

ecei

ver

ASP.NET

Input Queue

Output Queue

Message Bus

Receivers

Disp

atch

ers

SimpleMathMicroservices 1...n

Page 13: Beginning Microservices with .NET & RabbitMQ

Microservices as N-Tier Applications

AMQP

AMQP

AMQP

AMQPBrowser API Queue Microservice Instances

HttpRequestMapper

CommandMessageBuilder

MessageDispatcher

ResponseMessageParser

ResponseMessageConsumer CommandMessageParser

CommandMessageMapper

MessageDispatcher

ResponseMessageBuilder

ServiceCommand

2. Map HTTP Request to CommandMessage

3. Build CommandMessage

4. Dispatch CommandMessage to INPUT Queue

5. Parse and extract CommandMessage

6. Map CommandMessage to ServiceCommand

7. Execute ServiceCommand

8. Build ResponseMessage

9. Dispatch ResponseMessage to OUTPUT Queue

10. Consume ResponseMessage

11. Parse Response

SignalR

SignalR

1. Send REST HTTP Request

12. Return Response

WEB #1

APP #1

APP #2

HTTP

To downstream apps

Page 14: Beginning Microservices with .NET & RabbitMQ

Consistent Message Delivery

SimpleMath Microservice

Inbound Message Queue

Outbound Message Queue

Inbound Messages

Outbound Messages

1 2

3

4

5

ASP.NET App

Page 15: Beginning Microservices with .NET & RabbitMQ

Consistent Message Delivery

SimpleMath Microservice

Inbound Message Queue

Inbound Messages

ASP.NET App

1 2

3

4

4

4

5

Page 16: Beginning Microservices with .NET & RabbitMQ

Consistent Message Delivery

SimpleMath Microservice

Inbound Message Queue

Inbound Messages

ASP.NET App

1

3

Queue Pool

2

45

6

Queue Pool Queue

Page 17: Beginning Microservices with .NET & RabbitMQ

Load Balancing a RabbitMQ Cluster

Node #1 Node #2 Node #3

Load Balancer

Page 18: Beginning Microservices with .NET & RabbitMQ

Load Balancing a RabbitMQ Cluster

Node #1 Node #2 Node #3

Load Balancer

Client Application

1

2

3

Page 19: Beginning Microservices with .NET & RabbitMQ

Load Balancing a RabbitMQ Cluster

Node #1 Node #2 Node #3

Load Balancer

Client Application

NewQueue1 NewQueue2 NewQueue3

Page 20: Beginning Microservices with .NET & RabbitMQ

Load Balancing a RabbitMQ Cluster

Node #1 Node #2 Node #3

Client ApplicationRandomiser

Page 21: Beginning Microservices with .NET & RabbitMQ

Load Balancing a RabbitMQ Cluster

Node #1 Node #2 Node #3

Client Application

Monitor Service

Queue Metadata StoreRandomiser

Page 22: Beginning Microservices with .NET & RabbitMQ

Selling to the BusinessReal-world example of how to sell Microservices to techies and non-

techies alike.

Page 23: Beginning Microservices with .NET & RabbitMQ

Monolithic Flow #1

I want to book a flight

Page 24: Beginning Microservices with .NET & RabbitMQ

Monolithic Flow #2

Here are the available flights

Page 25: Beginning Microservices with .NET & RabbitMQ

Monolithic Flow #3

I want to book one of those flights

Page 26: Beginning Microservices with .NET & RabbitMQ

Monolithic Flow #4

Would you like to hire a car?

Page 27: Beginning Microservices with .NET & RabbitMQ

Business Drawbacks

One-way communication

Customer is in control

Website is idle when user is idle

Limited window of opportunity to interact

Reduced scope for ancillary revenue

Page 28: Beginning Microservices with .NET & RabbitMQ

Technical Drawbacks

Results in dependencies

Failure affects everything

Change is slow

Scale is expensive (minor features require unilateral scale)

Steep learning curve

Technology stack is limited to specific skillsets

Introduces legal pitfalls (PCI DSS, Compliance)

Duplicated components due to lack of explicit boundaries

Rigid – likely to break under pressure

Page 29: Beginning Microservices with .NET & RabbitMQ

Microservice Flow #1

Car Hire

Hotel

Flight

Taxi

User Profile

Fare Finder

Flights

Other

Page 30: Beginning Microservices with .NET & RabbitMQ

Microservice Flow #2

Car Hire

Hotel

Flight

Taxi

User Profile

Fare Finder

Flights

Taxis

Other

Page 31: Beginning Microservices with .NET & RabbitMQ

Microservice Flow #3

Car Hire

Hotel

Flight

Taxi

User Profile

Fare Finder

Flights

Taxis

Cars

Other

Page 32: Beginning Microservices with .NET & RabbitMQ

Microservice Flow #4

Car Hire

Hotel

Flight

Taxi

User Profile

Fare Finder

Flights

Taxis

Cars

Hotels

Other

Page 33: Beginning Microservices with .NET & RabbitMQ

Enhanced Flow Step #5

Car Hire

Hotel

Flight

Taxi

User Profile

Fare Finder

Flights

Taxis

Cars

Fares

Hotels

Other

Page 34: Beginning Microservices with .NET & RabbitMQ

Business Benefits

Two-way communication

We’re in control (think Google)

APIs are always working

Unlimited opportunities to interact

Broader scope for ancillary revenue

Page 35: Beginning Microservices with .NET & RabbitMQ

Technical Benefits

Eliminates dependencies

Failure is isolated

React to change quicker

Scale is less expensive (APIs scale individually)

More intuitive learning curve

Technology stack is not limited to specific skillsets

Shielded from legal pitfalls

Reusable components

Flexible – will bend rather than break under pressure

Page 36: Beginning Microservices with .NET & RabbitMQ

General Advice

Log everything

Log everything

Log some more

If a framework exists, use it

Try to avoid the technical swamp

Page 37: Beginning Microservices with .NET & RabbitMQ

Let’s Talk Further…

insidethecpu.com (search for “Microservices”)

https://github.com/daishisystems/Daishi.AMQP

@daishisystems

https://ie.linkedin.com/in/daishisystems

Q&A