Microservice Architecture
Beginning Microservices with .NET & RabbitMQ
Paul Mooney
@daishisystems | www.insidethecpu.com
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
Decoupled MiddlewareDispatcherReceiver
ASP.NET
ReceiverDispatcher
SimpleMathMicroservice
Input Queue
Output Queue
Message Bus
Decoupled Middleware
Microservice Daemon
Message Dispatcher
Event Listener
Microservice Daemon
Event Listener
Message Dispatcher
Service Bus
Queue #1
Queue #2
Message Message
Message Message
Circuit Breaker
Filter
CircuitBreaker
Service
Feature1Feature2Feature3
Client
Request
Circuit Breaker
Filter
CircuitBreaker
Service
Feature1Feature2Feature3
Client
requestCount < threshHold
Circuit Breaker
Filter
CircuitBreaker
Service
Feature1Feature2Feature3
Client
Request
requestCount >= threshHold
Flyball Governor
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
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
Flyball GovernorDispatcherReceiver
ASP.NET
ReceiverDispatcher
SimpleMathMicroservice
Input Queue
Output Queue
Message Bus
Flyball GovernorDispatcherReceiver
ASP.NET
Input Queue
Output Queue
Message Bus
ReceiversDispatchers
SimpleMathMicroservices 1...n
Microservices as N-Tier Applications
AMQP
AMQP
AMQP
AMQP
Browser 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
Consistent Message Delivery
SimpleMath
Microservice
Inbound Message Queue
Outbound Message Queue
Inbound Messages
Outbound Messages
1 2
3
4
5
ASP.NET App
Consistent Message Delivery
SimpleMath
Microservice
Inbound Message Queue
Inbound Messages
ASP.NET App
1 2
3
4
4
4
5
Consistent Message Delivery
SimpleMath
Microservice
Inbound Message Queue
Inbound Messages
ASP.NET App
1
3
Queue Pool
2
45
6
Queue Pool Queue
Load Balancing a RabbitMQ Cluster
Node #1 Node #2 Node #3
Load Balancer
Load Balancing a RabbitMQ Cluster
Node #1 Node #2 Node #3
Load Balancer
Client Application
1
2
3
Load Balancing a RabbitMQ Cluster
Node #1 Node #2 Node #3
Load Balancer
Client Application
NewQueue1 NewQueue2 NewQueue3
Load Balancing a RabbitMQ Cluster
Node #1 Node #2 Node #3
Client ApplicationRandomiser
Load Balancing a RabbitMQ Cluster
Node #1 Node #2 Node #3
Client Application
Monitor Service
Queue Metadata StoreRandomiser
Selling to the Business
Real-world example of how to sell Microservices to techies and non-
techies alike.
Monolithic Flow #1
I want to book a flight
Monolithic Flow #2
Here are the available flights
Monolithic Flow #3
I want to book one of those flights
Monolithic Flow #4
Would you like to hire a car?
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
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
Microservice Flow #1
Car Hire
Hotel
Flight
Taxi
User Profile
Fare Finder
Flights
Other
Microservice Flow #2
Car Hire
Hotel
Flight
Taxi
User Profile
Fare Finder
Flights
Taxis
Other
Microservice Flow #3
Car Hire
Hotel
Flight
Taxi
User Profile
Fare Finder
Flights
Taxis
Cars
Other
Microservice Flow #4
Car Hire
Hotel
Flight
Taxi
User Profile
Fare Finder
Flights
Taxis
Cars
Hotels
Other
Enhanced Flow Step #5
Car Hire
Hotel
Flight
Taxi
User Profile
Fare Finder
Flights
Taxis
Cars
Fares
Hotels
Other
Business Benefits
 Two-way communication
 We’re in control (think Google)
 APIs are always working
 Unlimited opportunities to interact
 Broader scope for ancillary revenue
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
General Advice
 Log everything
 Log everything
 Log some more
 If a framework exists, use it
 Try to avoid the technical swamp
Let’s Talk Further…
 insidethecpu.com (search for “Microservices”)
 https://github.com/daishisystems/Daishi.AMQP
 @daishisystems
 https://ie.linkedin.com/in/daishisystems
 Q&A

Beginning Microservices with .NET & RabbitMQ